0

My assignment is to:

Read the protein sequence from FILE A and calculate the molecular weight of
this protein using the dictionary created above.

So far, I have the code below:

import pprint
my_dict= {'A':'089Da', 'R':'174Da','N':'132Da','D':'133Da','B':'133Da','C':'121Da','Q':'146Da','E':'147Da',
          'Z':'147Da','G':'075Da','H':'155Da','I':'131Da','L':'131Da','K':'146Da','M':'149Da',
          'F':'165Da','P':'115Da','S':'105Da','T':'119Da','W':'204Da','Y':'181Da','V':'117Da'}
new=sorted(my_dict.items(), key=lambda x:x[1])
print("AA", "  ", "MW")
for key,value in new:
    print(key, " ", value)


with open('lysozyme.fasta','r') as content:
    fasta = content.read()
    for my_dict in fasta:

In which the top part of the code is my dictionary created. The task is to i.e open the rile and read 'MWAAAA' in the file, and then sum up the values associated with those keys using the dictionary I created. I'm not sure how to proceed after the for loop. Do I use an append function? Would appreciate any advice, thanks!

1 Answer 1

0

after read your file, you can check char by char:

for char in fasta:
    print(char)

output:

M
W
A
A
A
A

then use the char as a key for retrieve value of your dict

summ += my_dict[char]

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.