LSMA

LONDON SCHOOL OF MULTIOMICS & AI

Free course

Free course

0 of 73 lessons

Guided project

Module 6 · Genome assembly · Self-checked

Coverage and contiguity

Coverage and contiguity

Coverage and contiguity

How much sequencing does an assembly need? Subsample the reads, assemble each subset, and measure what you lose. Work through the six tasks, check each against its checkpoint, and tick it off. Nothing is submitted.

⏱ 13 min readModule 6 · Genome assembly · Self-checkedFree
Lesson at a glance8 steps · about 13 min
  1. How to approach this
  2. Subsample
  3. Assemble each
  4. Measure contiguity
  5. Check against the truth
  6. Genes recovered
  7. Recommend
  8. Variants against the true genome

Research question

How do contig number, N50 and gene recovery change as coverage falls from about 60× to about 3×, and what does the long-read assembly add?

How to approach this

This project is a small experiment in the proper sense: you change one thing, the amount of sequencing, and keep everything else fixed, then measure what happens. Subsampling means randomly keeping a fraction of the reads you already have, which imitates having ordered less sequencing. Because the practice genome is known exactly, you can measure the cost of lower coverage instead of guessing it.

Subsampling is the usual way to answer "how much sequencing do I need?" before paying for it. Sequencing the same isolate again at several depths would cost more and add new sources of variation, such as a different library; taking random subsets of one run changes only the amount of data. The answer you reach here applies to genomes like the practice one. A larger or more repetitive genome would need its own test, but the method is the same.

  • Two optional tasks look back at the reference. Tasks 1–6 measure assembly. Tasks 7 and 8 are an extension: they align the same reads back to the true genome, call variants and find the genes in uncovered stretches. They use tools the course has not taught yet, so install them first with conda install -c conda-forge -c bioconda bwa samtools bcftools bedtools.
  • Keep everything else constant. Use the same assembler, the same settings and the same reference for every assembly, so that any difference comes from coverage alone.
  • One folder per assembly. Name folders after the data they hold, for example by percentage, so that no output overwrites another and every number in your table can be traced back to a file.
  • Build the results table as you go. One row per assembly (full, 10%, 5% and the Flye assembly), with columns for coverage, contigs, total length, largest contig, N50, genome fraction, misassemblies and ORFs. By task 6 the table is your evidence.
  • Expect "about". Subsampling is random, so your counts may differ slightly from the checkpoints. That is why they say "about". A large difference is worth investigating; a small one is not.

Make a prediction before you run anything. Writing down what you expect, and then checking it, is what turns a set of runs into an experiment. Two lessons give you the tools. The Lander–Waterman estimate in What genome assembly is says that at 6× about e−6, roughly 0.25%, of the genome is never read, and at 3× about 5%. That alone would predict only small losses. But the assembler works on k-mers, not bases. In K-mers and genome size you saw that k-mer depth is lower than base coverage, and that k-mers seen only once or twice are treated as likely errors. At 3× base coverage, a typical genome k-mer is seen only two or three times, right where the error spike sits, so many real k-mers are thrown away with the errors. Expect assemblies to fall apart well before the genome stops being read.

One setting you do not control directly is k. SPAdes chooses its k values from the read length, which is the same in every subset, so they should match across runs. Confirm this in each spades.log; if they differ, note it, because then coverage is no longer the only thing that changed.

Coverage and contiguity · LSMA free course Three panels show the same genome covered by all the reads, by a 10% subset and by a 5% subset. As the fraction falls, the reads thin out and stretches of the genome are left with few or no reads. THE SAME READS, THREE DEPTHS Full data 10% subset 5% subset 7,500 pairs · about 59× about 750 pairs · about 6× about 400 pairs · about 3× every base read many times some stretches rarely read gaps where no read landed
Each subset keeps a random fraction of the same read pairs. Fewer reads means more of the genome is covered thinly or not at all, which is what you will measure in tasks 3 to 5. Read counts and coverage match the task 1 checkpoint. Schematic, not to scale.
1

Subsample

What genome assembly is and K-mers and genome size

  • Make 10% and 5% subsets of both read files with the same seed, so pairs stay matched: seqkit sample -p 0.1 -s 100 data/bact_R1.fastq.gz -o sub10_R1.fastq.gz, and the same for R2.
  • Work out each subset's coverage.

