Read A .Bam File With Biopython Module Bgzf Without Samtools
2
1
Entering edit mode
8.9 years ago

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

bam biopython python • 6.8k views
ADD COMMENT
0
Entering edit mode

Why not use pysam?

ADD REPLY
0
Entering edit mode

pysam is a python wrapper of samtools

ADD REPLY
0
Entering edit mode

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 REPLY
1
Entering edit mode

there is not easy way to install it on windows.

ADD REPLY
1
Entering edit mode
8.9 years ago
Peter 6.0k

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 COMMENT

Login before adding your answer.

Traffic: 1063 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