rotifer.db.uniprot.TaxonomyCursor#

class rotifer.db.uniprot.TaxonomyCursor(readers=['webapi'], writers=[], progress=True, tries=None, batch_size=None, threads=None, *args, **kwargs)[source]#

Bases: BaseUniProtRecordCursor

Fetch taxonomy records from UniProt.

UniProt describes a taxon far more fully than a lineage: the mnemonic its entries use, the strains it covers, how many proteins and proteomes it has. Every field it returns is kept, and the six columns rotifer.db.ncbi.TaxonomyCursor produces are added alongside them, derived from the same reply. The two cursors are therefore interchangeable for code that reads taxid, organism, superkingdom, lineage, classification or alternative_taxids, and only code wanting UniProt’s own fields need care which it called.

UniProt’s lineage is a list of ancestors rather than a string, so it is kept as lineage_taxa and the lineage column holds the reduced form the rest of rotifer expects.

Parameters:
readerslist of str, default ['webapi']

Backend reader modules, tried in order. ete3 is registered as well and answers from a local copy of NCBI’s taxonomy in milliseconds, but it produces only the six shared columns, so it is not a default: a query answered by it would silently lack everything UniProt adds. Ask for it by name when the shared columns are all you need: readers=['ete3','webapi'].

writerslist of str, default []

Backend writer modules.

progressbool, default True

Whether to report progress.

triesint, optional

Attempts per request. Defaults to the backend’s own setting.

batch_sizeint, optional

Identifiers per batch.

threadsint, optional

Simultaneous workers.

**kwargs

Passed to the backends, so UniProt query parameters such as fields remain available.

See also

rotifer.db.uniprot.webapi.TaxonomyCursor

the backend this delegates to

rotifer.db.ncbi.TaxonomyCursor

the same idea, for NCBI

Examples

>>> from rotifer.db import uniprot
>>> tc = uniprot.TaxonomyCursor()
>>> df = tc.fetchall([9606, 562])
>>> df[tc.taxcols]
classification(ancestors, organism)[source]#

Flatten one lineage into the string NCBI’s cursors produce.

Parameters:
ancestorslist of dict, or None

UniProt’s lineage, root first and without the taxon itself.

organismstr or None

Scientific name of the taxon, which closes the lineage.

Returns:
str

Names separated by '; ', root first.

empty()[source]#

Build an empty result.

Returns:
pandas.DataFrame

No rows, but the shared columns, so that a caller reading one of them need not first check whether anything matched.

fetchall(accessions, *args, **kwargs)[source]#

Fetch every taxon as a single dataframe.

Parameters:
accessionsstr, int or iterable

Taxon identifiers.

Returns:
pandas.DataFrame
fetchone(accessions, *args, **kwargs)[source]#

Iterate over taxonomy records, trying each backend in turn.

Parameters:
accessionsstr, int or iterable

Taxon identifiers.

Yields:
pandas.DataFrame

One block of rows, carrying the shared columns whichever backend produced it.

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

Extract the taxon identifiers a result answers for.

Parameters:
objpandas.DataFrame, list or None
Returns:
set of str
standardize(frame)[source]#

Add the columns every rotifer taxonomy cursor produces.

Only what is absent is derived, so a backend that already speaks in these terms – ete3 does – passes through untouched.

Parameters:
framepandas.DataFrame

One result, as a backend produced it.

Returns:
pandas.DataFrame

The same rows, with the shared columns first.