A comprehensive Python package for assigning raw metagenomic sequence reads to microbial gene and pathway databases using HUMAnN4, followed by downstream processing and analysis.
- Introduction
- Installation
- Workflow Overview
- Command Line Interface
- Input Methods
- Example Workflow
- Troubleshooting
- Getting Help
- License
humann4-tools provides a complete workflow for metagenomic analysis, from quality control to visualization. The package is designed to simplify and standardize the analysis of metagenomic data using the HUMAnN4 pipeline, with modular components that can be run individually or as a complete workflow.
IMPORTANT: humann4-tools, humann4-kneaddata, and humann4-humann4 tools require an installation of the humann4 workflow and is most conveniently installed using conda. After installation and configuration of humann dependencies and databases, the conda environement will include properly configured HUMAnN4, KneadData, and other dependencies. You must activate this environment before using these tools.
# Install humann4 environment (if not already installed)
conda create -n humann4 python=3.12
conda activate humann4
conda install -c biobakery -c conda-forge -c bioconda humann>=4.0 kneaddata=0.10.0
# Download and install necessary databases
# MetaPhlAn database (required for HUMAnN4)
metaphlan --install
# Install HUMAnN databases (if not already installed)
# humann_databases --download chocophlan full /path/to/databases
# humann_databases --download uniref uniref90_diamond /path/to/databases
# humann_databases --download utility_mapping full /path/to/databasesALWAYS ENSURE humann4 ENVIRONMENT IS ACTIVATED BEFORE RUNNING ANY COMMANDS
# Make sure humann4 is activated
conda activate humann4
# Install humann4-tools from the repository
pip install git+https://github.com/haslamdb/humann4_tools.gitFor development installation:
# Clone the repository
git clone https://github.com/haslamdb/humann4_tools.git
cd humann4_tools
# Make sure humann4 is activated
conda activate humann4
# Install in development mode
pip install -e .After installation, you can use either:
- Individual commands:
humann4-kneaddata,humann4-humann4, etc. - The unified interface:
humann4-tools kneaddata,humann4-tools humann4, etc.
To verify that humann4-tools is installed correctly:
# Make sure humann4 is activated
conda activate humann4
# Check version
humann4-tools --version
# List available commands
humann4-tools --helphumann4-tools provides a modular workflow for metagenomic analysis:
- KneadData: Quality control and host depletion
- HUMAnN4: Process cleaned sequences through HUMAnN4
- Join, Normalize, Unstratify: Combine, normalize, and split HUMAnN4 output files
- Statistical Testing: Perform statistical tests across groups
- Differential Abundance: Apply methods like ALDEx2, ANCOM, and ANCOM-BC
- Visualization: Generate plots and figures for publication
humann4-tools provides a consistent command-line interface for each step of the workflow. Each command can be accessed either through the main humann4-tools command or as individual commands.
IMPORTANT: Always make sure the humann4 environment is activated before running these commands.
conda activate humann4Quality control and host depletion:
# Using the main command
humann4-tools kneaddata --input-files sample_R1.fastq.gz sample_R2.fastq.gz --paired --reference-dbs human_db --output-dir kneaddata_output
# Using the standalone command
humann4-kneaddata --input-files sample_R1.fastq.gz sample_R2.fastq.gz --paired --reference-dbs human_db --output-dir kneaddata_outputKey options:
--input-files: Input FASTQ file(s)--paired: Flag if input files are paired-end reads--reference-dbs: Path to reference database(s) for decontamination--output-dir: Directory for output files--threads: Number of threads to use
Run HUMAnN4 on cleaned sequence files:
# Using the main command
humann4-tools humann4 --input-dir kneaddata_output --output-dir humann4_output --nucleotide-db chocophlan --protein-db uniref
# Using the standalone command
humann4-humann4 --input-dir kneaddata_output --output-dir humann4_output --nucleotide-db chocophlan --protein-db unirefKey options:
--input-dir: Directory containing KneadData output files--input-files: Alternatively, specify input files directly. If --paired is selected, files will first be concatenated.--nucleotide-db: Path to nucleotide database--protein-db: Path to protein database--output-dir: Directory for output files--threads: Number of threads to use--use-parallel: Process multiple samples in parallel--bypass-prescreen: Skip MetaPhlAn taxonomic prescreen (useful if MetaPhlAn database isn't installed)
Join, normalize, and unstratify HUMAnN4 output files:
# Using the main command
humann4-tools join --input-dir humann4_output/PathwayAbundance --pathabundance --output-dir joined_output --units cpm
# Using the standalone command
humann4-join --input-dir humann4_output/PathwayAbundance --pathabundance --output-dir joined_output --units cpmKey options:
--input-dir: Directory with HUMAnN4 output files- One of:
--pathabundance,--pathcoverage, or--genefamiliesto specify file type --output-dir: Directory for output files--units: Units for normalization (cpm or relab)--update-snames: Update sample names during normalization
Run statistical tests on processed data:
# Using the main command
humann4-tools stats --abundance-file joined_output/pathabundance_cpm_unstratified.tsv --metadata-file metadata.csv --output-dir statistical_results --group-col Treatment
# Using the standalone command
humann4-stats --abundance-file joined_output/pathabundance_cpm_unstratified.tsv --metadata-file metadata.csv --output-dir statistical_results --group-col TreatmentKey options:
--abundance-file: Path to unstratified abundance file--metadata-file: Path to metadata CSV file--output-dir: Directory for output files--group-col: Column name for grouping samples--feature-type: Type of features (pathway or gene)--alpha: Significance threshold (default: 0.05)
Run differential abundance analysis:
# Using the main command
humann4-tools diff --abundance-file joined_output/pathabundance_cpm_unstratified.tsv --metadata-file metadata.csv --output-dir diff_abundance --group-col Treatment --methods aldex2,ancom,ancom-bc
# Using the standalone command
humann4-diff --abundance-file joined_output/pathabundance_cpm_unstratified.tsv --metadata-file metadata.csv --output-dir diff_abundance --group-col Treatment --methods aldex2,ancom,ancom-bcKey options:
--abundance-file: Path to unstratified abundance file--metadata-file: Path to metadata CSV file--output-dir: Directory for output files--group-col: Column name for grouping samples--methods: Methods to use (aldex2, ancom, ancom-bc)--filter-groups: Filter groups for comparison (required for ALDEx2)--exclude-unmapped: Exclude unmapped features from analysis
Create visualizations from processed data:
# Using the main command
humann4-tools viz --abundance-file joined_output/pathabundance_cpm_unstratified.tsv --metadata-file metadata.csv --output-dir visualizations --pca --heatmap --barplot
# Using the standalone command
humann4-viz --abundance-file joined_output/pathabundance_cpm_unstratified.tsv --metadata-file metadata.csv --output-dir visualizations --pca --heatmap --barplotKey options:
--abundance-file: Path to unstratified abundance file--metadata-file: Path to metadata CSV file--output-dir: Directory for output files--group-col: Column name for coloring points- Plot selection:
--pca,--heatmap,--barplot,--abundance-hist --feature: Generate boxplot for a specific feature--format: Output format (svg, png, pdf)
humann4-tools supports three different input methods across all commands:
- Direct File Input: Specify the input files directly with
--input-files - Sample List File: Provide a tab-delimited file with sample IDs and file paths using
--samples-file - Metadata-Driven: Use a metadata CSV file to locate sequence files with
--metadata-fileand--seq-dir
Example for metadata-driven workflow:
humann4-tools kneaddata --metadata-file metadata.csv --seq-dir /path/to/sequences --r1-suffix _R1.fastq.gz --r2-suffix _R2.fastq.gz --paired --reference-dbs human_dbHere's a complete example workflow:
# Activate humann4 environment (REQUIRED)
conda activate humann4
# 1. Quality control with KneadData
humann4-tools kneaddata --input-files sample1_R1.fastq.gz sample1_R2.fastq.gz --paired --reference-dbs human_db --output-dir kneaddata_output --threads 8
# 2. HUMAnN4 functional profiling
humann4-tools humann4 --input-dir kneaddata_output --output-dir humann4_output --nucleotide-db chocophlan --protein-db uniref --threads 8
# 3. Join and normalize pathway abundance files
humann4-tools join --input-dir humann4_output/PathwayAbundance --pathabundance --output-dir joined_output --units cpm
# 4. Join and normalize gene family files
humann4-tools join --input-dir humann4_output/GeneFamilies --genefamilies --output-dir joined_output --units cpm
# 5. Statistical testing
humann4-tools stats --abundance-file joined_output/pathabundance_cpm_unstratified.tsv --metadata-file metadata.csv --output-dir statistical_results --group-col Treatment
# 6. Differential abundance analysis
humann4-tools diff --abundance-file joined_output/pathabundance_cpm_unstratified.tsv --metadata-file metadata.csv --output-dir diff_abundance --group-col Treatment
# 7. Visualization
humann4-tools viz --abundance-file joined_output/pathabundance_cpm_unstratified.tsv --metadata-file metadata.csv --output-dir visualizations --pca --heatmap --barplot-
Environment Issues:
- Make sure you've activated the humann4 environment:
conda activate humann4 - If you see errors about missing databases or tools, this is often because the humann4 environment is not activated
- Make sure you've activated the humann4 environment:
-
Missing Databases:
- MetaPhlAn error: Run
metaphlan --installto install the required database - HUMAnN4 database errors: Make sure to install the ChocoPhlAn and UniRef databases
- MetaPhlAn error: Run
-
Missing Input Files:
- Check file paths and naming patterns
- Verify that you're using the correct directory structure
-
Sample Key Issues:
- Ensure sample identifiers in the CSV match the file names
- Check for duplicate sample IDs
- Verify CSV encoding (use UTF-8)
-
KneadData Errors:
- Ensure reference databases are properly built and indexed
- For paired-end issues, try different
--decontaminate-pairsoptions
-
HUMAnN4 Errors:
- If you get a "No MetaPhlAn BowTie2 database found" error, run
metaphlan --install - As a workaround, you can use
--bypass-prescreento skip the MetaPhlAn step - Ensure nucleotide and protein databases are correctly installed
- Check that input files are in the correct format
- If you get a "No MetaPhlAn BowTie2 database found" error, run
-
Statistical Test Errors:
- ALDEx2 requires exactly two groups
- Check for missing values in abundance data
-
Memory Issues with Large Datasets:
- Run steps separately to manage memory usage
- Use
--threadsto control CPU usage
If you encounter issues not covered in this documentation, please:
- Check the log file for detailed error messages
- Set
--log-level DEBUGfor more verbose output - Verify you're using the humann4 environment
- Open an issue on the GitHub repository with a description of the problem and relevant log entries
This project is licensed under the MIT License - see the LICENSE file for details.