-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path10.py
40 lines (33 loc) · 1.36 KB
/
10.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
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
def ApproximatePatternCount(Pattern, DNA, allowedHammingDistance):
res = ApproximatePatternMatching(Pattern, DNA, allowedHammingDistance)
print(res)
print(len(res))
return len(res)
# Pattern = 'GAGG'
# DNA = 'TTTAGAGCCTTCAGAGG'
# allowedHammingDistance = 2
Pattern = 'GCCGA'
DNA = 'CTTAAAAGTAAAAACTTTTATAACGCTCTGTCAACCATACAAGTCAGAAACCTTCGTCGCCTTACTTCCGGCGTTTTAGAGCAAGGTTTGTCGTAAAGTCTGCACAGTCCGGGGGGTGTCGCAAACCAACGGAGCTCCTGCTAAAGTTTAAGCGTGCCGACCCTAGCCGGCACGAGGGTATGTGATAAGCGTGTCATAGATCTGAATCGGGTGGCAAAGTTGTAATCTGTAAGCGCGAACAATAGCAAGTCCGTTCATCTACTGTGAAACTTAACACGCAACTCCTTCGTCAAGGCGATTCCGGCACTTGACACCCCGCCATGG'
allowedHammingDistance = 3
res = ApproximatePatternCount(Pattern, DNA, allowedHammingDistance)
print(res)