Create bigwigs in python?
2
2
Entering edit mode
8.2 years ago
endrebak ▴ 970

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 • 5.3k views
ADD COMMENT
4
Entering edit mode
8.2 years ago

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.

ADD COMMENT
0
Entering edit mode

Wonderful, thanks for your effort! Python3 even <3

ADD REPLY
0
Entering edit mode

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...

ADD REPLY
0
Entering edit mode

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

ADD REPLY
0
Entering edit mode
5.6 years ago
endrebak ▴ 970

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

ADD COMMENT

Login before adding your answer.

Traffic: 1669 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6