Hi Santosh Anand, Thanks a lot for your reply.
If I understood your code correctly (I don't use python, sorry!), then you will calculte MD as 100 - (24 + 24 + 0 + 0 + 10 + 39) = 3
That seems right, but I'm not sure where you got the 100 from. I assume that's the aligned fragment length.
So while my code first summed the matches, you suggest summing the mismatches. I adapted my code following your suggestion:
sum([len(item) for item in re.split('[0-9^]', read.get_tag("MD"))]) / read.query_alignment_length
So now I:
- Take the MD string
- Split on every number or ^ character, retaining only the nucleotides to get the mismatches
- Sum the length of the nucleotides from the MD tag
- Divide that by the aligned read length
I asserted this code (without step 4) yields 6 in your example
sum([len(item) for item in re.split('[0-9^]', "24^A24C0A0G10^AA39")])
6
As is evident from the plots below this new calculation is definitely an improvement. The dots deviate less from the bisection, and the Pearson correlation coefficient is now 0.96. But it's not identical to the NM tag calculation, yet. I wonder if insertions are properly accounted for.




