booldog.bool_graph module

class booldog.bool_graph.BooleanGraph(graph, data_format='bnet', **kwargs)

Bases: object

A class to represent a Boolean graph.

n

The number of nodes/variables in the graph

Type

int

primes

Prime implicants of the Boolean graph. See PyBoolNet:prime implicants for more information.

Type

dict

nodes

Lists node names in the graph

Type

tuple of str

index

Dictionary of node name to integer index for indexing arrays

Type

dict

Initialise a Boolean graph.

Parameters
  • graph (str or dict) – A file path to the graph or a dictionary with the graph.

  • data_format ({'primes', 'interactions', 'bnet', 'graphml'}) – String specifying data format.

  • kwargs – #TODO Additional keyword arguments for the importer function.

primes_to_matrices()

Reduce graph to Activation and Inhibition Matrices.

Returns

  • Act (np.array) – n * n matrix with entry m_{i, j} = 1 iff node_j activates node_i

  • Inh (np.array) – n * n matrix with entry m_{i, j} = 1 iff node_j inhibits node_i

Notes

Only if graph is of type threshold (i.e. SQUAD) does this make sense. Used in SquadODE Create logic matrices

generate_states(fixed=None)

Generate all possible states of the graph.

Parameters

fixed (dict) – A dictionary of {node:state} to be kept fixed, with node in graph.nodes, and state in {0, 1}.

Yields

state (np.array) – length n array with a state of the graph.

boolean_simulation(initial_values=None, plot=True, export=False, **kwargs)

Compute a Boolean simulation (or state transition) from optional initial values.

Parameters
  • initial_values (int, str, list, dict, optional) – Initial state, see Notes for format

  • plot (bool, optional) – Whether to plot the simulation results

  • export (bool or path object or string, optional) – False, or a file path to save simulation results. Exports valu

  • **kwargs – If plot=True , additional keyword arguments are passed to plot_boolean_simulation().

Notes

This is a wrapper for pyboolnet.state_transition_graphs.primes2stg, and therefore takes the same argument format for initial states.

From PyBoolNet documentation:

Either a list of states in dict or str format::

    init = ["000", "111"]
    init = ["000", {"v1":1,"v2":1,"v3":1}]

or as a function that is called on every state and must return
either True or False to indicate whether the state ought to be initial::

    init = lambda x: x["v1"]>=x["v2"]

or by a subspace in which case all the states contained in it are
initial::

    init = "--1"
    init = {"v3":1}
plot_boolean_simulation(fig, booldog_style=True, plot_nodes=None)

Plot the state transition graph, from optional initial values.

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

  • initial_values (int, str, list, dict) – Initial state, see Notes for format

  • 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) – Subset of nodes to plot. If None, plot all nodes. Only valid if new_style is True.

plot_state_transitions(fig, booldog_style=True, plot_nodes=None)

Plot the state transition graph, from optional initial values.

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

  • initial_values (int, str, list, dict) – Initial state, see Notes for format

  • 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) – Subset of nodes to plot. If None, plot all nodes. Only valid if new_style is True.

steady_states()

All steady states of the Boolean graph.

get_parents(node)

Fetch regulators/inputs to a node

Parameters

node (str) – Node name

Returns

parents – Set of parent nodes

Return type

set

get_interactions(direction='out')

direction out: interactions[a][b] a –> b direction in: interactions[a][b] a <– b