Hint. In the command, -p 0.1 keeps each read with probability 0.1 and -s 100 sets the seed, the starting value of the random-number generator. With the same seed, seqkit makes the same sequence of keep-or-drop choices; because R1 and R2 list their reads in the same order, the same pairs are kept from both files. A different seed for R2 would break the pairs. For coverage, measure each subset with seqkit stats and use the calculation from What genome assembly is: total bases in both files, divided by the genome size.

Checkpoint: about 750 pairs (about 6×) and about 400 pairs (about 3×); R1 and R2 have the same number of reads.

2

Assemble each

Short-read assembly with SPAdes

  • Run SPAdes with --isolate on the full data and on each subset, into separate folders.

Hint. The command is the one from Short-read assembly with SPAdes; only the input files and the output folder given to -o change. Read spades.log for the low-coverage runs as well as their contigs: warnings there are part of the result. If you already have the full-data assembly from Short-read assembly with SPAdes, you can reuse it, as long as it was made with the same settings.

Checkpoint: three contigs.fasta files; the 5% assembly has many more contigs than the full one.

3

Measure contiguity

Judging an assembly

  • Use your N50 function to tabulate contigs, total length, largest contig and N50 for each assembly.

Hint. Judging an assembly already gives everything except the loop. Read each contigs.fasta into a sorted list of lengths; the number of contigs is the length of that list, the total length its sum, and the largest contig its first entry. Run the same steps for each of the three files so the numbers are directly comparable. Look at total length as well as N50: it tells you how much of the genome made it into the assembly at all.

Checkpoint: full data 5 contigs, N50 6,894; 10% about 8 contigs, N50 about 5,000; 5% about 28 contigs, N50 about 1,400, with only about 24 kb assembled.

4

Check against the truth

Judging an assembly

  • Run QUAST on all three together, with the reference: quast.py a.fasta b.fasta c.fasta -r data/practice_bacterium.fa -o quast_all.

Hint. Replace a.fasta, b.fasta and c.fasta with the paths to your three contig files. When QUAST is given several assemblies, its report.txt has one column per assembly, so the lines you selected with grep in Judging an assembly now compare all three side by side. Keep the two kinds of measure apart in your mind: genome fraction is about completeness, misassemblies and mismatches are about correctness.

One difference to expect: QUAST ignores contigs shorter than 500 bases by default, while your own N50 function from task 3 counts every contig. For the fragmented 5% assembly, the two can therefore disagree on the number of contigs and on N50. That is not an error in either; note which cut-off each number used.

Checkpoint: genome fraction falls as coverage falls, while misassemblies stay at or near zero: low coverage fragments an assembly more than it corrupts it.

5

Genes recovered

Genes on your assembly: a first count, and is it complete?

  • Count ORFs of 300+ bases in each assembly, and in the Flye assembly.

Hint. Reuse find_orfs from Genes on your assembly: a first count, and is it complete? unchanged and point it at each file in turn, including flye_out/assembly.fasta from Long reads and repeats. When you explain the Flye count, return to Long reads and repeats: think about what one inserted or deleted base does to every codon after it, and how that changes where a stop codon appears. At low coverage, think instead about a gene that falls across a gap between two contigs.

Checkpoint: 35 ORFs in the full short-read assembly, fewer at low coverage; the unpolished Flye assembly gives a different count, because its indels break or merge reading frames. Explain the difference.

6

Recommend

Long reads and repeats and Finishing and sharing a genome

  • Write a short recommendation: how much short-read coverage you would order for a new isolate of this kind, and whether to add long reads. Include a methods paragraph.

Hint. Base the recommendation on your results table, not on general rules. Ask where the gain from extra coverage levels off, and what no amount of short-read coverage changed in your results. Short-read assembly with SPAdes gave the distance between read pairs and the size of the repeat; Long reads and repeats showed what long reads add and what they still need. For the methods paragraph, follow the pattern of the sentence in Finishing and sharing a genome and include every tool, version and setting you used, including the subsampling seed.

Checkpoint: your answer weighs cost against completeness, and notes that no short-read coverage resolves the 2 kb repeat.

7

Variants against the true genome

Aligning reads to a genome · optional extension

  • Align the full short reads to data/practice_bacterium.fa, call variants, and count the calls.
  • Look at every call that remains and explain where it comes from.

Hint. Index the genome with bwa index and align data/bact_R1.fastq.gz and data/bact_R2.fastq.gz with bwa mem, sorting and indexing the result with samtools as before. Then run bcftools mpileup -f with the genome, piped into bcftools call -mv. A bacterium carries one copy of its chromosome, so add --ploidy 1; with the default diploid model, every real difference would be forced into a choice between "same as the reference" and "both copies changed". This is a control experiment: the practice reads were simulated from this very genome, so a perfect pipeline would report almost nothing. Before counting, think about where false calls would come from: positions near the read ends, and above all the 2 kb repeat, where reads from three copies pile onto one place and the aligner cannot say which copy each read came from.

Checkpoint: very few calls, if any. For each one, you can say whether it sits in the repeat, has low depth or low mapping quality, or has a low QUAL score. A sample with no true differences is the best way to learn what false positives look like.

8

Which genes fall in the gaps?

Text processing with awk and sed · optional extension

  • Align the 5% subset to the true genome and find the stretches with no coverage.
  • Find the ORFs of the true genome that touch those stretches, using bedtools intersect.

Hint. Align the 5% reads exactly as in task 7, then run bedtools genomecov -bga on the BAM file. It writes every stretch of the genome with its depth, including stretches with none; keep the lines whose fourth column is 0. For the genes, run find_orfs on data/practice_bacterium.fa and write each ORF as a BED line: chromosome name, start − 1, end. The "− 1" is the BED convention of counting from zero, the most common source of off-by-one errors. bedtools intersect -a orfs.bed -b zero_cov.bed -u then lists each ORF that touches at least one uncovered stretch, once. The same command, with peaks instead of uncovered stretches, is how ChIP-seq and ATAC-seq peaks are matched to genes.

Checkpoint: a short list of ORFs. Compare it with task 5: genes that touch uncovered stretches are the likeliest to be broken or missing in the 5% assembly, because no read covered part of their sequence.

Go deeper: how much a random subset varies

With -p 0.1, seqkit keeps each of the 7,500 pairs independently with probability 0.1. The number kept therefore varies from seed to seed: on average 7,500 × 0.1 = 750, with a standard deviation (the typical distance from the average) of the square root of 7,500 × 0.1 × 0.9, about 26. So most runs keep between about 700 and 800 pairs. For 5%, the average is 375 with a standard deviation of about 19, so a count near 400 is unremarkable.

The seed makes one run repeatable, but it does not make it typical: a different seed gives a different, equally valid subset. To see how much a number such as N50 varies at 3×, repeat the subsampling with three or four seeds and report the range. Keep the seed identical for R1 and R2 in every repeat, and check that both files still hold the same number of reads.

Take it further

Polish the Flye assembly with the short reads (for example with Polypolish) and check whether the ORF count returns to 35. Then give a hybrid assembler, such as Unicycler, the short and long reads together and compare its assembly with your polished Flye one, using the measures from Judging an assembly. Finally, try the same steps on a public bacterial dataset from ENA.

For the polishing step, remember that a polisher needs the short reads lined up against the Flye assembly first; check the polisher's documentation for the exact input it expects. When you choose a public dataset, look for an isolate with both short and long reads deposited under the same BioSample, as described in Finishing and sharing a genome, so you can repeat the full comparison from this project on real data.

When you write up the project, separate what you measured from what you infer. "At 3× the assembly held about 24 kb in about 28 contigs" is a measurement from your table. "Low coverage loses k-mers into the error spike" is an explanation, and it is stronger if you can point to evidence for it, such as the k-mer spectrum of the 5% subset drawn with the code from K-mers and genome size.

This module ends with a genome you built and checked yourself, and a list of open reading frames that are only candidates for genes. If you did the optional tasks 7 and 8, you also aligned the same reads back to the true genome and matched variant calls and uncovered stretches to genes. Module 7, From genes to function, starts from exactly that point. Its first lesson turns ORFs into properly predicted and annotated genes, and the lessons after it ask what those genes do: which protein families and domains they belong to, what shapes their proteins fold into, and which pathways and networks they take part in. The assembly skills from this module stay in use there, because every annotation is only as good as the sequence underneath it.

End of Module 6: Genome assemblyYou can stop here: this module is complete on its own. Or carry on to Module 7, From genes to function (Advanced).

Further reading · Module 6QUAST: the evaluation tool and its documentation. · The Polypolish wiki: polishing with short reads. · Unicycler: hybrid assembly of bacterial genomes. · Why are de Bruijn graphs useful for genome assembly?: a short, open-access primer on assembly graphs. Read this one even if you read nothing else. · All reading for this course

Up next

Lesson 1

Finding genes and annotating a genome

Ask BioTutor

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