rotifer.db.sql.sqlite3.GeneNeighborhoodCursor#

class rotifer.db.sql.sqlite3.GeneNeighborhoodCursor(path, replace=False, identical=None, identical_column='c100i100', 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=False, *args, **kwargs)[source]#

Bases: GeneNeighborhoodCursor, BaseSQLite3Cursor

Fetch gene neighborhoods cached in a local SQLite3 database.

All parameters accepted at initialization are also exposed as mutable attributes that can be changed between calls to tune the cursor’s behaviour. Failed lookups are tracked through the inherited missing registry.

Parameters:
pathstr

Path to a SQLite3 database file.

replacebool, default False

If True, overwrite the database file.

columnstr, default ‘pid’

Name of the features table column to match against the queried accessions. See rotifer.genome.data.NeighborhoodDF.

beforeint, default 7

Keep at most this number of features, of the same type as the target, upstream of each target.

afterint, default 7

Keep at most this number of features, of the same type as the target, downstream of each target.

min_block_distanceint, default 0

Minimum distance between two consecutive blocks.

strandstr, optional

How to evaluate rows relative to the strand of the target. One of:

  • None : ignore strand

  • same : same strand as the target

    • : positive strand features and targets only

    • : negative strand features and targets only

fttypestr, default ‘same’

How to process feature types when counting neighbors:

  • same : consider only features of the same type as the target

  • any : ignore feature type when setting neighborhood boundaries

eukaryotesbool, default False

Whether the queried genomes are eukaryotic.

exclude_typelist of str, default [‘source’, ‘gene’, ‘mRNA’]

Feature types to ignore.

autopidbool, default False

Automatically set protein identifiers.

codontablestr or int, default ‘Bacterial’

Default codon table, used when not set in the data.

progressbool, default False

Whether to print a progress bar.

See also

rotifer.db.methods.GeneNeighborhoodCursor

shared gene neighborhood interface

rotifer.db.sql.sqlite3.IPGCursor

identical protein group cursor

Examples

Using the dictionary-like interface, fetch the gene neighborhood around the gene encoding a target protein:

>>> from rotifer.db.sql import sqlite3 as rdss
>>> gnc = rdss.GeneNeighborhoodCursor("genomes.sqlite3")
>>> df = gnc["EEE9598493.1"]

Fetch all gene neighborhoods for a sample of proteins:

>>> q = ['WP_012291365.1','WP_013208129.1','WP_122330970.1']
>>> df = gnc.fetchall(q)
__getitem__(accession, ipgs=None)[source]#

Fetch gene neighborhoods, dictionary style.

Parameters:
accessionstr or iterable of str

Database identifiers.

ipgspandas.DataFrame, optional

Identical protein group report used to restrict results to nucleotides confirmed by NCBI’s IPG database.

Returns:
rotifer.genome.data.NeighborhoodDF

Neighborhood rows for the found accessions. Accessions not found in the features table are registered in self.missing.

fetchall(ids, ipgs=None)[source]#

Fetch all gene neighborhoods at once.

Parameters:
idslist of str

Database identifiers.

ipgspandas.DataFrame, optional

Identical protein group report, passed through to __getitem__() to avoid recomputing it.

Returns:
rotifer.genome.data.NeighborhoodDF

Examples

>>> from rotifer.db.sql import sqlite3 as rdss
>>> gnc = rdss.GeneNeighborhoodCursor("genomes.sqlite3")
>>> n = gnc.fetchall(['WP_063732599.1'])
fetchone(proteins, ipgs=None)[source]#

Iterate over gene neighborhoods, one block at a time.

Parameters:
proteinslist of str

Database identifiers.

ipgspandas.DataFrame, optional

Identical protein group report, passed through to __getitem__() to avoid recomputing it.

Yields:
rotifer.genome.data.NeighborhoodDF

The rows of one neighborhood block.

Examples

>>> from rotifer.db.sql import sqlite3 as rdss
>>> gnc = rdss.GeneNeighborhoodCursor("genomes.sqlite3", progress=True)
>>> for n in gnc.fetchone(['WP_063732599.1']):
...     print(n.groupby('nucleotide').block_id.nunique())
insert(data)[source]#

Store genome annotation data in the SQLite3 database.

Rows already present in the features table (matched by block_id) are skipped.

Parameters:
datarotifer.genome.data.NeighborhoodDF

Gene neighborhood dataframe.