CODE CHALLENGE: Implement LinearSpectrum.
Input: An amino acid string Peptide.
Output: The linear spectrum of Peptide.
def spectrum(Peptide):
linear_spec = []
mass = []
mass.append(0)
linear_spec.append(0)
f = open('aa_mass.txt')
lines = f.readlines()
for i in range(0, len(Peptide)):
for line in lines:
if line[0] == Peptide[i]:
#print (int(line[2:int(len(line))]))
mass.append(int(mass[i]) + int(line[2:int(len(line))]))
mass.sort()
#print (mass)
for i in range(0, len(mass)-1):
for j in range(i+1, len(mass)):
#print()
#print (mass[j] - mass[i])
linear_spec.append(mass[j]-mass[i])
f.close()
linear_spec.sort()
for i in range(len(linear_spec)):
linear_spec[i] = str(linear_spec[i])
return " ".join(linear_spec)
print (spectrum("NQEL"))
Легко)) всего то два дня по часу.. и correct!
Input: An amino acid string Peptide.
Output: The linear spectrum of Peptide.
Sample Input:
NQEL
Sample Output:
0 113 114 128 129 242 242 257 370 371 484
def spectrum(Peptide):
linear_spec = []
mass = []
mass.append(0)
linear_spec.append(0)
f = open('aa_mass.txt')
lines = f.readlines()
for i in range(0, len(Peptide)):
for line in lines:
if line[0] == Peptide[i]:
#print (int(line[2:int(len(line))]))
mass.append(int(mass[i]) + int(line[2:int(len(line))]))
mass.sort()
#print (mass)
for i in range(0, len(mass)-1):
for j in range(i+1, len(mass)):
#print()
#print (mass[j] - mass[i])
linear_spec.append(mass[j]-mass[i])
f.close()
linear_spec.sort()
for i in range(len(linear_spec)):
linear_spec[i] = str(linear_spec[i])
return " ".join(linear_spec)
print (spectrum("NQEL"))
Легко)) всего то два дня по часу.. и correct!
Немає коментарів:
Дописати коментар