rotifer.db.methods.GeneNeighborhoodCursor#

class rotifer.db.methods.GeneNeighborhoodCursor[source]#

Bases: object

Mixin for cursors that return gene neighborhood dataframes.

A gene neighborhood is the set of annotated features located around a target gene, identified by the accession of its protein product. Neighborhood tables follow the layout of rotifer.genome.data.NeighborhoodDF.

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

Fetch all gene neighborhoods as a single dataframe.

Parameters:
accessionslist of str

NCBI protein identifiers.

ipgspandas.DataFrame, optional

Precomputed identical protein group reports, passed to fetchone to avoid repeated downloads.

Returns:
rotifer.genome.data.NeighborhoodDF

The concatenated neighborhoods.

genome_ids(obj)[source]#

Extract genome identifiers from neighborhood dataframes.

Parameters:
objpandas.DataFrame or list of pandas.DataFrame

Neighborhood dataframes.

Returns:
set of str

The unique values of the cursor’s target column, usually assembly accessions.

getids(obj, ipgs=None)[source]#

Extract protein accessions from neighborhood data.

Parameters:
objpandas.DataFrame, str or iterable

A neighborhood dataframe, a single accession or an iterable of accessions. For dataframes, the columns named by the cursor’s column attribute are scanned, plus the pid, replaced and representative columns when proteins are being searched.

ipgspandas.DataFrame, optional

Identical protein group reports. When given, accessions that share an IPG with the identifiers found in obj are also returned.

Returns:
set of str

Protein accessions.

ipg_proteins(ipgs)[source]#

List every protein accession mentioned in IPG reports.

Parameters:
ipgspandas.DataFrame

Identical protein group reports.

Returns:
set of str

The union of the pid and representative columns.

ipgs_to_dict(ipgs, column='assembly')[source]#

Group IPG rows and map each protein to its representative.

Parameters:
ipgspandas.DataFrame

Identical protein group reports.

columnstr, default ‘assembly’

Column to group by, usually assembly or nucleotide.

Returns:
dict

Keys are the values of column; values are dictionaries mapping each protein accession (pid) to its IPG representative.