I am writing code that modifies a 3 letter sequence at all 3 positions separately by exchanging that position with one of the following A, T, C, or G.
I have been able to create 3 lists where the initial element has either the 1st, 2nd, or 3rd position modified to one of the other 3 different letters.
I have written a dictionary that encodes each key (amino acid in this case) and it's corresponding codon sequences (which would be the elements I am modifying). .
Now, I aim to check each modified list's elements against this dictionary, and see which dict key they correspond to. I wish see if changes in the initial element change the resulting key associated with it.
I am unable to figure out how to proceed; how can I get the corresponding key for the values of my modified lists?
Here is my code so far:
thisdict = {
"Arg": ['CGT', 'CGC','CGA','CGG'],
"Phe": ['TTT','TTC'],
"Leu": ['TTA','TTG','CTT','CTC','CTA','CTG'],
"Ile": ['ATT','ATC'],
"Met": ['ATA','ATG'],
"Val": ['GTT','GTC','GTA','GTG'],
"Ser": ['TCT','TCC','TCA','TCG','AGT','AGC'],
"Pro": ['CCT,','CCC','CCA','CCG'],
"Ala": ['GCT','GCC','GCA','GCG'],
"Thr": ['ACT','ACC','ACA','ACG'],
"Tyr": ['TAT','TAC'],
"His": ['CAT','CAC'],
"Gln": ['CAA','CAG'],
"Asn": ['AAT','AAC'],
"Lys": ['AAA','AAG'],
'Asp': ['GAT','GAC'],
"Glu": ['GAA','GAG'],
"Cys": ['TGT','TGC'],
"Trp": ['TGA','TGG'],
"Gly": ['GGT','GGC','GGA','GGG'],
"end(*)":['TAA','TAG','AGA','AGG'],
}
def degenerated_sites(codon):
print(thisdict)
a_codon = list(codon)
b_codon = list(codon)
c_codon = list(codon)
nucleotides = ['A','C','T','G']
codons1=[]
codons2=[]
codons3=[]
for i in range(len(nucleotides)):
a_codon[0] = nucleotides[i]
first_site = "".join(a_codon)
codons1.append(first_site)
for i in range (len(nucleotides)):
b_codon[1] = nucleotides[i]
second_site = "".join(b_codon)
codons2.append(second_site)
for i in range (len(nucleotides)):
c_codon[2] = nucleotides[i]
third_site = "".join(c_codon)
codons3.append(third_site)
codons1.remove(codon)
codons2.remove(codon)
codons3.remove(codon)
print(codons1)
print(codons2)
print(codons3)
for key, value in thisdict.items():
for i in range(len(codons1)):
if value == codons1[i]:
print(key)
#I have encoded the 64 codons with their asssocaited amino acids in a dictionary. I have changed the codon site 1, 2, and 3 and stored them in lists. Now I am trying to check if the initial amino acid has been chagned, and determine the degeneracy of each site of the codon (0-fold if any change in causes amino acid change, 2-fold if only 2 out of 4 nucleotides cause amino acid change, and 4-fold if any change in nucleotide results in no change of amino acid)
degenerated_sites('CGT')
#I am confused why I am not getting any keys
My desired outcome is to have something like where the numbers above the codon indicate the degeneracy of that site, and extend this code for longer sequences.
004
CGT
CodePudding user response:
At the following line:
if value == codons1[i]:
It looks like you are comparing a single codon to a list of codons, so you are never getting a match.
Try instead:
if codons1[i] in value:
I tried this and it seemed to work
Ser
Cys
Gly
CodePudding user response:
You need to check if the item from the codon list is in the value of the dict, which is a list. So if codons1[i] in value
thisdict = {
"Arg": ['CGT', 'CGC','CGA','CGG'],
"Phe": ['TTT','TTC'],
"Leu": ['TTA','TTG','CTT','CTC','CTA','CTG'],
"Ile": ['ATT','ATC'],
"Met": ['ATA','ATG'],
"Val": ['GTT','GTC','GTA','GTG'],
"Ser": ['TCT','TCC','TCA','TCG','AGT','AGC'],
"Pro": ['CCT,','CCC','CCA','CCG'],
"Ala": ['GCT','GCC','GCA','GCG'],
"Thr": ['ACT','ACC','ACA','ACG'],
"Tyr": ['TAT','TAC'],
"His": ['CAT','CAC'],
"Gln": ['CAA','CAG'],
"Asn": ['AAT','AAC'],
"Lys": ['AAA','AAG'],
'Asp': ['GAT','GAC'],
"Glu": ['GAA','GAG'],
"Cys": ['TGT','TGC'],
"Trp": ['TGA','TGG'],
"Gly": ['GGT','GGC','GGA','GGG'],
"end(*)":['TAA','TAG','AGA','AGG'],
}
def degenerated_sites(codon):
# print(thisdict)
a_codon = list(codon)
b_codon = list(codon)
c_codon = list(codon)
nucleotides = ['A','C','T','G']
codons1=[]
codons2=[]
codons3=[]
for i in range(len(nucleotides)):
a_codon[0] = nucleotides[i]
first_site = "".join(a_codon)
codons1.append(first_site)
for i in range (len(nucleotides)):
b_codon[1] = nucleotides[i]
second_site = "".join(b_codon)
codons2.append(second_site)
for i in range (len(nucleotides)):
c_codon[2] = nucleotides[i]
third_site = "".join(c_codon)
codons3.append(third_site)
codons1.remove(codon)
codons2.remove(codon)
codons3.remove(codon)
for key, value in thisdict.items():
for i in range(len(codons1)):
if codons1[i] in value: # this is the magic line
print("key found!!!!", end=" ")
print(key)
degenerated_sites('CGT')
