rotifer.db.ncbi.entrez.GeneNeighborhoodCursor#
- class rotifer.db.ncbi.entrez.GeneNeighborhoodCursor(column='pid', before=7, after=7, min_block_distance=0, strand=None, fttype='same', eukaryotes=False, exclude_type=['source', 'gene', 'mRNA'], autopid=False, codontable='Bacterial', progress=True, tries=3, sleep_between_tries=1, batch_size=20, threads=10)[source]#
Bases:
GeneNeighborhoodCursor,NucleotideFeaturesCursorFetch gene neighborhoods from nucleotide annotation.
Target proteins are first resolved to nucleotide sequences through identical protein group (IPG) reports, and the annotated regions around each target are then extracted from the nucleotide entries downloaded with EFetch. This backend does not require a genome assembly, so it also covers proteins encoded on unassembled sequences.
- Parameters:
- columnstr, default ‘pid’
Name of the column to scan for matches to the accessions. See
rotifer.genome.data.NeighborhoodDF.- beforeint, default 7
Keep at most this number of features, of the same type as the target, before each target.
- afterint, default 7
Keep at most this number of features, of the same type as the target, after each target.
- min_block_distanceint, default 0
Minimum distance between two consecutive blocks.
- strandstr, optional
How to evaluate rows concerning the value of the strand column. Supported values:
None: ignore strandsame: same strand as the targets+: positive strand features and targets only-: negative strand features and targets only
- fttype{‘same’, ‘any’}, default ‘same’
How to process feature types of neighbors. With
same, only features of the same type as the target are considered. Withany, all features count when setting neighborhood boundaries.- eukaryotesbool, default False
Whether to process eukaryotic nucleotide sequences.
- exclude_typelist of str, default
['source', 'gene', 'mRNA'] Feature types to ignore.
- autopidbool, default False
Automatically set protein identifiers.
- codontablestr or int, default ‘Bacterial’
Codon table used when the data does not define one.
- 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.
See also
rotifer.db.ncbi.GeneNeighborhoodCursordelegator that combines this backend with the FTP and mirror backends
Examples
>>> from rotifer.db.ncbi import entrez >>> gnc = entrez.GeneNeighborhoodCursor(progress=True) >>> df = gnc.fetchall(["EEE9598493.1"])
- __getitem__(accessions, ipgs=None)[source]#
Find gene neighborhoods around one or more target proteins.
- Parameters:
- accessionsstr or iterable of str
NCBI protein accessions.
- ipgspandas.DataFrame, optional
Precomputed identical protein group reports. When not given, they are downloaded with
IPGCursor.
- Returns:
- rotifer.genome.data.NeighborhoodDF
The neighborhoods found. Empty when nothing could be retrieved.
- fetchone(accessions, ipgs=None)[source]#
Iterate over gene neighborhoods as downloads complete.
Results are yielded in completion order, not input order.
- Parameters:
- accessionslist of str
NCBI protein identifiers.
- ipgspandas.DataFrame, optional
Precomputed identical protein group reports, used to avoid downloading IPGs again.
- Yields:
- rotifer.genome.data.NeighborhoodDF
One dataframe per retrieved gene neighborhood.
- getids2(obj, *args, **kwargs)[source]#
List protein identifiers per nucleotide sequence.
- Parameters:
- objpandas.DataFrame
A neighborhood dataframe.
- Returns:
- list of str
The identifiers found in the
pidand, when present,replacedcolumns.
- nucleotide_ids(obj)[source]#
Extract nucleotide accessions from neighborhood dataframes.
- Parameters:
- objpandas.DataFrame or list of pandas.DataFrame
Neighborhood dataframes.
- Returns:
- set of str
The unique values of the
nucleotidecolumn.
- parser(stream, accession, proteins)[source]#
Extract gene neighborhoods from a nucleotide stream.
- Parameters:
- streamfile-like
Open stream returned by the fetcher.
- accessionstr
Nucleotide accession.
- proteinsdict
Mapping of each target protein accession to its identical protein group representative.
- Returns:
- list of rotifer.genome.data.NeighborhoodDF
The neighborhoods found, one dataframe per nucleotide sequence, each with a
replacedcolumn mapping proteins to the queries they represent.
- Raises:
- ValueError
If the sequence is eukaryotic and
eukaryotesis False.
- splitter(accessions, ipgs)[source]#
Group targets and their IPG rows into per-nucleotide batches.
- Parameters:
- accessionsset of str
Target protein accessions.
- ipgspandas.DataFrame
Identical protein group reports restricted to the selected nucleotide sequences.
- Returns:
- list of list of tuple
Batches of
(proteins, ipg_rows)pairs, one pair per nucleotide sequence, at mostbatch_sizepairs per batch.
- worker(chunk)[source]#
Process one batch of nucleotide sequences in a worker process.
- Parameters:
- chunklist of tuple
Batch entries produced by
splitter(). Each entry holds a set of target protein accessions and the IPG rows of one nucleotide sequence.
- Returns:
- dict
A dictionary with two keys:
result, a list of neighborhood dataframes (one per gene block), andmissing, the registry of entries that could not be retrieved.