-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmotif.py
64 lines (64 loc) · 1.33 KB
/
motif.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
"""
Algorithm description:
First make a list of all substring of first amino acid
then chose a random selected amino acid compare the
list of substring with the selected amino acid
remove the substrings which do not match
repeat above process may in a random order or not
Random amino acid is choosen because to reduce
the number of similar substring
PS:I'm not gonna apply random method because i don't know a efficent way
to chose a random number which has not been choseen already
instead it is better to apply normal method
"""
"""
sample input and outputs
>>> Rosalind_1
GATTACA
>Rosalind_2
TAGACCA
>Rosalind_3
ATACA
AC
"""
""" rm is a remove function which deletes the strings which
will not occur because a its substring is not present
"""
def motifing(index):
q=[]
global sub_strings
global l
for key in sub_strings:
if key not in l[index]:
q.append(key)
for key in q:
del sub_strings[key]
import sys
ip=sys.stdin.readlines()
s=''
l=[]
for line in ip:
if '>' in line:
if len(s)==0:
continue
else:
l.append(s)
s=''
else:
s+=line[:-1]
k=len(l)
x=l[0]
y=len(x)
sub_strings={}
for i in range(y):
for j in range(i+1,y):
sub_strings[x[i:j]]=1
for j in range(1,k):
motifing(j)
for key in sub_strings:
k=[key,len(key)]
break
for key in sub_strings:
if len(key)>k[1]:
k=[key,len(key)]
print(k[0])