napistu.network.data_handling

Functions

add_results_table_to_graph(napistu_graph, ...)

Add Results Table to Graph

napistu.network.data_handling._create_data_table_column_mapping(entity_data: DataFrame, attribute_names: str | List[str] | Dict[str, str], table_type: str | None = 'species') Dict[str, str]

Select attributes from an sbml_dfs data table.

This function validates the attribute names and returns a mapping of original names to new names.

Parameters:
  • entity_data (pd.DataFrame) – The data table to select attributes from.

  • attribute_names (str or list of str, optional) –

    Either:
    • The name of the attribute to add to the graph.

    • A list of attribute names to add to the graph.

    • A regular expression pattern to match attribute names.

    • A dictionary with attributes as names and re-named attributes as values.

    • If None, all attributes in the species_data table will be added.

  • table_type (str, optional) – The type of table to use. Must be one of {VALID_SBML_DFS_DATA_TYPES}. (Only used for error messages).

Returns:

A dictionary mapping original column names to their new names. For non-renamed columns, the mapping will be identity (original -> original).

Return type:

Dict[str, str]

napistu.network.data_handling._create_graph_attrs_config(column_mapping: Dict[str, str], data_type: str | None, table_name: str, transformation: str = 'identity') Dict[str, Dict[str, Dict[str, str]]] | Dict[str, Dict[str, str]]

Create a configuration dictionary for graph attributes.

Parameters:
  • column_mapping (Dict[str, str]) – A dictionary mapping original column names to their new names in the graph

  • data_type (str or None) – The type of data (e.g. “species”, “reactions”). If None, returns the inner dict directly.

  • table_name (str) – The name of the table containing the data

  • transformation (str, optional) – The transformation to apply to the data, by default “identity”

Returns:

A nested dictionary containing the graph attributes configuration If data_type is None, returns the inner dict directly: {

new_col_name: {

“table”: table_name, “variable”: original_col_name, “trans”: transformation

}

} Otherwise, returns the full nested structure: {

data_type: {
new_col_name: {

“table”: table_name, “variable”: original_col_name, “trans”: transformation

}

}

}

Return type:

Dict[str, Dict[str, Dict[str, str]]] or Dict[str, Dict[str, str]]

napistu.network.data_handling._select_sbml_dfs_data_table(sbml_dfs: SBML_dfs, table_name: str | None = None, table_type: str = 'species') DataFrame

Select an SBML_dfs data table by name and type.

This function validates the table type and name and returns the table.

Parameters:
  • sbml_dfs (sbml_dfs_core.SBML_dfs) – The sbml_dfs object containing the data tables.

  • table_name (str, optional) – The name of the table to select. If not provided, the first table of the given type will be returned.

  • table_type (str, optional) – The type of table to select. Must be one of {VALID_SBML_DFS_DATA_TYPES}.

Returns:

entity_data

Return type:

pd.DataFrame

napistu.network.data_handling.add_results_table_to_graph(napistu_graph: NapistuGraph, sbml_dfs: sbml_dfs_core.SBML_dfs, attribute_names: str | List[str] | None = None, table_name: str = None, table_type: str = 'species', graph_attr_modified: str = 'vertices', transformation: Callable | None = None, custom_transformations: Dict[str, Callable] | None = None, mode='fresh', overwrite=False, inplace: bool = True)

Add Results Table to Graph

This function extracts one or more attributes from an sbml_dfs species_data table, applies an optional transformation, and adds the result as a vertex attributes to a Napistu graph.

Parameters:
  • napistu_graph (NapistuGraph) – The Napistu graph to which attributes will be added.

  • sbml_dfs (sbml_dfs_core.SBML_dfs) – The sbml_dfs object containing the species_data table.

  • attribute_names (str or list of str, optional) –

    Either:
    • The name of the attribute to add to the graph.

    • A list of attribute names to add to the graph.

    • A regular expression pattern to match attribute names.

    • If None, all attributes in the species_data table will be added.

  • table_name (str, optional) – The name of the species_data table to use. If not provided, then a single table will be expected in species_data.

  • table_type (str, optional) – The type of table to use (e.g., species for species_data, reactions for reaction_data). Currently, only species is supproted.

  • graph_attr_modified (str, optional) – The type of graph attribute to modify: vertices or edges. Certain table_types can only modify vertices (species) while others can modify either vertices or edges (reactions). Currently, ignore.

  • transformation (str or Callable, optional) –

    Either:
    • the name of a function in custom_transformations or the built-in transformations.

    • A function to apply to the attribute.

    If not provided, the attribute will not be transformed.

  • custom_transformations (dict, optional) – A dictionary of custom transformations which could be applied to the attributes. The keys are the transformation names and the values are the transformation functions.

  • mode (str, optional) – The mode to use for adding the attributes. Must be one of “fresh” or “extend”.

  • overwrite (bool, optional) – If True, the attributes will be overwritten if they already exist.

  • inplace (bool, optional) – If True, the attribute will be added to the graph in place. If False, a new graph will be returned.

Returns:

napistu_graph – If inplace is False, the Napistu graph with attributes added.

Return type:

NapistuGraph