booldog.simulation_result

Submodules

Classes

ContinuousSimulationResult

Class to contain simulation results

BooleanSimulationResult

Class to contain simulation results

BooleanStateSpace

Class to contain a subspace of a Boolean Network.

Package Contents

class booldog.simulation_result.ContinuousSimulationResult(network, t, y, ode_system, node_events=None, edge_events=None)

Class to contain simulation results

network
ode_system
t
y
node_events = None
edge_events = None
export(outfile, decimals=5)

Export simulation results to a file.

Parameters:
  • outfile (str or Path) – Path to the output file. The file will be created if it does not exist. If the file already exists, it will be overwritten.

  • decimals (int) – Number of decimals to round the output values to. Default is 5.

Notes

The output file will contain:
  • nodelist

  • ODE transform

  • ODE parameters

  • node_events

  • timepoints

  • solution/y

The output will be tab-separated and can be read into a pandas DataFrame. If you want to use pandas to read the file, you can use the following code: df = pd.read_csv(outfile, sep=” “)

plot(file=None, plot_nodes=None, title=None, figsize=(20, 10))

Plot simulation results.

Called by continous_simulation().

Parameters:
  • plot_nodes (None or list of str or list of lists of str, optional) – Subset of nodes to plot. If None, plot all nodes. If a list of lists, each sublist is plotted as a subplot.

  • title (None or string or list of string) – If str, main title of the plot. If a list of str, subtitles of subplots as defined by plot_node. In this case plot_nodes should be a list of lists, and title should be the same length as plot_nodes.

  • figsize ((float, float)) – Width, height in inches.

Returns:

  • fig (matplotlib.figure.Figure)

  • axes (array of matplotlib.axes.Axes)

_plot_one_ax(ax, x, y, legend_labels, vlines=None, title=None)

Helper func that plots on a subplot axes

class booldog.simulation_result.BooleanSimulationResult(network, stg, initial_states)

Class to contain simulation results

network
stg
initial_states
plot_stg(file=None, booldog_style=True, plot_nodes=None, use_names=True, num_characters=5)

Plot the state transition graph.

Parameters:
  • fig (str) – File name of generated figure

  • new_style (bool) – Whether to use booldog style, or PyBoolNet style (default) to plot the state transition graph. Requires pygraphviz (If not installed, will default to PyBoolNet version.)

  • plot_nodes (None or list of str, optional) – List of identifiers of subset of nodes to plot. If None, plot all nodes. Only valid if booldog_style is True.

  • use_names (bool) – Whether to use node names instead of node identifiers in the labels. Only valid if booldog_style is True.

num_charactersint

Number of characters to use for node names in the labels. Only valid if booldog_style is True.

Returns:

The state transition graph. If booldog_style is True and pygraphviz is installed, a pygraphviz AGraph object is returned. Otherwise, a networkx graph is returned.

Return type:

networkx graph or pygraphviz AGraph

Notes

If booldog_style is True, the nodes in the state transition graph are represented as tables, with each cell representing a node in the Boolean network. The cells are coloured green for “on” nodes and red for “off” nodes. If use_names is True, the node names are used instead of the node identifiers in the labels.

plot_state_space(title='State Heatmap', cmap=None)

Plot the states of the Boolean network as a heatmap.

Parameters:
  • title (str, optional) – Title of the heatmap, default is “State Heatmap”.

  • cmap (ListedColormap, optional) – Colormap to use for the heatmap. Default is binary with green (1) and grey (0).

export(file)

Export Boolean simulation result to ??

make_animation(base_suid, gif=None, mp4=None, initial_state=None, colour_on=None, colour_off=None, cycle_repeats=3, max_steps=None, duration=400, loop=0, sleep=1)
Parameters:
  • base_suid (int) – The network SUID from Cytoscape, of the network to base the animation on.

  • gif (None or a file path) – Path to save animation (GIF) to.

  • mp4 (None or a file path) – Not recommended to use, as this feature is experimental. Path to save animation (MP4) to.

  • initial_state (str) – Initial state for the simulation. For valid initial states, see the object attributes initial_states

  • colour_on (str) – Hex code for colour of “on” nodes, default=”#b2df8a” (light green),

  • colour_off (str) – Hex code for colour of “on” nodes, default=”#6f6f6f” (light grey)

  • cycle_repeats (int) – If there’s a cycle in the simulation, how many times should it repeat, default=3,

  • max_steps=None – Maximum number of frames to include in the animation. If none, will be num_state + len(cycle)*cycle_repeats, where num_states is the number of states in the simulation, and len(cycle) is the length of the cycle (if one exists). default=None

  • duration=400 – Time on each frame (in milliseconds)

  • loop (int) – Number of loops to the animation. 0 is infinite. default=0.

  • sleep (int) – Seconds to sleep between Cytoscape network exports. (See notes).

Notes

Do not interact with Cytoscape while the networks are being rendered, as this will interfere with the selection and colouring of nodes.

Occasionally Cytoscape exports get corrupted (e.g. node borders are rendered in the wrong order, node fills are placed on the wrong node). This is independent of booldog, and it is unclear why it happens. Rerunning the function may help, and increasing the sleep parameter may also help.

Mp4 export is in development, and not recommended to use.

class booldog.simulation_result.BooleanStateSpace(network, state_space)

Class to contain a subspace of a Boolean Network.

network
state_space
set_node_state(node_id, state)

Set the state of a node in all states of the state space.

Parameters:
  • node_id (str) – The identifier of the node to set the state for.

  • state (int) – The state to set for the node (0 or 1).

Raises:

ValueError – If node_id is not a valid node identifier in the network, or if state is not 0 or 1.

plot_state_space(title='State Heatmap', cmap=None)

Plot the states of the Boolean network as a heatmap.

Parameters:
  • title (str, optional) – Title of the heatmap, default is “State Heatmap”.

  • cmap (ListedColormap, optional) – Colormap to use for the heatmap. Default is binary with green (1) and grey (0).

__repr__()