Metadata-Version: 2.4
Name: taxdumpy
Version: 0.1.1
Summary: Python package for efficiently parsing NCBI's taxdump database
Project-URL: Documentation, https://github.com/omegahh/taxdumpy
Project-URL: Issues, https://github.com/omegahh/taxdumpy/issues
Project-URL: Source, https://github.com/omegahh/taxdumpy
Author-email: Omega HH <omeganju@gmail.com>
License: MIT License
        
        Copyright (c) 2025 Omega HH
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
License-File: LICENSE
Keywords: NCBI,metagenomics,taxonomy,tree-of-life
Classifier: Development Status :: 5 - Production/Stable
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Requires-Python: >=3.10
Requires-Dist: rapidfuzz
Requires-Dist: tqdm
Provides-Extra: dev
Requires-Dist: black; extra == 'dev'
Requires-Dist: build; extra == 'dev'
Requires-Dist: pytest; extra == 'dev'
Description-Content-Type: text/markdown

# Taxdumpy 🧬

#### NCBI Taxonomy Toolkit for Python

*A high-performance parser for NCBI Taxonomy databases with lineage resolution and taxonomy search*

![](https://img.shields.io/badge/license-MIT-blue.svg)
![](https://img.shields.io/badge/python-3.10+-blue.svg)
![](https://img.shields.io/pypi/v/taxdumpy?color=green)

## Features

- **Blazing Fast Parsing**  
  Optimized loading of NCBI taxdump files (`nodes.dmp`, `names.dmp`, etc.) with optional pickle caching

- **Comprehensive Taxon Operations**  
  - TaxID validation and lineage tracing
  - Scientific name resolution
  - Rank-based filtering (species → kingdom)
  - Merged/deleted node handling

- **Fuzzy Search**  
  Rapid approximate name matching using `rapidfuzz` (supports misspellings)

- **Memory Efficient**  
  Lazy loading and optimized data structures for large taxonomies

## Installation

```bash
pip install taxdumpy
```

Or from source:
```bash
git clone https://github.com/yourusername/taxdumpy.git
cd taxdumpy
pip install -e .
```

## Quick Start

```python
from taxdumpy import TaxDb, Taxon

# Initialize database (auto-downloads if needed)
taxdb = TaxDb("/path/to/taxdump")

# Create taxon object
human = Taxon(9606, taxdb)  # Homo sapiens

# Access lineage
print(human.name_lineage)
# ['Homo sapiens', 'Homo', 'Hominidae', ..., 'cellular organisms']

# Search organisms
taxdb._rapid_fuzz("Influenza", limit=5)
```

## Command Line Interface

```bash
# Cache full database
taxdumpy cache -d /path/to/taxdump

# Search organism
taxdumpy search --fast "Escherichia coli"

# Trace lineage
taxdumpy lineage --fast 511145  # E. coli K-12
```

## Database Setup

1. Download NCBI taxdump:  
   ```bash
   mkdir -p ~/.taxonkit
   wget ftp://ftp.ncbi.nlm.nih.gov/pub/taxonomy/taxdump.tar.gz -P ~/.taxonkit
   tar -xzf ~/.taxonkit/taxdump.tar.gz -C ~/.taxonkit
   ```

2. (Optional) Create optimized cache:  
   ```bash
   taxdumpy cache -d ~/.taxonkit
   ```

## Advanced Usage

### Custom Caching
```python
# Fast cache with specific taxids
with open("important_taxids.txt", "w") as f:
    f.write("\n".join(["9606", "511145"]))
    
# CLI
taxdumpy fast-cache -d ~/.taxonkit -f important_taxids.txt
```

### API Reference
```python
class Taxon:
    """Represents a taxonomic unit"""
    
    @property
    def lineage(self) -> List[Node]: ...
    @property
    def rank_lineage(self) -> List[str]: ...
    @property
    def is_legacy(self) -> bool: ...
```

## Performance Tips

- Use `fast=True` when loading for ~3x speedup (requires pre-caching)
- For batch processing, reuse `TaxDb` instances
- Set `TAXDB_PATH` environment variable to avoid path repetition

## Contributing

PRs welcome! Please:
1. Format with `black`
2. Include type hints
3. Add tests under `/tests`

## License

MIT © 2025 [Omega HH](https://github.com/omegahh)
