KGBN.vis¶
- KGBN.vis.is_entire_rule_negated(rule)[source]¶
Check if the entire rule is a single negated expression like !(A | B).
- Returns True for rules like:
!(A | B)
!(A & B & C)
! (A | B)
- Returns False for rules like:
!(A) | B (negation is only partial)
A & !B (negation is on individual variable)
!A (no parentheses)
- KGBN.vis.read_logic_rules(source)[source]¶
Reads logic rules from a file path or from a string containing rules.
- Args:
source (str): Path to the file or the string containing logic rules.
- Returns:
dict: Mapping from variable names to their logic rules.
- KGBN.vis.extract_logic_rules_from_network(network)[source]¶
Extract logic rules from a BooleanNetwork or PBN object using stored equations.
- Args:
network: BooleanNetwork or ProbabilisticBN object
- Returns:
dict: Mapping from variable names to their logic rules (for BN) or list of rules (for PBN) dict: Mapping from edges to probabilities (for PBN) or empty dict (for BN)
- KGBN.vis.build_igraph_pbn(logic_rules, edge_probabilities)[source]¶
Build igraph for PBN with multiple rules per node.
- KGBN.vis.create_matplotlib_visualization(logic_rules, removed_nodes=None, removed_edges=None, measured_nodes=None, perturbed_nodes=None, color_node=None)[source]¶
Create a matplotlib-based visualization for Jupyter notebooks.
- Args:
color_node (str): If provided, all nodes will use this color (overrides default coloring)
- KGBN.vis.vis_network(source, output_html='network_graph.html', interactive=False, removed_nodes=None, removed_edges=None, measured_nodes=None, perturbed_nodes=None, color_node=None, color_edge=None, physics=True, figsize=(13, 8), title='Boolean Network', node_groups=None, layout='hierarchical', layout_kwargs=None, activation_color='#D73027', inhibition_color='#4575B4', node_size=1500, font_size=9, ax=None, return_fig=False, seed=42)[source]¶
Visualize the Boolean network.
When
interactive=False(default), produces a publication-quality matplotlib figure with a configurable layout and clearly distinguished activation / inhibition edges.When
interactive=True, saves an interactive HTML file via PyVis.- Args:
- source: Logic rules — dict, file path (str), network string (str),
BooleanNetwork, or ProbabilisticBN object.
output_html (str): Output HTML file name (interactive mode only). interactive (bool): If
True, generate an interactive HTML file. removed_nodes (set): Nodes shown as removed (light grey). removed_edges (set): Edges shown as removed (interactive mode only). measured_nodes (set): Measured / readout nodes (orange). perturbed_nodes (set): Perturbed nodes (red). color_node (str): Uniform node colour override (interactive mode only). color_edge (str): Uniform edge colour override (interactive mode only). physics (bool): Enable physics simulation (interactive mode only).- figsize (tuple): Figure size
(width, height)in inches (static mode only).
title (str): Figure title (static mode only). node_groups (dict): Custom colour groups that override
connectivity-based defaults. Format:
{group_name: (node_set, color)}
Example:
{'Drug targets': ({'BCL2', 'SYK'}, '#E1F2D0'), 'Mutations': ({'NRAS'}, '#D783FF')}
layout (str): Node placement algorithm (static mode only). Options:
'hierarchical'(default) — layered top-down.'spring'— force-directed (dense/cyclic nets).'kamada_kawai'— stress-minimisation.'circular'— evenly spaced on a circle.'shell'— concentric shells.'spectral'— eigenvector-based.'dot'— Graphvizdot(requirespygraphvizorpydot).
- layout_kwargs (dict): Extra keyword arguments for the layout
algorithm. For
'hierarchical',x_gap(default 3.0) andy_gap(default 2.5) control inter-node spacing.
activation_color (str): Edge colour for activation (static mode only). inhibition_color (str): Edge colour for inhibition (static mode only). node_size (int): Node marker size in matplotlib units (static mode only). font_size (int): Label font size in points (static mode only). ax: Existing
matplotlib.axes.Axesto draw on; a new figureis created when None (static mode only).
- return_fig (bool): If
True, return(fig, ax)instead of calling
plt.show()(static mode only).
seed (int): Random seed for reproducible layouts (static mode only).
- Returns:
None, or(fig, ax)when return_fig isTrueandinteractive=False.
- KGBN.vis.vis_compression(original_network, compressed_network, compression_info, output_html='compression_comparison.html', interactive=False)[source]¶
Visualize the original network with removed/collapsed nodes highlighted.
- Args:
original_network: Original BooleanNetwork or ProbabilisticBN compressed_network: Compressed network (not used for visualization) compression_info: Dictionary with compression information output_html (str): Output HTML file name interactive (bool): If True, return network visualization in interactive html file
- KGBN.vis.vis_extension(original_network, extended_network, output_html='network+KG.html', interactive=True, color_node='#AED6F1', color_edge=None, extension_color_node='#FBE1BE', extension_color_edge=None, physics=True, figsize=(22, 9), title=None, node_groups=None, layout='hierarchical', layout_kwargs=None, edge_scores=None, activation_color='#D73027', inhibition_color='#4575B4', node_size=1500, font_size=9, return_fig=False, seed=9)[source]¶
Visualize the network with KG (Knowledge Graph) extension, highlighting new nodes and edges.
When
interactive=True(default), saves an interactive HTML file via PyVis. Wheninteractive=False, produces a side-by-side publication-quality matplotlib figure comparing the original and extended networks.- Args:
original_network: Original BooleanNetwork or ProbabilisticBN. extended_network: Extended network with additional nodes / edges. output_html (str): Output HTML file name (interactive mode only). interactive (bool): If
True, generate an interactive HTML file. color_node (str): Fill colour for original-network nodes. color_edge (str): Uniform edge colour override (interactive mode only). extension_color_node (str): Fill colour for nodes added by the KG. extension_color_edge (str): Edge colour override for KG-added edges(interactive mode only).
physics (bool): Enable physics simulation (interactive mode only).
- figsize (tuple): Overall figure size
(width, height)in inches (static mode only).
title (str): Super-title above both panels (static mode only). node_groups (dict): Optional extra colour groups applied to both
panels, overriding color_node / extension_color_node for the listed nodes. Format:
{group_name: (node_set, color)}
Example:
{'Drug targets': ({'BCL2', 'SYK'}, '#FBE1BE'), 'Mutations': ({'NRAS'}, '#D783FF')}
- layout (str): Node placement algorithm shared by both panels
(static mode only). See
vis_network()for available options.- layout_kwargs (dict): Extra keyword arguments for the layout
algorithm (static mode only).
- edge_scores (dict): Optional
{(src, tgt): score}mapping used to scale new-edge line widths by evidence score (static mode only). Build this from the
all_relationslist returned byload_signor_network():_, relations = load_signor_network(genes, ...) edge_scores = { (src, tgt): score for src, tgt, _, score in relations if score is not None }
Width is mapped as
0.5 + score × 4.
activation_color (str): Colour for activation edges (static mode only). inhibition_color (str): Colour for inhibition edges (static mode only). node_size (int): Node marker size (static mode only). font_size (int): Label font size in points (static mode only). return_fig (bool): If
True, return(fig, axes)instead ofcalling
plt.show()(static mode only).seed (int): Random seed for reproducible layouts (static mode only).
- figsize (tuple): Overall figure size
- Returns:
None, or(fig, axes)when return_fig isTrueandinteractive=False.
- KGBN.vis.create_matplotlib_extension_visualization(logic_rules, new_nodes, new_edges, color_node='lightblue', extension_color_node='#E1F2D0', extension_color_edge=None)[source]¶
Create a matplotlib-based visualization for extension comparison.
- Args:
logic_rules: Dictionary of logic rules new_nodes: Set of new node names from KG extension new_edges: Set of new edge tuples from KG extension color_node (str): Color for nodes from the original network extension_color_node (str): Color for new nodes from KG extension_color_edge (str): Color for new edges from KG. If None, uses default color