Package: taxadb
Taxadb:warning: **This project will not receive updates for the time being :warning:Taxadb is an application to locally query the ncbi taxonomy. Taxadb is written in python, and access its database using thepeeweelibrary.In brief Taxadb:is a small tool to query thencbitaxonomy.is written in python >= 3.5.has built-in support forSQLite,MySQLandPostgreSQL.has available pre-built SQLite databases.has a comprehensive API documentation.InstallationTaxadb requires python >= 3.5 to work. To install taxadb with sqlite support, simply type the following in your terminal:pip3 install taxadbIf you wish to use MySQL or PostgreSQL, please refer to the fulldocumentationUsageQuerying the DatabaseFirstly, make sure you havebuiltthe databaseBelow you can find basic examples. For more complete examples, please refer to the completeAPI documentation>>>fromtaxadb.taxidimportTaxID>>>taxid=TaxID(dbtype='sqlite',dbname='mydb.sqlite')>>>name=taxid.sci_name(33208)>>>print(name)Metazoa>>>lineage=taxid.lineage_name(33208)>>>print(lineage)['Metazoa','Opisthokonta','Eukaryota','cellular organisms']>>>lineage=taxid.lineage_name(33208,reverse=True)>>>print(lineage)['cellular organism','Eukaryota','Opisthokonta','Metazoa']>>>taxid.has_parent(33208,'Eukaryota')TrueGet the taxid from a scientific name.>>>fromtaxadb.namesimportSciName>>>names=SciName(dbtype='sqlite',dbname='mydb.sqlite')>>>taxid=names.taxid('Physisporinus cinereus')>>>print(taxid)2056287Get the taxonomic information for accession number(s).>>>fromtaxadb.accessionidimportAccessionID>>>my_accessions=['X17276','Z12029']>>>accession=AccessionID(dbtype='sqlite',dbname='mydb.sqlite')>>>taxids=accession.taxid(my_accessions)>>>taxids<generatorobjecttaxidat0x1051b0830>>>>fortaxintaxids: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 setconfigparameter to__init__object method:>>>fromtaxadb.accessionidimportAccessionID>>>my_accessions=['X17276','Z12029']>>>accession=AccessionID(config='/path/to/taxadb.cfg')>>>taxids=accession.taxid(my_accessions)>>>...or set environment variableTAXADB_CONFIGwhich point to configuration file:$exportTAXADB_CONFIG='/path/to/taxadb.cfg'then>>>fromtaxadb.accessionidimportAccessionID>>>my_accessions=['X17276','Z12029']>>>accession=AccessionID()>>>taxids=accession.taxid(my_accessions)>>>...Check documentation for more information.Creating the DatabaseDownload dataThe following commands will download the necessary files from the ncbi ftp into the directorytaxadb.$ taxadb download -o taxadbInsert dataSQLite$ taxadb create -i taxadb --dbname taxadb.sqliteYou can then safely remove the downloaded files$ rm -r taxadbMySQLCreating 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;Load data$ taxadb create -i taxadb --dbname taxadb --dbtype mysql --username <user> --password <pwd> ...PostgreSQLCreating 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$ psql -U $user -d postgres
$ psql> CREATE DATABASE taxadb;Load data$ taxadb create -i taxadb --dbname taxadb --dbtype postgres --username <user> --password <pwd> ...You can easily rerun the same command,taxadbis able to skip already insertedtaxidas well asaccession.TestsYou can easily run some tests. Go to the root directory of this projectscd /path/to/taxadband runnosetests.This simple command will run tests against anSQLitetest database calledtest_db.sqlitelocated intaxadb/testdirectory.It is also possible to only run tests related to accessionid or taxid as follow$ nosetests -a 'taxid'
$ nosetests -a 'accessionid'You can also use the configuration file located in root distributiontaxadb.inias follow. This file should contains
database connection settings:$ nosetests --tc-file taxadb.iniYou can easily override configuration file settings using command line options--tcsuch as:$ nosetest --tc-file taxadb.ini --tc=sql.dbname:another_dbnameMore info atnose-testconfigRunning tests against PostgreSQL or MySQLFirst create a test database to insert test dataPostgreSQL$ createdb <test_db>or$ psql -U postgres
psql> CREATE DATABASE <test_db>;MySQL$ mysql -u root
mysql> CREATE DATABASE <test_db>;Load test dataPostgreSQL$ gunzip -c /path/to/taxadb/taxadb/test/test_mypg_db.sql.gz | psql -d <test_db> -U <user>MySQL$ gunzip -c /path/to/taxadb/taxadb/test/test_mypg_db.sql.gz | mysql -D <test_db> -u <user> -pRun testsEither edittaxadb.inito fit database configuration or use--tccommand line option and set appropriate values likeusername, password, port, hostname, dbtype(postgres or mysql), dbname.PostgreSQL$ nosetests --tc-file taxadb.ini
OR
$ nosetests -tc-file taxadb.ini --tc=sql.dbtype:postgres --tc=sql.username:postgres --tc=sql.dbname:test_db2MySQL$ nosetests --tc-file taxadb.ini
OR
$ nosetests -tc-file taxadb.ini --tc=sql.dbtype:mysql --tc=sql.username:root --tc=sql.dbname:newdbnameLicenseCode is under theMITlicense.IssuesFound a bug or have a question? Please open anissueContributingThought about a new feature that you'd like us to implement? Open anissueor fork the repository and submit apull request