Mercurial > repos > xuebing > bowtie_to_bed
diff bowtie_to_bed.pl @ 1:7cce5b64ee41 default tip
Uploaded
author | xuebing |
---|---|
date | Sat, 31 Mar 2012 22:57:16 -0400 |
parents | |
children |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bowtie_to_bed.pl Sat Mar 31 22:57:16 2012 -0400 @@ -0,0 +1,45 @@ +#!/usr/bin/perl + +# write bowtie output to bed file + +# perl bowtie2bed.pl s_5_trimmed.map outputfile 200 +# input +# inputfile +# extension + +$inputfile = $ARGV[0]; +$extension = $ARGV[2]; +$outputfile = $ARGV[1];#$inputfile.".extended_$extension"."bp.bed"; + +print "input file: $inputfile\n"; +print "output file: $outputfile\n"; +print "track name: $outputfile\n"; + +open (IN,$inputfile) or die $!; +open (OUT,">$outputfile") or die $!; + +print OUT "track name=$outputfile itemRgb=On\n"; + +while(<IN>) +{ + @flds = split/\t/; + $flds[0] =~ s/ /-/g;#substitute space to dash + + if ($flds[1] eq "+") + { + 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"); + } + else + { + + 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"); + } +} +close(IN); +close(OUT); + +sub max() +{ + ($a,$b) = @_; + return $a>$b?$a:$b; +}