Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Mass of a protein
#2
aa_mass = {
    'A': 71.03711,   'G': 57.02146,   'M': 131.04049, 'S': 87.03203,
    'C': 103.00919,  'H': 137.05891,  'N': 114.04293, 'T': 101.04768,
    'D': 115.02694,  'I': 113.08406,  'P': 97.05276,  'V': 99.06841,
    'E': 129.04259,  'K': 128.09496,  'Q': 128.05858, 'W': 186.07931,
    'F': 147.06841,  'L': 113.08406,  'R': 156.10111, 'Y': 163.06333
}

gen_id = input('Enter gen ID:')
sequence = input('Enter amino acid sewuence:')
mass=sum(aa_mass.get(aa.upper(), 0) for aa in sequence)
print(f"Protein {gen_id} has a mass of {mass:.2f} Da.") # better use f-string
if you prefer ordinary loop instead of list comprehension

mass = 0
for aa in sequence:
    mass += aa_mass.get(aa.upper(), 0)
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply


Messages In This Thread
Mass of a protein - by tfak - Mar-21-2021, 07:59 PM
RE: Mass of a protein - by buran - Mar-21-2021, 08:37 PM
RE: Mass of a protein - by tfak - Mar-22-2021, 08:11 AM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020