The Genetic Code

genetic_code() returns the standard nuclear genetic code (NCBI translation table 1) as a joint Distribution over a codon and the amino acid it codes for, with the 64 codons drawn uniformly.

The map is deterministic but many-to-one, which makes it a compact example of a lossy channel built from real biology rather than construction: \(H[\mathrm{Codon}] = 6\) bits exactly, while \(H[\mathrm{AminoAcid}] \approx 4.2181\) bits, so translation erases \(H[\mathrm{Codon} \mid \mathrm{AminoAcid}] \approx 1.7819\) bits – the average size of a synonymous codon family. Because the map is deterministic, the mutual information equals the amino-acid entropy. See [Cri68] and [Yoc05] for the biological and information-theoretic background.

In [1]: from dit.example_dists import genetic_code

In [2]: d = genetic_code()

In [3]: dit.shannon.entropy(d.marginal('Codon'))
Out[3]: 6.0

In [4]: dit.shannon.entropy(d.marginal('AminoAcid'))
Out[4]: 4.218139062229566

In [5]: dit.shannon.conditional_entropy(d, ['Codon'], ['AminoAcid'])
Out[5]: 1.7818609377704338

Passing rna=True swaps thymine for uracil. Passing bases=True expands the codon into three nucleotide random variables Base1, Base2, Base3, which exposes the “wobble” asymmetry: the third codon position carries far less information about the amino acid than the first two, so third-position mutations are frequently silent.

In [6]: from dit.multivariate import coinformation as I

In [7]: b = genetic_code(bases=True)

In [8]: [I(b, [[f'Base{i}'], ['AminoAcid']]) for i in (1, 2, 3)]
Out[8]: [1.7417292966721742, 1.8708646483360871, 0.43688906222956625]

APIs

genetic_code(rna=False, bases=False)[source]

The joint distribution of codons and the amino acids they code for.

Codons are drawn uniformly from the 64 nucleotide triplets, and each codon is mapped to its amino acid (or Stop) by the standard nuclear genetic code. The map is deterministic, so conditioning on the full codon (or on all three bases) leaves no residual amino-acid uncertainty, and the mutual information equals the amino-acid entropy (\(H(\mathrm{AminoAcid}) \approx 4.22\) bits).

By default the two random variables are, in order:

  • Codon – one of the 64 triplets (e.g. ATG or AUG).

  • AminoAcid – one of 20 amino acids (three-letter names) or Stop.

With bases=True the codon is expanded into its three nucleotide positions, yielding:

  • Base1, Base2, Base3 – the first, second, and third bases.

  • AminoAcid – as above.

The per-base form makes the classic “wobble” asymmetry visible: the third position carries far less information about the amino acid than the first two.

Parameters:
  • rna (bool) – If False (default), codons use the DNA alphabet {T, C, A, G}. If True, thymine is replaced by uracil and codons use the RNA alphabet {U, C, A, G}.

  • bases (bool) – If False (default), return the joint over (Codon, AminoAcid). If True, expand each codon into three base random variables and return the joint over (Base1, Base2, Base3, AminoAcid).

Returns:

d – The joint distribution over (Codon, AminoAcid), or over (Base1, Base2, Base3, AminoAcid) when bases=True.

Return type:

Distribution