cana.graphs package

NetworkX graph builders derived from Boolean networks.

Submodules:

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() (when signed=True).

  • name (str) – Network name used in the digraph name attribute.

  • 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_constants is True. Ignored otherwise.

Returns:

The interaction graph.

Return type:

G (networkx.DiGraph)

cana.graphs.fill_wiring_signs(G, nodes)[source]

Set edge sign frozensets from each target node’s input_signs.

Parameters:
  • G (networkx.DiGraph) – Digraph whose nodes are integer node ids.

  • nodes (sequence) – Nodes with .inputs and .input_signs(), indexed by id (typically BooleanNetwork.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_eg is never mutated.

Parameters:
  • nodes (sequence) – Nodes with .name, .inputs, and .edge_effectiveness (and .input_signs when signed).

  • name (str) – Network name used in the digraph name attribute.

  • bound (str) – Bound forwarded to edge_effectiveness. One of "lower", "mean", "upper", "tuple". Ignored when base_eg is provided.

  • threshold (float, optional) – Keep edges with weight > threshold.

  • signed (bool) – Attach interaction sign frozensets. 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 None or threshold >= base_eg.graph["threshold"]. Built from nodes when 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_ag is never mutated.

Parameters:
  • nodes (sequence) – Nodes with .name, .inputs, .activities(), and .input_signs() (when signed=True). Ignored for edge weights when base_ag is provided.

  • name (str) – Network name used in the digraph name attribute.

  • threshold (float, optional) – Keep edges with activity > threshold. When None, keep all wiring edges (including weight 0).

  • signed (bool) – Attach interaction sign frozensets. When True, works on a deep copy of the unsigned graph. Defaults to False.

  • base_ag (networkx.DiGraph, optional) – Cached activity graph. Must satisfy base_ag.graph["threshold"] is None or threshold >= base_ag.graph["threshold"]. Built from nodes when omitted.

Returns:

Activity graph with weight and sign.

G.graph["threshold"] records the applied threshold.

Return type:

G (networkx.DiGraph)

Submodules