Skip to content

MetaPhlAn 4.3

Claudia Mengoni edited this page Nov 26, 2026 · 1 revision

MetaPhlAn is a computational tool for species-level microbial profiling (bacteria, archaea, eukaryotes, and viruses) from metagenomic shotgun sequencing data. StrainPhlAn (available within MetaPhlAn) allows strain-level microbial population genomics.

MetaPhlAn 4, as of the database mpa_vJan26_CHOCOPhlAnSGB_202611, relies on ~14.6M unique clade-specific marker genes (the latest marker information file can be found here) spanning 71,511 bacterial and archaeal species-level genome bins (SGBs, http://segatalab.cibio.unitn.it/data/Pasolli_et_al.html) and 6,035 eukaryotic genome bins (EGBs) (the full list of the species included in the latest database can be found here).

MetaPhlAn 4.3 allows:

  • unambiguous taxonomic assignments;
  • accurate estimation of organismal relative abundance;
  • SGB-level resolution for bacteria and archaea, and EGB-level resolution for eukaryotes (fungi and protists);
  • quantification of metagenomic reads matching viruses;
  • metagenomic strain-level population genomics and strain tracking (with StrainPhlAn 4);
  • profiling of long-read sequencing data.

The documentation below provides an overview on MetaPhlAn 4.3 basic usage, more usage examples are available in the MetaPhlAn 4.1 tutorial page, be aware that some parameters have been updated since 4.1 and you may need to update the commands to include these changes. You can find the full list of changes in the release notes. The documentation of the previous version is available here.

Important changes with respect to MetaPhlAn 4.2.*

Eukaryotic genome bins (EGBs)

The database mpa_vJan26_CHOCOPhlAnSGB_202611 introduces a new strategy for eukaryotic profiling, which replaces the previous eukaryotic (EUK) markers. Eukaryotes are now organized in Eukaryotic Genome Bins (EGBs), the eukaryotic counterpart of SGBs, and are reported in the profiles as t__EGB<id>, for example:

k__Eukaryota|p__Ascomycota|c__Saccharomycetes|o__Saccharomycetales|f__Debaryomycetaceae|g__Candida_CUG_Ser1_incertae_sedis|s__Candida_pseudocylindracea|t__EGB2566
  • 6,035 EGBs (5,348 fungal and 687 protist) built from 20,304 genomes: NCBI isolate genomes, JGI MycoCosm/PhycoCosm genomes, NCBI MAGs and newly assembled MAGs from food, marine and human skin metagenomes
  • genomes are clustered into EGBs at 95% ANI (fungi) and 98% ANI (protists); 5,807 known EGBs (with at least one isolate genome) and 228 unknown EGBs (MAGs only)
  • 1,188,304 eukaryotic markers, up to 200 markers per EGB
  • the eukaryotic taxonomy follows the NCBI taxonomy (November 2026); special characters in taxon names are replaced with _
  • bacterial and archaeal markers are unchanged from the vJan26 database

Profiles from databases with EUK markers and from mpa_vJan26_CHOCOPhlAnSGB_202611 should not be merged or compared directly (see Merging Tables).

Quantile for eukaryotes: --stat_q_egb

The new parameter --stat_q_egb sets the quantile of the robust average (see --stat_q) used only for EGBs. By default it is the same as --stat_q (0.2). On synthetic metagenomes, --stat_q_egb 0.1 gave a good trade-off between precision and recall. For example:

$ metaphlan metagenome.fastq --input_type fastq --mapout metagenome.bowtie2.bz2 --nproc 5 --stat_q_egb 0.1 -o profiled_metagenome.txt

--stat_q_egb only changes how the abundance is estimated, not the mapping, so it can be applied to an existing --mapout file without re-mapping the reads.

Long reads: minimap2 index built at installation

The minimap2 index for --long_reads is now built once with metaphlan --install --long_reads (see Database installation), instead of during the first profiling run, so that parallel jobs no longer compete to build it. If the index is missing, profiling stops and prints the command to build it.

Renamed parameters (since MetaPhlAn 4.2)

MetaPhlAn relies on minimap2 for long reads and on bowtie2 for short reads, therefore:

  • --bowtie2out has been renamed to --mapout
  • --input_type can take as input mapout, no longer bowtie2out
  • --bowtie2db has been renamed to --db_dir

Unclassified estimation as default (since MetaPhlAn 4.2)

MetaPhlAn estimates the unclassified fraction of the metagenome by default. Therefore the --unclassified_estimation parameter is no longer existing. The unclassified estimation can be turned off with --skip_unclassified_estimation

Recommended installation

The best way to install MetaPhlAn is through conda via the Bioconda channel. If you have not configured your Anaconda installation to fetch packages from Bioconda, please follow these steps to set up the channels.

You can install the MetaPhlAn package by running

$ conda install -c bioconda metaphlan=4.3

But we recommend to create a dedicated conda environment with MetaPhlAn into it.

$ conda create --name mpa -c bioconda metaphlan=4.3

Other ways to install

If during the installation you encounter an incompatibility error with the glibc package, we suggest you to add the conda-forge channel to conda or run one of the following commands.

$ conda install -c conda-forge -c bioconda metaphlan=4.3
$ conda create --name mpa -c conda-forge -c bioconda python=3.10 metaphlan=4.3

This allows having the correct version of all the dependencies isolated from the system's python installation.

Before using MetaPhlAn, you should activate the mpa environment:

$ conda activate mpa

MetaPhlAn is also available in PyPi

$ pip install metaphlan==4.3

Alternatively, you can manually download from GitHub or clone the repository using the following command

$ git clone https://github.com/biobakery/MetaPhlAn.git

and install MetaPhlAn by running

$ pip install .

If you choose this way, you'll need to install manually some dependencies! MetaPhlAn requires python 3 or newer with numpy, and Biopython libraries installed. Python libraries are automatically installed by pip. MetaPhlAn relies on BowTie2 (version 2.3 or higher) to map reads against marker genes. Check that bowtie2 is present in the system path with execute and read permissions. Minimap2 (version 2.26 or higher) is required for long-read sequencing data.

Database installation

MetaPhlAn needs the clade markers and the database to be downloaded locally. To obtain them:

$ metaphlan --install

Important! The MetaPhlAn 4 database has been substantially increased in comparison with the previous versions. Thus, for running MetaPhlAn 4, a minimum of 30GB of memory is needed. The mpa_vJan26_CHOCOPhlAnSGB_202611 database is a ~51GB download and takes ~68GB of disk space once installed; the minimap2 index for long reads needs ~71GB more.

If you have installed MetaPhlAn using Anaconda, it is advised to install the database in a folder outside the Conda environment. To do this, run

$ metaphlan --install --db_dir <database folder>

If you install the database in a different location, remember to run MetaPhlAn using --db_dir <database folder>!

By default, the latest MetaPhlAn database is downloaded and built. You can download a specific version with the --index parameter

$ metaphlan --install --index mpa_vJan26_CHOCOPhlAnSGB_202611 --db_dir <database folder>

When --index is specified, MetaPhlAn skips the check for the latest database version and run the analysis using the database version provided by --index located in --db_dir.

This option is recommended when MetaPhlAn is run on HPC clusters or containerized

Long-read database (minimap2 index)

To profile long reads, build the minimap2 index once, after (or together with) the database installation and before launching parallel profiling jobs:

$ metaphlan --install --long_reads --index mpa_vJan26_CHOCOPhlAnSGB_202611 --db_dir <database folder>

The index is built for the minimap2 presets given with --minimap2_ps (default presets if not given). If you profile with custom presets, build the index with the same presets, for example:

$ metaphlan --install --long_reads --index mpa_vJan26_CHOCOPhlAnSGB_202611 --db_dir <database folder> --minimap2_ps='-x asm20 -B 3 -O 3,12'

If you have issues in downloading the database, you can get it from:

Just download the .tar, .md5, and the mpa_latest files and place them in the metaphlan_databases folder (the _bt2.tar and _bt2.md5 files are in the bowtie2_indexes folder).


Basic Usage

$ metaphlan metagenome.fastq --input_type fastq -o profiled_metagenome.txt

It is highly recommended to save the intermediate BowTie2 output for re-running MetaPhlAn extremely quickly (--mapout), and use multiple CPUs (--nproc) if available:

$ metaphlan metagenome.fastq --mapout metagenome.bowtie2.bz2 --nproc 5 --input_type fastq -o profiled_metagenome.txt

If you already mapped your metagenome against the marker DB (using a previous MetaPhlAn run), you can obtain the results in few seconds by using the previously saved --mapout file and specifying the input (--input_type mapout):

$ metaphlan metagenome.bowtie2.bz2 --nproc 5 --input_type mapout -o profiled_metagenome.txt

mapout files generated with MetaPhlAn versions below 3.0 are not compatible. Starting from MetaPhlAn 3, the BowTie2 output now includes the size of the profiled metagenome.

If --mapout is not given, the mapping output is written next to the input file (<input>.mapout.txt).

To set a different quantile for EGBs, add --stat_q_egb (see above):

$ metaphlan metagenome.fastq --mapout metagenome.bowtie2.bz2 --nproc 5 --input_type fastq --stat_q_egb 0.1 -o profiled_metagenome.txt

You can also provide an externally BowTie2-mapped SAM if you specify this format with --input_type. Two steps here: first map your metagenome with BowTie2 and then feed MetaPhlAn with the obtained SAM:

$ bowtie2 --sam-no-hd --sam-no-sq --no-unal --very-sensitive -S metagenome.sam -x metaphlan_databases/mpa_vJan26_CHOCOPhlAnSGB_202611  -U metagenome.fastq
$ metaphlan metagenome.sam --input_type sam -o profiled_metagenome.txt

MetaPhlAn estimates the unclassified fraction of the metagenome by default. If you want to scale the relative abundance profile according only to the percentage of reads mapping to a clade in the database use --skip_unclassified_estimation.

$ metaphlan metagenome.fastq --mapout metagenome.bowtie2.bz2 --nproc 5 --input_type fastq --skip_unclassified_estimation -o profiled_metagenome.txt

MetaPhlAn can also natively handle paired-end metagenomes (but does not use the paired-end information, except for when it performs subsampling on paired reads, see below), and, more generally, metagenomes stored in multiple files (but you need to specify the --mapout parameter):

$ metaphlan metagenome_1.fastq,metagenome_2.fastq --mapout metagenome.bowtie2.bz2 --nproc 5 --input_type fastq -o profiled_metagenome.txt

It is possible to subsample the reads before the MetaPhlAn run by passing the number of reads to use (which must be < than the total number of reads of the sample) to --subsampling. In the following example, subsampling to 10,000 reads:

$ metaphlan metagenome.fastq --input_type fastq --subsampling 10000 -o profiled_metagenome_subsampled_10000.txt

Since MetaPhlAn 4.1.1, it is possible to use paired-end information during subsampling (above, paired-end reads would be treated as single-end, i.e., independent). For that, use --subsampling_paired instead:

metaphlan --subsampling_paired <N_PAIRED_READS> -1 <R1_FASTQ> -2 <R2_FASTQ> --input_type fastq --subsampling_out <SUBSAMPLED_READS_OUTPUT> -o <METAPHLAN_OUTPUT> --mapout <MAPOUT>

Long reads

MetaPhlAn can profile long-read data. In this case, MetaPhlAn relies on minimap2 for mapping reads against markers. First build the minimap2 index once (see Long-read database):

metaphlan --install --long_reads --db_dir <database folder>

This is the minimal command to profile a long-read sample from a fastq file:

metaphlan metagenome.fastq --long_reads --input_type fastq --mapout <MAPOUT> --db_dir <database folder> -o profiled_metagenome.txt

If the minimap2 index is not found, MetaPhlAn stops and prints the command to build it.

The same rules apply to long-reads data to profile from sam file, however you must make sure you perfomed the mapping with Minimap2.

Database version

You can provide the specific database version with --index.

By default MetaPhlAn is run with --index latest: the latest version of the database is used; if it is not available, MetaPhlAn will try to download it.

When --index is specified, MetaPhlAn skips the check for the latest database version and run the analysis using the database version provided by --index located in --db_dir.

For advanced options and other analysis types (such as strain tracking) please refer to the full command-line options metaphlan --help.

Utility Scripts

MetaPhlAn's repository features a few utility scripts to aid in the manipulation of sample output and its visualization. These scripts can be found under the utils folder in the MetaPhlAn directory.

Merging Tables

The script merge_metaphlan_tables.py allows to combine MetaPhlAn output from several samples to be merged into one table Bugs (rows) vs Samples (columns) with the table enlisting the relative normalized abundances per sample per bug.

To merge multiple output files, run the script as below

$ merge_metaphlan_tables.py metaphlan_output1.txt metaphlan_output2.txt > output/merged_abundance_table.txt

Wildcards can be used as needed:

$ merge_metaphlan_tables.py metaphlan_output*.txt > output/merged_abundance_table.txt

Empty profiles are skipped with a warning; malformed input files stop the merge with an error.

Output files can be merged only if the profiling was performed with the same version of the MetaPhlAn database.

There is no limit to how many files you can merge.

Converting SGB profiles to the GTDB taxonomy

The script sgb_to_gtdb_profile.py allows to convert a SGB-based MetaPhlAn 4 output into a GTDB-taxonomy-based profile. The SGB-to-GTDB table for mpa_vJan26_CHOCOPhlAnSGB_202611 is included in MetaPhlAn 4.3 and is selected automatically from the database name in the profile header. GTDB covers only bacteria and archaea, so EGBs are not reported in the GTDB profile.

To do so, run the script as below

$ sgb_to_gtdb_profile.py -i metaphlan_output.txt -o metaphlan_output_gtdb.txt

Alpha and beta diversity calculation

The script calculate_diversity.R allows to compute alpha and/or beta diversity, with different metrics of choice, starting from a merged MetaPhlAn table. Available alpha-diversity metrics are richness, shannon, simpson, and gini. Available beta-diversity distance functions are bray-curtis, jaccard, weighted-unifrac, unweighted-unifrac, centered log-ratio, and aitchison. For example, to generate a beta diversity distance matrix with bray-curtis, you need to run the script as below:

Rscript calculate_diversity.R -f merged_mpa4_profiles.tsv -d beta -m bray-curtis

To compute UniFrac distances, the SGB tree in the Newick format must be provided. The tree of the mpa_vJan26_CHOCOPhlAnSGB_202611 database is available here. The tree contains SGBs only (no EGBs).

For the full list of options, please run:

Rscript calculate_diversity.R

Clone this wiki locally