-
Notifications
You must be signed in to change notification settings - Fork 0
/
11.py
46 lines (37 loc) · 1 KB
/
11.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
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 Suffix(Pattern):
return Pattern[1:]
def Neighbors(Pattern, d):
if d == 0:
return {Pattern}
if len(Pattern) == 1:
return {'A', 'C', 'G', 'T'}
Neighborhood = set()
SuffixNeighbors = Neighbors(Suffix(Pattern), d)
# for each string Text from SuffixNeighbors:
for Text in SuffixNeighbors:
if HammingDistance(Suffix(Pattern), Text) < d:
# for each nucleotide x:
for x in 'ATCG':
# add x • Text to Neighborhood
Neighborhood.add(x+Text)
else:
# add FirstSymbol(Pattern) • Text to Neighborhood
Neighborhood.add(Pattern[0]+Text)
return Neighborhood
samp = 'CATCACGTGC'
# x = Suffix(samp)
# print(x)
# z = Neighbors('ACG', 1)
z = Neighbors(samp, 2)
print(z)
for i in list(z):
print(i)
print(len(list(z)))