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.
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 \
--verbosemosh 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 \
--verboseKey parameters to consider:
--p-presetscontrols the sensitivity/speed trade-off.meta-sensitivegives better results on complex communities at the cost of runtime.meta-largeis designed for large metagenomes (>100 Gbp input data).--p-min-contig-lenfilters 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.
Alternative assembler: SPAdes
For datasets where MEGAHIT produces fragmented assemblies, you can try assemble-spades instead:
mosh assembly assemble-spades \
--i-reads cache:reads \
--p-meta \
--p-threads 8 \
--o-contigs cache:contigs \
--verboseSPAdes is generally more accurate but substantially slower and more memory-intensive than MEGAHIT, particularly on large datasets. Most metagenomic workflows use MEGAHIT as their default.
Starting from external contigs
If you have contigs assembled outside of QIIME 2 (e.g., from a previous run), you can import them with:
mosh tools cache-import \
--type 'SampleData[Contigs]' \
--input-path /path/to/contigs/ \
--output-path cache:contigsWhen importing contigs from another tool, contig identifiers may not be unique across samples, which can cause downstream errors. Use rename-contigs to ensure uniqueness:
mosh assembly rename-contigs \
--i-contigs cache:contigs \
--p-uuid-type shortuuid \
--o-renamed-contigs cache:contigs_renamed \
--verboseSee the import how-to for more details.
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 \
--verboseComprehensive 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 \
--verbosePass --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 \
--verboseTo 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 \
--verboseQC 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-lenor 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¶
End-to-end tutorial — Assembly chapter — worked example with mock-community data including reference-based QUAST
Cocoa tutorial — MAG recovery — assembly in a real-world context, including parsl HPC configuration
How to use parsl parallelization — configuring parallel execution for
assemble-megahitHow to import data from other tools — importing externally assembled contigs