-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbedLength.pl
executable file
·47 lines (41 loc) · 1.1 KB
/
bedLength.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#!/usr/bin/env perl
=hey
Author: Shijian Sky Zhang
E-mail: [email protected]
=cut
use 5.012;
use warnings;
use Getopt::Long;
use File::Basename;
use lib dirname $0;
use pm::bedParser;
use pm::gpeParser;
sub usage{
my $scriptName = basename $0;
print <<HELP;
Usage: perl $scriptName INPUT >OUTPUT
If INPUT isn't specified, input from STDIN
Option:
-h --help Print this help information
HELP
exit(-1);
}
GetOptions(
'h|help' => sub{usage()}
) || usage();
$ARGV[0] = '-' unless defined $ARGV[0];
open IN, "$ARGV[0]" or die "Can't read file ($ARGV[0]): $!";
while(<IN>){
chomp;
my ($chr, $start, $end, $name, $score, $strand, $thickStart, $thickEnd, undef, $blockCount, $sizes, $relStarts) = split "\t";
my $length;
if(defined $relStarts){
my @sizes = split ',', $sizes;
my @relStarts = split ',', $relStarts;
my ($starts, $ends) = &bedParser::getAbsLoc($start, \@sizes, \@relStarts);
$length = &gpeParser::getExonsLength($starts, $ends);
}else{
$length = $end - $start;
}
say join "\t", ($_, $length);
}