File: python_flagstat.py

package info (click to toggle)
python-pysam 0.10.0%2Bds-2
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 14,196 kB
  • ctags: 10,087
  • sloc: ansic: 79,627; python: 8,569; sh: 282; makefile: 215; perl: 41
file content (23 lines) | stat: -rw-r--r-- 622 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
"""compute number of reads/alignments from BAM file
===================================================

This is a benchmarking utility script with limited functionality.

Compute simple flag stats on a BAM-file using
the pysam python interface.
"""

import sys
import pysam

assert len(sys.argv) == 2, "USAGE: {} filename.bam".format(sys.argv[0])

is_paired = 0
is_proper = 0

for read in pysam.AlignmentFile(sys.argv[1], "rb"):
    is_paired += read.is_paired
    is_proper += read.is_proper_pair

print ("there are alignments of %i paired reads" % is_paired)
print ("there are %i proper paired alignments" % is_proper)