I am used to gzip
/biopython
solutions when dealing with sequencing data, but now I wish to switch to more elegant pysam
. So I looked at the manual, but ran into quite bizarre troubles with the first couple of lines using my bam file
import pysam
samfile = pysam.AlignmentFile("3_Tms_1_mapped.bam", "rb")
for read in samfile.fetch('3_Tms_b3v08_scaf000159'):
print(read)
samfile.close()
returns ValueError: fetching by region is not available for SAM files
. Well, the file is bam
. I tried to google the error but the only hits I found are the lines in the source code of pysam that check if the file is bam/cram or sam, so somehow pysam
thinks that my bam is a sam. How can I convince it otherwise? I have also noticed that the manual is for python 2.7, that's maybe where the problem comes from...