Skip to content

Instantly share code, notes, and snippets.

@wdecoster
Last active April 14, 2017 12:52
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/5f1c10401b1d567a2fd132deb90b80cd to your computer and use it in GitHub Desktop.
Save wdecoster/5f1c10401b1d567a2fd132deb90b80cd to your computer and use it in GitHub Desktop.
import sys
import re
import pysam
def extractDisagreement(bam):
samfile = pysam.AlignmentFile(bam, "rb")
for read in samfile.fetch():
NMdef = read.get_tag("NM")/read.query_alignment_length
MDdef = sum([len(item) for item in re.split('[0-9^]', read.get_tag("MD"))])/read.query_alignment_length
if NMdef - MDdef > 0.2:
print('\t'.join(
[
str(read.get_tag("NM")),
str(sum([len(item) for item in re.split('[0-9^]', read.get_tag("MD"))])),
read.get_tag("MD"),
read.cigarstring,
])
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment