Skip to content

Instantly share code, notes, and snippets.

@yoavram
Created May 20, 2015 13:05
Show Gist options
  • Select an option

  • Save yoavram/a08ccfa0ba0fff875280 to your computer and use it in GitHub Desktop.

Select an option

Save yoavram/a08ccfa0ba0fff875280 to your computer and use it in GitHub Desktop.
Boolean model for regulatory networks
#########################################
## Boolean model for regulatory networks
#########################################
def update_node(G, states, i):
''' Return new state of node i given states vector '''
def update(G, states):
''' Return the next states vector - apply transition function to all nodes '''
def run(G, init, track = False):
''' Start with init vector, and run until steady state
Does not detect loops for the moment
Return the fixed point vector '''
#############################################
### Input network - toy example from lecture
print("Toy example:")
nodes = ['A','B','C','D','E','F']
init = [1, 0, 1, 0, 0, 0]
G = [
[ 0, 0, 0, 1, 0, 0],
[-1, 0, 0,-1,-1, 0],
[-1, 0, 0, 0, 0, 0],
[ 1, 0, 0, 0, 1, 0],
[ 0, 0, 0, 0, 0, 1],
[ 0, 0, 0,-1, 1,-1]
]
print(nodes)
run(G, init, True)
#############################################
### Input network - yeast cell-cycle
### "The Yeast Cell-Cycle Network is Robustly Designed", Li et.al, PNAS, 2004
##print("Yeast cell cycle:")
##nodes = ['Cln3','MBF','SBF','Cln1,2','Cdh1','Swi5','Cdc20/Cdc14','Clb5,6','Sic1','Clb1,2','Mcm1/SFF']
##
##init = [1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0] #simulation of this is in the paper
##
##G = [
## [-1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0],
## [ 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0],
## [ 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0],
## [ 0, 0, 0,-1,-1, 0, 0, 0,-1, 0, 0],
## [ 0, 0, 0, 0, 0, 0, 0, 0, 0,-1, 0],
## [ 0, 0, 0, 0, 0,-1, 0, 0, 1, 0, 0],
## [ 0, 0, 0, 0, 1, 1,-1,-1, 1,-1, 0],
## [ 0, 0, 0, 0,-1, 0, 0, 0,-1, 1, 1],
## [ 0, 0, 0, 0, 0, 0, 0,-1, 0,-1, 0],
## [ 0,-1,-1, 0,-1,-1, 1, 0,-1, 0, 1],
## [ 0, 0, 0, 0, 0, 1, 1, 0, 0, 1,-1]
## ]
##
##print(nodes)
##run(G, init, True)
##
##final = [0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0] #according to paper, 1764 initial vectors end here
##print(attractor_size(G, final), "initial vectors end at", final)
##def update_node(G, states, i):
## ''' Return new state of node i given states vector '''
## n = len(states)
## s = 0
##
## for j in range(n):
## s += G[j][i] * states[j]
## if s > 0:
## new = 1
## elif s < 0:
## new = 0
## else:
## new = states[i]
##
## return new
##
##def update(G, states):
## ''' Return the next states vector - apply transition function to all nodes '''
## n = len(states)
## next_states = [-1]*n
##
## for i in range(n):
## next_states[i] = update_node(G, states,i)
## return next_states
##
##
##def run(G, init, track = False):
## ''' Start with init vector, and run until steady state
## Does not detect loops for the moment
## Return the fixed point vector '''
## if track:
## print(init)
##
## states = init
## next_states = update(G, states)
##
## while next_states != states:
## if track:
## print(next_states)
## states = next_states
## next_states = update(G, states)
## return states #steady state (attractor) reached
##import itertools
##
##def attractor_size(G, attractor):
## ''' count how many initial vectors end up in the attractor vector '''
## cnt=0
## n = len(G)
## for states in itertools.product([0,1], repeat=n): #cartesian product
## states = list(states) #convert tuple-->list
## final = run(G, states)
## if final == attractor:
## cnt+=1
## return cnt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment