-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmotif_search.py
82 lines (73 loc) · 1.17 KB
/
motif_search.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
def search(pat, text):
m=len(pat)
n=len(text)
i=0
l=[]
while i<n-m:
j=0
k=i
while j<m and text[k]==pat[j]:
j+=1
k+=1
if j==m:
l.append(i)
i+=1
print(l)
search('AABA','AABAACAADAABAAABAA')
def search_unexact(pat, text):
m=len(pat)
n=len(text)
i=0
l=[]
while i<n-m:
j=0
k=i
b=False
while j<m and text[k]==pat[j]:
j+=1
k+=1
if b==False:
if j!=m and text[k]!=pat[j]:
if text[k+1]==pat[j+1]:
j+=1
k+=1
b=True
if j==m:
l.append(i)
i+=1
print(l)
def search_unexact2(pat, text):
m=len(pat)
n=len(text)
i=0
l=[]
dico={}
motifs_trouvés=[]
while i<n-m:
j=0
k=i
while j<m:
j+=1
k+=1
motifs_trouvés.append(text[k-1])
dico[i]=''.join(motifs_trouvés)
motifs_trouvés=[]
i+=1
li=[]
for i in dico:
li.append(dico[i])
tmp=0
leng=len(li)
for i in range(0,leng-1):
tmp=li[i]
fn_rec(tmp, pat)
def fn_rec(chaine, pat):
tmp=0
for i in range(len(chaine)):
if chaine[i]==pat[i]:
tmp+=1
if tmp>=3:
print(chaine, tmp)
else:
print(-1)
search_unexact2('AABA','AABBAACAACACAABAAABAA')