-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbgTrim.pl
executable file
·52 lines (44 loc) · 1.05 KB
/
bgTrim.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
47
48
49
50
51
52
#!/bin/env perl
=hey
Author: Shijian Sky Zhang
E-mail: zhangsjsky@pku.edu.cn
=cut
use strict;
use 5.010;
use Getopt::Long;
use File::Basename;
my $chrSizeFile;
GetOptions(
's|size=s' => \$chrSizeFile,
'h|help' => sub{usage()}
) || usage();
$ARGV[0] = '-' unless defined $ARGV[0];
open IN, "$ARGV[0]" or die "Can't open $ARGV[0]: $!";
open SIZE, "$chrSizeFile" or die "Cann't open file $chrSizeFile: $!";
my %chrSizes;
while(<SIZE>){
chomp;
my ($chr, $size) = split "\t";
$chrSizes{$chr} = $size;
}
while(<IN>){
next if /^track/;
chomp;
my @fields = split "\t";
my ($chr, $start, $end) = @fields;
if($start < $chrSizes{$chr}){
$fields[2] = $chrSizes{$chr} if $end > $chrSizes{$chr};
say join "\t", @fields;
}
}
sub usage{
my $scriptName = basename $0;
print <<HELP;
Usage: perl $scriptName INPUT >OUTPUT
If INPUT isn't specified, input from STDIN
Option:
-s --size FILE Chromosome size file
-h --help Print this help information
HELP
exit(-1);
}