This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Is there equivalent of bgzip in Python?

Hello,

I want to use bgzip in Python and index it with tabix. I figured out tabix part with pysam.tabix_index but I don't know how to create gz file. I've tried gzip module from Python itself but pysam.tabix_index was unhappy about it.

Does anyone know how to do it?

python bgzip

2 answers

If you're already using pysam anyway, the function you are looking for is pysam.tabix_compress.

Thanks a lot for bringing that to my attention! I actually tried it before and didn't work but it totally works now. I guess it didn't work before because of other parts of my code. Thanks again!

Read and write BGZF compressed files (the GZIP variant used in BAM).

https://biopython.org/docs/1.78/api/Bio.bgzf.html

Oh I was really hoping that I wouldn't need another package just for compression but oh well. Thanks a lot!

Log in to answer this question.