[bio-tips] genomeCoverageBed: BAM2Wig
Last post introduced the basic usage of genomeCoverageBed. Here is some update to deal with BAM2WIG processing.
As the default output of genomeCoverageBed is formatted as following:
chr start depth
However, WIG file format is different. The chromosome information is recorded in the header line:
variableStep chrom=chr1 span=1
Thus needed information exact work should be done.
Here I share with you my homemade Perl script that manages to help you out.
#!/usr/bin/perl -w
my ($in, $out) = @ARGV;
die $! && <DATA> unless (@ARGV ==2);
open IN, $in;
open OUT, ">$out";
print OUT "track type=wiggle_0 name="NAME" color=250,100,100 visibility=full autoScale=off viewLimits=0.0:99.0 yLineOnOff=off priority=10\n";
my $tmp = "NA";
while ( <IN> ) {
chomp;
my ($chr, $start, $v) = (split /\t/, $_)[0,1,2];
my $tag = 0;
$tag = 1 if ($tmp eq $chr);
if ($tag == 1 ){
print OUT "$start\t$v\n";
}
elsif ($tag == 0){
$tmp = $chr;
print OUT "variableStep chrom=$chr span=1\n";
print OUT "$start\t$v\n";
}
}
== End && reference
== afters
thx god and thx girlfriend
浙公网安备 33010602011771号