This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Create bigwigs in python?

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.

chip-seq

2 answers

You want pyBigWig. I wrote that for bigWig IO in deepTools, since we needed faster read access than bx-python provided and wanted to get rid of UCSC tools for bigWig creation.

Wonderful, thanks for your effort! Python3 even <3

It seems like bw.addEntries would take four enormous lists if I know all the entries upfront. I guess I should chunk the data and add a 1000 entries at a time...

You can add one at a time, that works just as well.

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.