1 |
#!/usr/bin/perl |
2 |
use strict; |
3 |
use Getopt::Std; |
4 |
use FindBin;use lib $FindBin::Bin; |
5 |
|
6 |
my $usage = q/Usage: |
7 |
bowtie_rangeflt.pl <chr>[<strand>]:<start_coord>-<end_coord> bowtie_map_data.. |
8 |
|
9 |
Show only those bowtie mappings found in the specified genomic region. |
10 |
/; |
11 |
umask 0002; |
12 |
getopts('o:') || die($usage."\n"); |
13 |
my $outfile=$Getopt::Std::opt_o; |
14 |
die($usage."\n") unless $ARGV[0]; |
15 |
my $range=shift(@ARGV); |
16 |
my ($chr, $start_coord, $end_coord)= |
17 |
($range=~m/^([^\:]+)\:(\d+)[\.\-]+(\d+)/); |
18 |
die("$usage\n") unless $start_coord>=1 && $end_coord>$start_coord; |
19 |
my $strand=$1 if ($chr=~s/([\-\+])$//); |
20 |
if ($outfile) { |
21 |
open(OUTF, '>'.$outfile) || die("Error creating output file $outfile\n"); |
22 |
select(OUTF); |
23 |
} |
24 |
while (<>) { |
25 |
my $line=$_; |
26 |
chomp; |
27 |
my @t=split(/\t/); |
28 |
my $mlen=length($t[4]); |
29 |
next if $strand && $strand ne $t[1]; |
30 |
next if $chr && $chr ne $t[2]; |
31 |
next if ($start_coord && $t[3]+$mlen<$start_coord); |
32 |
next if ($end_coord && $t[3]>=$end_coord); |
33 |
print $line; |
34 |
} |
35 |
# -- |
36 |
if ($outfile) { |
37 |
select(STDOUT); |
38 |
close(OUTF); |
39 |
} |
40 |
|
41 |
#************ Subroutines ************** |