1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
|
# cython: language_level=3
from pysam.libcalignmentfile cimport AlignmentFile, AlignedSegment
from pysam.libcalignmentfile cimport BAM_FPROPER_PAIR, BAM_FPAIRED
from pysam.libcalignedsegment cimport pysam_get_flag
def count(AlignmentFile samfile):
cdef int is_proper = 0
cdef int is_paired = 0
cdef AlignedSegment read
cdef int f
for read in samfile:
f = pysam_get_flag(read._delegate)
if f & BAM_FPAIRED:
is_paired += 1
if f & BAM_FPROPER_PAIR:
is_proper += 1
return is_paired, is_proper
|