Entering edit mode
4.3 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!
The general recipe (with a couple hints) for this is:
Change your sequence into a list of characters
seq = list(seq)
Fill a dictionary with the replacements that you want to do, e.g.
repl = {"UCA": ["UCU", "UCG", "UCC"] , ... }
Iterate over your sequence in substrings of 3 (=codons). Hint: the
range
function can take 3 parameters, one of those is step size.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
Turn your sequence back into a string
"".join(seq)
edit: formatting