Skip to article frontmatterSkip to article content

How to assemble contigs

Bokulich Lab

Step 1 — Assemble reads with MEGAHIT

MEGAHIT builds a simplified De Bruijn graph from your reads and outputs assembled contigs. It is the recommended assembler in the assembly plugin for most metagenomic datasets.

With parsl parallelization
Without parallelization
mosh assembly assemble-megahit \
    --i-reads cache:reads \
    --p-presets meta-sensitive \
    --p-num-cpu-threads 8 \
    --p-min-contig-len 500 \
    --o-contigs cache:contigs \
    --parallel-config parallel.config.toml \
    --verbose

Key parameters to consider:

  • --p-presets controls the sensitivity/speed trade-off. meta-sensitive gives better results on complex communities at the cost of runtime. meta-large is designed for large metagenomes (>100 Gbp input data).

  • --p-min-contig-len filters very short contigs at the assembly stage. 500 bp is a common starting point; lower it if you expect short viral or plasmid sequences.

  • --p-coassemble (default: false) assembles all samples together into a single set of contigs instead of assembling each sample independently. This can improve assembly for low-coverage samples but discards per-sample information needed for differential abundance analysis.


Step 2 — Evaluate assembly quality

After assembly, assess contig quality before spending resources on indexing and binning. Two complementary actions are available.

Quick evaluation with evaluate-contigs

This pipeline is fast and produces N(x) curves, GC content distributions, and length histograms for each sample:

mosh assembly evaluate-contigs \
    --i-contigs cache:contigs \
    --p-n-cpus 4 \
    --o-results cache:contig_qc_results \
    --o-visualization contigs-qc.qzv \
    --verbose

Comprehensive evaluation with evaluate-quast (optional)

QUAST computes additional metrics including potential misassemblies and, if you provide reference genomes, estimates what fraction of each reference is covered by your assembly:

mosh assembly evaluate-quast \
    --i-contigs cache:contigs \
    --p-threads 4 \
    --o-results-table cache:quast_results \
    --o-reference-genomes cache:quast_ref_genomes \
    --o-visualization contigs-qc-quast.qzv \
    --verbose

Pass --i-references cache:reference_genomes if you have reference sequences (e.g., for a mock community). QUAST is significantly slower than evaluate-contigs and requires more memory; for large studies evaluate-contigs is usually sufficient.


Step 3 — Filter contigs (optional)

You can remove short contigs or entire samples using filter-contigs. Contig length is controlled with --p-length-threshold (keep contigs of that length and longer):

mosh assembly filter-contigs \
    --i-contigs cache:contigs \
    --p-length-threshold 1000 \
    --o-filtered-contigs cache:contigs_filtered \
    --verbose

To retain only specific samples (or drop empty samples after length filtering), pass sample metadata and an optional --p-where clause:

mosh assembly filter-contigs \
    --i-contigs cache:contigs \
    --m-metadata-file sample-metadata.tsv \
    --p-where "[sample-type]='fecal'" \
    --p-length-threshold 1000 \
    --p-remove-empty \
    --o-filtered-contigs cache:contigs_filtered \
    --verbose

QC checkpoint

Before proceeding to binning, check the following in your assembly QC visualization:

  • N50 — a higher N50 means your reads were assembled into longer contigs; values above 10–50 kbp are generally considered good for complex metagenomes.

  • Number of contigs — a very large number of short contigs indicates a fragmented assembly; consider adjusting --p-min-contig-len or using a different preset.

  • GC content — verify the distribution looks unimodal or consistent with your expected community; multimodal distributions are expected in diverse samples.


Further reading