Beginner Bioinformatics in Python — Part 4

Input: GGACCGTTGAC
GGACCGTTGAC
Output: 3
def HammingDistance(p, q):
return reduce(lambda a, b: a + b, list(map(lambda x, y: int(x != y), list(p), list(q))), 0)
def pattern_count_with_mismatch(text, pattern, mismatch_threshold):
return sum(1 for i in range(len(text) - len(pattern) + 1) if HammingDistance(text[i:i + len(pattern)], pattern) <= mismatch_threshold)

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store