rotifer.db.ncbi.entrez.SequenceCursor#

class rotifer.db.ncbi.entrez.SequenceCursor(database='nucleotide', progress=True, tries=3, sleep_between_tries=1, batch_size=20, threads=10, *args, **kwargs)[source]#

Bases: SequenceCursor, SimpleParallelProcessCursor

Fetch annotated sequences from NCBI with the E-utilities.

Sequences are downloaded with EFetch and parsed from GenBank format, the most richly annotated format NCBI provides.

Parameters:
databasestr, default ‘nucleotide’

A valid NCBI sequence database name, such as protein or nucleotide.

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. The default may be changed by the module configuration.

threadsint, default 10

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

See also

FastaCursor

faster download without annotations

rotifer.db.ncbi.SequenceCursor

delegator that combines backends

Examples

Fetch a protein sequence:

>>> from rotifer.db.ncbi import entrez
>>> sc = entrez.SequenceCursor(database="protein")
>>> seqrec = sc.fetchall("YP_009724395.1")

Fetch several nucleotide entries:

>>> import sys
>>> from Bio import SeqIO
>>> query = ['CP084314.1', 'NC_019757.1', 'AAHROG010000026.1']
>>> sc = entrez.SequenceCursor(database="nucleotide")
>>> for seqrec in sc.fetchone(query):
...     SeqIO.write(seqrec, sys.stdout, "genbank")
__getitem__(accession)[source]#

Download data for one batch of entries, dictionary style.

Entries that fail with a recoverable error are retried once in a second pass.

Parameters:
accessionstr or iterable of str

NCBI database entry identifiers. A string may contain several accessions separated by commas.

Returns:
Bio.SeqRecord.SeqRecord or list of Bio.SeqRecord.SeqRecord

A single record when a single accession yields a single record, otherwise a list.

fetcher(accession)[source]#

Run EFetch and return the response stream.

Parameters:
accessionstr or iterable of str

Database entry identifiers.

Returns:
file-like

The open EFetch response.

parser(stream, accession)[source]#

Parse an EFetch stream into sequence records.

Parameters:
streamfile-like

Open stream returned by fetcher().

accessionstr or iterable of str

Database entry identifiers, kept for interface compatibility.

Returns:
list of Bio.SeqRecord.SeqRecord

The parsed records.