napistu.network.net_create
Functions
|
Create a NapistuGraph network from a mechanistic network using one of a set of wiring approaches. |
|
Process Consensus Graph. |
- napistu.network.net_create._augment_network_edges(network_edges: DataFrame, sbml_dfs: SBML_dfs, cspecies_features: DataFrame) DataFrame
Add reversibility and other metadata from reactions, and species features.
- Parameters:
network_edges (pd.DataFrame) – DataFrame of network edges.
sbml_dfs (sbml_dfs_core.SBML_dfs) – The SBML_dfs object containing reaction data.
cspecies_features (pd.DataFrame) – DataFrame containing species features to merge with edges.
- Returns:
DataFrame of network edges with additional metadata.
- Return type:
pd.DataFrame
- Raises:
ValueError – If required attributes are missing from network_edges.
- napistu.network.net_create._augment_network_nodes(network_nodes: DataFrame, sbml_dfs: SBML_dfs, species_graph_attrs: dict = {}, custom_transformations: dict | None = None) DataFrame
Add species-level attributes, expand network_nodes with s_id and c_id and then map to species-level attributes by s_id.
This function merges species-level attributes from sbml_dfs into the provided network_nodes DataFrame, using the mapping in species_graph_attrs. Optionally, custom transformation functions can be provided to transform the attributes as they are added.
- Parameters:
network_nodes (pd.DataFrame) – DataFrame of network nodes. Must include columns ‘name’, ‘node_name’, and ‘node_type’.
sbml_dfs (sbml_dfs_core.SBML_dfs) – The SBML_dfs object containing species data.
species_graph_attrs (dict, optional) – Dictionary specifying which attributes to pull from species_data and how to transform them. The structure should be {attribute_name: {“table”: …, “variable”: …, “trans”: …}}.
custom_transformations (dict, optional) – Dictionary mapping transformation names to functions. If provided, these will be checked before built-in transformations. Example: {“square”: lambda x: x**2}
- Returns:
The input network_nodes DataFrame with additional columns for each extracted and transformed attribute.
- Return type:
pd.DataFrame
- Raises:
ValueError – If required attributes are missing from network_nodes.
- napistu.network.net_create._create_napistu_graph_bipartite(sbml_dfs: SBML_dfs) DataFrame
Turn an sbml_dfs model into a bipartite graph linking molecules to reactions.
- Parameters:
sbml_dfs (sbml_dfs_core.SBML_dfs) – The SBML_dfs object containing the model data.
- Returns:
DataFrame representing the bipartite network edges.
- Return type:
pd.DataFrame
- napistu.network.net_create._reverse_network_edges(augmented_network_edges: DataFrame) DataFrame
Flip reversible reactions to derive the reverse reaction.
- Parameters:
augmented_network_edges (pd.DataFrame) – DataFrame of network edges with metadata.
- Returns:
DataFrame with reversed edges for reversible reactions.
- Return type:
pd.DataFrame
- Raises:
ValueError – If required variables are missing or if the transformation fails.
- napistu.network.net_create.create_napistu_graph(sbml_dfs: SBML_dfs, directed: bool = True, wiring_approach: str = 'regulatory', drop_reactions_when: str = 'same_tier', deduplicate_edges: bool = True, verbose: bool = False) NapistuGraph
Create a NapistuGraph network from a mechanistic network using one of a set of wiring approaches.
- Parameters:
sbml_dfs (sbml_dfs_core.SBML_dfs) – A model formed by aggregating pathways.
directed (bool, optional) – Whether to create a directed (True) or undirected (False) graph. Default is True.
wiring_approach (str, optional) –
- Type of graph to create. Valid values are:
’bipartite’: substrates and modifiers point to the reaction they drive, this reaction points to products
’regulatory’: non-enzymatic modifiers point to enzymes, enzymes point to substrates and products
’surrogate’: non-enzymatic modifiers -> substrates -> enzymes -> reaction -> products
’bipartite_og’: old method for generating a true bipartite graph. Retained primarily for regression testing.
drop_reactions_when (str, optional) –
- The condition under which to drop reactions as a network vertex. Valid values are:
’same_tier’: drop reactions when all participants are on the same tier of a wiring hierarchy
’edgelist’: drop reactions when the reaction species are only 2 (1 reactant + 1 product)
’always’: drop reactions regardless of tiers
deduplicate_edges (bool, optional) – Whether to deduplicate edges with the same FROM -> TO pair, keeping only the first occurrence. Default is True for backwards compatibility.
verbose (bool, optional) – Extra reporting. Default is False.
- Returns:
A NapistuGraph network (subclass of igraph.Graph).
- Return type:
- Raises:
ValueError – If wiring_approach is not valid or if required attributes are missing.
- napistu.network.net_create.process_napistu_graph(sbml_dfs: SBML_dfs, directed: bool = True, wiring_approach: str = 'bipartite', weighting_strategy: str = 'unweighted', reaction_graph_attrs: dict | None = None, custom_transformations: dict = None, deduplicate_edges: bool = True, drop_reactions_when: str = 'same_tier', verbose: bool = False) NapistuGraph
Process Consensus Graph.
Sets up a NapistuGraph network and then adds weights and other malleable attributes.
- Parameters:
sbml_dfs (sbml_dfs_core.SBML_dfs) – A model formed by aggregating pathways.
directed (bool, optional) – Whether to create a directed (True) or undirected (False) graph. Default is True.
wiring_approach (str, optional) – Type of graph to create. See create_napistu_graph for valid values.
weighting_strategy (str, optional) –
- A network weighting strategy. Options:
’unweighted’: all weights (and upstream_weight for directed graphs) are set to 1.
’topology’: weight edges by the degree of the source nodes favoring nodes with few connections.
’mixed’: transform edges with a quantitative score based on reaction_attrs; and set edges without quantitative score as a source-specific weight.
reaction_graph_attrs (dict, optional) – Dictionary containing attributes to pull out of reaction_data and a weighting scheme for the graph.
custom_transformations (dict, optional) – Dictionary of custom transformation functions to use for attribute transformation.
deduplicate_edges (bool, optional) – Whether to deduplicate edges with the same FROM -> TO pair, keeping only the first occurrence. Default is True for backwards compatibility.
drop_reactions_when (str, optional) –
- The condition under which to drop reactions as a network vertex. Valid values are:
’same_tier’: drop reactions when all participants are on the same tier of a wiring hierarchy
’edgelist’: drop reactions when the reaction species are only 2 (1 reactant + 1 product)
’always’: drop reactions regardless of tiers
Default is ‘same_tier’.
verbose (bool, optional) – Extra reporting. Default is False.
- Returns:
A weighted NapistuGraph network (subclass of igraph.Graph).
- Return type: