def main(): print "time_evol module is the main code." ## to import a network of 3-node example EDGE_FILE = 'C:\Boolean_Delay_in_Economics\Manny\EDGE_FILE.dat' NODE_FILE = 'C:\Boolean_Delay_in_Economics\Manny\NODE_FILE.dat' net = inet.read_network_from_file(EDGE_FILE, NODE_FILE) nodes_list = inet.build_nodes_list(NODE_FILE) ''' ## to obtain time series data for all possible initial conditions for 3-node example network timeSeriesData = ensemble_time_series(net, nodes_list, 2, 10)#, Nbr_States=2, MAX_TimeStep=20) initState = 1 biStates = decimal_to_binary(nodes_list, initState) print 'initial state', biStates ## to print time series data for each node: a, b, c starting particualr decimal inital condition 1 print 'a', timeSeriesData['a'][1] print 'b', timeSeriesData['b'][1] print 'c', timeSeriesData['c'][1] ''' ## to obtain and visulaize transition map in the network state space decStateTransMap = net_state_transition(net, nodes_list) nx.write_graphml(decStateTransMap,'C:\Boolean_Delay_in_Economics\Manny\Results\BDE.graphml') '''
def main(): print "time_evol module is the main code." EDGE_FILE = '../data/example/example-net-edges.dat' NODE_FILE = '../data/example/example-net-nodes.dat' net = inet.read_network_from_file(EDGE_FILE, NODE_FILE) nodes_list = inet.build_nodes_list(NODE_FILE) timeSeriesData = ensemble_time_series(net, nodes_list, 2, 10)#, Nbr_States=2, MAX_TimeStep=20) initState = 1 biStates = decimal_to_binary(nodes_list, initState) print 'initial state', biStates print 'CycD', timeSeriesData['CycD'][1] print 'Rb', timeSeriesData['Rb'][1] print 'E2F', timeSeriesData['E2F'][1] print 'CycE', timeSeriesData['CycE'][1] print 'CycA', timeSeriesData['CycA'][1] print 'P27', timeSeriesData['P27'][1] print 'Cdc20', timeSeriesData['Cdc20'][1] print 'UbcH10', timeSeriesData['UbcH10'][1] print 'Cdh1', timeSeriesData['Cdh1'][1] print 'CycB', timeSeriesData['CycB'][1] decStateTransMap = net_state_transition(net, nodes_list) #nx.draw(decStateTransMap) plt.show() nx.write_graphml(decStateTransMap, '/home/tessa/Documents/cyclegraph.graphml') attractors = find_attractor(decStateTransMap) print attractors
def main(): print "updating_rule module is the main code." EDGE_FILE = '../data/example/example-net-edges.dat' NODE_FILE = '../data/example/example-net-nodes.dat' net = inet.read_network_from_file(EDGE_FILE, NODE_FILE) nodes_list = inet.build_nodes_list(NODE_FILE) #prevState = {'CycD':0.0, 'b':0.0, 'c':1.0} prevState = {} prevState['CycD'] = float(sys.argv[1]) prevState['Rb'] = float(sys.argv[2]) prevState['E2F'] = float(sys.argv[3]) prevState['CycE'] = float(sys.argv[4]) prevState['CycA'] = float(sys.argv[5]) prevState['P27'] = float(sys.argv[6]) prevState['Cdc20'] = float(sys.argv[7]) prevState['Cdh1'] = float(sys.argv[8]) prevState['UbcH10'] = float(sys.argv[9]) prevState['CycB'] = float(sys.argv[10]) #print "network state @ previous step", OrderedDict(sorted(prevState.items(), key=lambda t: t[0])) for v in nodes_list: print prevState[v], currState = sigmoid_updating(net, prevState) print '\n' #print "network state @ current step", OrderedDict(sorted(currState.items(), key=lambda t: t[0])) for v in nodes_list: print currState[v],
def main(): outpath = 'test.csv' print "updating_rule module is the main code." EDGE_FILE = '../data/example/example-net-edges.dat' NODE_FILE = '../data/example/example-net-nodes.dat' net = inet.read_network_from_file(EDGE_FILE, NODE_FILE) nodes_list = inet.build_nodes_list(NODE_FILE) #prevState = {'CycD':0.0, 'b':0.0, 'c':1.0} prevState = {} prevState['CycD'] = 1 prevState['Rb'] = 0 prevState['E2F'] = 0 prevState['CycE'] = 0 prevState['CycA'] = 1 prevState['P27'] = 0 prevState['Cdc20'] = 1 prevState['Cdh1'] = 0 prevState['UbcH10'] = 1 prevState['CycB'] = 1 #print "network state @ previous step", OrderedDict(sorted(prevState.items(), key=lambda t: t[0])) with open(outpath, "w") as f: writer = csv.writer(f) writer.writerow(nodes_list) #for v in nodes_list: prevList = [] for v in nodes_list: prevList.append(prevState[v]) with open(outpath, "a") as f: writer = csv.writer(f) writer.writerow(prevList) currState = cell_updating(net, prevState) currList = [] for v in nodes_list: currList.append(currState[v]) with open(outpath, "a") as f: writer = csv.writer(f) writer.writerow(currList) repeat = 0 while(repeat < 6): prevState = currState.copy() currState = cell_updating(net, prevState) currList = [] for v in nodes_list: currList.append(currState[v]) with open(outpath, "a") as f: writer = csv.writer(f) writer.writerow(currList) repeat += 1
def main(): EDGE_FILE = '../data/fission-net/fission-net-edges.txt' NODE_FILE = '../data/fission-net/fission-net-nodes.txt' BIO_INIT_FILE = '../data/fission-net/fission-net-bioSeq-initial.txt' net = inet.read_network_from_file(EDGE_FILE, NODE_FILE) nodes_list = inet.build_nodes_list(NODE_FILE) bio_initStates = inet.read_init_from_file(BIO_INIT_FILE) decStateTransMap = net_state_transition(net, nodes_list) attractors = find_attractor(decStateTransMap) print attractors
def main(): ''' print "time_evol module is the main code." ## to import a network of 3-node example EDGE_FILE = '../data/example/example-net-edges.dat' NODE_FILE = '../data/example/example-net-nodes.dat' net = inet.read_network_from_file(EDGE_FILE, NODE_FILE) nodes_list = inet.build_nodes_list(NODE_FILE) ## to obtain time series data for all possible initial conditions for 3-node example network timeSeriesData = ensemble_time_series(net, nodes_list, 2, 10)#, Nbr_States=2, MAX_TimeStep=20) initState = 1 biStates = decimal_to_binary(nodes_list, initState) print 'initial state', biStates ## to print time series data for each node: a, b, c starting particualr decimal inital condition 1 print 'a', timeSeriesData['a'][1] print 'b', timeSeriesData['b'][1] print 'c', timeSeriesData['c'][1] ## to obtain and visulaize transition map in the network state space decStateTransMap = net_state_transition(net, nodes_list) nx.draw(decStateTransMap) plt.show() ## to find fixed point attractors and limited cycle attractors with given transition map. attractors = find_attractor(decStateTransMap) print attractors ''' ## to obtain biological sequence for the Fission Yeast Cell-Cycle Net starting from biological inital state EDGE_FILE = '../data/fission-net/fission-net-edges.txt' NODE_FILE = '../data/fission-net/fission-net-nodes.txt' #BIO_INIT_FILE = '../data/fission-net/fission-net-bioSeq-initial.txt' BIO_INIT_FILE = '../data/fission-net/fission-net-bioSeq-initial.txt' net = inet.read_network_from_file(EDGE_FILE, NODE_FILE) nodes_list = inet.build_nodes_list(NODE_FILE) bio_initStates = inet.read_init_from_file(BIO_INIT_FILE) outputFile = '../results/fission-net/fission-net-bioSeq.txt' bioSeq = biological_sequence(net, nodes_list, bio_initStates, outputFile)
def main(args): ## to obtain biological sequence for the Fission Yeast Cell-Cycle Net starting from biological inital state EDGE_FILE = '../data/fission-net/fission-net-edges.txt' NODE_FILE = '../data/fission-net/fission-net-nodes.txt' BIO_INIT_FILE = '../data/fission-net/fission-net-bioSeq-initial.txt' net = inet.read_network_from_file(EDGE_FILE, NODE_FILE) nodes_list = inet.build_nodes_list(NODE_FILE) #input_file_name1 = 'time-series/%s-step%d-trans0.dat'%(network_index, maxStep) #input_file1 = open( input_file_name1, 'r') Nbr_Initial_States = np.power(2,len(nodes_list)) maxStep = 20 Nbr_States = 2 historyLength = 5 result_ai = open('../results/fission-net/ai-step%d-trans0-h%d.dat'%(maxStep, historyLength),'w') result_te = open('../results/fission-net/te-step%d-trans0-h%d.dat'%(maxStep, historyLength),'w') timeSeries = tev.time_series(net, nodes_list, Nbr_Initial_States, Nbr_States, MAX_TimeStep=20) print 'AI' AI = {} for n in nodes_list: AI[n] = info.compute_AI(timeSeries[n], historyLength, Nbr_Initial_States, Nbr_States) result_ai.write('%s\t%f\n'%(n, AI[n])) print n, AI[n] print 'done AI' print 'TE' TE = defaultdict(float) for v in nodes_list: for n in nodes_list: TE[(v, n)] = info.compute_TE(timeSeries[v], timeSeries[n], historyLength, Nbr_Initial_States, Nbr_States) result_te.write('%s\t%s\t%f\n'%(v, n,TE[(v, n)] )) print v, n, TE[(v, n)] print 'done TE'
def main(args): EDGE_FILE = "net-edges.dat" NODE_FILE = "net-nodes.dat" net = inet.read_network_from_file(EDGE_FILE, NODE_FILE, node_delete="none", edge_delete="none") nodes_list = inet.build_nodes_list(NODE_FILE, node_delete="none") nbrRanNet = 10 # the number of random networks # generate global random networks (ER nets)# for i in range(0, nbrRanNet): result_file = open("p53-gr%d.dat" % (i), "w") gr_net = global_random_network(net) for u, v in gr_net.edges_iter(): result_file.write("%s\t%s\t%d\n" % (u, v, gr_net[u][v]["weight"])) # generate local random networks (SF nets)# for i in range(0, nbrRanNet): result_file = open("p53-lr%d.dat" % (i), "w") lr_net = local_random_network(net) for u, v in lr_net.edges_iter(): result_file.write("%s\t%s\t%d\n" % (u, v, lr_net[u][v]["weight"]))
def main(args): EDGE_FILE = '../data/fission-net/fission-net-edges.txt' NODE_FILE = '../data/fission-net/fission-net-nodes.txt' net = inet.read_network_from_file(EDGE_FILE, NODE_FILE) nodes_list = inet.build_nodes_list(NODE_FILE) nbrRanNet = 10 # the number of random networks #generate global random networks (ER nets)# for i in range(0, nbrRanNet): result_file = open('../random-samples/fission-gr%d.dat'%(i), 'w') gr_net = global_random_network(net) for u, v in gr_net.edges_iter(): result_file.write('%s\t%s\t%d\n'%(u, v, gr_net[u][v]['weight'])) #generate local random networks (SF nets)# for i in range(0, nbrRanNet): result_file = open('../random-samples/fission-lr%d.dat'%(i), 'w') lr_net = local_random_network(net) for u, v in lr_net.edges_iter(): result_file.write('%s\t%s\t%d\n'%(u, v, lr_net[u][v]['weight']))
def main(args): maxStep = int(raw_input("Type in the length of time steps (maxStep): ")) # the length of time steps starting from each initial state Nbr_States = 2 # the number of all possible states of a node historyLength = int(raw_input("Type in the length of history states (h): ")) # the length of history states ## 1. Network Information from Data File ## random_network = str(raw_input("Type l for local random, g for global random: ")) NODE_FILE = 'net-nodes.dat' # Asks user if network has been damaged. damage = raw_input("Type in 1 for DNA damage and 0 for no damage: ") # Asks user if there has been a node deletion. node_delete = str(raw_input("Type in node for deletion or none for no deletion: ")) # Asks user if there has been a single edge link deletion. u = str(raw_input("Type in upstream node of edge for deletion or none for no deletion: ")) if u != 'none': v = str(raw_input("Type in downstream node of edge for deletion: ")) edge_delete = u,v else: edge_delete = u for i in range(10): ran_network_filename = i if random_network == 'g': EDGE_FILE = 'p53-gr%s.dat'%(ran_network_filename) elif random_network == 'l': EDGE_FILE = 'p53-lr%s.dat'%(ran_network_filename) ## 2. To Build net and nodes_list: Module 'input_net' is required ## net = inet.read_network_from_file(EDGE_FILE, NODE_FILE, node_delete, edge_delete) nodes_list = inet.build_nodes_list(NODE_FILE, node_delete) ## 5. To generate time series data from 1, 2 and 3: Modules 'time_evol' and 'updating_rule' are required ## timeSeries_Type = ['all_initial'] # 'all_initial', 'primary_attractor', 'one_trajectory' if 'all_initial' in timeSeries_Type: ## 5-1. time series for all possible initial network states. Nbr_All_Initial_States = np.power(Nbr_States, len(nodes_list)) # the number of initial states of the network timeSeriesAll = tev.time_series_all(net, nodes_list, damage, Nbr_All_Initial_States, Nbr_States, maxStep) # To generate time series data over all possible initial states if 'primary_attractor' in timeSeries_Type: ## 5-2. time series for initial network states that converge to primary (or biological) attractor decStateTransMap = tev.net_state_transition(net, nodes_list, Nbr_States) # To build transition map between network states over network state space attractors = tev.find_attractor(decStateTransMap) # To find attractors ==> attractors = {attractor state1: {'type': 'fixed', 'basin-size': 2, 'basin': [network state a, network state b]}, attractor state2: {}, ... } primary_attractor = attractors.keys()[0] #attractors is ordered with basin size from the function "find_attractor" and hence primary attractor is the first one. Initial_States_List = list(attractors[primary_attractor]['basin']) # To assign all initial states in the basin of primary attractor to the list of initail states timeSeriesPa = tev.time_series_pa(net, nodes_list, Initial_States_List, Nbr_States, maxStep) # To generate time series data over all initial states that converge to the primary attractor if 'one_trajectory' in timeSeries_Type: ## 5-3. time sereis for one initial network state InitBiState = { 'SK': 1, 'Cdc2_Cdc13': 0, 'Ste9': 1, 'Rum1': 1, 'Slp1': 0, 'Cdc2_Cdc13_active': 0, 'Wee1_Mik1': 1, 'Cdc25': 0, 'PP': 0 } # initial state for fission yeast #InitBiState = {'Cln3': 1, 'MBF':0, 'SBF': 0, 'Cln1_2':0, 'Cdh1':1, 'Swi5':0, 'Cdc20_Cdc14':0, 'Clb5_6':0, 'Sic1': 1, 'Clb1_2':0, 'Mcm1_SFF':0} # initial state for budding yeast timeSeriesOne = tev.time_series_one(net, nodes_list, InitBiState, Nbr_States, maxStep) # To generate time series data for one particular initial state ''' The format for timeSeries ==> timeSeries = { node1: {1st initial_state: [0,1,1, ......, 0], ...... , Nth initial_state: [1,0,1, ......, 1]}, node 2: {1st initial_state: [1,1,1, ......, 0], ...... , Nth initial_state: [1,0,0, ......, 0]}, .......} ==> timeSeries[node2][initial_state 1] = [1,1,1, ......, 0] ''' ## 4. Output files ## #result_ai = open('../results/fission-net/ai-step%d-trans0-h%d.dat'%(maxStep, historyLength),'w') #result_te = open('../results/fission-net/te-step%d-trans0-h%d.dat'%(maxStep, historyLength),'w') ## 6. To measure active information (AI) and transfer entropy (TE): using 'compute_AI' and 'compute_TE' from Module 'info_dyn" ## ## 6-1. For all possible initial network states if 'all_initial' in timeSeries_Type: ## 6-1-a. To compute AI if random_network == 'n': result_ai_all = open('ai-all-step%d-h%d-%s.dat'%(maxStep, historyLength,damage),'w') elif random_network == 'g': result_ai_all = open('ai-all-step%d-h%d-gr%s-%s.dat'%(maxStep, historyLength, ran_network_filename,damage),'w') elif random_network == 'l': result_ai_all = open('ai-all-step%d-h%d-lr%s-%s.dat'%(maxStep, historyLength, ran_network_filename,damage),'w') AI_all = {} for n in nodes_list: AI_all[n] = info.compute_AI(timeSeriesAll[n], historyLength, Nbr_All_Initial_States, Nbr_States) result_ai_all.write('%s\t%f\n'%(n, AI_all[n])) print n, AI_all[n] ## 6-1-b. To compute TE if random_network == 'n': result_te_all = open('te-all-step%d-h%d-%s.dat'%(maxStep, historyLength,damage),'w') elif random_network == 'g': result_te_all = open('te-all-step%d-h%d-gr%s-%s.dat'%(maxStep, historyLength, ran_network_filename,damage),'w') elif random_network == 'l': result_te_all = open('te-all-step%d-h%d-lr%s-%s.dat'%(maxStep, historyLength, ran_network_filename,damage),'w') TE_all = defaultdict(float) for v in nodes_list: for n in nodes_list: TE_all[(v, n)] = info.compute_TE(timeSeriesAll[v], timeSeriesAll[n], historyLength, Nbr_All_Initial_States, Nbr_States) result_te_all.write('%s\t%s\t%f\n'%(v, n,TE_all[(v, n)] )) print v, n,TE_all[(v, n)] result_file_name = 'ai-all-scale-step%d-h%d-%sr%s-%s.dat'%(maxStep, historyLength, random_network, ran_network_filename,damage) viz_file_name = 'ai-all-scale-step%d-h%d-%sr%s-%s.pdf'%(maxStep, historyLength, random_network, ran_network_filename,damage) draw_plots.plot_AI_scale(AI_all, result_file_name, viz_file_name) result_file_name = 'te-all-scale-step%d-h%d-%sr%s-%s.dat'%(maxStep, historyLength, random_network, ran_network_filename,damage) viz_file_name = 'te-all-scale-step%d-h%d-%sr%s-%s.pdf'%(maxStep, historyLength, random_network, ran_network_filename,damage) draw_plots.plot_TE_scale(TE_all, result_file_name, viz_file_name) ## 6-2. For initial network states that converge to the primary attractor if 'primary_attractor' in timeSeries_Type: ## 6-2-a. To compute AI result_ai_pa = open('../results/fission-net/ai-pa-step%d-trans0-h%d.dat'%(maxStep, historyLength),'w') AI_pa = {} for n in nodes_list: AI_pa[n] = info.compute_AI(timeSeriesPa[n], historyLength, len(Initial_States_List), Nbr_States) result_ai_pa.write('%s\t%f\n'%(n, AI_pa[n])) ## 6-2-b. To compute TE result_te_pa = open('../results/fission-net/te-pa-step%d-trans0-h%d.dat'%(maxStep, historyLength),'w') TE_pa = defaultdict(float) for v in nodes_list: for n in nodes_list: TE_pa[(v, n)] = info.compute_TE(timeSeriesPa[v], timeSeriesPa[n], historyLength, len(Initial_States_List), Nbr_States) result_te_pa.write('%s\t%s\t%f\n'%(v, n,TE_pa[(v, n)] )) ## 6-2-c. Scale behavior for AI (optional) result_file_name = '../results/fission-net/ai-pa-scale-step%d-trans0-h%d.dat'%(maxStep, historyLength) viz_file_name = '../viz/fission-net/ai-pa-scale-step%d-trans0-h%d.pdf'%(maxStep, historyLength) draw_plots.plot_AI_scale(AI_pa, result_file_name, viz_file_name) ### plot and result file for AI scale ## 6-2-d. Scale behavior for TE (optional) result_file_name = '../results/fission-net/te-pa-scale-step%d-trans0-h%d.dat'%(maxStep, historyLength) viz_file_name = '../viz/fission-net/te-pa-scale-step%d-trans0-h%d.pdf'%(maxStep, historyLength) draw_plots.plot_TE_scale(TE_pa, result_file_name, viz_file_name) ### plot and result file for TE scale ## 6-3. For a particular initial network state if 'one_trajectory' in timeSeries_Type: ## 6-3-a. To compute AI result_ai_one = open('../results/fission-net/ai-one-step%d-trans0-h%d.dat'%(maxStep, historyLength),'w') AI_one = {} for n in nodes_list: AI_one[n] = info.compute_AI(timeSeriesOne[n], historyLength, 1, Nbr_States) result_ai_one.write('%s\t%f\n'%(n, AI_one[n])) ## 6-3-b. To compute TE result_te_one = open('../results/fission-net/te-one-step%d-trans0-h%d.dat'%(maxStep, historyLength),'w') TE_one = defaultdict(float) for v in nodes_list: for n in nodes_list: TE_one[(v, n)] = info.compute_TE(timeSeriesOne[v], timeSeriesOne[n], historyLength, 1, Nbr_States) result_te_one.write('%s\t%s\t%f\n'%(v, n,TE_one[(v, n)] )) ## 6-3-c. Scale behavior for AI (optional) result_file_name = '../results/fission-net/ai-one-scale-step%d-trans0-h%d.dat'%(maxStep, historyLength) viz_file_name = '../viz/fission-net/ai-one-scale-step%d-trans0-h%d.pdf'%(maxStep, historyLength) draw_plots.plot_AI_scale(AI_one, result_file_name, viz_file_name) ### plot and result file for AI scale ## 6-3-d. Scale behavior for TE (optional) result_file_name = '../results/fission-net/te-one-scale-step%d-trans0-h%d.dat'%(maxStep, historyLength) viz_file_name = '../viz/fission-net/te-one-scale-step%d-trans0-h%d.pdf'%(maxStep, historyLength) draw_plots.plot_TE_scale(TE_one, result_file_name, viz_file_name) ### plot and result file for TE scale
def edge_print(EDGE_FILE,NODE_FILE,node_delete,edge_delete,damage,random_network,i,node_number): net = inet.read_network_from_file(EDGE_FILE, NODE_FILE, node_delete,edge_delete) nodes_list = inet.build_nodes_list(NODE_FILE,node_delete) initState = 1 biStates = decimal_to_binary(nodes_list, initState) #print 'initial state', biStates decStateTransMap = net_state_transition(net, nodes_list, damage, Nbr_States=2) u = edge_delete #if u != 'none': #v = edge_delete.pop([0]) # Exports network and attractor landscape for use in cytoscape. if random_network == 'n': if (u == 'none') and (node_delete == 'none'): nx.write_graphml(net,"network_%s_p53_%s_normal.graphml"%(damage,node_number)) nx.write_graphml(decStateTransMap,"attractor_%s_p53_%s_normal.graphml"%(damage,node_number)) attractor_file = 'attractors_%s_%s_%s_%s_%s.txt'%(random_network,damage,node_number,node_delete,edge_delete) elif (u == 'none') and (node_delete != 'none'): nx.write_graphml(net,"network_%s.graphml"%(node_delete)) nx.write_graphml(decStateTransMap,"attractor_%s.graphml"%(node_delete)) attractor_file = 'attractors_%s_%s_%s_%s_%s.txt'%(random_network,damage,node_number,node_delete,edge_delete) elif (u != 'none'): nx.write_graphml(net,"network_%s_%s.graphml"%(u,v)) nx.write_graphml(decStateTransMap,"attractor_%s_%s.graphml"%(u,v)) attractor_file = 'attractors_%s_%s_%s_%s_%s.txt'%(random_network,damage,node_number,node_delete,edge_delete) elif random_network == 'g': nx.write_graphml(net,"network_p53_gr%s_%s.graphml"%(i,damage)) nx.write_graphml(decStateTransMap,"attractor_p53_gr%s_%s.graphml"%(i,damage)) attractor_file = 'attractors_%s_%s.txt'%(random_network,damage) elif random_network == 'l': nx.write_graphml(net,"network_p53_lr%s_%s.graphml"%(i,damage)) nx.write_graphml(decStateTransMap,"attractor_p53_lr%s_%s.graphml"%(i,damage)) attractor_file = 'attractors_%s_%s.txt'%(random_network,damage) # Prints out all attractors attractors = find_attractor_old(decStateTransMap) print attractors print '\n' with open(attractor_file,'a') as f: f.write('%s, %s'%(i,attractors)) f.write('\n') # Prints out the fixed attractors for the network with values in a matrix format. f.write('*** fixed ***\n') for a in attractors['fixed']: biState = decimal_to_binary(nodes_list,a) b = [] c = [] keymaster = [] for key, values in biState.items(): b.append(values) keymaster.append(key) c = np.concatenate(b, axis=0) size = len(a) d = np.transpose(c.reshape((len(nodes_list),size))) print a print d, '\n' print keymaster, '\n' f.write('%s\n'%(a)) f.write('%s\n'%(keymaster)) f.write('%s\n'%(d)) f.write('\n') f.write('\n') # Prints out the cyclic attractors for the network with values in a matrix format. f.write('*** cyclic ***\n') for a in attractors['cycle']: biState = decimal_to_binary(nodes_list,a) b = [] c = [] keymaster = [] for key, values in biState.items(): b.append(values) keymaster.append(key) c = np.concatenate(b, axis = 0) size = len(a) d = np.transpose(c.reshape((len(nodes_list),size))) print a print d, '\n' print keymaster, '\n' f.write('%s\n'%(a)) f.write('%s\n'%(keymaster)) f.write('%s\n\n'%(d)) f.write('\n') ''' # Writes to a file the time series data. Nbr_Nodes = len(net.nodes()) Nbr_All_Initial_States = np.power(2, Nbr_Nodes) timeSeriesData = time_series_all(net, nodes_list, damage, Nbr_All_Initial_States, Nbr_States=2, MAX_TimeStep=20) if (u == 'none') and (node_delete == 'none'): TIME_FILE = 'timeseries_data_%s_normal.txt' %(damage) elif (u == 'none') and (node_delete != 'none'): TIME_FILE = 'timeseries_data_%s_damaged.txt' %(node_delete) elif (u != 'none'): TIME_FILE = 'timeseries_data_%s_%s_damaged.txt' %(u,v) with open(TIME_FILE,'a') as f: f.writelines('{}:{}\n'.format(k,v) for k, v in timeSeriesData.items()) f.write('\n') ''' ''' print 'ATM', timeSeriesData['ATM'][n] print 'p53', timeSeriesData['p53'][n] print 'Mdm2', timeSeriesData['Mdm2'][n] print 'MdmX', timeSeriesData['MdmX'][n] print 'Wip1', timeSeriesData['Wip1'][n] print 'cyclinG', timeSeriesData['cyclinG'][n] print 'PTEN', timeSeriesData['PTEN'][n] print 'p21', timeSeriesData['p21'][n] print 'AKT', timeSeriesData['AKT'][n] print 'cyclinE', timeSeriesData['cyclinE'][n] print 'Rb', timeSeriesData['Rb'][n] print 'E2F1', timeSeriesData['E2F1'][n] print 'p14ARF', timeSeriesData['p14ARF'][n] print 'Bcl2', timeSeriesData['Bcl2'][n] print 'Bax', timeSeriesData['Bax'][n] print 'caspase', timeSeriesData['caspase'][n] ''' return
## to obtain and visulaize transition map in the network state space decStateTransMap = net_state_transition(net, nodes_list) nx.draw(decStateTransMap) plt.show() ## to find fixed point attractors and limited cycle attractors with given transition map. attractors = find_attractor(decStateTransMap) print attractors ''' ## to obtain biological sequence for the Fission Yeast Cell-Cycle Net starting from biological inital state EDGE_FILE = '../data/fission-net/fission-net-edges.txt' NODE_FILE = '../data/fission-net/fission-net-nodes.txt' <<<<<<< HEAD #BIO_INIT_FILE = '../data/fission-net/fission-net-bioSeq-initial.txt' ======= BIO_INIT_FILE = '../data/fission-net/fission-net-bioSeq-initial.txt' >>>>>>> origin/master net = inet.read_network_from_file(EDGE_FILE, NODE_FILE) nodes_list = inet.build_nodes_list(NODE_FILE) bio_initStates = inet.read_init_from_file(BIO_INIT_FILE) outputFile = '../results/fission-net/fission-net-bioSeq.txt' bioSeq = biological_sequence(net, nodes_list, bio_initStates, outputFile) if __name__=='__main__': main()
def main(args): maxStep = 20 # the length of time steps starting from each initail state Nbr_States = 2 # the number of all possible states of a node historyLength = 5 # the length of history states ## 1. Network Information from Data File ## EDGE_FILE = '../data/fission-net/fission-net-edges.txt' NODE_FILE = '../data/fission-net/fission-net-nodes.txt' #EDGE_FILE = '../data/budding-net/budding-net-edges.txt' #NODE_FILE = '../data/budding-net/budding-net-nodes.txt' ## 2. To Build net and nodes_list: Module 'input_net' is required ## net = inet.read_network_from_file(EDGE_FILE, NODE_FILE) nodes_list = inet.build_nodes_list(NODE_FILE) ## 5. To generate time series data from 1, 2 and 3: Modules 'time_evol' and 'updating_rule' are required ## timeSeries_Type = ['all_initial'] # 'all_initial', 'primary_attractor', 'one_trajectory' if 'all_initial' in timeSeries_Type: ## 5-1. time series for all possible initial network states. Nbr_All_Initial_States = np.power(Nbr_States, len(nodes_list)) # the number of initial states of the network timeSeriesAll = tev.time_series_all(net, nodes_list, Nbr_All_Initial_States, Nbr_States, maxStep) # To generate time series data over all possible initial states if 'primary_attractor' in timeSeries_Type: ## 5-2. time series for initial network states that converge to primary (or biological) attractor decStateTransMap = tev.net_state_transition(net, nodes_list, Nbr_States) # To build transition map between network states over network state space attractors = tev.find_attractor(decStateTransMap) # To find attractors ==> attractors = {attractor state1: {'type': 'fixed', 'basin-size': 2, 'basin': [network state a, network state b]}, attractor state2: {}, ... } primary_attractor = attractors.keys()[0] #attractors is ordered with basin size from the function "find_attractor" and hence primary attractor is the first one. Initial_States_List = list(attractors[primary_attractor]['basin']) # To assign all initial states in the basin of primary attractor to the list of initail states timeSeriesPa = tev.time_series_pa(net, nodes_list, Initial_States_List, Nbr_States, maxStep) # To generate time series data over all initial states that converge to the primary attractor if 'one_trajectory' in timeSeries_Type: ## 5-3. time sereis for one initial network state InitBiState = { 'SK': 1, 'Cdc2_Cdc13': 0, 'Ste9': 1, 'Rum1': 1, 'Slp1': 0, 'Cdc2_Cdc13_active': 0, 'Wee1_Mik1': 1, 'Cdc25': 0, 'PP': 0 } # initial state for fission yeast #InitBiState = {'Cln3': 1, 'MBF':0, 'SBF': 0, 'Cln1_2':0, 'Cdh1':1, 'Swi5':0, 'Cdc20_Cdc14':0, 'Clb5_6':0, 'Sic1': 1, 'Clb1_2':0, 'Mcm1_SFF':0} # initial state for budding yeast timeSeriesOne = tev.time_series_one(net, nodes_list, InitBiState, Nbr_States, maxStep) # To generate time series data for one particular initial state ''' The format for timeSeries ==> timeSeries = { node1: {1st initial_state: [0,1,1, ......, 0], ...... , Nth initial_state: [1,0,1, ......, 1]}, node 2: {1st initial_state: [1,1,1, ......, 0], ...... , Nth initial_state: [1,0,0, ......, 0]}, .......} ==> timeSeries[node2][initial_state 1] = [1,1,1, ......, 0] ''' ## 4. Output files ## #result_ai = open('../results/fission-net/ai-step%d-trans0-h%d.dat'%(maxStep, historyLength),'w') #result_te = open('../results/fission-net/te-step%d-trans0-h%d.dat'%(maxStep, historyLength),'w') ## 6. To measure active information (AI) and transfer entropy (TE): using 'compute_AI' and 'compute_TE' from Module 'info_dyn" ## ## 6-1. For all possible initial network states if 'all_initial' in timeSeries_Type: ## 6-1-a. To compute AI result_ai_all = open('../results/fission-net/ai-all-step%d-trans0-h%d.dat'%(maxStep, historyLength),'w') AI_all = {} for n in nodes_list: AI_all[n] = info.compute_AI(timeSeriesAll[n], historyLength, Nbr_All_Initial_States, Nbr_States) result_ai_all.write('%s\t%f\n'%(n, AI_all[n])) print n, AI_all[n] ## 6-1-b. To compute TE result_te_all = open('../results/fission-net/te-all-step%d-trans0-h%d.dat'%(maxStep, historyLength),'w') TE_all = defaultdict(float) for v in nodes_list: for n in nodes_list: TE_all[(v, n)] = info.compute_TE(timeSeriesAll[v], timeSeriesAll[n], historyLength, Nbr_All_Initial_States, Nbr_States) result_te_all.write('%s\t%s\t%f\n'%(v, n,TE_all[(v, n)] )) print v, n,TE_all[(v, n)] ## 6-1-c. Scale behavior for AI (optional) result_file_name = '../results/fission-net/ai-all-scale-step%d-trans0-h%d.dat'%(maxStep, historyLength) viz_file_name = '../viz/fission-net/ai-all-scale-step%d-trans0-h%d.pdf'%(maxStep, historyLength) draw_plots.plot_AI_scale(AI_all, result_file_name, viz_file_name) ### plot and result file for AI scale ## 6-1-d. Scale behavior for TE (optional) result_file_name = '../results/fission-net/te-all-scale-step%d-trans0-h%d.dat'%(maxStep, historyLength) viz_file_name = '../viz/fission-net/te-all-scale-step%d-trans0-h%d.pdf'%(maxStep, historyLength) draw_plots.plot_TE_scale(TE_all, result_file_name, viz_file_name) ### plot and result file for TE scale ## 6-2. For initial network states that converge to the primary attractor if 'primary_attractor' in timeSeries_Type: ## 6-2-a. To compute AI result_ai_pa = open('../results/fission-net/ai-pa-step%d-trans0-h%d.dat'%(maxStep, historyLength),'w') AI_pa = {} for n in nodes_list: AI_pa[n] = info.compute_AI(timeSeriesPa[n], historyLength, len(Initial_States_List), Nbr_States) result_ai_pa.write('%s\t%f\n'%(n, AI_pa[n])) ## 6-2-b. To compute TE result_te_pa = open('../results/fission-net/te-pa-step%d-trans0-h%d.dat'%(maxStep, historyLength),'w') TE_pa = defaultdict(float) for v in nodes_list: for n in nodes_list: TE_pa[(v, n)] = info.compute_TE(timeSeriesPa[v], timeSeriesPa[n], historyLength, len(Initial_States_List), Nbr_States) result_te_pa.write('%s\t%s\t%f\n'%(v, n,TE_pa[(v, n)] )) ## 6-2-c. Scale behavior for AI (optional) result_file_name = '../results/fission-net/ai-pa-scale-step%d-trans0-h%d.dat'%(maxStep, historyLength) viz_file_name = '../viz/fission-net/ai-pa-scale-step%d-trans0-h%d.pdf'%(maxStep, historyLength) draw_plots.plot_AI_scale(AI_pa, result_file_name, viz_file_name) ### plot and result file for AI scale ## 6-2-d. Scale behavior for TE (optional) result_file_name = '../results/fission-net/te-pa-scale-step%d-trans0-h%d.dat'%(maxStep, historyLength) viz_file_name = '../viz/fission-net/te-pa-scale-step%d-trans0-h%d.pdf'%(maxStep, historyLength) draw_plots.plot_TE_scale(TE_pa, result_file_name, viz_file_name) ### plot and result file for TE scale ## 6-3. For a particular initial network state if 'one_trajectory' in timeSeries_Type: ## 6-3-a. To compute AI result_ai_one = open('../results/fission-net/ai-one-step%d-trans0-h%d.dat'%(maxStep, historyLength),'w') AI_one = {} for n in nodes_list: AI_one[n] = info.compute_AI(timeSeriesOne[n], historyLength, 1, Nbr_States) result_ai_one.write('%s\t%f\n'%(n, AI_one[n])) ## 6-3-b. To compute TE result_te_one = open('../results/fission-net/te-one-step%d-trans0-h%d.dat'%(maxStep, historyLength),'w') TE_one = defaultdict(float) for v in nodes_list: for n in nodes_list: TE_one[(v, n)] = info.compute_TE(timeSeriesOne[v], timeSeriesOne[n], historyLength, 1, Nbr_States) result_te_one.write('%s\t%s\t%f\n'%(v, n,TE_one[(v, n)] )) ## 6-3-c. Scale behavior for AI (optional) result_file_name = '../results/fission-net/ai-one-scale-step%d-trans0-h%d.dat'%(maxStep, historyLength) viz_file_name = '../viz/fission-net/ai-one-scale-step%d-trans0-h%d.pdf'%(maxStep, historyLength) draw_plots.plot_AI_scale(AI_one, result_file_name, viz_file_name) ### plot and result file for AI scale ## 6-3-d. Scale behavior for TE (optional) result_file_name = '../results/fission-net/te-one-scale-step%d-trans0-h%d.dat'%(maxStep, historyLength) viz_file_name = '../viz/fission-net/te-one-scale-step%d-trans0-h%d.pdf'%(maxStep, historyLength) draw_plots.plot_TE_scale(TE_one, result_file_name, viz_file_name) ### plot and result file for TE scale ## to obtain biological sequence for the Fission Yeast Cell-Cycle Net starting from biological inital state EDGE_FILE = '../data/fission-net/fission-net-edges.txt' NODE_FILE = '../data/fission-net/fission-net-nodes.txt' BIO_INIT_FILE = '../data/fission-net/fission-net-bioSeq-initial.txt' net = inet.read_network_from_file(EDGE_FILE, NODE_FILE) nodes_list = inet.build_nodes_list(NODE_FILE) #input_file_name1 = 'time-series/%s-step%d-trans0.dat'%(network_index, maxStep) #input_file1 = open( input_file_name1, 'r') Nbr_Initial_States = np.power(2,len(nodes_list)) maxStep = 20 Nbr_States = 2 historyLength = 5 result_ai = open('../results/fission-net/ai-step%d-trans0-h%d.dat'%(maxStep, historyLength),'w') result_te = open('../results/fission-net/te-step%d-trans0-h%d.dat'%(maxStep, historyLength),'w') timeSeries = tev.time_series_all(net, nodes_list, Nbr_Initial_States, Nbr_States, MAX_TimeStep=20) print 'AI' AI = {} for n in nodes_list: AI[n] = info.compute_AI(timeSeries[n], historyLength, Nbr_Initial_States, Nbr_States) result_ai.write('%s\t%f\n'%(n, AI[n])) print n, AI[n] print 'done AI' print 'TE' TE = defaultdict(float) for v in nodes_list: for n in nodes_list: TE[(v, n)] = info.compute_TE(timeSeries[v], timeSeries[n], historyLength, Nbr_Initial_States, Nbr_States) result_te.write('%s\t%s\t%f\n'%(v, n,TE[(v, n)] )) print v, n, TE[(v, n)] print 'done TE'