Lesson 1 of 9
Module 7 · From genes to function
A genome arrives as unlabelled letters. Learn how open reading frames, gene-finding programs and outside evidence turn it into a list of genes, and why genes with introns are so much harder to find.
From a string of letters to a list of genes
Module 6 took you from raw reads to an assembled genome, judged it for contiguity and completeness, and gave a first count of the genes it seems to hold. A count is only a start: it says how many genes there might be, not what any of them do. This module turns that list of positions into biology, step by step, beginning with the question of how the genes were found in the first place.
A newly assembled genome (Module 6) is millions of letters long, and none of them come labelled. Before anyone can ask what an organism can do, someone has to find where its genes are. That job is called gene prediction, or gene finding. Adding names, functions and other notes to each predicted gene is called annotation. The result is the GFF file and the feature table of a GenBank record that you met in File formats you will meet: FASTA, GenBank, GFF, VCF, PDB.
In Genes on your assembly: a first count, and is it complete? you counted the long ORFs on your own assembly with a short script and checked that the genome was complete. This lesson explains what was going on underneath: how reading frames work, how real gene finders choose between candidates, why plant and animal genes are much harder, and how an annotation pipeline turns predictions into named genes.
This module follows the path from gene to function: where the genes are (this lesson), what their proteins are made of (Protein families, domains and motifs), how those proteins fold (Protein structure: from sequence to fold), and what groups of genes do together (Pathways and enrichment analysis).
The code in this lesson needs Biopython. In your Colab notebook, run !pip install biopython in the first cell, as in Module 4.
Reading frames and open reading frames
The genetic code is read in codons, groups of three bases, and each codon stands for one amino acid or for "stop". A stretch of DNA can be cut into codons in three ways, depending on whether you start at the first, second or third base. Each way is a reading frame. DNA has two strands, and genes can sit on either, so you also read the reverse complement: the other strand, read in its own 5′ to 3′ direction. Three frames on each strand gives six frames in total.
Why look at all six? Because nothing in the DNA says which frame or strand a gene uses. In a bacterial genome, genes sit on both strands in roughly similar numbers, and neighbouring genes often use different frames. Reading only the + strand in frame 1 would miss most of them. Shifting by one base changes every codon after it: ATG GCT GAA reads as M A E, but the same letters shifted by one, TGG CTG AA…, read as W L and so on. This is also why a single inserted or deleted base inside a gene, a frameshift, usually ruins the protein from that point on.
An open reading frame (ORF) is a run of codons that starts with a start codon, usually ATG (which codes for methionine, M), and continues without interruption until a stop codon: TAA, TAG or TGA. "Open" means no stop gets in the way. Every protein-coding gene contains an ORF, but not every ORF is a gene. That difference is the whole problem of gene prediction.
The reverse is also worth knowing: an ORF can be real sequence that is never made into protein. Long ORFs turn up inside introns, inside transposons and on the opposite strand of real genes, where the reverse complement of a coding sequence happens to lack stops for a long way. A gene finder has to tell these apart from true genes, and it cannot do that from start and stop codons alone.
How to read this figure
The dark bar in the middle is the DNA. The three bars above it are the three ways of cutting the + strand into codons, read left to right. The three bars below are the same for the other strand, which runs the opposite way, so they are read right to left. The shaded arrows are ORFs and point in the direction of reading. Notice that an ORF on the − strand is still described with + strand positions; that is how GFF files and genome browsers do it, with a separate column for the strand.
Finding ORFs in code
The sequence below was made up for teaching, so you can see every frame at once. First, translate all six frames.
from Bio.Seq import Seq
# A short DNA sequence, made up for teaching
dna = Seq("CCATGGCTGAAATTCGTAAACTGGGTCATTGGTAAAGCTTCAATCCGGGTAAAACAGAACTTTGGTAGACATTTAG")
print(len(dna), "bases")
for strand, s in [("+", dna), ("-", dna.reverse_complement())]:
for frame in range(3):
piece = s[frame:]
piece = piece[: len(piece) // 3 * 3] # whole codons only
print(f"{strand}{frame + 1}", piece.translate())What this does
Seq(...)makes a Biopython sequence object, which knows how to translate and reverse-complement itself.- The outer loop runs twice: once for the + strand and once for
dna.reverse_complement(), the − strand. s[frame:]drops 0, 1 or 2 bases from the start, giving the three frames.len(piece) // 3 * 3rounds the length down to a whole number of codons, so Biopython does not warn about a leftover partial codon.piece.translate()turns each codon into a one-letter amino acid code. A stop codon becomes*.
Reading the output
The first line confirms the length: 76 bases. Each line after it is one frame. Frame +1 has no stop at all, but it also has no M, so it holds no ORF. Frame +3 begins MAEIRKLGHW*: a start, ten amino acids and a stop. Frame −2 holds MSTKVLFYPD*. Frame −1 ends in M with no stop after it, because the sequence runs out; in a real genome, that ORF might continue beyond what we have.
Now search each frame for runs that start with M and end at the first stop, and keep only those at least 8 amino acids long.
import re
min_aa = 8 # shortest ORF to report
for strand, s in [("+", dna), ("-", dna.reverse_complement())]:
for frame in range(3):
piece = s[frame:]
protein = str(piece[: len(piece) // 3 * 3].translate())
for m in re.finditer(r"M[^*]*\*", protein): # M ... first stop
aa = len(m.group()) - 1 # leave out the stop
if aa < min_aa:
continue
start = frame + m.start() * 3 # 0-based, on this strand
end = frame + m.end() * 3
if strand == "-": # convert to + strand
start, end = len(dna) - end, len(dna) - start
print(f"{strand}{frame + 1} bases {start + 1}-{end} {aa} aa {m.group()}")What this does
min_aa = 8sets the shortest ORF worth reporting. Real tools use much longer cut-offs; the worked example below explains why.re.finditer(r"M[^*]*\*", protein)is a regular expression, a search pattern for text. It means: an M, then any number of characters that are not a stop, then a stop. Each match is one ORF, from its first M to its stop.m.start() * 3converts a position in the protein back to a position in the DNA, because each amino acid is three bases. Addingframeaccounts for the bases skipped at the start.- For the − strand,
len(dna) - endandlen(dna) - startflip the positions back onto the + strand. The final+ 1in the print turns Python's counting from 0 into the usual counting from 1.
Reading the output
Two ORFs pass the cut-off. The first lies on the + strand in frame 3, from base 3 to base 35: 33 bases, which is 10 codons plus one stop codon. The second lies on the − strand, from base 40 to base 72 in + strand positions, and is also 10 amino acids long. The short fragments seen in other frames, such as NS* in frame +2, either lack an M or are too short. This is roughly what the NCBI ORFfinder web tool does for you, with more options.
A common pitfall is the way positions are counted. Python counts from 0 and its slices leave out the end position, while GFF files and genome browsers count from 1 and include both ends. The code handles this with the + 1 in the print, so the first ORF is reported as bases 3 to 35, exactly as a browser would show it. When you compare your own coordinates with a GFF file and they differ by one, this is almost always the reason.
Worked example · how long an ORF can arise by chance
Why not report every ORF longer than 8 codons? Because random DNA is full of them. Assume, for simplicity, that all 64 codons are equally likely.
average run before a stop ≈ 64 ÷ 3 ≈ 21 codons
chance of 100 codons with no stop = (61/64)100 ≈ 0.008
Step by step. In random sequence, each codon has a 3 in 64 chance of being a stop, so on average a stop turns up about every 21 codons. The chance that a codon is not a stop is 61/64, about 0.953. For 100 codons in a row to be stop-free, that must happen 100 times, so multiply 0.953 by itself 100 times: about 0.008, or 1 in 120. A genome of a few million bases, read in six frames, offers many thousands of starting points, so even 100-codon ORFs will turn up by chance, though far less often than short ones.
What the answer means. Short ORFs are almost all noise, which is why ORF finders set a minimum length, often 75 or 100 codons. Length alone is still not proof: a long ORF can be chance, and a real gene can be short. Better gene finders add more evidence, as the next section explains.
Two ways to predict genes
Ab initio prediction (Latin for "from the beginning") uses only the genome sequence itself. The program learns what genes in this organism look like: their codon usage, the signals around start codons, and in eukaryotes the signals at the edges of introns. It then scans the genome for stretches that fit. Most such programs use a hidden Markov model, a statistical model that treats the sequence as passing through hidden states, such as "coding", "intron" or "between genes", each with its own typical letters. Prodigal and GeneMark are widely used for bacteria; AUGUSTUS is widely used for eukaryotes.
To see how a hidden Markov model helps, picture it walking along the genome one base at a time. In the "coding" state, the letters follow the codon usage of real genes, three bases at a time; between genes they look more like background sequence. The model cannot see which state it is in, but it can work out the most likely path of states that explains the letters it sees. Where that path stays in "coding" for a long stretch, framed by a plausible start and stop, it predicts a gene. Because the typical letters differ between species, the model must be trained, its parameters estimated from genes known or confidently predicted in that organism or a close relative. A model trained on the wrong species can miss many genes or split them wrongly.
Evidence-based prediction uses outside data. RNA-seq reads (Module 1) show which parts are transcribed and where introns are spliced out. Known proteins from related species, aligned to the genome as in Module 4, show where similar coding sequence lies. A gene supported by both is far more convincing than one predicted from sequence alone.
Evidence has its own limits. RNA-seq only shows genes that were switched on in the tissues and conditions that were sampled, so a gene active only in one organ or at one stage of development may have no RNA support at all. Protein alignments work well for genes shared with related species, but say nothing about genes unique to this one. This is why neither source is used on its own.
Modern pipelines combine the two: they run several ab initio predictors, align all available RNA and protein evidence, and merge everything into one consensus set of gene models.
Prodigal is described in Hyatt et al. 2010, BMC Bioinformatics (doi: 10.1186/1471-2105-11-119). It trains itself on the genome it is given, using codon statistics and ribosome binding sites. For short or mixed sequences, such as metagenome fragments, it has a separate mode that uses pre-built models instead. When you cite a gene set, name the tool, its version and the mode used, because these change the predictions. Very short genes remain the hardest case for any ab initio tool, so treat a missing short gene as unknown, not absent.
Prokaryotic and eukaryotic genes
In bacteria and archaea (prokaryotes), genes are packed tightly, often making up close to nine-tenths of the genome, and nearly every gene is one unbroken ORF. Finding them is mostly a matter of finding long ORFs and choosing the right start codon, and good tools find the great majority correctly.
In eukaryotes, such as plants, fungi and animals, most genes are split. The coding parts, exons, are interrupted by introns, which are copied into RNA and then cut out by splicing. In human genes the introns are often far longer than the exons, and protein-coding exons make up less than 2 per cent of the genome. One gene can also be spliced in more than one way, giving several transcripts. So a eukaryotic gene is not one ORF but an ORF assembled from pieces, and finding those pieces is much harder.
What helps is that introns have recognisable edges. Most begin with GT and end with AG, read on the strand of the gene, and a short signal called the branch point lies a little before the end. These signals are short, so they also turn up by chance all over the genome; a gene finder has to decide which GT and which AG really mark an intron, and keep the exons on either side in the same reading frame. A mistake at a single splice site can drop an exon, add a piece of intron or shift the frame of everything after it.
How to read this figure
The grey lines are DNA and the shaded boxes are coding sequence. In the top gene, one box runs from start codon to stop. In the bottom gene, three boxes are separated by introns, labelled with the two letters most introns begin and end with. The short row at the bottom shows the exons joined after splicing: only then does the coding sequence read as one ORF. A gene finder working on the genome sees the middle row, not the bottom one, so it has to guess where every intron starts and ends.
Go deeper: choosing the right start codon
In bacteria, ATG is not the only start. In E. coli, roughly four genes in five start with ATG; most of the rest start with GTG, and a few with TTG. All three are read as methionine when they are the first codon. So a gene finder cannot simply take the first ATG it meets.
It also looks upstream. Many bacterial genes have a ribosome binding site, a short purine-rich stretch, close to AGGAGG, about 5 to 10 bases before the start. It pairs with the ribosome's own RNA and positions it on the right codon. A candidate start with a good binding site the right distance away is favoured over one without. Getting the start wrong does not lose the gene, but it adds or removes amino acids at the front of the protein, which can hide or invent a signal peptide.
Annotation pipelines
An annotation pipeline is a fixed series of steps that turns an assembled genome into a set of named, described genes. The details differ, but most follow the same outline:
- Mask repeats. Repeated elements, such as transposons, are marked so they are not mistaken for genes.
- Gather evidence. RNA-seq reads and proteins from related species are aligned to the genome.
- Predict. Ab initio programs, trained for this organism, propose gene models.
- Combine. The predictions and evidence are merged into one set of gene models, each with its exons, start and stop.
- Assign function. Each predicted protein is compared with known proteins and searched for domains (Protein families, domains and motifs), and given a name and, where possible, Gene Ontology terms (Pathways and enrichment analysis).
- Check quality. Tools such as BUSCO ask what share of a set of genes expected in almost every species of that group were found complete.
The order matters. Repeats are masked first because transposons carry their own ORFs, often long ones, for the enzymes they use to copy themselves; left unmasked, they would be predicted as thousands of genes. Many pipelines use soft-masking, writing repeats in lower-case letters rather than replacing them, so the sequence is still there but the gene finder knows to treat it with suspicion. Evidence is gathered before prediction so that the predictors can use it as hints, and function is assigned last because it depends on having the final protein sequences.
Large public pipelines include the NCBI Eukaryotic Genome Annotation Pipeline, which produces the RefSeq annotation of many species, the NCBI Prokaryotic Genome Annotation Pipeline (PGAP), and the Ensembl gene annotation system. For human, the reference gene set is not left to automation alone: teams of expert curators review gene models by hand.
Function names are often only as good as the best match. A protein called "putative kinase" was probably named because it resembles a known kinase, not because anyone tested it. Errors can also spread when one genome's predicted names are used to annotate the next. Read a function label as a hypothesis with a source, as you learned to do with evidence codes in Reading a gene record and a protein record.
Key point
An ORF is a candidate, not a gene. Gene prediction weighs sequence signals and outside evidence, and eukaryotic genes are hard because introns split their coding sequence.
A second example: in a newly sequenced fungus, an ab initio program predicts a gene with four exons, but RNA-seq reads join exon 2 straight to exon 4. The RNA evidence suggests exon 3 is wrong, or is skipped in the tissue that was sequenced. A pipeline would favour the model the RNA supports, and a careful annotator would note both.
Further reading · Module 7NCBI ORFfinder, the web tool for finding ORFs. · The NCBI Eukaryotic Genome Annotation Pipeline. · The NCBI Prokaryotic Genome Annotation Pipeline. · Ensembl: how genes are annotated. · The Biopython tutorial. · All reading for this course
Check your understanding
1. A program reports a 40-codon ORF in a bacterial genome, with no RNA or protein evidence. What is the fairest conclusion?
2. Why is gene prediction harder in human DNA than in bacterial DNA?
3. An ORF lies on the minus strand. How will a GFF file usually give its position?
Up next
Lesson 2
Protein families, domains and motifs