Replacing codons using codon table on python
Entering edit mode
3.7 years ago
kilo • 0

Hi there! I am trying to pull out a particular codon out of my DNA sequence and run it through a codon table/dictionary to get it to replace with another degenerate codon. I have managed to slice the particular codon out but I am not sure how to run it through the codon table and make it replace accordingly so that the amino acid is still the same.

Eg. I do not want UCA as my codon, hence I run it through a dictionary so that it will replace it with either UCC, UCA, UCG for the amino acid serine.

Much appreciated!

DNA Python • 2.4k views
Entering edit mode

The general recipe (with a couple hints) for this is:

  1. Change your sequence into a list of characters seq = list(seq)

  2. Fill a dictionary with the replacements that you want to do, e.g.

    repl = {"UCA": ["UCU", "UCG", "UCC"] , ... }

  3. Iterate over your sequence in substrings of 3 (=codons). Hint: the range function can take 3 parameters, one of those is step size.

  4. IF the current codon is in your replacements dictionary:

    a. choose the replacement codon (random?)

    b. use slicing to replace the current codon with one replacement codon: seq[i:i+3] = replacement

  5. Turn your sequence back into a string "".join(seq)

edit: formatting


Login before adding your answer.

Traffic: 2182 users visited in the last hour
Help About
Access RSS

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6