adding values of dictionaries

Please support our Python advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Jul 2006
Posts: 34
Reputation: msaenz is an unknown quantity at this point 
Solved Threads: 0
msaenz msaenz is offline Offline
Light Poster

adding values of dictionaries

 
0
  #1
Jul 1st, 2006
Hi everyone,
I am doing a bioinformatics project and I have this code:

  1. def three2one(prot):
  2. code = {"G" : "6", "A" : "7", "L" : "1", "I" : "4",
  3. "R" : "2", "K" : "3", "M" : "5", "C" : "8",
  4. "Y" : "9", "T" : "10", "P" : "11", "S" : "12",
  5. "W" : "14", "D" : "15", "E" : "16", "N" : "17",
  6. "Q" : "18", "F" : "19", "H" : "20", "V" : "21" , "R" : "22"}
  7.  
  8. newprot = ""
  9. for aa in prot:
  10. newprot+=code.get(aa)
  11. return newprot
  12.  
  13. prot ="""FGYYHFRPTKLRQWEI"""
  14. print three2one(prot)

what I am trying to do is take a protein sequence in prot variable and have the values that are assigned to those letters in the dictionary to add them. I would really appreciate anyone's help thank you! Currently it only takes the first letter value...this is not homework this is a separate indepedant project of learning.
Last edited by msaenz; Jul 1st, 2006 at 6:03 pm.
Reply With Quote Quick reply to this message  
Join Date: Jul 2005
Posts: 1,221
Reputation: bumsfeld will become famous soon enough bumsfeld will become famous soon enough 
Solved Threads: 138
bumsfeld's Avatar
bumsfeld bumsfeld is offline Offline
Nearly a Posting Virtuoso

Re: adding values of dictionaries

 
0
  #2
Jul 2nd, 2006
I assume you want to sum numeric values. Here is slight modification, also removing return statement out of the loop:
  1. def three2one(prot):
  2. code = {"G" : "6", "A" : "7", "L" : "1", "I" : "4",
  3. "R" : "2", "K" : "3", "M" : "5", "C" : "8",
  4. "Y" : "9", "T" : "10", "P" : "11", "S" : "12",
  5. "W" : "14", "D" : "15", "E" : "16", "N" : "17",
  6. "Q" : "18", "F" : "19", "H" : "20", "V" : "21" , "R" : "22"}
  7.  
  8. newprot = 0
  9. for aa in prot:
  10. newprot += int(code.get(aa))
  11. print newprot # just for testing
  12. return newprot
  13.  
  14. prot ="""FGYYHFRPTKLRQWEI"""
  15. # split this up to make testing go better
  16. result = three2one(prot)
  17. print "result =", result
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:




Views: 2058 | Replies: 1
Thread Tools Search this Thread



Tag cloud for Python
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC