Question: Read A .Bam File With Biopython Module Bgzf Without Samtools
0
gravatar for loic.laureote
5.4 years ago by
loic.laureote10 wrote:

hi, I tried to read a .bam file, by uncompress the file with bgzf module provided by biopython but only some indexed parts are readable. I saw that the file is build by different compressed block, but how to read it with biopython ?

from Bio import SeqIO
import gzip
from Bio import bgzf
import struct
import gzip
handle = bgzf.BgzfReader("Example.bam", "r")
print handle.read(100)

Thanks for your help !!

python bam biopython • 4.4k views
ADD COMMENTlink modified 2.0 years ago by se69farahi0 • written 5.4 years ago by loic.laureote10

Why not use pysam?

ADD REPLYlink written 5.4 years ago by matted7.0k

pysam is a python wrapper of samtools

ADD REPLYlink written 5.3 years ago by loic.laureote10

Sure, but I guess I meant to ask if there's a specific reason you don't want to use samtools (even if wrapped in python).

ADD REPLYlink written 5.3 years ago by matted7.0k
1

there is not easy way to install it on windows.

ADD REPLYlink written 5.3 years ago by loic.laureote10
1
gravatar for Peter
5.3 years ago by
Peter5.7k
Scotland, UK
Peter5.7k wrote:

The current versions of Biopython do NOT include a SAM/BAM parser, just the BGZF code which handles random access to the compressed file, see: http://blastedbio.blogspot.co.uk/2011/11/bgzf-blocked-bigger-better-gzip.html

(And as noted above, try pysam https://code.google.com/p/pysam/ for a Python SAM/BAM library wrapping the samtools C API)

ADD COMMENTlink modified 5.3 years ago • written 5.3 years ago by Peter5.7k
Please log in to add an answer.

Help
Access

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 966 users visited in the last hour