I would like to return reads with a flag of 0x02 similar to this
$ samtools view -f 0x02 in.bam 1:100-200
without using system calls in pysam (which are slower to my knowledge)
#!/usr/bin/python import pysam pos = "1:100-200" # open bam bam = pysam.AlignmentFile(bam_fh,"rb") # I would like to do something like this, syntax is not correct i imagine reads = bam.fetch(region=pos,until_eof=True) good_reads = reads.flag("0x02") print len(good_reads)
or is it impossible to subset reads using a flag in pysam without iterating. In that case I'll default to the csamtools commands.