comparison bowtie2bed.pl @ 11:b7f1d9f8f3bc

Uploaded
author xuebing
date Sat, 10 Mar 2012 07:59:27 -0500
parents
children
comparison
equal deleted inserted replaced
10:1558594a3c2e 11:b7f1d9f8f3bc
1 #!/usr/bin/perl
2
3 # write bowtie output to bed file
4
5 # perl bowtie2bed.pl s_5_trimmed.map outputfile 200
6 # input
7 # inputfile
8 # extension
9
10 $inputfile = $ARGV[0];
11 $extension = $ARGV[2];
12 $outputfile = $ARGV[1];#$inputfile.".extended_$extension"."bp.bed";
13
14 print "input file: $inputfile\n";
15 print "output file: $outputfile\n";
16 print "track name: $outputfile\n";
17
18 open (IN,$inputfile) or die $!;
19 open (OUT,">$outputfile") or die $!;
20
21 print OUT "track name=$outputfile itemRgb=On\n";
22
23 while(<IN>)
24 {
25 @flds = split/\t/;
26 $flds[0] =~ s/ /-/g;#substitute space to dash
27
28 if ($flds[1] eq "+")
29 {
30 print OUT join("\t",$flds[2],$flds[3],$flds[3]+$extension+length($flds[4]),$flds[0],1,$flds[1],$flds[3],$flds[3]+length($flds[4]),"255,0,0","\n");
31 }
32 else
33 {
34
35 print OUT join("\t",$flds[2],max(0,$flds[3]-$extension),$flds[3]+length($flds[4]),$flds[0],1,$flds[1],$flds[3],$flds[3]+length($flds[4]),"0,255,0","\n");
36 }
37 }
38 close(IN);
39 close(OUT);
40
41 sub max()
42 {
43 ($a,$b) = @_;
44 return $a>$b?$a:$b;
45 }