annotate bowtie_to_bed.pl @ 1:7cce5b64ee41 default tip

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