, ,
This tutorial introduces the workflow for clustering assembled metagenomic contigs into genomes (binning), evaluating their quality, and assigning taxonomic labels using modern bioinformatics tools.
Overview
Time estimation: 1H
Version: main
Last update: 2026-09-18
Questions:Objectives:
How do I bin metagenomic contigs into Metagenome-Assembled Genomes (MAGs)?
What are the algorithmic differences and use-cases for MaxBin and MetaBAT?
How can I objectively classify MAGs using the Genome Taxonomy Database?
How do I assess and filter MAG quality using CheckM2?
Prepare coverage profiles from mapped sequencing reads for binning algorithms.
Execute MaxBin and MetaBAT to cluster contigs into putative genomes.
Classify recovered bins using GTDB-Tk for standardized, phylogeny-aware taxonomy.
Evaluate bin quality (completeness, contamination, strain heterogeneity) with CheckM2.
Apply MIMAG quality standards to select high-quality MAGs for downstream analysis.
Prerequisites
- Basic knowledge of Unix/Linux command line operations.
- Completion of the Metagenomic Assembly tutorial or equivalent assembly experience.
- Familiarity with NGS data formats (FASTA, BAM, FASTQ).
- We assume you are working in a computational environment with sufficient CPU cores (e.g., 28). All commands specifying thread counts can be adjusted (
-threador--cpus) to match your available resources.
After assembling metagenomic sequencing reads into contigs, binning algorithms attempt to cluster these contigs into discrete groups, each representing a single microbial genome. This process resolves complex community mixtures into individual organisms, enabling the study of uncultivated microbes directly from environmental samples.
Modern binning tools typically leverage two complementary signals:
Why Binning Matters Binning transforms heterogeneous metagenomic data into isolated, high-quality Metagenome-Assembled Genomes (MAGs). This enables functional annotation, comparative genomics, and ecological modeling of previously inaccessible microorganisms.
Most binning algorithms require a coverage file that indicates how many sequencing reads map to each contig. We will extract this information from your mapped reads (megahit_sorted.bam).
cd ~/workdir/WGS-data/megahit_out
mkdir maxbin metabat
cd maxbin
# Calculate per-contig coverage from the sorted BAM file
pileup.sh in=../megahit_sorted.bam out=cov.txt
# Extract contig headers and their corresponding depth values
awk '{print $1"\t"$5}' cov.txt | grep -v '^#' > abundance.txt
MaxBin is a widely used binning software that clusters metagenomic contigs into species-level bins using an Expectation-Maximization (EM) algorithm. It integrates tetranucleotide frequency and coverage information, iteratively enriching potential bins by identifying single-copy marker genes.
Execute the binning process using your assembly and the generated coverage file:
cd ~/workdir/WGS-data/megahit_out/maxbin
run_MaxBin.pl -thread 28 -contig ../final.contigs.fa -out maxbin -abund abundance.txt
Environment Setup If
run_MaxBin.plreturns a “command not found” error, source the environment module or the .bashrc first:source /etc/environment source ~/.bashrc run_MaxBin.pl -thread 28 -contig ../final.contigs.fa -out maxbin -abund abundance.txt
Assuming your output prefix is maxbin, the tool generates several key files:
| File Name | Description |
|---|---|
maxbin.0XX.fasta |
Individual bin files (XX is a bin number, e.g., maxbin.001.fasta) |
maxbin.summary |
Classification table detailing contig-to-bin assignments |
maxbin.log |
Execution log recording algorithm steps and convergence status |
maxbin.marker |
Marker gene presence counts per bin (ready for R/Python visualization) |
maxbin.noclass |
Contigs passing the minimum length threshold but failing classification |
maxbin.tooshort |
Contigs filtered out for being below the minimum length requirement |
Validating Your Bins Now that you have bins, how would you verify their taxonomic identity or assess if the community structure matches expectations?
Solution You can run gene prediction on each bin using
prodigal, followed by a BLAST search against reference databases. Additionally, compare predicted 16S rRNA abundances in your bins against your original 16S amplicon sequencing profile to check for consistency.
MetaBAT (Metagenome Binning Algorithm Toolkit) is an automated binning tool that integrates empirical probabilistic distances of genome abundance and tetranucleotide frequency. It is optimized for high precision and often recovers a larger number of bins compared to composition-only methods.
Navigate to your output directory and execute the binner:
cd ~/workdir/WGS-data/megahit_out/metabat
# Run MetaBAT using the assembler and sorted BAM file
runMetaBat.sh ../final.contigs.fa ../megahit_sorted.bam
MetaBAT will automatically distribute contigs into multiple bins based on coverage and compositional signatures. You can inspect the generated bins with:
ls -l final.contigs.fa.metabat-bins*
Bin Quality Considerations MetaBAT often produces a larger number of bins, which increases total genome recovery but may also yield more fragmented or chimeric assemblies. Downstream validation, dereplication, and quality filtering are crucial steps before downstream analysis.
Once bins are recovered, assigning objective, standardized taxonomic labels is essential. GTDB-Tk is a tool that classifies bacterial and archaeal genomes based on the Genome Taxonomy Database (GTDB). It replaces traditional 16S-based taxonomy with a fixed, phylogeny-aware framework, making it the current standard for MAG classification.
The reference database is substantial (~64 GB). We will download it from local storage and extract it:
cd ~/workdir
wget -qO- https://openstack.cebitec.uni-bielefeld.de:8080/swift/v1/denbi-mg-course/gtdbtk_v2_data.tar.gz | tar xvz
Extraction Time Extracting large tar archives can take several minutes depending on disk I/O. The terminal may appear to hang; allow the process to complete fully.
We need to download the mash database, since it takes some time to create:
cd /mnt/release207_v2
wget https://openstack.cebitec.uni-bielefeld.de:8080/swift/v1/mg_databases/mash.msh
Set paths for GTDB-Tk to locate the database and executables:
# Point to the extracted database directory
export GTDBTK_DATA_PATH=~/workdir/release207_v2
# Activate GTDB-tk environment:
source ~/gtdb_env/bin/activate
Run the classification pipeline on your MaxBin output folder:
cd ~/workdir/WGS-data/megahit_out/maxbin
gtdbtk classify_wf \
--extension fasta \
--cpus 28 \
--genome_dir . \
--out_dir gtdbtk_out \
--mash_db ~/workdir/release207_v2/mash.msh
Running GTDB-tk without mash db You can run GTDB-tk without a mash db which takes substantially more time, but will give you tree files to inspect:
gtdbtk classify_wf \ --extension fasta \ --cpus 28 \ --genome_dir . \ --out_dir gtdbtk_out \ --skip_ani_screen
Similarly, classify the MetaBAT bins for downstream comparison. Navigate to the MetaBAT bin directory (adjust the folder name as generated by the binner) and run:
cd ~/workdir/WGS-data/megahit_out/metabat/final.contigs.fa.metabat-bins.*YOUR_FOLDERNAME*
# Run classification on the bin directory
gtdbtk classify_wf \
--extension fa \
--cpus 28 \
--genome_dir . \
--out_dir gtdbtk_out \
--mash_db ~/workdir/release207_v2/mash.msh
Comparing Binning Classifications After both runs finish, how would you compare the taxonomic resolution and bin completeness between MaxBin and MetaBAT outputs?
Solution You can cross-reference GTDB-Tk lineage assignments with quality metrics from tools like CheckM or BUSCO. GTDB-Tk provides consistent, phylogeny-based ranks, allowing direct comparison of community composition, dominant phyla, and bin recovery rates across both binning approaches.
After binning and taxonomy classification, it is essential to evaluate the quality of each recovered genome. CheckM2 improves upon traditional marker gene methods by utilizing deep learning to predict genome quality metrics. It estimates completeness, contamination, and strain heterogeneity, which are critical for downstream ecological and functional analyses.
First, we activate the conda environmnt for checkm2:
conda activate checkm2
CheckM2 relies on a reference database to perform its predictions. Since this database is substantial, we will explicitly download it to a dedicated location:
checkm2 database --download --path ~/workdir/checkm2_db
Why CheckM2 over traditional CheckM? Unlike traditional CheckM, which relies on a fixed set of 120 single-copy marker genes and linear regression models, CheckM2 uses a deep neural network trained on thousands of high-quality reference genomes. This allows it to achieve significantly higher accuracy, especially for draft-quality MAGs and underrepresented phyla. CheckM2’s machine learning approach captures complex genomic signatures beyond simple marker gene presence/absence, providing more robust completeness and contamination estimates for diverse and fragmented metagenomic assemblies.
Navigate to the MaxBin output directory containing your bins and run CheckM2:
cd ~/workdir/WGS-data/megahit_out/maxbin
checkm2 predict \
--input . \
-x fasta \
--output-directory checkm2 \
--threads 28 \
--database_path ~/workdir/checkm2_db/CheckM2_database/uniref100.KO.1.dmnd
Similarly, run CheckM2 on the MetaBAT bins:
cd ~/workdir/WGS-data/megahit_out/metabat/YOUR_BINFOLDER_NAME
checkm2 predict \
--input . \
-x fa \
--output-directory checkm2 \
--threads 28 \
--database_path ~/workdir/checkm2_db/CheckM2_database/uniref100.KO.1.dmnd
CheckM2 generates a summary_table.txt file containing global quality metrics for each bin:
| Metric | Description |
|---|---|
Completeness |
Predicted percentage of conserved single-copy genes present. |
Contamination |
Predicted percentage of redundant or multi-origin contigs in the bin. |
Strain Heterogeneity |
Indicates potential contamination from closely related strains. |
CheckM2 Score |
A composite quality metric combining the above factors. |
Evaluating Genome Quality The MIMAG standards define “High-quality” MAGs as having ≥90% completeness and ≤5% contamination, while “Medium-quality” requires ≥50% completeness and ≤10% contamination. How would you use the CheckM2 summary table to filter your bins for downstream analysis?
Solution You can parse the
summary_table.txtto filter bins meeting the MIMAG thresholds (e.g., usingawkor a script). Typically, you would select bins with high completeness (>70-90%) and low contamination (<5-10%). Lower quality bins might still be useful for specific functional or phylogenetic analyses but should be excluded from comparative genomic studies unless appropriately weighted.
Key Points
Binning relies on sequence composition (e.g., tetranucleotide frequency) and coverage depth profiles across samples.
MaxBin uses an Expectation-Maximization approach with marker genes, while MetaBAT integrates probabilistic distances of coverage and composition.
GTDB-Tk provides a unified, phylogeny-aware taxonomic framework based on whole-genome relationships.
CheckM2 employs machine learning to estimate completeness and contamination more accurately than traditional marker gene sets.
Author(s): Nils Kleinbölting , Sebastian Jünemann , Alexander Sczyrba