Entering edit mode
8.7 years ago
sa9
▴
860
I am trying to count BAM reads with flag 83 using pysam version 0.8.3. I tried to use bitwise operation AND:
counter = 0
for read in bam:
if read.flag & 83 == 83:
counter += 1
which shows 561 reads while using samtools:
samtools view -f 83 example.bam | wc -l
shows 565 reads. There are 4 extra reads with flag 371 listed by samtools option -f
that are not captured by my pysam code.
Is this the right way to simulate option -f
in samtools?
Here is the example.bam file used for this question (260 kb)
https://www.dropbox.com/s/c35kmfktgx7c5va/example.bam
Thanks