annotate bowtie2bed.pl @ 11:b7f1d9f8f3bc

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