Created
October 8, 2013 03:44
-
-
Save informationsea/6879152 to your computer and use it in GitHub Desktop.
Count mapped reads and unmapped reads in bam files.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import argparse | |
import pysam | |
def _main(): | |
parser = argparse.ArgumentParser(description="Count mapped reads and unmapped reads") | |
parser.add_argument('bam', nargs='+') | |
options = parser.parse_args() | |
print '\t'.join(['file', 'mapped', 'unmapped', 'total']) | |
for one in options.bam: | |
onefile = pysam.Samfile(one, 'rb') | |
print '\t'.join([str(x) for x in [one, onefile.mapped, onefile.unmapped, onefile.mapped+onefile.unmapped]]) | |
if __name__ == '__main__': | |
_main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment