def simulation(): # creating the transition graph, the verbose parameter sets the nodes to # either short names like 1, 2, 3 or long (binary) names like 10001 # # the logfile contains the transition edges and the identity of the nodes trans = network.TransGraph(logfile='timemodel.log', verbose=True) # create the model, you may use a text string or a filename model = boolean2.Model(text='timemodel.txt', mode='time') # here we generates all initial states # # IMPORTANT: Only uninitialized nodes will get new values, # to keep a node the same in all iterations initialize it in the rules # # when the limit parameter is a number it will takes the first that # many initial values, leave it to None to use all initial values initializer = state.all_initial_states(model.nodes, limit=None) # the data is a dictionary with the inital data, print it to see what it contains # the initfunc is the initializer function that can be used for data, initfunc in initializer: model.initialize(missing=initfunc) model.iterate(100) trans.add(model.states, times=range(100)) # saves the transition graph into a gml file trans.save('timemodel.gml') G = nx.read_gml('timemodel.gml') nx.write_gml(G, "timemodel_2.gml")
def test_main(): text = """ A = True B = Random C = Random D = Random B* = A or C C* = A and not D D* = B and C """ repeat = 5000 coll = util.Collector() for i in range(repeat): update_progress(i, repeat) model = boolean2.Model(text, mode='async') model.initialize() model.iterate(steps=15) # in this case we take all nodes # one could just list a few nodes such as [ 'A', 'B', 'C' ] nodes = model.nodes # this collects states for each run coll.collect(states=model.states, nodes=nodes) # this step averages the values for each node # returns a dictionary keyed by nodes and a list of values # with the average state for in each timestep avgs = coll.get_averages(normalize=True) # make some shortcut to data to for easier plotting valueB = avgs["B"] valueC = avgs["C"] valueD = avgs["D"] # # plot the state of the nodes # p1, = plt.plot(valueB, 'ob-') p2, = plt.plot(valueC, 'sr-') p3, = plt.plot(valueD, '^g-') plt.legend([p1, p2, p3], ["B", "C", "D"]) plt.show() plt.savefig('t-05_figure.png')
def test_this(): def set_value( state, name, value, p ): "Custom value setter" # detect the node of interest if name == 'C': print 'now setting node %s' % name value = random.choice ( (True, False) ) # value = 1 # this sets the attribute setattr( state, name, value ) return value text = """ A = True B = False C = False D = True 1: B* = A or C 1: C* = A and not D 1: D* = B and C """ model = boolean2.Model( text, mode='plde') model.parser.RULE_SETVALUE = set_value model.initialize() model.iterate( fullt=7, steps=150 ) # generate the plot # p1 = plt.plot( model.data["B"] , 'ob-' ) p2 = plt.plot( model.data["C"] , 'sr-' ) p3 = plt.plot( model.data["D"] , '^g-' ) plt.legend( [p1,p2,p3], ["B","C","D"]) plt.show() plt.savefig('t-06_output.jpg')
def test_this(): text = """ A = True B = False C = False D = True 1: B* = A or C 1: C* = A and not D 1: D* = B and C """ model = boolean2.Model(text, mode='plde') model.initialize() model.iterate(fullt=7, steps=150) # generate the plot # p1 = plt.plot(model.data["B"], 'ob-') p2 = plt.plot(model.data["C"], 'sr-') p3 = plt.plot(model.data["D"], '^g-') plt.legend([p1, p2, p3], ["B", "C", "D"]) plt.show() plt.savefig('t-06_output.jpg')
# # these nodes will be set to false and their corresponding updating # rules will be removed # off = ["B"] # # this modifies the original states to apply to overexpressed and knockouts # text = boolean2.modify_states(text, turnon=on, turnoff=off) # # see tutorial 3 for more details on what happens below # seen = {} for i in range(10): model = boolean2.Model(text, mode='sync') model.initialize() model.iterate(steps=20) size, index = model.detect_cycles() # fingerprint of the first state key = model.first.fp() # keep only the first 10 states out of the 20 values = [x.fp() for x in model.states[:10]] # store the fingerprinted values for each initial state seen[key] = (index, size, values) # print out the observed states