#!/usr/bin/env python # coding: utf-8 # # Stochastic simulation of Boolean network with MaBoSS # # This notebook show the basic features of the `maboss` Python module by reproducing part of the official MaBoSS tutorial at https://maboss.curie.fr/pub/TutorialMaBoSS_2_0.pdf # In[1]: import maboss import ginsim # ### Model # # The input model is a simple Boolean network created with GINsim. We download it from MaBoSS website and display its regulatory graph using the `ginsim` Python module: # In[2]: lrg = ginsim.load("https://maboss.curie.fr/pub/example.zginml") # In[3]: ginsim.show(lrg) # ### Building the `Simulation` object # # A GINsim model can be converted to MaBoSS using the `to_maboss` function: # In[4]: masim = ginsim.to_maboss(lrg) # MaBoSS allows to specify some nodes as "internal": the value of internal nodes is hidden in the output of simulations. # By default, (if the network was built from scratch or if the `.cfg` file did not contain the information for a given node), all nodes have the attribute `is_internal` set to `False`. This can be changed within the script # In[5]: masim.network['DNAdam'].is_internal = True # You can change other MaBoSS parameters with the function update_parameters: # In[6]: masim.update_parameters(time_tick=0.1, max_time=4) # Once all the parameters are set, you can run the simulation. The following line will create two temporary files that contains everything MaBoSS needs to know to run properly. The result of the simulation are stored in a `Result` object. # # To run the simulation, use the command below. This command can be quickly written by going to MaBoSS -> Simulation -> run. # ### Performing simulations # # The `run` method of the simulation object will call MaBoSS to perfom the requested simulations. A result object is then returned. # In[7]: res = masim.run() # ### Result visualizations # The result object provides access to the simulation output, and provides simple plotting functions. # # The `plot_trajectory` method displays the mean probability of each state (composed of non-internal nodes) along time: # In[8]: res.plot_trajectory() # The `plot_piechart` method displays the proportion of states in which each simulation ended, providing an approximation of the probability to reach the different attractors. # In[9]: res.plot_piechart(autopct=True) # ### Simulating mutations # # The `maboss` Python module allow to modify a network model to perform the mutation of a node, that is forcing its value to be always 1 ("ON") or always 0 ("OFF"). # # In the following cell, we copy the initial model and configure a gain of function mutant for the node `Mdm2nuc`: # In[10]: mutsim = masim.copy() mutsim.mutate("Mdm2nuc", "ON") # The resulting model can then be simulated: # In[11]: mutres = mutsim.run() # In[12]: mutres.plot_piechart() # In[ ]: