Network¶
Boolean Network¶
Main class for Boolean network objects.
-
class
cana.boolean_network.
BooleanNetwork
(name='', Nnodes=0, logic=None, sg=None, stg=None, stg_r=None, _ef=None, attractors=None, constants={}, Nconstants=0, keep_constants=False, bin2num=<built-in function binstate_to_statenum>, num2bin=<built-in function statenum_to_binstate>, verbose=False, *args, **kwargs)[source]¶ -
activity_graph
(threshold=None)[source]¶ Returns the activity graph as proposed in Ghanbarnejad & Klemm (2012) EPL, 99
- Parameters
threshold (float) – Only return edges above a certain activity threshold. This is usefull when computing graph measures at diffent levels.
- Returns
directed graph
- Return type
(networkx.DiGraph)
-
approx_dynamic_impact
(source, n_steps=1, target_set=None, bound='mean', threshold=0.0)[source]¶ Use the network structure to approximate the dynamical impact of a perturbation to node for each of n_steps for details see: Gates et al (2020).
- Parameters
source (int) – the source index for perturbations
n_steps (int) – the number of time steps
- bound (str)the bound for the effective graph
‘mean’ - edge effectiveness ‘upper’ - activity
- Returns
approximate dynamical impact for each node at each step (2 x n_steps x n_nodes)
- Return type
(matrix)
-
attractor
(initial)[source]¶ Computes the trajectory starting at
initial
until it reaches an attracor (this is garanteed)- Parameters
initial (string) – the initial state.
- Returns
the atractor state.
- Return type
attractor (string)
-
attractor_driver_nodes
(min_dvs=1, max_dvs=4, verbose=False)[source]¶ Get the minimum necessary driver nodes by iterating the combination of all possible driver nodes of length \(min <= x <= max\).
- Parameters
min_dvs (int) – Mininum number of driver nodes to search.
max_dvs (int) – Maximum number of driver nodes to search.
- Returns
The list of driver nodes found in the search.
- Return type
(list)
Note
This is an inefficient bruit force search, maybe we can think of better ways to do this?
-
attractors
(mode='stg')[source]¶ Find the attractors of the boolean network.
- Parameters
mode (string) –
stg
orsat
. Defaults tostg
.stg
: Uses the full State Transition Graph (STG) and identifies the attractors as strongly connected components.bns
: Uses the SAT-basedcana.bns
to find all attractors.- Returns
A list containing all attractors for the boolean network.
- Return type
attractors (list)
See also
-
average_trajectory_length
(nsamples=10, random_seed=None, method='random')[source]¶ The average length of trajectories from a random initial configuration to its attractor.
- Parameters
nsamples (int) – The number of samples per hammimg distance to get.
random_seed (int) – The random state seed.
method (string) – specify the method you want. either ‘random’ or ….
- Returns
The average trajectory length to an attractor.
- Return type
trajlen (float)
-
conditional_effective_graph
(conditioned_nodes={}, bound='mean', threshold=None)[source]¶ Computes and returns the BN effective graph conditioned on some known states.
- Parameters
conditioned_nodes (dict) – a dictionary mapping node ids to their conditioned states. dict of form { nodeid : nodestate }
bound (string) – The bound to which compute input redundancy. Can be one of : [“lower”, “mean”, “upper”, “tuple”]. Defaults to “mean”.
threshold (float) – Only return edges above a certain effective connectivity threshold. This is usefull when computing graph measures at diffent levels.
- Returns
directed graph
- Return type
(networkx.DiGraph)
See also
-
controlled_attractor_graph
(driver_nodes=[])[source]¶ - Parameters
cstg (networkx.DiGraph) – A Controlled State-Transition-Graph (CSTG)
- Returns
The Controlled Attractor Graph (CAG)
- Return type
(networkx.DiGraph)
-
controlled_state_transition_graph
(driver_nodes=[])[source]¶ Returns the Controlled State-Transition-Graph (CSTG). In practice, it copies the original STG, flips driver nodes (variables), and updates the CSTG.
- Parameters
driver_nodes (list) – The list of driver nodes.
- Returns
The Controlled State-Transition-Graph.
- Return type
(networkx.DiGraph)
-
derrida_coefficient
(nsamples=10, random_seed=None, method='random')[source]¶ The Derrida Coefficient. When “mode” is set as “random” (default), it would use random sampling to estimate Derrida value If “mode” is set as “sensitivity”, it would use c-sensitivity to calculate Derrida value (slower) You can refer to :cite:’kadelka2017influence’ about why c-sensitivity can be used to caculate Derrida value
- Parameters
nsamples (int) – The number of samples per hammimg distance to get.
random_seed (int) – The random state seed.
method (string) – specify the method you want. either ‘random’ or ‘sensitivity’
- Returns
The dx and dy of the curve.
- Return type
(dx,dy) (tuple)
-
derrida_curve
(nsamples=10, max_hamm=None, random_seed=None, method='random')[source]¶ The Derrida Curve (also reffered as criticality measure \(D_s\)). When “mode” is set as “random” (default), it would use random sampling to estimate Derrida value If “mode” is set as “sensitivity”, it would use c-sensitivity to calculate Derrida value (slower) You can refer to :cite:’kadelka2017influence’ about why c-sensitivity can be used to caculate Derrida value
- Parameters
nsamples (int) – The number of samples per hammimg distance to get.
max_hamm (int) – The maximum Hamming distance between starting states. default: self.Nnodes
random_seed (int) – The random state seed.
method (string) – specify the method you want. either ‘random’ or ‘sensitivity’
- Returns
The dx and dy of the curve.
- Return type
(dx,dy) (tuple)
-
dist_from_attractor
()[source]¶ Find the distance from attractor for each configuration.
- Returns
distance (dict). Nodes are dictionary indexes and distances the values.
-
dynamics_canalization_map
(output=None, simplify=True)[source]¶ Computes the Dynamics Canalization Map (DCM). In practice, it asks each node to compute their Canalization Map and then puts them together, simplifying it if possible.
- Parameters
output (int) – The output DCM to return. Default is
None
, retuning both [0,1].simplify (bool) – Attemps to simpify the DCM by removing thresholds nodes with :math:` ao=1`.
- Returns
a directed graph representation of the DCM.
- Return type
DCM (networkx.DiGraph)
See also
boolean_node.canalizing_map()
for the CM anddrawing.draw_dynamics_canalizing_map_graphviz()
for plotting.
-
effective_graph
(bound='mean', threshold=None)[source]¶ Computes and returns the effective graph of the network. In practive it asks each
BooleanNode
for theiredge_effectiveness()
.- Parameters
bound (string) – The bound to which compute input redundancy. Can be one of : [“lower”, “mean”, “upper”, “tuple”]. Defaults to “mean”.
threshold (float) – Only return edges above a certain effective connectivity threshold. This is usefull when computing graph measures at diffent levels.
- Returns
directed graph
- Return type
(networkx.DiGraph)
See also
-
effective_indegrees
()[source]¶ Returns the in-degrees of the Effective Graph. Sorted.
- Returns
(list)
-
effective_outdegrees
()[source]¶ Returns the out-degrees of the Effective Graph. Sorted.
- Returns
(list)
-
feedback_vertex_set_driver_nodes
(graph='structural', method='grasp', max_iter=1, max_search=11, keep_self_loops=True, *args, **kwargs)[source]¶ The minimum set of necessary driver nodes to control the network based on Feedback Vertex Set (FVS) theory.
- Parameters
graph (string) – Which graph to perform computation
method (string) – FVS method.
bruteforce
orgrasp
(default).max_iter (int) – The maximum number of iterations used by the grasp method.
max_search (int) – The maximum number of searched used by the bruteforce method.
keep_self_loops (bool) – Keep or remove self loop in the graph to be searched.
- Returns
A list-of-lists with FVS solution nodes.
- Return type
(list)
Note
When computing FVS on the structural graph, you might want to use
remove_constants=True
to make sure the resulting set is minimal – since constants are not controlabled by definition. Also, when computing on the effective graph, you can define the desiredthreshold
level.
-
fraction_pinned_attractors
(pcstg_dict)[source]¶ Returns the Number of Accessible Attractors
- Parameters
pcstg_dict (dict of networkx.DiGraph) – The dictionary of Pinned Controlled State-Transition-Graphs.
- Returns
Number of Accessible Attractors
- Return type
(int)
-
fraction_pinned_configurations
(pcstg_dict)[source]¶ Returns the Fraction of successfully Pinned Configurations
- Parameters
pcstg_dict (dict of networkx.DiGraph) – The dictionary of Pinned Controlled State-Transition-Graphs.
- Returns
the Fraction of successfully Pinned Configurations to each attractor
- Return type
(list)
-
classmethod
from_dict
(logic, keep_constants=True, **kwargs)[source]¶ Instanciaets a BoolleanNetwork from a logic dictionary.
- Parameters
logic (dict) – The logic dict.
keep_constants (bool) –
- Returns
(BooleanNetwork)
See also
-
classmethod
from_file
(file, type='cnet', keep_constants=True, **kwargs)[source]¶ Load the Boolean Network from a file.
- Parameters
file (string) – The name of a file containing the Boolean Network.
type (string) – The type of file, either ‘cnet’ (default) or ‘logical’ for Boolean logical rules.
- Returns
The boolean network object.
- Return type
BooleanNetwork (object)
See also
from_string()
from_dict()
-
classmethod
from_string_boolean
(string, keep_constants=True, **kwargs)[source]¶ Instanciates a Boolean Network from a Boolean update rules format.
- Parameters
string (string) – A boolean update rules format representation of a Boolean Network.
- Returns
The boolean network object.
- Return type
Examples
String should be structured as follow
# BOOLEAN RULES (this is a comment) # node_name*=node_input_1 [logic operator] node_input_2 ... NODE3*=NODE1 AND NODE2 ...
See also
from_string()
from_dict()
-
classmethod
from_string_cnet
(string, keep_constants=True, **kwargs)[source]¶ Instanciates a Boolean Network from a string in cnet format.
- Parameters
string (string) – A cnet format representation of a Boolean Network.
- Returns
(BooleanNetwork)
Examples
String should be structured as follow:
#.v = number of nodes .v 1 #.l = node label .l 1 node-a .l 2 node-b #.n = (node number) (in-degree) (input node 1) … (input node k) .n 1 2 4 5 01 1 # transition rule
See also
-
get_node_name
(iterable=[])[source]¶ Return node names. Optionally, it returns only the names of the ids requested.
- Parameters
iterable (int,list, optional) – The id (or list of ids) of nodes to which return their names.
- Returns
The name of the nodes.
- Return type
names (list)
-
mean_controlable_configurations
(cstg)[source]¶ The Mean Fraction of Controlable Configurations
- Parameters
cstg (networkx.DiGraph) – The Controlled State-Transition-Graph.
- Returns
Mean Fraction of Controlable Configurations.
- Return type
(float)
-
mean_fraction_pinned_configurations
(pcstg_dict)[source]¶ Returns the mean Fraction of successfully Pinned Configurations
- Parameters
pcstg_dict (dict of networkx.DiGraph) – The dictionary of Pinned Controlled State-Transition-Graphs.
- Returns
the mean Fraction of successfully Pinned Configurations
- Return type
(int)
-
mean_reachable_attractors
(cag, norm=True)[source]¶ The Mean Fraction of Reachable Attractors to a specific Controlled Attractor Graph (CAG).
- Parameters
cag (networkx.DiGraph) – A Controlled Attractor Graph (CAG).
- Returns
(float) Mean Fraction of Reachable Attractors
-
mean_reachable_configurations
(cstg)[source]¶ Returns the Mean Fraction of Reachable Configurations
- Parameters
cstg (networkx.DiGraph) – The Controlled State-Transition-Graph.
- Returns
Mean Fraction of Reachable Configurations
- Return type
(float)
-
minimum_dominating_set_driver_nodes
(graph='structural', max_search=5, keep_self_loops=True, *args, **kwargs)[source]¶ The minimun set of necessary driver nodes to control the network based on Minimum Dominating Set (MDS) theory.
- Parameters
max_search (int) – Maximum search of additional variables. Defaults to 5.
keep_self_loops (bool) – If self-loops are used in the computation.
- Returns
A list-of-lists with MDS solution nodes.
- Return type
(list)
-
network_bias
()[source]¶ Network Bias. The sum of individual node biases divided by the number of nodes. Practically, it asks each node for their own bias.
See also
-
number_interactions
()[source]¶ Returns the number of interactions in the Structural Graph (SG). Practically, it returns the number of edges of the SG.
- Returns
int
-
partial_derative_node
(node, n_traj=10, t=1)[source]¶ The partial derivative of node on all other nodes after t steps
- Parameters
node (int) – the node index for perturbations
t (int) – the number of time steps the system is run before impact is calculated.
n_traj (int) – the number of trajectories used to approximate the dynamical impact of a node. if 0 then the full STG is used to calculate the true value instead of the approximation method.
- Returns
the partial derivatives
- Return type
(vector)
-
pinned_step
(initial, pinned_binstate, pinned_var)[source]¶ Steps the boolean network 1 step from the given initial input condition when the driver variables are pinned to their controlled states.
- Parameters
initial (string) – the initial state.
n (int) – the number of steps.
- Returns
The stepped binary state.
- Return type
(string)
-
pinning_controlled_state_transition_graph
(driver_nodes=[])[source]¶ Returns a dictionary of Controlled State-Transition-Graph (CSTG) under the assumptions of pinning controllability.
In practice, it copies the original STG, flips driver nodes (variables), and updates the CSTG.
- Parameters
driver_nodes (list) – The list of driver nodes.
- Returns
The Pinning Controlled State-Transition-Graph.
- Return type
(networkx.DiGraph)
-
set_constant
(node, value=None)[source]¶ Sets or unsets a node as a constant.
- Parameters
node (int) – The node
id
in the logic dict.
-
state_transition_graph
()[source]¶ Creates and returns the full State Transition Graph (STG) for the Boolean Network.
- Returns
The state transition graph for the Boolean Network.
- Return type
(networkx.DiGraph)
-
state_transition_graph_reachability
(filename=None)[source]¶ Generates a State-Transition-Graph Reachability (STG-R) dictionary. This dict/file will be used by the State Transition Graph Control Analysis.
- Parameters
filename (string) – The location to a file where the STG-R will be stored.
- Returns
The STG-R in dict format.
- Return type
(dict)
-
step
(initial)[source]¶ Steps the boolean network ‘n’ step from the given initial input condition.
- Parameters
initial (string) – the initial state.
n (int) – the number of steps.
- Returns
The stepped binary state.
- Return type
(string)
-
stg_indegree
()[source]¶ Returns the In-degrees of the State-Transition-Graph (STG). Sorted.
- Returns
list
-
structural_controllability_driver_nodes
(graph='structural', keep_self_loops=True, *args, **kwargs)[source]¶ The minimum set of necessary driver nodes to control the network based on Structural Controlability (SC) theory.
- Parameters
keep_self_loops (bool) – If self-loops are used in the computation.
- Returns
A list-of-lists with SC solution nodes.
- Return type
(list)
-
structural_graph
(remove_constants=False)[source]¶ Calculates and returns the structural graph of the boolean network.
- Parameters
remove_constants (bool) – Remove constants from the graph. Defaults to
False
.- Returns
The boolean network structural graph.
- Return type
G (networkx.Digraph)
-
structural_indegrees
()[source]¶ Returns the in-degrees of the Structural Graph. Sorted.
- Returns
the number of in-degrees.
- Return type
(int)
-
structural_outdegrees
()[source]¶ Returns the out-degrees of the Structural Graph. Sorted.
- Returns
out-degrees.
- Return type
(list)
-
to_cnet
(file=None, adjust_no_input=False)[source]¶ Outputs the network logic to
.cnet
format, which is similar to the Berkeley Logic Interchange Format (BLIF). This is the format used by BNS to compute attractors.- Parameters
file (string,optional) – A string of the file to write the output to. If not supplied, a string will be returned.
adjust_no_input (bool) – Adjust output string for nodes with no input.
- Returns
The
.cnet
format string.- Return type
(string)
Note
See BNS for more information.
-
trajectory
(initial, length=2)[source]¶ Computes the trajectory of
length
steps without the State Transition Graph (STG).
-
trajectory_to_attractor
(initial, precompute_attractors=True, return_attractor=False)[source]¶ Computes the trajectory starting at initial until it reaches an attracor (this is garanteed).
- Parameters
initial (string) – the initial binstate.
precompute_attractors (bool) – use precomputed attractors, default True.
return_attractor (bool) – also return the attractor reached, default False.
- Returns
the state trajectory between initial and the final attractor state. if return_attractor: (list): the attractor
- Return type
(list)
-
BNS Attractors Interface¶
This module interfaces CANA with the [B]oolean [N]etworks with [S]ynchronous update (BNS) [DT11] to compute attractors.
BNS is a software tool for computing attractors in Boolean Networks with Synchronous update. Synchronous Boolean networks are used for the modeling of genetic regulatory networks.
BNS implements the algorithm presented in which is based on a SAT-based bounded model checking. BNS uses much less space compared to BooleNet or other BDD-based approaches for computing attractors. It can handle several orders of magnitude larger networks.
Note
You must have bns
compiled for you system. Alternatively, you can download the binary from the bns website directly.
Last updated: March 2017.
-
cana.bns.
attractors
(cnet, bnspath='/Users/rionbr/Sites/CANA/cana/bns', cleanup=True)[source]¶ Makes a subprocess call to bns supplying a temporary file with the boolean logic.
- Parameters
cnet (file,string) – A .cnet formated string or file.
bnspath (string) – The path to the bns binary.
cleanup (bool) – If cnet is a string, this function creates a temporary file. This forces the removal of this temp file.
- Returns
the list of attractors
- Return type
list