Skip to content

Instantly share code, notes, and snippets.

@wdecoster
Last active April 14, 2017 13:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wdecoster/308c31006323175bed555d159d42641a to your computer and use it in GitHub Desktop.
Save wdecoster/308c31006323175bed555d159d42641a to your computer and use it in GitHub Desktop.
import pysam
def extractNMFromBam(bam):
'''
loop over a bam file and get the edit distance to the reference genome
stored in the NM tag
scale by aligned read length
'''
samfile = pysam.AlignmentFile(bam, "rb")
return [read.get_tag("NM")/read.query_alignment_length for read in samfile.fetch()]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment