-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCyclopeptideScoringProblem.py
55 lines (51 loc) · 1.31 KB
/
CyclopeptideScoringProblem.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
table = {
'G': 57,
'A': 71,
'S': 87,
'P': 97,
'V': 99,
'T': 101,
'C': 103,
'I': 113,
'L': 113,
'N': 114,
'D': 115,
'K': 128,
'Q': 128,
'E': 129,
'M': 131,
'H': 137,
'F': 147,
'R': 156,
'Y': 163,
'W': 186,
}
def score(peptid,exSpectrum):
def cyclospectrum(peptide):
mass = lambda x: sum([table[i] for i in x])
n = len(peptide)
peptide2 = peptide + peptide[0:-1]
return list(map(int,
(sorted(
[0, mass(peptide2[0:n])] + [mass(k) for k in [peptide2[j:j + i]
for i in range(1, n)
for j in range(0, n)]]))))
teorSpectrum=cyclospectrum(peptid)
score = 0
i = 0
j = 0
while (i < len(teorSpectrum) and j < len(exSpectrum)):
if (teorSpectrum[i] == exSpectrum[j]):
i += 1
j += 1
score += 1
else:
if (teorSpectrum[i] < exSpectrum[j]):
i += 1
else:
j += 1
return score
if __name__ == "__main__":
peptid=input()
experimentalSpectrum=list(map(int, input().split(" ")))
print(score(peptid,experimentalSpectrum))