Get the taxonomic information for accession number(s).
>>> from taxadb.accessionid import AccessionID
>>> my_accessions = ['X17276', 'Z12029']
>>> accession = AccessionID(dbtype='sqlite', dbname='mydb.sqlite')
>>> taxids = accession.taxid(my_accessions)
>>> taxids
<generator object taxid at 0x1051b0830>
>>> for tax in taxids:
print(tax)
('X17276', 9646)
('Z12029', 9915)
You can also use a configuration file in order to automatically set database
connection parameters at object build. Either set config parameter to __init__
object method:
The following commands will download the necessary files from the ncbi ftp into the directory taxadb.
$ taxadb download -o taxadb
Insert data
SQLite
$ taxadb create -i taxadb --dbname taxadb.sqlite
You can then safely remove the downloaded files
$ rm -r taxadb
MySQL
Creating databases is a very vendor specific task. Peewee, as most ORMs, can create tables but not databases.
In order to use taxadb with MySQL, you’ll have to create the database yourself.
Connect to your mysql server
$ mysql -u $user -p
$ mysql> CREATE DATABASE taxadb;
Creating databases is a very vendor specific task. Peewee, as most ORMs, can create tables but not databases.
In order to use taxadb with PosgreSQL, you’ll have to create the database yourself.
Either edit taxadb.ini to fit database configuration or use --tc command line option and set appropriate values like
username, password, port, hostname, dbtype(postgres or mysql), dbname.
Taxadb
Taxadb is an application to locally query the ncbi taxonomy. Taxadb is written in python, and access its database using the peewee library.
In brief Taxadb:
Installation
Taxadb requires python >= 3.5 to work. To install taxadb with sqlite support, simply type the following in your terminal:
If you wish to use MySQL or PostgreSQL, please refer to the full documentation
Usage
Querying the Database
Firstly, make sure you have built the database
Below you can find basic examples. For more complete examples, please refer to the complete API documentation
Get the taxid from a scientific name.
Get the taxonomic information for accession number(s).
You can also use a configuration file in order to automatically set database connection parameters at object build. Either set
configparameter to__init__object method:or set environment variable
TAXADB_CONFIGwhich point to configuration file:then
Check documentation for more information.
Creating the Database
Download data
The following commands will download the necessary files from the ncbi ftp into the directory
taxadb.Insert data
SQLite
You can then safely remove the downloaded files
MySQL
Creating databases is a very vendor specific task. Peewee, as most ORMs, can create tables but not databases. In order to use taxadb with MySQL, you’ll have to create the database yourself.
Connect to your mysql server
Load data
PostgreSQL
Creating databases is a very vendor specific task. Peewee, as most ORMs, can create tables but not databases. In order to use taxadb with PosgreSQL, you’ll have to create the database yourself.
Connect to your postgresql server
Load data
You can easily rerun the same command,
taxadbis able to skip already insertedtaxidas well asaccession.Tests
You can easily run some tests. Go to the root directory of this projects
cd /path/to/taxadband runnosetests.This simple command will run tests against an
SQLitetest database calledtest_db.sqlitelocated intaxadb/testdirectory.It is also possible to only run tests related to accessionid or taxid as follow
You can also use the configuration file located in root distribution
taxadb.inias follow. This file should contains database connection settings:You can easily override configuration file settings using command line options
--tcsuch as:More info at nose-testconfig
Running tests against PostgreSQL or MySQL
First create a test database to insert test data
or
Load test data
PostgreSQL
MySQL
Run tests
Either edit
taxadb.inito fit database configuration or use--tccommand line option and set appropriate values likeusername, password, port, hostname, dbtype(postgres or mysql), dbname.PostgreSQL
MySQL
License
Code is under the MIT license.
Issues
Found a bug or have a question? Please open an issue
Contributing
Thought about a new feature that you’d like us to implement? Open an issue or fork the repository and submit a pull request