Question: Replacing codons using codon table on python
gravatar for kilo
5 weeks ago by
kilo0 wrote:

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 • 132 views
ADD COMMENTlink written 5 weeks ago by kilo0

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

ADD REPLYlink modified 5 weeks ago • written 5 weeks ago by cschu1812.5k
Please log in to add an answer.


Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 2228 users visited in the last hour