Skip to content

Instantly share code, notes, and snippets.

@nickloman
Created June 10, 2014 15:56
Show Gist options
  • Save nickloman/f48cdff87e846b677d50 to your computer and use it in GitHub Desktop.
Save nickloman/f48cdff87e846b677d50 to your computer and use it in GitHub Desktop.
mapping_stats.py - for BLASR SAM output, requires Pysam
import pysam
import sys
samfile = pysam.Samfile(sys.argv[1], "rb")
fields = ['Name', 'QueryLen', 'AlignLen', 'NumMismatches']
print "\t".join(fields)
for read in samfile:
t = dict(read.tags)
results = []
results.append(read.qname.ljust(25))
results.append(t['XQ'])
results.append(t['XL'])
results.append(t['NM'])
print "\t".join([str(r) for r in results])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment