Written and maintained by CASRAI Editorial Board
Last updated
Metagenomics is the study of DNA recovered directly from a mixed community of organisms, such as a stool, soil or water sample, instead of from individual organisms grown in culture. This guide shows how to take shotgun sequencing reads to a taxonomic profile with two documented tools, Kraken 2 and MetaPhlAn 4, how to read what they print, and where the nf-core/mag pipeline fits when you want assembled genomes. It is written for researchers who already have, or are planning, sequence data; the broader field is covered in what is genomics and what is bioinformatics.
What it is used for in research
Metagenomics answers the question of which organisms are in a sample and, with the right workflow, what genes they carry. Because no culture step is needed, it reaches organisms that are hard to grow, which is why it is common alongside classical work in microbiology and in bacterial identification.
16S amplicon sequencing versus shotgun metagenomics
There are two common designs. Amplicon sequencing targets one marker, the 16S rRNA gene, so it profiles bacteria and archaea only. Shotgun metagenomics sequences all DNA in the sample, which lets you profile other groups and recover gene content, but it also sequences host DNA when the sample contains any. The tools below work on shotgun reads.
Install or access (official source only)
Kraken 2
Kraken is a taxonomic sequence classifier that assigns taxonomic labels to DNA sequences; Kraken 2 stores only minimizers in a compact hash table. The source and manual are at github.com/DerrickWood/kraken2. From the extracted source directory, install with:
./install_kraken2.sh $KRAKEN2_DIR
Then build the standard database:
kraken2-build --standard --db $DBNAME
MetaPhlAn 4
MetaPhlAn 4 is a computational tool for profiling the composition of microbial communities from shotgun metagenomic data at species level, with StrainPhlAn for strain level. Documentation is on the bioBakery MetaPhlAn 4 wiki. Install with either of:
conda install -c bioconda metaphlan
pip install metaphlan
Then download its marker and database files:
metaphlan --install
Step-by-step task: from FASTQ to a taxonomic profile
Option A: Kraken 2
- Build or obtain a database (see above) and note its directory as
$DBNAME. - Classify single-end reads and write both a report and per-read output:
kraken2 --db $DBNAME --report k2_report.txt --output k2_output.txt sequence_data.fq - For paired-end reads, add
--pairedand name both files. The#in the--classified-outname becomes_1and_2in the two output files:kraken2 --paired --classified-out cseqs#.fq seqs_1.fq seqs_2.fq
Option B: MetaPhlAn 4
- Run
metaphlan --installonce to fetch the database files. - Profile a FASTQ file:
metaphlan metagenome.fastq --input_type fastq -o profiled_metagenome.txt - Use
--nprocto set the number of CPUs and--bowtie2outto save the intermediate mapping output.
Output and how to read it
The Kraken 2 report
The report file has one line per taxon, with six columns:
| Column | Meaning |
|---|---|
| 1 | Percent of fragments covered by the clade rooted at this taxon |
| 2 | Number of fragments covered by the clade rooted at this taxon |
| 3 | Number of fragments assigned directly to this taxon |
| 4 | Rank code (U for unclassified, R for root, D for domain, G for genus, S for species, and so on) |
| 5 | NCBI taxonomic ID |
| 6 | Scientific name, indented by depth in the taxonomy tree |
The difference between columns 2 and 3 matters: column 2 counts a taxon and everything below it, while column 3 counts only reads that could not be pushed to a more specific taxon. A genus with a large column 2 but a small column 3 simply has its reads spread across its species.
The MetaPhlAn 4 profile
MetaPhlAn reports relative normalized abundances. When you merge several profiles into one table, taxa are rows and samples are columns. Its reference is about 5.1 million unique clade-specific marker genes drawn from roughly 1 million microbial genomes (reference genomes and metagenome-assembled genomes), grouped into 26,970 species-level genome bins; a taxon absent from that reference cannot appear in the profile.
Troubleshooting
- Kraken 2 database build runs out of memory. The manual states that the default database size is 29 GB (as of January 2018) and that you need slightly more than that in RAM to build it. Check the current figure in the manual before sizing a machine.
- MetaPhlAn fails to start or cannot find its database. Run
metaphlan --install; the documentation says it downloads the marker and database files. The wiki also states a requirement of at least 15 GB of memory. - Paired-end output files are not what you expected. With Kraken 2, the
#in the--classified-outname is replaced by_1and_2, giving one classified file per mate. - The run is slow. For MetaPhlAn, raise
--nprocto match the CPUs you have.
Free alternatives
The three tools in this table are all openly documented; they do different jobs, so the choice follows from what you need out of the data.
| Tool | What it does (per its documentation) | Documentation |
|---|---|---|
| Kraken 2 | Assigns taxonomic labels to DNA sequences using a minimizer hash table | Kraken 2 manual |
| MetaPhlAn 4 | Profiles microbial community composition at species level from shotgun data; StrainPhlAn adds strain level | MetaPhlAn 4 wiki |
| nf-core/mag | Best-practice pipeline for assembly, binning and annotation of metagenomes | nf-core/mag |
When to assemble: nf-core/mag
Read-based tools such as Kraken 2 and MetaPhlAn tell you who is present. If you want genomes, use an assembly-and-binning workflow. nf-core/mag covers preprocessing (trimming, adapter removal, quality control), assembly with MEGAHIT and SPAdes (assembly quality with Quast), gene prediction with Prodigal and annotation with Prokka, binning with MetaBAT2, MaxBin2, CONCOCT, COMEBin, MetaBinner and SemiBin2, bin quality checks with BUSCO, CheckM or CheckM2, optional refinement with DAS Tool, taxonomy with GTDB-Tk and/or CAT, and a MultiQC report. It runs through Nextflow:
nextflow run nf-core/mag -profile <docker/singularity/podman/shifter/charliecloud/conda/institute> --input samplesheet.csv --outdir <OUTDIR>
After the analysis: depositing data
Raw reads are normally deposited in a public archive. The Sequence Read Archive and its BioSample records are described in our dictionary, and the submission steps are in submitting sequence data to NCBI SRA. If you are choosing a sequencing platform for long or short reads, see Illumina vs Nanopore.
FAQ
What is metagenomics?
It is the analysis of DNA taken straight from a mixed community, without culturing each organism first, to learn which organisms are present and what genes they carry.
Is 16S sequencing metagenomics?
16S amplicon sequencing targets one marker gene in bacteria and archaea. Shotgun metagenomics sequences all DNA in the sample. The two are often compared, and the tools in this guide work on shotgun reads.
Which tool should I start with for a taxonomic profile?
Kraken 2 classifies sequences against a database you build; MetaPhlAn 4 profiles species-level composition against its marker-gene reference. Both are documented above with the exact commands.
Can I get genomes, not just a list of taxa?
Yes, through assembly and binning; nf-core/mag is a documented pipeline for that.
Sources (official docs)
- Kraken 2 manual, https://github.com/DerrickWood/kraken2/wiki/Manual, checked 2026-10-29
- MetaPhlAn 4 wiki, https://github.com/biobakery/MetaPhlAn/wiki/MetaPhlAn-4, checked 2026-10-29
- nf-core/mag, https://nf-co.re/mag/latest/, checked 2026-10-29







