When introduced to Hamming distance, the number of changes needed to convert one sequence into another, I wrote this simple implementation:
def HamDist(s,t): return sum([1 for i in range(len (s)) if s[i] != t[i]])
It works and is easily understood. I found this from http://code.activestate.com/recipes/499304-hamming-distance/. I'm not sure I like summing truth values.
from itertools import imap import operator def HamDist(str1, str2): return sum(imap(operator.ne, str1, str2))
I'm learning pretty quickly. There's a lot to learn. I guess once one learns the language the faster code is readable.
Knowing the Hamming distance between a set of DNA, RNA, or AA sequences is the first step to building an un-rooted tree and this is the first step towards reconstructing the most likely ancestor sequences.
No comments:
Post a Comment