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