rotifer.db.ncbi.TaxonomyCursor#

class rotifer.db.ncbi.TaxonomyCursor(readers=['ete3', 'entrez'], writers=[], progress=True, tries=3, sleep_between_tries=1, batch_size=None, threads=None, *args, **kwargs)[source]#

Bases: SequentialDelegatorCursor

Fetch NCBI Taxonomy data as dataframes.

Taxonomy identifiers are first searched in the local ETE toolkit copy of the NCBI Taxonomy database and only the identifiers not found there are sent to NCBI Entrez.

Parameters:
readerslist of str, default ['ete3', 'entrez']

Backend reader modules, tried in order.

writerslist of str, default []

Backend writer modules.

progressbool, default True

Whether to print a progress bar.

triesint, default 3

Number of attempts to download data.

sleep_between_triesint, default 1

Number of seconds to wait between download attempts.

batch_sizeint, optional

Number of accessions per batch.

threadsint, optional

Number of simultaneous threads.

Attributes:
taxcolslist of str

Columns of the returned dataframes: taxid, organism, superkingdom, lineage, classification and alternative_taxids.

Examples

>>> from rotifer.db import ncbi
>>> tc = ncbi.TaxonomyCursor(progress=False)
>>> t = tc.fetchall([2599])
__getitem__(accessions, *args, **kwargs)[source]#

Fetch taxonomy data for one or more taxids, dictionary style.

Parameters:
accessionsint, str or iterable

NCBI Taxonomy identifiers.

Returns:
pandas.DataFrame

One row per taxon, with the columns listed in taxcols.

Examples

>>> from rotifer.db import ncbi
>>> tc = ncbi.TaxonomyCursor(progress=False)
>>> t = tc[2599]
fetchall(accessions, *args, **kwargs)[source]#

Fetch taxonomy data for all taxids as one dataframe.

Parameters:
accessionslist

NCBI Taxonomy identifiers.

Returns:
pandas.DataFrame

One row per taxon, with the columns listed in taxcols.

getids(obj, *args, **kwargs)[source]#

Extract taxonomy identifiers from taxonomy dataframes.

Parameters:
objpandas.DataFrame or list of pandas.DataFrame

Taxonomy dataframes produced by the cursor.

Returns:
set of str

All identifiers in the taxid and alternative_taxids columns.