-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpmotifParse.py
46 lines (40 loc) · 926 Bytes
/
pmotifParse.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 pmotifParse (motif):
'''takes a protein motif (str) and returns list with legal characters that
can be iteratet on'''
aa = ['A', 'R', 'N', 'D', 'C', 'E', 'Q', 'G', 'H', 'I', 'L', 'K', 'M', 'F',
'P', 'S', 'T', 'W', 'Y', 'V']
out = []
skip = 0
for i in range(len(motif)) :
if skip > 0 :
skip -= 1
continue
#check for is not
elif motif[i] == '{' :
exce = []
allowed = []
for s in range(len(motif[i:])) :
if motif[i+s+1] == '}' :
skip = s + 1
for a in aa:
if a in exce :
continue
else :
allowed.append(a)
out.append(allowed)
break
else :
exce.append(motif[i+s+1])
#check for is or
elif motif[i] == '[' :
allowed = []
for s in range(len(motif[i:])) :
if motif[i+s+1] == ']' :
skip = s + 1
out.append(allowed)
break
else :
allowed.append(motif[i+s+1])
else :
out.append(motif[i])
return out