Wonderful, thanks for your effort! Python3 even <3
I want to create bigwigs in Python. Is there a library that can do this?
Two ways of doing it that I'd rather avoid:
Currently I use rpy2 with rtracklayer and genomicranges through bioconda. This works, but is a bit heavy on the dependencies. Example code: https://github.com/endrebak/epic/blob/256ce4974a4ca6a10a0a5cca041c12a4e7ee9eb9/epic/bigwig/create_bigwigs.py
Another option is to use the UCSC binary tools: create a bedGraph and then convert it to bigwig by bedgraphtobigwig, but this is rather slow due to IO as you need to write files twice.
2 answers
Using pyBigWig, I've created a higher-level API for this in PyRanges:
import pyranges as pr
chromsizes = pr.db.ucsc.chromosome_sizes("hg19") # getting data using mysql
gr = pr.data.chipseq() # get some test data
gr.out.bigwig("newpath/chipseq.bw", chromsizes)
More info at https://biocore-ntnu.github.io/pyranges/writing-pyranges-to-disk.html
Log in to answer this question.