rotifer.db.ncbi.entrez.TaxonomyCursor#

class rotifer.db.ncbi.entrez.TaxonomyCursor(progress=True, tries=3, sleep_between_tries=1, batch_size=20, threads=10)[source]#

Bases: SequenceCursor

Fetch NCBI Taxonomy records with the E-utilities.

Taxonomy entries are downloaded as XML with EFetch and returned as dataframes.

Parameters:
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, default 20

Number of accessions per batch.

threadsint, default 10

Number of simultaneous threads. Capped at 3 without an NCBI API key and at 10 with one.

Attributes:
columnslist of str

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

See also

rotifer.db.ncbi.TaxonomyCursor

delegator that prefers the local ETE toolkit database

Examples

>>> from rotifer.db.ncbi import entrez
>>> tc = entrez.TaxonomyCursor()
>>> t = tc.fetchall([2599])
fetchall(accessions)[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 columns.

getids(obj)[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.

parser(stream, accession)[source]#

Parse an EFetch XML stream into a taxonomy dataframe.

Parameters:
streamfile-like

Open stream returned by the fetcher.

accessionstr or iterable of str

The queried taxonomy identifiers, kept for interface compatibility.

Returns:
list of pandas.DataFrame

A single element list holding the parsed dataframe.

Raises:
ValueError

If the stream contains no taxonomy records.