napistu.ontologies.renaming

Module for handling ontology aliases and validation.

Functions

rename_species_ontologies(sbml_dfs[, aliases])

Rename ontologies in the species identifiers table of an SBML_dfs object using provided aliases.

napistu.ontologies.renaming._create_alias_mapping(ontology_dict: Dict[str, Set[str]]) Dict[str, str]

Create a mapping from aliases to canonical ontology names.

Only creates mappings for the aliases specified in the input dictionary. Does not include mappings for canonical names to themselves.

Parameters:

ontology_dict (Dict[str, Set[str]]) – Dictionary mapping ontologies to their aliases

Returns:

Dictionary mapping each alias to its canonical ontology name

Return type:

Dict[str, str]

napistu.ontologies.renaming._log_ontology_updates(alias_mapping: Dict[str, str], species_ontologies: Set[str]) None

Log which ontology aliases will be updated.

Parameters:
  • alias_mapping (Dict[str, str]) – Dictionary mapping old ontology names to new ones

  • species_ontologies (Set[str]) – Set of ontology names present in the species identifiers

Raises:

ValueError – If there is no overlap between the aliases and species ontologies

napistu.ontologies.renaming.rename_species_ontologies(sbml_dfs: SBML_dfs, aliases={'corum': {'CORUM'}, 'ensembl_gene': {'ensembl_gene_id'}, 'ncbi_entrez_gene': {'ncbi_gene', 'ncbigene'}, 'signor': {'SIGNOR'}, 'uniprot': {'Uniprot'}})

Rename ontologies in the species identifiers table of an SBML_dfs object using provided aliases.

This function updates the ontology names in the species identifiers of the given SBML_dfs object according to the provided alias mapping. It validates the alias mapping, logs which ontologies will be updated, and replaces any matching aliases in the species identifiers with their canonical ontology names.

Parameters:
  • sbml_dfs (napistu.sbml_dfs_core.SBML_dfs) – The SBML_dfs object whose species table will be updated in-place.

  • aliases (dict[str, set[str]], optional) – Dictionary mapping canonical ontology names to sets of their aliases. By default, uses ONTOLOGY_SPECIES_ALIASES. All keys must be valid ontologies from ONTOLOGIES_LIST. Values must not overlap between keys or with keys themselves.

Returns:

The function updates sbml_dfs.species in-place and does not return a value.

Return type:

None

Raises:

ValueError – If the alias mapping is invalid (e.g., keys not in ONTOLOGIES_LIST, overlapping values, or values used as keys), or if there is no overlap between the provided aliases and the ontologies present in the species identifiers.

Examples

>>> from napistu.ontologies.renaming import rename_species_ontologies
>>> sbml_dfs = ...  # an SBML_dfs object
>>> aliases = {"ncbi_entrez_gene": {"ncbigene", "ncbi_gene"}, "uniprot": {"uniprot_id"}}
>>> rename_species_ontologies(sbml_dfs, aliases)