DNA is source code
Molecular biology explained to people who write software. A four-letter alphabet, an interpreter called the ribosome, and the bugs we call mutations.
Four letters: A, C, G, T. With these, about three billion times over, the human genome is written. If you write code, molecular biology is surprisingly familiar.
The language
DNA is read in groups of three bases, the codons. Four letters across three positions make 4³ = 64 combinations, to encode 20 amino acids plus the stop signals. The code is redundant: several codons mean the same amino acid, like synonyms. ATG is the entry point, our main(): it is the start codon, and it encodes methionine.
The interpreter
- Transcription: RNA polymerase copies a gene into a messenger RNA (where T becomes U).
- Translation: the ribosome reads the mRNA three bases at a time and, with the help of tRNAs, adds one amino acid after another.
More than a compiler, the ribosome is an interpreter: it runs the code one instruction at a time, in real time, until it hits a stop.
The bugs
- Substitution: a single base changes. It can be silent (a synonym), missense (a different amino acid) or nonsense (a premature stop).
- Insertion or deletion: if the number of bases is not a multiple of three, it shifts the whole reading frame (frameshift). It is the biological cousin of a misalignment bug: everything after it gets read wrong.
The textbook example is sickle cell disease: in the beta-globin gene, the codon GAG becomes GTG, and the glutamate at position 6 becomes valine. One letter out of more than four hundred, and haemoglobin starts behaving differently.
In a few lines of Python
from itertools import product
BASES = "TCAG"
AMINO = "FFLLSSSSYY**CC*WLLLLPPPPHHQQRRRRIIIMTTTTNNKKSSRRVVVVAAAADDEEGGGG"
CODON = {"".join(c): a for c, a in zip(product(BASES, repeat=3), AMINO)}
def translate(dna: str) -> str:
dna = dna.upper()
start = dna.find("ATG")
if start == -1:
return ""
protein = ""
for i in range(start, len(dna) - 2, 3):
aa = CODON[dna[i:i + 3]]
if aa == "*":
break
protein += aa
return protein
hbb = "ATGGTGCATCTGACTCCTGAGGAGAAGTAA" # start of beta-globin (+ stop)
print(translate(hbb)) # MVHLTPEEK
print(translate(hbb.replace("GAG", "GTG", 1))) # MVHLTPVEK
One letter changed in the input, one letter changed in the output: the E becomes a V. On paper it is a detail; in a red blood cell it is a disease.