forked from TatyanaV/Genome_Sequencing_Bioinformatics_II
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path20.LinearScore.py
48 lines (37 loc) · 1.4 KB
/
20.LinearScore.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
'''
'''
masses = {'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 linearSpectrum(peptide):
prefixMass = [0]
for i in range(0, len(peptide) - 1):
prefixMass.append(prefixMass[i] + masses[peptide[i]])
prefixMass.append(prefixMass[-1] + masses[peptide[-1]])
spectrum = [0]
for i in range(len(peptide) + 1):
for j in range(i + 1, len(peptide) + 1):
spectrum.append(prefixMass[j] - prefixMass[i])
return sorted(spectrum)
def countOccurrances(item, list):
count = 0
for i in list:
if i == item:
count += 1
return count
def score(spectrum, masses):
done = set([])
count = 0
for mass in spectrum:
if mass not in done and mass in masses:
occurrances = countOccurrances(mass, spectrum)
occurrancesPeptide = countOccurrances(mass, masses)
count += min(occurrances, occurrancesPeptide)
for i in range(occurrances):
done.add(mass)
return count
def linearScore(peptide, spectrum):
linear_spectrum = linearSpectrum(peptide)
return score(spectrum, linear_spectrum)
peptide = 'NQEL'
spectrum = [0, 99, 113, 114, 128, 227, 257, 299, 355, 356, 370, 371, 484]
print (linearScore(peptide, spectrum))