-
Notifications
You must be signed in to change notification settings - Fork 0
/
9.py
49 lines (38 loc) · 1.11 KB
/
9.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
with open('data9.txt', 'r') as file:
DNA9 = file.read().rstrip()
def HammingDistance(a, b):
a = a.lower()
b = b.lower()
hd = 0
for i in range(len(a)):
if a[i] != b[i]:
hd += 1
return(hd)
def ApproximatePatternMatching(Pattern, DNA, allowedHammingDistance):
pos = []
for i in range((len(DNA)+1)-len(Pattern)):
kmer = DNA[i:i+len(Pattern)]
# print(kmer)
hammingDistance = HammingDistance(Pattern, kmer)
if hammingDistance <= allowedHammingDistance:
print(f"K-mer: {kmer} => Hamming Distance = {hammingDistance}")
pos.append(i)
return pos
# Pattern = 'ATTCTGGA'
# DNA = 'CGCCCGAATCCAGAACGCATTCCCATATTTCGGGACCACTGGCCTCCACGGTACGGACGTCAATCAAAT'
# allowedHammingDistance = 3
# Pattern = 'GGGGTTCTCCA'
# DNA = DNA9
# allowedHammingDistance = 4
Pattern = 'AAAAA'
DNA = 'AACAAGCTGATAAACATTTAAAGAG'
allowedHammingDistance = 2
res = ApproximatePatternMatching(Pattern, DNA, allowedHammingDistance)
print(res)
df=open('out9.txt','w')
for i in res:
df.write(str(i))
df.write('\n')
print(i)
df.close()
# print(len(DNA9))