Introduction to Bioinformatics

Lesson 12 of 16 · 11 min

Translating DNA into protein

In earlier lessons you saw that DNA is a long string of four letters: A, C, G, and T. Cells use that string as a set of instructions for building proteins, the tiny machines that do almost all the work inside living things. In a living cell this happens in two steps: the DNA is first copied into a related molecule called RNA, and a machine called the ribosome then reads that RNA copy to assemble the protein. That second step, reading a sequence and building the matching protein, is called translation. Because the RNA copy lines up with the DNA one position at a time, in bioinformatics we usually translate the DNA sequence directly, and that is what you will do here: first by hand, then in code.

Codons and reading frame

The sequence is read three letters at a time. Each group of three letters is called a codon, and almost every codon stands for one amino acid, which is a building block of a protein. Reading a sequence in fixed groups of three, always starting from a chosen letter, is called a reading frame.

Where you start matters: beginning at the 1st, 2nd, or 3rd letter gives three different reading frames for one strand. DNA has two strands, so once you also read the reverse complement (the matching opposite strand), there are six reading frames in total.

Open reading frames

A protein-coding stretch usually begins at the start codon ATG, which also codes for the amino acid Met, and ends at a stop codon. An open reading frame, or ORF, is exactly that: a run that starts at an ATG and continues codon by codon until it reaches the next in-frame stop codon, which is TAA, TAG, or TGA. In-frame simply means the stop lines up with the same groups of three that the ATG started.

A worked example

text
ATGGCTTAA
ATG | GCT | TAA
Met | Ala | STOP

Reading three letters at a time gives ATG, then GCT, then TAA. ATG is Met (written as M), GCT is Ala (written as A), and TAA is a stop codon, so translation ends there. The finished protein is just the letters that came before the stop: MA.

python
# A codon table maps each 3-letter codon to a one-letter amino acid.
# "*" marks a stop codon, which ends the protein.
codon_table = {
    "ATG": "M",
    "GCT": "A", "GCC": "A", "GCA": "A", "GCG": "A",
    "TTT": "F", "TTC": "F",
    "GGT": "G", "GGC": "G", "GGA": "G", "GGG": "G",
    "TAA": "*", "TAG": "*", "TGA": "*",
}

def translate(seq):
    protein = ""
    # step through the sequence 3 bases at a time
    for i in range(0, len(seq) - 2, 3):
        codon = seq[i:i + 3]
        amino_acid = codon_table[codon]
        if amino_acid == "*":   # hit a stop codon, so stop here
            break
        protein += amino_acid
    return protein

print(translate("ATGGCTTAA"))
MA

Try it yourself: In the sequence AACCATGTTTGGGTAAACGT, find the first start codon ATG, then read codons in that frame until the first stop codon. Using the codon table above, translate the ORF by hand first, then check it in Python with: seq = "AACCATGTTTGGGTAAACGT"; start = seq.find("ATG"); print(translate(seq[start:])). You should get MFG (Met-Phe-Gly).