I would like to convert BAM files into wiggle files for viewing in IGB and UCSC. I am aware that I can open BAM files directly in IGB and IGV, but I would really like to make smaller wiggle files for quick viewing of the data, additionally lots of the people I do analysis for prefer to upload wiggles into UCSC, so even if this isn't the best method I need to do it.
I am currently using this one liner to generate a wiggle file, with a value roughly every 10bp and with a minimum depth of 3.
samtools pileup fileName.bam | \
perl -ne '
BEGIN { print "track type=wiggle_0 name=fileName description=fileName\n" };
($c, $start, undef, $depth) = split;
if ($c ne $lastC) { print "variableStep chrom=$c\n"; };
$lastC=$c;
next unless $. % 10 ==0;
print "$start\t$depth\n" unless $depth<3;' > fileName.wig
This is based on a solution I found here. But adapted to give smaller files and a header track line. It works, and generates an 11Mb wig file from a 728M bam file, but it takes it's time about it.
Does anyone have a more elegant and perhaps faster solution?
I am getting the following error If I use the
bam_to_wiggle.py
scriptThe command I am using is:
The file
/usr/local/lib/python2.7/subprocess.py
existsYou need to have the `wigToBigWig` executable available in your PATH. The script header has a bit more documentation: https://github.com/chapmanb/bcbb/blob/796cc2a1179df6f5030212fd5e7f36540351abdb/nextgen/scripts/bam_to_wiggle.py#L23 Hope this helps get it running.
Thanks. I have downloaded the file and added to PATH but forgot to reload the current working terminal. Its working now.