Integrate bigWig files into GBrowse

Lately, I have waisted quite a lot of time trying to integrate bigWig files into GBrowse.

At first, I had problems with installation of Bio::DB::BigWig in Ubuntu 14.04 x64. I had to combine tips from several places (this was the most helpful):

wget http://hgdownload.soe.ucsc.edu/admin/exe/userApps.v310.src.tgz
tar xfz userApps.src.tgz
cd userApps/kent/src/

# in inc/common.mk replace `CFLAGS=` line with `CFLAGS=-fPIC` 

cd lib/
make
cd ..

sudo -i
export MACHTYPE=x86_64
export KENT_SRC=`pwd`
cpan Bio::DB::BigWig

Then, I have spent quite a lot of time trying to incorporate multiple bigWig files at once. This can accomplished with Bio::DB::BigWigSet. Just add this to your genome.conf:

[RibosomalRNASeq:database]
db_adaptor      = Bio::DB::BigWigSet
db_args         = -dir /path/to/your/bigWig/files
                  -feature_type summary
[All]
database        = RibosomalRNASeq
feature         = summary
glyph           = wiggle_density
height          = 15
category        = Ribosomal RNA-Seq

Note, your bigWig files should be placed in one directory and end with .bw.
Additionally, you can create meta.bw file that will define additional information about your samples.

Advertisements

BAM2bigWig conversion using pybedtools

Today I was looking for a handy way of converting BAM to bigWig. Biostars turned out to be handy place for a start. Guess what, there is ready module implemented in pybedtools that does exactly that:

from pybedtools.contrib.bigwig import bam_to_bigwig
bam_to_bigwig(bam='path/to/bam', genome='hg19', output='path/to/bigwig')

Unfortunately, my genome of interested in not hosted at UCSC, so I needed to alter bam_to_bigwig slightly. In addition, I’ve replaced the read counting function mapped_read_count with my own implementation that rely on BAM index and therefore return number of alignments nearly instantly. This reduces the time by some minutes for large BAMs.

My own bam2bigwig.py implementation can be found github repo:

bam2bigwig.py -i SOME.BAM -g GENOME.fa -o SOME.BAM.bw