Skip to content

Instantly share code, notes, and snippets.

@juanfal
Created January 10, 2020 09:07
Show Gist options
  • Save juanfal/09d7fb53bd367742127e17284b9c47bf to your computer and use it in GitHub Desktop.
Save juanfal/09d7fb53bd367742127e17284b9c47bf to your computer and use it in GitHub Desktop.
Codon table in Python dict
codontab = {
'TCA': 'S', # Serina
'TCC': 'S', # Serina
'TCG': 'S', # Serina
'TCT': 'S', # Serina
'TTC': 'F', # Fenilalanina
'TTT': 'F', # Fenilalanina
'TTA': 'L', # Leucina
'TTG': 'L', # Leucina
'TAC': 'Y', # Tirosina
'TAT': 'Y', # Tirosina
'TAA': '*', # Stop
'TAG': '*', # Stop
'TGC': 'C', # Cisteina
'TGT': 'C', # Cisteina
'TGA': '*', # Stop
'TGG': 'W', # Triptofano
'CTA': 'L', # Leucina
'CTC': 'L', # Leucina
'CTG': 'L', # Leucina
'CTT': 'L', # Leucina
'CCA': 'P', # Prolina
'CCC': 'P', # Prolina
'CCG': 'P', # Prolina
'CCT': 'P', # Prolina
'CAC': 'H', # Histidina
'CAT': 'H', # Histidina
'CAA': 'Q', # Glutamina
'CAG': 'Q', # Glutamina
'CGA': 'R', # Arginina
'CGC': 'R', # Arginina
'CGG': 'R', # Arginina
'CGT': 'R', # Arginina
'ATA': 'I', # Isoleucina
'ATC': 'I', # Isoleucina
'ATT': 'I', # Isoleucina
'ATG': 'M', # Methionina
'ACA': 'T', # Treonina
'ACC': 'T', # Treonina
'ACG': 'T', # Treonina
'ACT': 'T', # Treonina
'AAC': 'N', # Asparagina
'AAT': 'N', # Asparagina
'AAA': 'K', # Lisina
'AAG': 'K', # Lisina
'AGC': 'S', # Serina
'AGT': 'S', # Serina
'AGA': 'R', # Arginina
'AGG': 'R', # Arginina
'GTA': 'V', # Valina
'GTC': 'V', # Valina
'GTG': 'V', # Valina
'GTT': 'V', # Valina
'GCA': 'A', # Alanina
'GCC': 'A', # Alanina
'GCG': 'A', # Alanina
'GCT': 'A', # Alanina
'GAC': 'D', # Acido Aspartico
'GAT': 'D', # Acido Aspartico
'GAA': 'E', # Acido Glutamico
'GAG': 'E', # Acido Glutamico
'GGA': 'G', # Glicina
'GGC': 'G', # Glicina
'GGG': 'G', # Glicina
'GGT': 'G' # Glicina
}
@mbhall88
Copy link

And the reverse table mapping amino acids to a list of codons

from collections import defaultdict

aminotab = defaultdict(list)
for codon, aa in codontab.items():
    aminotab[aa].append(codon)

The contents of the amino table

{'S': ['TCT', 'TCC', 'TCA', 'TCG', 'AGT', 'AGC'], 'L': ['TTA', 'TTG', 'CTT', 'CTC', 'CTA', 'CTG'], 'C': ['TGT', 'TGC'], 'W': ['TGG'], 'E': ['GAA', 'GAG'], 'D': ['GAT', 'GAC'], 'P': ['CCT', 'CCC', 'CCA', 'CCG'], 'V': ['GTT', 'GTC', 'GTA', 'GTG'], 'N': ['AAT', 'AAC'], 'M': ['ATG'], 'K': ['AAA', 'AAG'], 'Y': ['TAT', 'TAC'], 'I': ['ATT', 'ATC', 'ATA'], 'Q': ['CAA', 'CAG'], 'F': ['TTT', 'TTC'], 'R': ['CGT', 'CGC', 'CGA', 'CGG', 'AGA', 'AGG'], 'T': ['ACT', 'ACC', 'ACA', 'ACG'], '*': ['TAA', 'TAG', 'TGA'], 'A': ['GCT', 'GCC', 'GCA', 'GCG'], 'G': ['GGT', 'GGC', 'GGA', 'GGG'], 'H': ['CAT', 'CAC']}

@juanfal
Copy link
Author

juanfal commented Feb 18, 2022

Interesting, not only the defaultdict constructor, but the form to link a list of codons to every aa. It also could be done without resorting to that python library. In fact it returns some noise:
defaultdict(<class 'list'>, {'S': ['TCA',..

with:

aminotab = {}
for codon, aa in codontab.items():
    if aa in aminotab:
        aminotab[aa].append(codon)
    else:
        aminotab[aa] = [codon]

print(aminotab)

wich I suspect is faster, more independent (and easier to remember) and doesn't yield artefacts.

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment