rotifer.db.ncbi.entrez.IPGCursor#

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

Bases: IPGCursor, SequenceCursor

Fetch identical protein group (IPG) reports from NCBI.

IPG reports are downloaded with EFetch from the ipg database and returned as dataframes, one row per identical sequence, with the genomic coordinates of the encoding nucleotide sequences.

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.

Notes

Three columns are added to the original NCBI report: order (position of each row within its IPG), is_query (whether the row’s protein was part of the query) and representative (the query protein that represents the IPG).

Examples

>>> from rotifer.db.ncbi import entrez
>>> ic = entrez.IPGCursor()
>>> ipgs = ic.fetchall(["WP_063732599.1"])
fetchall(accessions)[source]#

Fetch the IPG reports of all accessions as one dataframe.

Parameters:
accessionslist of str

NCBI protein accessions.

Returns:
pandas.DataFrame

The concatenated reports. Empty, but with the expected columns, when nothing could be retrieved.

fetchone(accessions)[source]#

Iterate over IPG reports as they are retrieved.

Reports whose accessions were all seen in previously yielded reports are skipped.

Parameters:
accessionslist of str

NCBI protein accessions.

Yields:
pandas.DataFrame

One IPG report per batch.

parser(stream, accession)[source]#

Parse an EFetch stream into an IPG dataframe.

Rows with malformed identifiers are dropped, query proteins are flagged in the is_query column, the original row order is recorded and each IPG is annotated with the query protein that represents it.

Parameters:
streamfile-like

Open stream returned by the fetcher.

accessionstr or iterable of str

The queried protein accessions.

Returns:
pandas.DataFrame

The parsed report.

Raises:
ValueError

If no valid IPG rows remain after error removal.