Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
53 lines (39 sloc) 1.06 KB
from collections import Counter
protein_mass={}
with open("protein_masses.txt","rU") as f:
for line in f:
x=line.split()
protein_mass[x[0]]=round(float(x[1]),6)
def mass(x):
m=0
for s in x:
m+=protein_mass[s]
return m
proteins=[]
spectrum=Counter()
with open("rosalind_prsm.txt","rU") as f:
n=int(f.readline().strip())
for i in range(n):
proteins.append(f.readline().strip())
for line in f:
p=line.strip()
spectrum[round(float(p),6)]+=1
maxn=0
for x in proteins:
answer=Counter()
S=Counter()
for i in range(1,len(x)):
m=mass(x[0:i])
S[round(m,6)]+=1
m=mass(x[i:])
S[round(m,6)]+=1
m=mass(x)
S[round(m,6)]+=1
for t in S.keys():
for u in spectrum.keys():
answer[round(u-t,6)]+=1
if answer.most_common(1)[0][1]>maxn:
maxn=answer.most_common(1)[0][1]
maxp=x
print maxn
print maxp
You can’t perform that action at this time.