Taxonomy
Prints the full taxonomic classification of organisms from gi numbers, NCBI taxIDs, or Latin names. Essential tool for taxonomic analysis that integrates with the BBTools taxonomy ecosystem including database setup automation and classification workflows.
Overview
The taxonomy tool is part of BBTools' comprehensive taxonomy package designed for processing NCBI taxonomy information. It provides taxonomic classification for sequences and organisms using various identifier formats, working in conjunction with other BBTools taxonomy utilities to enable sequence filtering, binning, and classification workflows.
Related Tools and Workflows
- fetchTaxonomy.sh (pipelines/): Automates taxonomy database setup from NCBI
- gi2taxid.sh: Converts gi/accession numbers to taxIDs for efficient processing
- filterbytaxa.sh: Filters sequences by taxonomic classification
- splitbytaxa.sh: Bins sequences into taxonomic groups
- BBSketch + Seal: Content-based taxonomic classification
- JGI Taxonomy Server: Web-based alternative at taxonomy.jgi.doe.gov
Database Setup
Before using taxonomy.sh, you must set up NCBI taxonomy databases. The simplest approach uses the automated pipeline script:
Automated Setup (Recommended)
# Navigate to desired taxonomy directory
cd /usr/tax/
# Run automated fetch and format script
fetchTaxonomy.sh
# Use with taxonomy tools
taxonomy.sh taxpath=/usr/tax/ homo_sapiens
Manual Setup (Advanced Users)
# Download taxonomy data from NCBI
wget ftp://ftp.ncbi.nih.gov/pub/taxonomy/taxdmp.zip
wget ftp://ftp.ncbi.nih.gov/pub/taxonomy/accession2taxid/*.gz
# Extract and process taxonomy files
unzip taxdmp.zip
taxtree.sh names.dmp nodes.dmp tree.taxtree.gz
# Optional: Create gi table for gi number support
gitable.sh shrunk.*.accession2taxid.gz gitable.int1d.gz
Memory Requirements
- TaxTree only: ~500MB RAM, loads in seconds
- With GI table: ~4GB RAM, loads in ~1 minute
- With accessions: ~45GB RAM, loads in ~10 minutes
Recommendation: Use taxID format (tid|123|) for sequences to avoid loading large mapping tables.
Supported Sequence Formats
The taxonomy tool recognizes six standard sequence header formats. Understanding these formats is crucial for proper taxonomic identification:
1. NCBI Taxonomic Identifier (Recommended)
>tid|123|other stuff
Advantage: Fastest processing, lowest memory usage, no lookup tables required.
2. GI Number (Legacy NCBI)
>gi|123|other stuff
Requirements: Requires gitable.int1d.gz file (~4GB RAM).
3. Accession Number (Current NCBI)
>AC1234.1 other stuff
Requirements: Requires accession2taxid files (~45GB RAM).
4. Latin Scientific Names
>Homo_sapiens
>Escherichia_coli
>Gammaproteobacteria
Format: Genus_species or higher taxonomic levels. Case-insensitive, underscores optional.
5. Silva Database Format
>GCVF01000431.1.2369 Bacteria;Proteobacteria;Gammaproteobacteria;...
Requirements: Use silva=t parameter. Semicolon-delimited taxonomy follows accession.
6. IMG Database Format
>2547132486 EuzAGGAGA464_NODE_7_len_49232_cov_91_7699...
>img|2547132486| other stuff
>tid|123|img|2547132486| other stuff
Usage: For IMG genome data, often used with renameimg.sh preprocessing.
Basic Usage
taxonomy.sh tree=<tree file> <identifier>
taxonomy.sh tree=<tree file> in=<file>
The taxonomy tool accepts organism identifiers as command-line arguments or reads them from input files. For users at NERSC/Genepool, use tree=auto to access pre-built databases.
Parameters
Processing Parameters
- in=<file>
- Input file containing named sequences or organism identifiers. Supports FASTA, FASTQ, or text format.
- out=<file>
- Output file for taxonomic classifications. If blank, prints to stdout.
- tree=<file>
- TaxTree file like tree.taxtree.gz containing NCBI taxonomic hierarchy. Use 'auto' on Genepool/NERSC.
- gi=<file>
- GI table file like gitable.int1d.gz for gi number to taxID mapping. Use 'auto' on Genepool. Only needed for gi| format sequences.
- accession=<file>
- Comma-delimited NCBI accession to taxID files. Requires ~45GB memory for complete NCBI data. Use 'auto' on Genepool. Only needed for accession format sequences.
- level=null
- Extract specific taxonomic level (species, genus, family, order, class, phylum, kingdom, superkingdom). Default prints full lineage.
- minlevel=-1
- Minimum taxonomic level to print. Use -1 for no restriction. Filters lower levels from multi-level output.
- maxlevel=life
- Maximum taxonomic level to print. Default 'life' includes all levels. Useful for excluding root-level classifications.
- silva=f
- Enable Silva database parsing mode. Set to true for semicolon-delimited taxonomic strings in Silva format.
- taxpath=auto
- Path to taxonomy database directory. 'auto' only works at NERSC. For other sites, specify full path like /usr/tax/
Additional Processing Parameters
- counts=<file>
- Output file for taxonomic node counts. Records number of sequences classified at each taxonomic node.
- verbose=f
- Print verbose status messages during processing. Helpful for monitoring large dataset processing.
- table=<file>
- Alias for gi parameter. Specify gitable file for gi number to taxID mapping.
- printname=t
- Print query identifier before taxonomy result. Essential for tracking results in batch processing.
- reverse=t
- Reverse taxonomic level order in output. True prints specific-to-general (species→kingdom), false prints general-to-specific.
- unite=f
- Enable UNITE database mode for fungal taxonomy. Adjusts parsing for UNITE-specific formatting conventions.
- simple=f
- Skip non-canonical taxonomic levels. Only includes standard ranks: kingdom, phylum, class, order, family, genus, species.
- column=-1
- Parse taxonomy from specific column in tab-delimited files. Enables in-place taxonomy translation for structured datasets.
- name=<string>
- Specify organism names as comma-delimited list. Alternative to individual command-line arguments.
- names=<string>
- Alias for name parameter. Comma-delimited organism name specification.
- id=<string>
- Specify organism IDs as comma-delimited list. Accepts taxIDs, gi numbers, or accessions.
- ids=<string>
- Alias for id parameter. Comma-delimited organism ID specification.
Java Parameters
- -Xmx
- Java memory allocation. -Xmx20g specifies 20GB RAM, -Xmx200m specifies 200MB. Maximum typically 85% of physical memory. Large taxonomy databases require substantial memory allocation.
- -eoom
- Exit on out-of-memory exception. Requires Java 8u92+. Prevents hanging when taxonomy databases exceed available memory.
- -da
- Disable Java assertions. Minor performance improvement for production use.
Examples
Basic Organism Lookup
taxonomy.sh tree=tree.taxtree.gz homo_sapiens canis_lupus 9606
Look up taxonomy for human (Latin name), dog (Latin name), and human (NCBI taxID). Demonstrates multiple identifier types in single command.
Processing FASTA Sequences
taxonomy.sh tree=tree.taxtree.gz gi=gitable.int1d.gz in=sequences.fasta out=taxonomy_results.txt
Process FASTA file containing sequences with gi numbers in headers. Outputs complete taxonomic classifications for each sequence.
Specific Taxonomic Level Extraction
taxonomy.sh tree=tree.taxtree.gz level=genus in=species_list.txt
Extract only genus-level classification from organism list. Useful for taxonomic summarization at specific ranks.
Silva Database Processing
taxonomy.sh tree=tree.taxtree.gz silva=t in=silva_sequences.fasta
Process Silva-formatted sequences with semicolon-delimited taxonomy strings. Essential for 16S rRNA analysis workflows.
Taxonomic Range Filtering
taxonomy.sh tree=tree.taxtree.gz minlevel=family maxlevel=kingdom in=organisms.txt
Display taxonomic levels from family to kingdom only. Excludes species/genus details for higher-level analysis.
Using Automated Database Setup
# Setup taxonomy databases
cd /path/to/taxonomy/
fetchTaxonomy.sh
# Use with custom taxonomy path
taxonomy.sh taxpath=/path/to/taxonomy/ tree=auto gi=auto escherichia_coli
Complete workflow from database setup to organism lookup using automated taxonomy database creation.
Alternative: JGI Taxonomy Server
# Instead of local databases, use web service
gi2taxid.sh in=sequences.fa out=renamed.fa server
# Or query directly via web browser
# https://taxonomy.jgi.doe.gov/name/homo_sapiens,escherichia_coli
# https://taxonomy.jgi.doe.gov/id/9606
# https://taxonomy.jgi.doe.gov/gi/123456
Demonstrates JGI taxonomy server as alternative to local database processing, useful for occasional queries without database setup.
Algorithm Details
The taxonomy tool implements high-performance taxonomic classification using PrintTaxonomy.java with optimized TaxTree data structures and multi-stage identifier resolution.
Core Processing Architecture
PrintTaxonomy orchestrates taxonomic lookup through specialized processing pipelines:
- processNames(): Command-line identifier processing with direct taxLevelExtended comparison for immediate results
- processFile(): TextFile line-by-line processing with optional keyColumn extraction for structured data
- processReads(): ConcurrentReadInputStream processing enabling multi-threaded FASTA/FASTQ sequence handling
- parseNodeFromHeader(): Delegates to TaxTree.parseNodeFromHeader() for identifier pattern recognition and extraction
TaxTree Data Structure Implementation
The TaxTree class maintains NCBI's complete taxonomic hierarchy using memory-optimized storage:
- nodes array: Direct O(1) access to TaxNode objects indexed by taxonomic ID, enabling instant lookups
- nameMap HashMap: Scientific name to node list mapping with collision handling for synonyms and alternative names
- getNodesByNameExtended(): Returns List<TaxNode> supporting multiple matches for ambiguous scientific names
- levelExtended encoding: Numeric hierarchy levels enabling efficient parent-child traversal and level filtering
Multi-Stage Identifier Resolution
Three specialized mapping systems handle different NCBI identifier formats with optimized storage:
- GiToTaxid.initialize(): Integer array mapping from gi numbers to taxIDs, requires ~4GB RAM for complete NCBI gi database
- AccessionToTaxid.load(): HashMap-based string mapping from accessions to taxIDs, requires ~45GB RAM for complete NCBI accession database
- TaxTree.parseNodeFromHeader(): Regular expression pattern matching for embedded identifiers in sequence headers across multiple formats
- Direct taxID resolution: Array index access via tree.getNode(taxID) provides fastest possible lookup performance
Tree Traversal and Lineage Generation
Taxonomic lineage construction uses parent-following traversal with intelligent filtering:
- Parent traversal loop: while(tn.id != tn.pid) using tn=tree.getNode(tn.pid) follows parent links to root
- Level-based filtering: tn.levelExtended comparisons against minLevelExtended/maxLevelExtended parameters enable taxonomic range selection
- Canonical rank filtering: tn.isSimple() method excludes non-standard taxonomic ranks like 'no rank' and intermediate levels
- Output formatting: TextStreamWriter with configurable tab-delimited level/id/name structure or semicolon-delimited format
Output Generation Strategies
Multiple output methods accommodate different analytical workflows:
- printTaxonomy(): Complete lineage generation with tab-delimited level/id/name format for comprehensive taxonomic information
- printTaxLevel(): Single taxonomic level extraction using level comparison and parent traversal until target level reached
- makeTaxLine(): Semicolon-delimited format with level__name structure compatible with phylogenetic analysis tools
- translateLine(): In-place column replacement for tab-delimited files, enabling taxonomy annotation of existing datasets
Memory Management and Scalability
Resource usage scales with database components loaded:
- TaxTree only: NCBI nodes array with HashMap requires 8-16GB RAM, loads in 2-5 seconds
- With GiToTaxid: Additional 2-4GB memory overhead for gi number mapping, extends loading to ~1 minute
- With AccessionToTaxid: String key HashMap storage requires ~45GB for complete NCBI accession data, loading takes 5-10 minutes
- Processing throughput: Limited by identifier resolution speed rather than tree traversal, which operates at array access speeds
Concurrency and Thread Safety
Multi-threaded processing components enable scalable sequence analysis:
- ConcurrentReadInputStream: Multi-threaded FASTA/FASTQ parsing with configurable thread pools for high-throughput processing
- TextStreamWriter: Thread-safe output stream management with internal buffering and synchronization
- Immutable TaxTree: Read-only tree structure after loading supports unlimited concurrent access without synchronization overhead
- Thread-safe mappings: GiToTaxid and AccessionToTaxid provide concurrent lookup capability across processing threads
Taxonomy Database Management
Understanding taxonomy database requirements and setup procedures is essential for effective use of the taxonomy tool.
Database Files Overview
- tree.taxtree.gz: Core taxonomic hierarchy (REQUIRED, ~500MB-2GB)
- gitable.int1d.gz: GI number mappings (optional, ~2-4GB)
- *.accession2taxid.gz: Accession mappings (optional, ~20-45GB)
NCBI Data Sources
# Core taxonomy data (always required)
ftp://ftp.ncbi.nih.gov/pub/taxonomy/taxdmp.zip
# Accession mappings (optional, for accession format sequences)
ftp://ftp.ncbi.nih.gov/pub/taxonomy/accession2taxid/nucl_gb.accession2taxid.gz
ftp://ftp.ncbi.nih.gov/pub/taxonomy/accession2taxid/nucl_wgs.accession2taxid.gz
ftp://ftp.ncbi.nih.gov/pub/taxonomy/accession2taxid/prot.accession2taxid.gz
# ... additional accession2taxid files as needed
Database Generation Commands
# Extract and process core taxonomy
unzip taxdmp.zip
taxtree.sh names.dmp nodes.dmp tree.taxtree.gz
# Generate accession mappings (if needed)
gitable.sh nucl_gb.accession2taxid.gz,nucl_wgs.accession2taxid.gz gitable.int1d.gz
Sequence Optimization Workflow
To minimize memory requirements and maximize performance, convert sequences to taxID format:
# Convert gi/accession sequences to taxID format (recommended)
gi2taxid.sh in=sequences.fasta out=renamed.fasta tree=auto table=auto accession=auto taxpath=/path/to/taxonomy/
# Now use taxonomy tool with minimal memory
taxonomy.sh tree=tree.taxtree.gz in=renamed.fasta out=results.txt
Database Location Strategies
- NERSC/Genepool users: Use tree=auto, gi=auto, accession=auto parameters
- Other users: Specify full paths or use taxpath parameter for database directory
- Shared systems: Install databases in /usr/local/tax/ or similar shared location
- Personal use: Create taxonomy directory in home directory or project space
Integration with BBTools Ecosystem
The taxonomy tool serves as a foundation for BBTools' comprehensive taxonomic analysis capabilities.
Preprocessing Pipeline
# 1. Setup taxonomy databases
fetchTaxonomy.sh
# 2. Convert sequences to efficient taxID format
gi2taxid.sh in=sequences.fa out=renamed.fa taxpath=/taxonomy/path/
# 3. Get taxonomic classifications
taxonomy.sh tree=auto in=renamed.fa out=classifications.txt taxpath=/taxonomy/path/
Taxonomic Filtering Workflow
# Filter sequences by taxonomy
filterbytaxa.sh in=sequences.fa out=bacteria_only.fa names=Bacteria level=superkingdom include=t tree=auto
# Split sequences into taxonomic bins
splitbytaxa.sh in=sequences.fa out=%.fa level=phylum tree=auto
Abundance Analysis Integration
# Generate taxonomic counts
taxonomy.sh tree=auto in=sequences.fa counts=taxa_counts.txt
# Classify reads with Seal at specific taxonomic level
seal.sh in=reads.fq ref=database.fa out=classified.fq taxonomy level=genus tree=auto
Quality Control and Validation
- Unknown classifications: Monitor "UNKNOWN" entries in output for sequence header parsing issues
- Memory monitoring: Use -Xmx parameter tuning based on database components loaded
- Performance optimization: Convert to taxID format for repeated analyses to avoid lookup table loading
- Cross-validation: Compare results with JGI taxonomy server for critical analyses
Support and Resources
Comprehensive support resources for taxonomy tool usage and troubleshooting.
Documentation
- Primary Guide: bbtools/docs/guides/TaxonomyGuide.txt - Comprehensive taxonomy workflow documentation
- Website: bbmap.org - Latest documentation and updates
- Alternative Service: taxonomy.jgi.doe.gov - Web-based taxonomy queries
Contact and Community
- Email Support: bbushnell@lbl.gov
- Bug Reports: GitHub issues or direct email to developer
Performance Optimization Tips
- Use taxID format sequences (tid|123|) for best performance and lowest memory usage
- Load only required database components (avoid accessions if not needed)
- Consider JGI taxonomy server for occasional queries instead of local database setup
- Use fetchTaxonomy.sh for simplified database setup and maintenance