ncip
Network constructor and information propagator (ncip) contains functions for constructing the communication network for the Reactome TopLevelPathways.
- class CoRe.ncip.ncip(_property=None)[source]
- add_edges(session, reaction_info)[source]
Adds information about an edge to the edge_data and node_data.
- Parameters:
session (neo4j session) – To query the neo4j reactome database
command_set (dict) – Set of commands to query the neo4j reactome database.
reaction_info (list) – Row entry of the ReactionLikeEvents dataframe containing stId, category, schemaClass, and name.
- apply_BC(sources)[source]
Computes the final state of the network using the initial state X and the information transfer matrix C_dense. The state of the sources are fixed during the information transfer. The number of nodes in the network is n and the number of states for each node is m.
- Parameters:
sources (list) – Node numbers that are sources in the network, whose probabilistic state, e.g. {P[v=1],P[v=0]} has to be fixed during information propagation.
- construct_C(rho=0, h=1, neglect_modules=[])[source]
Creates the information transition matrix for the graph using the adjacency matrix and interference due to multiple information sources.
- Parameters:
G_d (networkx DiGraph) – Graph of a Reactome TopLevelPathway consisting of ReactionLikeEvents and regulations.
rho (float) – Communication error in each edge.
- Returns:
C – Information transition matrix of the network.
- Return type:
numpy matrix
- construct_edges(inputs, outputs, neglect_ids=[], neglect_class=[])[source]
Converts reactions into a local graph topology. If a reaction is: A + B -> C + D + E, then A and B are two input nodes to three separate output nodes C, D, and E. If the reaction is chemically balanced then the edges are bidirectional, else edges are unidirectional.
- Parameters:
inputs (neo4j result) – Result object from neo4j containing Reactome physical entities nodes that are inputs to an event.
outputs (neo4j result) – object from neo4j containing Reactome physical entities nodes that are outputs to an event.
neglect_ids (list) – stId of Reactome physical entities that should be neglected from the network.
neglect_class (list) – schemaClass of Reactome physical entities that should be neglected from the network.
- Returns:
edge_nodes – Dict containing the fields [‘inputs’,’outputs’,’input_names’,’output_names’]. ‘inputs’ and ‘outputs’ for the input and output node property values of an edge. ‘input names’ and ‘output_names’ are tuples (displayName,schemaClass) with values from the Reactome Data Schema, https://reactome.org/content/schema/PhysicalEntity.
- Return type:
dict
- construct_exo_edges(inputs, neglect_ids=[], neglect_class=[])[source]
Converts reactions into a local graph topology. If a reaction is: A + B -> C + D + E, then A and B are two input nodes to three separate output nodes C, D, and E. If the reaction is chemically balanced then the edges are bidirectional, else edges are unidirectional.
- Parameters:
inputs (neo4j result) – Result object from neo4j containing Reactome physical entities nodes that are inputs to an event.
neglect_ids (list) – stId of Reactome physical entities that should be neglected from the network.
neglect_class (list) – schemaClass of Reactome physical entities that should be neglected from the network.
- Returns:
edge_nodes – Dict containing the fields [‘inputs’,’outputs’,’input_names’,’output_names’]. ‘inputs’ and ‘outputs’ for the input and output node property values of an edge. ‘input names’ and ‘output_names’ are tuples (displayName,schemaClass) with values from the Reactome Data Schema, https://reactome.org/content/schema/PhysicalEntity.
- Return type:
dict
- disconnect_drug_nodes(skip='None')[source]
Removes nodes of the specified class from the network communication (or transition) matrix.
- Parameters:
classname (string) – Class of the nodes to be disconnected from the network communication matrix.
sources (list) – List of source nodes which remains to be connected to the communication matrix.
- disconnect_nodes(classname, sources)[source]
Removes nodes of the specified class from the network communication (or transition) matrix.
- Parameters:
classname (string) – Class of the nodes to be disconnected from the network communication matrix.
sources (list) – List of source nodes which remains to be connected to the communication matrix.
- entropy_drop_and_gain(state_1, state_2, reference_state, sources)[source]
Computes the difference between two Kullback-Leibeler divergences, D_KL(state_1||reference_state), and D_KL(state_2||reference_state), for each unconstrained node in the network.
- Parameters:
state (array_like) – A [mn,1] numpy array.
sources (list) – Node numbers that are sources in the network.
- Returns:
drop (float) – Sum of all difference in the relative entropy values for all the nodes in the network where, state_2 > state_1.
gain (float) – Sum of all difference in the relative entropy values for all the nodes in the network where, state_1 <= state_2.
- get_final_state(X, sources)[source]
Computes the final state of the network using the initial state X and the information transfer matrix C_dense. The state of the sources are fixed during the information transfer. The number of nodes in the network is n and the number of states for each node is m.
- Parameters:
X (array_like) – A [mn,1] numpy array.
sources (list) – Node numbers that are sources in the network, whose probabilistic state, e.g. {P[v=1],P[v=0]} has to be fixed during information propagation.
- Returns:
X (array_like) – Stationary state of the network.
steps (int) – Number of steps it took to reach the stationary state of the network.
- get_final_state_old(X, sources)[source]
Computes the final state of the network using the initial state X and the information transfer matrix C_dense. The state of the sources are fixed during the information transfer. The number of nodes in the network is n and the number of states for each node is m.
- Parameters:
X (array_like) – A [mn,1] numpy array.
sources (list) – Node numbers that are sources in the network, whose probabilistic state, e.g. {P[v=1],P[v=0]} has to be fixed during information propagation.
- Returns:
X (array_like) – Stationary state of the network.
steps (int) – Number of steps it took to reach the stationary state of the network.
- initialize_network_state(additional_sources, source_state)[source]
Saves the network as a gml file.
- Parameters:
pathway_name (string) – Name of the Reactome top level pathway.
network_type (string) – Additional description about the network.
- make_graph()[source]
Creates a networkx graph using the connecitivity data and assigns a color value to each edge depending the subpathway they belong to.
- save_edges_and_nodes(pathway_nametag, network_type)[source]
Saves the network nodes and edges as csv and pickled files.
- Parameters:
pathway_name (string) – Name of the Reactome top level pathway.
network_type (string) – Additional description about the network.
- save_network(pathway_nametag, network_type)[source]
Saves the network as a gml file.
- Parameters:
pathway_name (string) – Name of the Reactome top level pathway.
network_type (string) – Additional description about the network.
- save_nullspace(outfile)[source]
Computes and saves the nullspace for the communication matrix.
- Parameters:
outfile (string) – Name of the file to store the nullspace. The numpy array is saved in csv format.
- state_entropy(state, sources, reference_state=[])[source]
Computes the entropy of the network state with respect to the maximum entropy state. For binary valued network nodes, the state is: {P(v=1),P(v=0)}, where v=1 means the physical entity at high concentration (or copy number). Similary, v=0 means the physical entity is at low concentration (or copy number). The total number of nodes in the network is n and the number of states for each node is m.
Nodes that act as sources are neglected from the entropy calculation, to determine only the effect of the information propagation through the network.
- Parameters:
state (array_like) – A [mn,1] numpy array.
sources (list) – Node numbers that are sources in the network.
- Returns:
H – Entropy of the network state in bits.
- Return type:
float