Skip to main content

TaxonTools

TaxonTools can help you use NCBI Taxonomy database

Installation

pip install taxontools

Usage

StoreTaxonDB: convert NCBI Taxonomy database to sqlite format

usage: TaxonTools StoreTaxonDB [-h] taxdump_tar_gz_file taxdump_db_file

positional arguments:
  taxdump_tar_gz_file  Path for taxdump.tar.gz file
  taxdump_db_file      Path for sqlite3 file

optional arguments:
  -h, --help           show this help message and exit

ID2Lineage: extract taxonomy information and lineage information from NCBI Taxonomy database by taxon ID

usage: TaxonTools ID2Lineage [-h] [-l TAXON_ID_LIST] [-o OUTPUT_FILE] taxdump_db_file

positional arguments:
  taxdump_db_file       Path for taxdump_db_file from StoreTaxonDB

optional arguments:
  -h, --help            show this help message and exit
  -l TAXON_ID_LIST, --taxon_id_list TAXON_ID_LIST
                        query taxon ID, you can give me a file path or taxon IDs separate by comma
  -o OUTPUT_FILE, --output_file OUTPUT_FILE
                        Output file name (default as $STDOUT)

Name2Lineage: extract taxonomy information and lineage information from NCBI Taxonomy database by taxon Name

usage: TaxonTools Name2Lineage [-h] [-l TAXON_NAME_LIST] [-o OUTPUT_FILE] taxdump_db_file

positional arguments:
  taxdump_db_file       Path for taxdump_db_file from StoreTaxonDB

optional arguments:
  -h, --help            show this help message and exit
  -l TAXON_NAME_LIST, --taxon_name_list TAXON_NAME_LIST
                        query taxon Name, you can give me a file path or taxon names separate by comma
  -o OUTPUT_FILE, --output_file OUTPUT_FILE
                        Output file name (default as $STDOUT)

Example

  1. Download NCBI Taxonomy database
wget ftp://ftp.ncbi.nlm.nih.gov/pub/taxonomy/taxdump.tar.gz
  1. Convert NCBI Taxonomy database to sqlite format
TaxonTools StoreTaxonDB taxdump.tar.gz taxdump.db
  1. Extract taxonomy information and lineage information from NCBI Taxonomy database by taxon ID
# query taxon ID 9606,10090,10116
TaxonTools ID2Lineage -l 9606,10090,10116 -o taxon_lineage.txt taxdump.db
# query taxon ID from file
TaxonTools ID2Lineage -l taxon_id_list.txt -o taxon_lineage.txt taxdump.db
  1. Extract taxonomy information and lineage information from NCBI Taxonomy database by taxon Name
# query taxon ID Arabidopsis thaliana, Mus musculus, Rattus norvegicus
TaxonTools Name2Lineage -l "Arabidopsis\ thaliana,Mus\ musculus,Rattus\ norvegicus" -o taxon_lineage.txt taxdump.db
# query taxon ID from file
TaxonTools Name2Lineage -l taxon_name_list.txt -o taxon_lineage.txt taxdump.db
  1. Use in python
  • convert NCBI taxonomy database to sqlite3 file
from taxontools import build_taxon_database, store_taxon_record_into_sqlite

taxon_record_dict = build_taxon_database(taxdump_tar_gz_file)
store_taxon_record_into_sqlite(taxon_record_dict, taxdump_db_file)
  • extract taxon record by taxon ID
from taxontools import read_taxon_record_dict_db

tax_id = '3702'
taxon_dict = read_taxon_record_dict_db(
    taxdump_db_file, tax_id_list=[tax_id])
vars(taxon_dict[tax_id])
  • extract taxon record by taxon name
from taxontools import read_taxon_name_record_dict_db

tax_name = 'Arabidopsis thaliana'
taxon_dict = read_taxon_name_record_dict_db(
    taxdump_db_file, tax_name_list=[tax_name])
vars(taxon_dict[tax_name])
  • get MRCA of a taxon list and common tree
from taxontools import get_MRCA_taxon_id

tax_id_list = ['3702', '4128']
taxon_dict = read_taxon_record_dict_db(
    taxdump_db_file, tax_id_list=tax_id_list)
MRCA_id = get_MRCA_taxon_id([taxon_dict[i] for i in taxon_dict])
print(read_taxon_record_dict_db(
    taxdump_db_file, tax_id_list=[MRCA_id])[MRCA_id])
  • get common tree
from taxontools import get_common_tree
from Bio import Phylo

tax_id_list = ['3702', '4128', '4081']
common_tree = get_common_tree(tax_id_list, taxdump_db_file)
Phylo.draw_ascii(common_tree)

Metadata

Release files for taxontools 0.2.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for taxontools 0.2.1
File Size Uploaded Provenance Actions
taxontools-0.2.1.tar.gz 74.9 kB Without provenance Details for taxontools-0.2.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for taxontools 0.2.1
File Interpreter ABI Platform Actions
taxontools-0.2.1-py3-none-any.whl Python 3 none any Details for taxontools-0.2.1-py3-none-any.whl

Total release size: 151.3 kB

Release files / taxontools-0.2.1.tar.gz

Download URL taxontools-0.2.1.tar.gz
Size 74.9 kB
Tags Source
SHA-256 checksum
How to use checksums
517dcccbb253ba9e0cf52e16feb7c42cee597a4d1093fdcf2475cb9b5aae7e4b
BLAKE2b-256 checksum
How to use checksums
22166628ccf99df94f096b05208b38ff67c5c0ba34830d61cf062f3881e747f3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.9.13

Release files / taxontools-0.2.1-py3-none-any.whl

Download URL taxontools-0.2.1-py3-none-any.whl
Size 76.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
4a8dcab28782539181b6d9f58b3776b0fa1a26fcbd8243d9c0926bd2cac8053e
BLAKE2b-256 checksum
How to use checksums
4fd0afee10b649889428df3933b1811c6eccd7efcfbbc7ae8d08ebbf17c84588
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.9.13

Security for taxontools 0.2.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page