annotate tools/mytools/bowtie2bed.pl @ 2:c2a356708570

Uploaded
author xuebing
date Fri, 09 Mar 2012 19:45:42 -0500
parents 9071e359b9a3
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
1 #!/usr/bin/perl
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
2
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
3 # write bowtie output to bed file
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
4
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
5 # perl bowtie2bed.pl s_5_trimmed.map outputfile 200
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
6 # input
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
7 # inputfile
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
8 # extension
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
9
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
10 $inputfile = $ARGV[0];
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
11 $extension = $ARGV[2];
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
12 $outputfile = $ARGV[1];#$inputfile.".extended_$extension"."bp.bed";
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
13
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
14 print "input file: $inputfile\n";
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
15 print "output file: $outputfile\n";
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
16 print "track name: $outputfile\n";
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
17
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
18 open (IN,$inputfile) or die $!;
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
19 open (OUT,">$outputfile") or die $!;
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
20
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
21 print OUT "track name=$outputfile itemRgb=On\n";
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
22
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
23 while(<IN>)
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
24 {
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
25 @flds = split/\t/;
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
26 $flds[0] =~ s/ /-/g;#substitute space to dash
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
27
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
28 if ($flds[1] eq "+")
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
29 {
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
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");
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
31 }
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
32 else
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
33 {
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
34
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
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");
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
36 }
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
37 }
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
38 close(IN);
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
39 close(OUT);
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
40
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
41 sub max()
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
42 {
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
43 ($a,$b) = @_;
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
44 return $a>$b?$a:$b;
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
45 }