hklarner / pyboolnet

PyBoolNet is a Python package for the generation, modification and analysis of Boolean networks.
43 stars 21 forks source link

how to compute attractors for many boolean networks #24

Closed crptcusco closed 3 years ago

crptcusco commented 5 years ago

Escuse Me, hklarner

I want to create several boolean networks in the same script. But when trying this the variables of the previous prime remain. I perceive this when I try to calculate the attractors, they have more states. The code I am using is below. Thanks

#route of the Boolean Network files ( in bnet format)
v_path = "files/rddas_r3_v5/"
#save the name of each Boolean Network file
list_directory = listdir(v_path)
l_primes =[]
v_cont = 0
#for every Boolean Network file, we find the attractors
for bnet in list_directory:
    print (v_path + bnet)
    primes = PyBoolNet.FileExchange.bnet2primes(v_path + bnet)
    l_primes.append(primes)
    l_signals_acoplament = PrimeImplicants.find_constants(l_primes[v_cont])
    v_num_signal_acoplament = len(l_signals_acoplament)
    #create and modify a static variables 
    for v_permutacion in product(list('01'), repeat=v_num_signal_acoplament):
        v_cont_signal = 0
        l_added_variables = []    
        print(v_permutacion)    
        for v_signal_value in zip(l_signals_acoplament,v_permutacion):
            PrimeImplicants.create_variables(l_primes[v_cont], { v_signal_value[0] : v_signal_value[1]})
            v_cont_signal = v_cont_signal + 1
        stg = StateTransitionGraphs.primes2stg(l_primes[v_cont], "synchronous")        
        l_attractors = Attractors.compute_attractors_tarjan(stg)
        for v_atrator in l_attractors:
            print (v_atrator)    
    v_cont = v_cont + 1        
print ("-------------------------") 
hklarner commented 5 years ago

i don't understand anything you write

crptcusco commented 5 years ago

i update the question

hklarner commented 5 years ago

can you use code formatting? I can read anything.

crptcusco commented 5 years ago

now the code is okey.

hklarner commented 5 years ago

1) if you want to find all attractors for a network in which all constants are replaced by inputs (see 3.4.4 input combinations, p.39), use the example given in the reference for create_inputs (p.63):

constants = find_constants(primes)
create_inputs(primes, constants)
stg = StateTransitionGraphs.primes2stg(primes, "synchronous")        
attractors = Attractors.compute_attractors_tarjan(stg)

You can also use input_combinations if you want to group by "signals":

constants = find_constants(primes)
create_inputs(primes, constants)

for signal in input_combinations(primes, "dict"):
    print("signal: {}".format(signal))

    primes_modified = create_constants(primes, signal, Copy=True)
    stg = StateTransitionGraphs.primes2stg(primes_modified, "synchronous")        
    steadystates, cyclic = Attractors.compute_attractors_tarjan(stg)

2) explain what you mean with "the variables of the previous prime remain". Add print(list(l_primes[v_cont].keys())) to you program and show me the output.

crptcusco commented 5 years ago

the output of print(list(l_primes[v_cont].keys())) is : ['v1', 'v2', 'v3', 'v4', 'v5', 'v6', 'v7', 'v8'] in the Boolean Network 1 and ['v1', 'v10', 'v11', 'v12', 'v13', 'v2', 'v3', 'v6', 'v7', 'v8', 'v9'] in the Boolean Network 2

but v1, v2, v3 must not exist in the Boolean network 2, this is the mean of "the variables of the previous prime remain", because the Networks only have 5 variables and 3 constants = 8 variables , i attach the files of the description of the network and the output of the program.

rdda1_r3_v5.txt rdda2_r3_v5.txt output.txt

hklarner commented 5 years ago

The file rdda2_r3_v5.txt does contain the variables v1, v2 and v3. They are used by the update function of v10. A network needs to define all its variables. How would you define v1, v2 and v3? PyBoolNet assumes that they are inputs, defined by

v1, v1
v2, v2
v3, v3
crptcusco commented 5 years ago

escuse me , i pass the wrong file rdda2_r3_v5.txt , now it is working well , but i dont understand why in the output of Attractors.compute_attractors_tarjan(stg) have [] in blank. i attach again the files of the description of the network and the output of the program.

Have one form to order the output variables in the atractors ['v1', 'v11', 'v12', 'v13', 'v14', 'v15', 'v2', 'v3'] like ['v1', 'v2', 'v3', 'v11', 'v12', 'v13', 'v14', 'v15']. I want recognized in this order.

output.txt rdda3_r3_v5.txt rdda2_r3_v5.txt rdda1_r3_v5.txt

hklarner commented 5 years ago

have you read the documentation for Attractors.compute_attractors_tarjan(stg)? It returns two objects, the steady states and the cyclic attractors. It should be called like this:

steadystates, cyclic = Attractors.compute_attractors_tarjan(stg)
crptcusco commented 5 years ago

Oh thats rigth , it have two list one for steady states and other for the cyclic attractors , thanks you very much. The problem has been solved, now I can find the attractors of several different Boolean networks, I leave the code with which it worked.

#IMPORTS
import PyBoolNet
#import sys
from PyBoolNet import Attractors
from PyBoolNet import PrimeImplicants
from PyBoolNet import StateTransitionGraphs
from itertools import product
from os import listdir

#route of the Boolean Network files ( in bnet format)
v_path = "files/rddas_r3_v5/"
#save the name of each Boolean Network file
list_directory = listdir(v_path)
l_primes =[]
v_cont = 0
#for every Boolean Network file, we find the attractors
for bnet in list_directory:
    print (v_path + bnet)
    primes = PyBoolNet.FileExchange.bnet2primes(v_path + bnet)
    l_primes.append(primes)
    l_signals_acoplament = PrimeImplicants.find_constants(l_primes[v_cont])
    v_num_signal_acoplament = len(l_signals_acoplament)
    #create and modify a static variables 
    for v_permutacion in product(list('01'), repeat=v_num_signal_acoplament):
        v_cont_signal = 0
        l_added_variables = []    
        print(v_permutacion)    
        for v_signal_value in zip(l_signals_acoplament,v_permutacion):
            PrimeImplicants.create_variables(l_primes[v_cont], { v_signal_value[0] : v_signal_value[1]})
            v_cont_signal = v_cont_signal + 1
        stg = StateTransitionGraphs.primes2stg(l_primes[v_cont], "synchronous")        
        l_attractors = Attractors.compute_attractors_tarjan(stg)
        #print (l_attractors)
        for v_atrator in l_attractors:
            print (v_atrator)

        #for v_atrator in l_attractors:
        #    print (v_atrator)

    print(list(l_primes[v_cont].keys()))     
    v_cont = v_cont + 1   

print ("-------------------------")
hklarner commented 5 years ago

Let me know how you are using PyBoolNet in the future. I am happy to make suggestions and help if I can.