How to write a program in python 2.6 that decodes DNA codons?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Eric King
    New Member
    • Feb 2011
    • 1

    How to write a program in python 2.6 that decodes DNA codons?

    Hello,
    My name is Eric and I am using python version 2.6
    I am trying to write a program that decodes DNA codons. I have to prompt the user to enter a DNA sequence that is a multiple of 3 and have the program spit out the letters that each 3 letter string represents. Here's an example of what it should look like:
    Input a DNA sequence: ACTCTAGCTTTG
    ---> TLAL
    Using the DNA codon table at Wikipedia to find what proteins the 3 letters give. I am very lost on how to do this.
    Please help!
  • Rabbit
    Recognized Expert MVP
    • Jan 2007
    • 12517

    #2
    You could use a loop to loop through the string 3 characters at a time and use a switch to do the translation.

    Comment

    • bvdet
      Recognized Expert Specialist
      • Oct 2006
      • 2851

      #3
      Create a list of each triplet by iterating on the string "ACTCTAGCTT TG" Hint:
      Code:
      for i in range(0, len(seq), 3)
      Define a mapping object (dictionary) to associate each triplet with the corresponding letter.
      Code:
      {"ACT": "T", "CTA": "L", "GCT": "A", "TTG": "L"}
      Iterate on the list of triplets, mapping each triplet to the corresponding letter. Join the letters into one string.
      Code:
      "".join([mappedList])
      Alternatively, you could concatenate the letters into one string.
      Code:
      >>> result = ""
      >>> for letter in ["T", "L", "A", "L"]:
      ... 	result += letter
      ... 	
      >>> result
      'TLAL'
      >>>

      Comment

      • Zulhaj Choudhur
        New Member
        • Feb 2011
        • 1

        #4
        Hello,

        I am having difficulty writing the same program. Being new to python and programming, I do not fully understand your post. It would be great if you can give me a more specific example or show me how to start the code. Right now I am assigning each amino acid to a DNA codon and then using an if statement to print the single-leter data-base code. For example:

        Code:
        Isoleucine = ("ATT") , ("ATC") , ("ATA")
        Leucine = ("CTT") , ("CTC") , ("CTA") , ("CTG") , ("TTA") , ("TTG")
        Valine = ("GTT") , ("GTC") , ("GTA") , ("GTG")
        Phenylalanine = ("TTT") , ("TTC")
        
        while True:
            DNA = raw_input("Please enter a DNA sequence in multiples of three:")
            
            if Isoleucine:
                print "I"
            if Leucine: 
                print "L"
            if Valine:
                print "V"
            if Phenylalanine:
                print "F"

        here is the result I get

        Please enter a DNA sequence in multiples of three:ATT
        I
        L
        V
        F
        Please enter a DNA sequence in multiples of three:

        If someone can guide me in the right direction or tell me how to start that would be great.
        Last edited by bvdet; Feb 7 '11, 03:38 AM. Reason: Add code tags

        Comment

        • bvdet
          Recognized Expert Specialist
          • Oct 2006
          • 2851

          #5
          You would begin by defining the dictionary that maps a given triplet to a protein. Example:
          Code:
          tripletDict = {"ATT": "Isoleucine", "CTT": "Leucine"}
          The code I posted suggested splitting the input string into parts using slicing. The resulting list of triplets can then be mapped to the proteins in the dictionary in a for loop.
          Code:
          >>> seq = "ATTCTTATT"
          >>> [seq[i:i+3] for i in range(0, len(seq), 3)]
          ['ATT', 'CTT', 'ATT']
          >>> for triplet in [seq[i:i+3] for i in range(0, len(seq), 3)]:
          ... 	print tripletDict[triplet]
          ... 	
          Isoleucine
          Leucine
          Isoleucine
          >>>

          Comment

          Working...