Bioinformatics Algorithms
Hidden Matches
Back to Index
This example find all the near matches within Hamming distance d
of a pattern in a sequence.
Experiment with different value for p, s, and d. Keep in mind that p should
be significantly shorter than s and that d should be smaller than p.
#!/usr/bin/python
p="GAGG"
s="TTTAGAGCCTTCAGAGG"
d=2
matches=[]
m = ""
for i in range(0,len(s)-len(p)+1):
segment=s[i:i+len(p)]
score=0
for n in range(0,len(p)):
if p[n] != segment[n]:
score = score + 1
if score<=d:
matches.append(i)
m = m + "^"
else:
m = m + "."
print p
print s
print m
print len(matches)
print matches
Main Index