Last active
April 14, 2017 13:07
-
-
Save wdecoster/308c31006323175bed555d159d42641a to your computer and use it in GitHub Desktop.
This file contains 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
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