No need to ask the same question twice: pysam and samtools
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 !!
2 answers
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)
Hi, I use visual studio code for debug my python code. I have install pysam and samtools in my linux but my "import pysam" code does not run and has error. What's the problem?
Log in to answer this question.
Why not use pysam?
pysam is a python wrapper of samtools
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).
there is not easy way to install it on windows.