cana.graphs package
NetworkX graph builders derived from Boolean networks.
Submodules:
interaction_graph— wiring / interaction topology (optionally signed)effective_graph— edge-effectiveness weighted digraphs and conditioned variantsactivity_graph— activity-weighted digraphs (optionally signed)
- cana.graphs.build_interaction_graph(nodes, name='', remove_constants=False, signed=True, constant_ids=None)[source]
Build the interaction graph from a sequence of Boolean nodes.
- Parameters:
nodes (sequence) – Nodes with
.name,.inputs, and.input_signs()(whensigned=True).name (str) – Network name used in the digraph
nameattribute.remove_constants (bool) – Drop constant nodes. Defaults to
False.signed (bool) – Compute and attach interaction signs. Defaults to
True.constant_ids (iterable, optional) – Node ids removed when
remove_constantsis True. Ignored otherwise.
- Returns:
The interaction graph.
- Return type:
G (networkx.DiGraph)
- cana.graphs.fill_wiring_signs(G, nodes)[source]
Set edge
signfrozensets from each target node’sinput_signs.- Parameters:
G (networkx.DiGraph) – Digraph whose nodes are integer node ids.
nodes (sequence) – Nodes with
.inputsand.input_signs(), indexed by id (typicallyBooleanNetwork.nodes).
- Returns:
The same graph, mutated in place.
- Return type:
G (networkx.DiGraph)
- cana.graphs.build_effective_graph(nodes, name='', bound='mean', threshold=None, signed=False, base_eg=None)[source]
Build the effective graph of a Boolean network.
Edge weights are edge effectiveness. Pass
base_eg(an unsigned, unthresholded EG) to reuse a cached graph without recomputing effectiveness;base_egis never mutated.- Parameters:
nodes (sequence) – Nodes with
.name,.inputs, and.edge_effectiveness(and.input_signswhen signed).name (str) – Network name used in the digraph
nameattribute.bound (str) – Bound forwarded to
edge_effectiveness. One of"lower","mean","upper","tuple". Ignored whenbase_egis provided.threshold (float, optional) – Keep edges with
weight > threshold.signed (bool) – Attach interaction
signfrozensets. When True, works on a deep copy of the unsigned graph.base_eg (networkx.DiGraph, optional) – Cached effective graph. Must satisfy
base_eg.graph["threshold"] is Noneorthreshold >= base_eg.graph["threshold"]. Built fromnodeswhen omitted.
- Returns:
- Possibly signed and/or thresholded EG.
G.graph["threshold"]records the applied threshold.
- Return type:
G (networkx.DiGraph)
- cana.graphs.build_conditional_effective_graph(nodes, conditioned_nodes=None, bound='mean', threshold=None, signed=False, name='', base_eg=None)[source]
Build an effective graph conditioned on fixed node states.
Propagates constants induced by conditioning, recomputing edge effectiveness on the remaining inputs of affected successors.
- Parameters:
nodes (sequence) – Original network nodes (not mutated).
conditioned_nodes (mapping) –
{node_id: state}fixed values.bound (str) – Bound for edge effectiveness.
threshold (float, optional) – Drop edges with
weight <= threshold.signed (bool) – Attach signs from conditioned LUTs.
name (str) – Network name for digraph naming.
base_eg (networkx.DiGraph, optional) – Unsigned unthresholded EG to start from. Built via
build_effective_graph()if omitted.
- Returns:
Conditioned effective graph.
- Return type:
(networkx.DiGraph)
- cana.graphs.build_activity_graph(nodes, name='', threshold=None, signed=False, base_ag=None)[source]
Build the activity graph from a sequence of Boolean nodes.
Pass
base_ag(typically an unsigned, unthresholded AG) to reuse a cached graph without recomputing activities;base_agis never mutated.- Parameters:
nodes (sequence) – Nodes with
.name,.inputs,.activities(), and.input_signs()(whensigned=True). Ignored for edge weights whenbase_agis provided.name (str) – Network name used in the digraph
nameattribute.threshold (float, optional) – Keep edges with activity
> threshold. WhenNone, keep all wiring edges (including weight0).signed (bool) – Attach interaction
signfrozensets. When True, works on a deep copy of the unsigned graph. Defaults toFalse.base_ag (networkx.DiGraph, optional) – Cached activity graph. Must satisfy
base_ag.graph["threshold"] is Noneorthreshold >= base_ag.graph["threshold"]. Built fromnodeswhen omitted.
- Returns:
- Activity graph with
weightandsign. G.graph["threshold"]records the applied threshold.
- Activity graph with
- Return type:
G (networkx.DiGraph)