LSMA

LONDON SCHOOL OF MULTIOMICS & AI

Free course

Free course

0 of 73 lessons

Lesson 7 of 9

Module 6 · Genome assembly

Genes on your assembly

Genes on your assembly

Genes on your assembly

You have contigs; what is on them? Count the long open reading frames on your own assembly with a short script, see how close a first count gets to the real genes, and check that the genome is complete and clean.

⏱ 10 min readModule 6 · Genome assemblyFree
Lesson at a glance4 steps · about 10 min
  1. Your genes, a first count
  2. What this does
  3. Reading the output
  4. Is the genome complete and clean?

Your genes, a first count

You now have a set of contigs. The next question is what is on them, and the first step is to find the genes. This lesson does that quickly, on your own assembly, and then checks whether the genome is complete. Finding genes and annotating a genome explains properly how gene finding works, including the harder genes of plants and animals.

The contigs here are the short-read ones from Short-read assembly with SPAdes, which Judging an assembly found to be fragmented but very accurate base by base. That accuracy matters for gene finding. In Long reads and repeats you saw that a single indel shifts the reading frame, so an unpolished long-read assembly with 16 small indels would show genes cut short at false stop codons, and a gene count from it would be wrong in a way that no contiguity number reveals. Finding genes is therefore also a check on base accuracy: many short, broken ORFs where you expect long ones is a sign that the assembly needs polishing.

For now you need one idea. A protein-coding gene is read in codons, groups of three bases, from a start codon (usually ATG) to a stop codon (TAA, TAG or TGA). A stretch like that with no stop in between is an open reading frame (ORF). Stops are common in random sequence, about one in every 21 codons, so a long ORF of 100 codons or more is a good first guess at a gene, especially in bacteria, whose genomes are packed with genes. The script below finds every long ORF on both strands of your contigs.

Python
from Bio import SeqIO

def find_orfs(seq, min_len=300):
    """Open reading frames (ATG to stop) of at least min_len bases, on both strands."""
    orfs = []
    for strand, s in [("+", seq), ("-", seq.reverse_complement())]:
        for frame in range(3):
            end = frame + 3 * ((len(s) - frame) // 3)          # whole codons only
            protein = str(s[frame:end].translate())
            for chunk in protein.split("*")[:-1]:              # pieces that end in a stop
                start = chunk.find("M")
                if start != -1 and (len(chunk) - start + 1) * 3 >= min_len:
                    orfs.append((strand, (len(chunk) - start + 1) * 3))
    return orfs

total = 0
for record in SeqIO.parse("spades_out/contigs.fasta", "fasta"):
    orfs = find_orfs(record.seq)
    total += len(orfs)
    print(record.id.split("_cov")[0], len(orfs), "ORFs")
print("total", total)
NODE_1_length_7294 10 ORFs NODE_2_length_6894 10 ORFs NODE_3_length_6189 8 ORFs NODE_4_length_5888 7 ORFs NODE_5_length_2001 0 ORFs total 35

What this does

  • Both strands. The outer loop runs twice: once on the contig as written (+) and once on its reverse_complement(), which is the other strand read in its own direction (-).
  • Three frames. for frame in range(3) starts reading at letter 0, 1 or 2. The line with end trims the sequence so that it holds whole codons only, because translating a leftover one or two letters would make no sense.
  • Translate, then split. translate() turns each codon into its one-letter amino acid code and writes every stop codon as *. Splitting the protein string at * gives the stretches between stops. The last piece is dropped with [:-1], because it runs off the end of the contig without reaching a stop.
  • Find the start. In each piece, chunk.find("M") finds the first methionine, the first ATG. If there is one, the ORF runs from it to the stop. Its length in bases is (amino acids from M to the end of the piece, plus 1 for the stop codon) × 3.
  • Keep the long ones. Only ORFs of at least min_len = 300 bases, that is 100 codons including the stop, are kept. Each is stored as its strand and length.
  • The main loop runs the function on every contig, prints the contig's name without the coverage part (split("_cov")[0]) and the number of ORFs found, and adds up the total.

Reading the output

Each line is one contig and its count of ORFs of 300 bases or more. The four long contigs hold 10, 10, 8 and 7, and NODE_5 has none, giving 35 in all. As a rough check, about 31.95 kb of genome at around one gene per kilobase would suggest about 30 genes, close to what was found.

The one-gene-per-kilobase rule works for bacteria because their genomes are dense: typically around 85–90% of the sequence codes for protein, and an average bacterial gene is about 1,000 bases long. It does not work for plants and animals, whose genes are interrupted and spread out, which is one of the topics of Module 7.

Two features of the output are worth a closer look. First, the script drops the last stretch of each frame because it never reaches a stop. A gene that runs off the end of a contig is therefore not counted at all. With five contigs this costs little, but a short-read assembly with a hundred contigs has up to two hundred contig ends, and genes cut at those ends are lost or reported as partial. Real gene finders report partial genes and mark them as such. Second, NODE_5, the collapsed repeat, has no long ORF in this practice genome. In real bacteria, though, insertion sequences usually carry a gene for a transposase, the enzyme that moves the element. When the repeat is collapsed, that gene appears once in the assembly while the cell carries several copies, so a gene count from a short-read assembly can undercount repeated genes, as What genome assembly is warned.

Worked example · 35 ORFs, 30 real genes

compared with practice_bacterium_genes.tsv: all 30 genes are found
24 exactly · 6 starting at an earlier ATG in the same frame
5 extra ORFs overlap real genes, mostly on the opposite strand: “shadow” ORFs, not genes

Real gene finders such as Prodigal, and annotation pipelines such as Bakta or Prokka, use codon usage, start-site signals and protein databases to drop shadow ORFs, choose the right start, and name each gene.

Step by step. Of the 35 ORFs, 30 match real genes and 35 − 30 = 5 do not. Of the 30 matches, 24 have exactly the right start and stop, and 30 − 24 = 6 have the right stop but begin too early. The recall is perfect (30 of 30 genes found), but 5 of 35 predictions, about one in seven, are false.

Why the starts are wrong. The function takes the first M in each stretch, which gives the longest possible ORF. If an ATG happens to sit upstream of the real start, in the same frame and with no stop in between, the prediction begins there instead. Bacteria also start some genes with GTG or TTG rather than ATG, which a search for M alone cannot see. Gene finders weigh such clues as the short sequence immediately before a start, where the ribosome binds, to choose between candidate starts.

Why shadows appear. A real gene is a long stretch with no stops in one frame. Read on the opposite strand, the same stretch happens to contain few stops in some frames too, so a long ORF can appear there by accident. Codon usage, the pattern of which codons an organism prefers for each amino acid, helps tell them apart: a real gene uses the organism's preferred codons, while its shadow does not.

Go deeper: how often a long ORF appears by chance

In random sequence with all four bases equally common, each codon avoids being a stop with probability 61 ÷ 64. A run of 100 codons with no stop therefore has a probability of (61 ÷ 64) to the power of 100, about 0.008, under 1%. That is why a 300-base cut-off removes most chance ORFs.

The calculation hides a pitfall. All three stop codons, TAA, TAG and TGA, are rich in A and T. In a genome with a high GC content (the share of G and C bases), as in Streptomyces or Pseudomonas, stops are rarer in random sequence, so long chance ORFs become common, especially shadow ORFs on the opposite strand. A fixed length cut-off then reports many false genes, which is one reason gene finders such as Prodigal first learn the statistics of each genome from the genome itself.

Is the genome complete and clean?

Without a reference, completeness is judged from genes every organism of that kind should have. BUSCO, met in Judging an assembly, and CheckM2, built for bacteria and archaea, report the share of such single-copy marker genes found: close to 100% means complete, and many duplicated markers suggest contamination with a second organism. Comparing the assembly's GC content and coverage across contigs catches contamination too.

The two numbers that come out of a completeness check are read together. CheckM2, for example, reports a completeness and a contamination percentage for each genome. A clean, nearly complete isolate shows completeness close to 100% and contamination close to 0%. A genome with high completeness but high contamination, for instance well above 5%, probably contains sequence from a second organism; one with low completeness and low contamination is clean but missing pieces, often because of low coverage. Neither tool can judge everything. Plasmids rarely carry marker genes, so a missing plasmid does not lower the score, and the 32 kb practice genome is far too small to hold a full marker set, which is why this lesson checks its genes against the known gene table instead.

A single-copy marker gene is a gene that nearly every member of a group of organisms carries, exactly once. Genes for core parts of the ribosome are typical examples. The logic is simple: if a group's genomes all carry a set of such genes and your assembly contains 98% of them, about 98% of the genome is probably there. If many appear twice, a second genome is probably mixed in, since a single genome should hold only one copy of each. GC content, the share of bases that are G or C, is fairly constant along one bacterial genome but differs between species, so a group of contigs with a clearly different GC content, often at a different coverage too, is a warning sign.

The GC check is easy to run yourself. seqkit fx2tab -n -g spades_out/contigs.fasta prints each contig's name with its GC percentage, and the contig headers already give the coverage. Plotting GC against coverage, one point per contig, usually shows the genome as one tight cluster; a second cluster elsewhere on the plot points to contamination. Use judgement with short contigs, though: a contig of a few hundred bases can have an unusual GC content by chance, and plasmids or recently acquired genes can differ from the chromosome while still belonging to the same cell.

Finding genes and annotating a genome explains how gene finders work, why reading frames matter, and how annotation pipelines name each gene.

Before that, the next lesson, Finishing and sharing a genome, covers the last steps of this module: turning a checked assembly into a record that others can find, trust and reuse.

Prodigal is described by Hyatt et al. (2010, BMC Bioinformatics), Prokka by Seemann (2014, Bioinformatics) and Bakta by Schwengers et al. (2021, Microbial Genomics). CheckM2 is Chklovski et al. (2023, Nature Methods), the machine-learning successor to CheckM by Parks et al. (2015, Genome Research). Scores are often judged against MIMAG, a community standard for genomes recovered from mixed samples (Bowers et al. 2017, Nature Biotechnology), in which a high-quality draft needs, among other things, over 90% completeness and under 5% contamination. These tools rely on databases, so report both the tool version and the database version.

Key point

ORF finding is a first pass. Gene names and functions come from comparing the predicted proteins with curated databases, and every annotation tool's version should be reported.

A second example of why this matters: even in well-studied bacteria, a sizeable share of predicted genes match nothing of known function and are labelled "hypothetical protein". The prediction says a gene is probably there; only database matches or experiments say what it does. Because databases grow, re-annotating the same genome with a newer version often names genes that were hypothetical before, which is why the version must be reported.

Further reading · Module 6The Prodigal wiki: how the gene finder works. · Bakta: annotation of bacterial genomes. · CheckM2: completeness and contamination for bacteria and archaea. · All reading for this course

Check your understanding

1. Why is a long open reading frame, 100 codons or more, a good first guess at a gene?

2. Why did the repeat contig (NODE_5) have no ORFs?

3. What does BUSCO or CheckM2 measure?

Up next

Lesson 8

Finishing and sharing a genome

Ask BioTutor

Create a free website with Framer, the website builder loved by startups, designers and agencies.