def HubAnalysis(dic,organism): """ This function performs statistics on the substrate reaction graph from the point of view of HUBS. In particular it performs the following tasks: - it counts the number of valid regulations (irreversible and non-feedback) and those that are regulated by hub nodes among them. - it counts (terminal output) and lists (text file output) the set of reactions that are catalyzed by a hub node, indicating if the catalysis is active or passive and wether it is stabilizing or not, - it counts the number of irreversible reactions catalyzed by hub nodes, - generates a graph of the HUB nodes, describing their interaction. """ HUB = ['ATP','ADP','AMP','NADP','NADPH','NAD','NADH','ACETYL-COA','CA+2','MG+2','Pi','PPI','CO-A','AMMONIUM'] counter1 = 0 counter2 = 0 with open('./results/'+organism+'/logfiles/HUBcontrol.log','w') as out: out.write('This file lists all valid regulations (irreversible and non-feedback) that are not controlled by HUBS') for e in dic.elst: if e.rct.reversible != True: if e.activation != False or len([p.name for p in dic.plst if e.cs[0].name in p.totgraph.vs['name'][:] and e.rct.name in p.totgraph.vs['name'][:] and p.totgraph.are_connected(e.rct.name,e.cs[0].name)])!=0: counter1 += 1 if intersection(e.rct.innames,HUB) != [] and intersection(e.rct.outnames,HUB) != []: counter2 += 1 else: out.write('\nENAME:\t'+e.name+'\nRNAME:\t'+e.rct.name+'\nINPATH:\t'+', '.join([i for i in e.rct.inpath])+'\nACT:\t'+', '.join([c.name for c in e.cs])+'\n') print('\nNumber of valid regulations (irreversible and non-feedback) catalyzed by hubs:\t'+str(counter2)+'\tout of '+str(counter1)+' valid regulations\n') contcounter = 0 hubcontcounter = 0 tpluscount = 0 tminuscount = 0 flowregcounter = 0 with open('./results/'+organism+'/logfiles/HUBirrev.log','w') as out1: with open('./results/'+organism+'/logfiles/HUBStat.log','w') as out2: out1.write('# This file contains a list of all reactions that are irreversible and use a hub as driving force\n# Structure of file:\tREACTION-NAME\tINNAMES\tOUTNAMES\n\n') out2.write('# This file contains a list of all reactions that are regulated by hubs, indicating if the regulation is stabilizing or destabilizing\n\n') for r in dic.rlst: # hubs as substrates if intersection(r.innames,HUB) != [] and intersection(r.outnames,HUB) != [] and r.reversible == False: out1.write(str(r.name)+'\t'+str(r.innames)+'\t'+str(r.outnames)+'\n') flowregcounter += 1 # control through hubs if len(r.elst) != 0: contcounter += 1 pluscount = 0 minuscount = 0 hubelst = [e for e in r.elst if intersection([c.name for c in e.cs],HUB) != []] if len(hubelst) != 0: hubcontcounter += 1 out2.write('\nReaction name:\t'+r.name+'\t(Reversible: '+str(r.reversible)+', common name: '+','.join(map(str,r.commname))+')\nIN-PWY: '+','.join(map(str,r.inpath))+'\nIN/OUT:\t'+str(r.innames)+'\t'+str(r.outnames)+'\n') for e in hubelst: if e.stab() in [True,False]: out2.write('Act: '+str(e.activation)+'\tStab: '+str(e.stab)+'\t'+','.join(map(str,[c.name for c in e.cs]))+'\n') if e.stab() == True: pluscount += 1 else: minuscount += 1 out2.write('TOTAL [#stabilizing,#destabilizing]:\t'+str([pluscount,minuscount])) tpluscount += pluscount tminuscount += minuscount print('\n# of HUB-driven irreversible reactions: \t'+str(flowregcounter)+'\tout of\t'+str(len([1 for r in dic.rlst if r.reversible == False]))+' irreversible reactions\n') print('\n# of HUB-regulated reactions:\t'+str(hubcontcounter)+'\tout of\t'+str(contcounter)+' regulated reactions\n\t\t\tstabilizing:\t'+str(tpluscount)+'\n\t\t\tdestabilizing:\t'+str(tminuscount)) #creation of the HUB-graph gr = Graph(0, directed = True) gr.add_vertices(HUB) for r in dic.rlst: if intersection(r.innames,HUB) != [] or intersection(r.outnames,HUB) != []: gr.add_vertices([r.name]) for h in intersection(r.innames,HUB): gr.add_edges([(h,r.name)]) for h in intersection(r.outnames,HUB): gr.add_edges([(r.name,h)]) if r.reversible == True: for h in intersection(r.innames,HUB): gr.add_edges([(r.name,h)]) for h in intersection(r.outnames,HUB): gr.add_edges([(h,r.name)]) GO.write_hub_gml(gr,[e for e in dic.elst if intersection([c.name for c in e.cs],HUB) != []],'./results/'+organism+'/graphs/HUB_rct_graph.gml') #creation of the pathway HUB-graph #coupling di reazioni attraverso pathways, ma come? il problema e che reazioni diverse devono essere accoppiate #guardare grafo senza hub #this graph has as nodes the hubs and the pathways connecting them. #the connection pathways, that can be seen as reactions, are chosen if in at least one reaction in the pathway there is an intersection between the principal in elements and the hublist AND an intersection between the principal out elements and the hubs (in practice, if there is a reaction that is hub driven). gp = Graph(0, directed = True) gp.add_vertices(HUB) for p in dic.plst: inlst = [] outlst = [] rlst = [] if p.substrates != [] and p.byproducts != []: inlst = intersection([c.name for c in p.substrates if c != None],HUB) outlst = intersection([c.name for c in p.byproducts if c != None],HUB) if intersection(inlst,HUB) != [] and intersection(outlst,HUB) != []: print p.name print inlst print outlst print '\n' gp.add_vertices([p.name]) for h in inlst: gp.add_edges([(h,p.name)]) for h in outlst: gp.add_edges([(p.name,h)]) GO.write_hub_gml(gp,[e for e in dic.elst if intersection([c.name for c in e.cs],HUB) != []],'./results/'+organism+'/graphs/HUB_path_graph.gml') #the connection pathways, that can be seen as reactions, are chosen if in at least one reaction in the pathway there is an intersection between the principal in elements and the hublist OR an intersection between the principal out elements and the hubs (so these are pathways that couple weakly hubs). gp = Graph(0, directed = True) gp.add_vertices(HUB) for p in dic.plst: inlst = [] outlst = [] rlst = [] for i,prim in enumerate(p.primlst): if intersection([c.name for c in prim[0]],HUB) != [] or intersection([c.name for c in prim[1]],HUB) != []: inlst.extend(intersection([c.name for c in prim[0]],HUB)) outlst.extend(intersection([c.name for c in prim[1]],HUB)) rlst.append(p.rlst[i]) if rlst != []: gp.add_vertices([p.name]) for h in inlst: gp.add_edges([(h,p.name)]) for h in outlst: gp.add_edges([(p.name,h)]) GO.write_hub_gml(gp,[e for e in dic.elst if intersection([c.name for c in e.cs],HUB) != []],'./results/'+organism+'/graphs/HUB_path_weak_graph.gml')
def HubAnalysis(dic, organism): """ This function performs statistics on the substrate reaction graph from the point of view of HUBS. In particular it performs the following tasks: - it counts the number of valid regulations (irreversible and non-feedback) and those that are regulated by hub nodes among them. - it counts (terminal output) and lists (text file output) the set of reactions that are catalyzed by a hub node, indicating if the catalysis is active or passive and wether it is stabilizing or not, - it counts the number of irreversible reactions catalyzed by hub nodes, - generates a graph of the HUB nodes, describing their interaction. """ HUB = [ 'ATP', 'ADP', 'AMP', 'NADP', 'NADPH', 'NAD', 'NADH', 'ACETYL-COA', 'CA+2', 'MG+2', 'Pi', 'PPI', 'CO-A', 'AMMONIUM' ] counter1 = 0 counter2 = 0 with open('./results/' + organism + '/logfiles/HUBcontrol.log', 'w') as out: out.write( 'This file lists all valid regulations (irreversible and non-feedback) that are not controlled by HUBS' ) for e in dic.elst: if e.rct.reversible != True: if e.activation != False or len([ p.name for p in dic.plst if e.cs[0].name in p.totgraph.vs['name'][:] and e.rct.name in p.totgraph.vs['name'][:] and p.totgraph.are_connected(e.rct.name, e.cs[0].name) ]) != 0: counter1 += 1 if intersection(e.rct.innames, HUB) != [] and intersection( e.rct.outnames, HUB) != []: counter2 += 1 else: out.write('\nENAME:\t' + e.name + '\nRNAME:\t' + e.rct.name + '\nINPATH:\t' + ', '.join([i for i in e.rct.inpath]) + '\nACT:\t' + ', '.join([c.name for c in e.cs]) + '\n') print( '\nNumber of valid regulations (irreversible and non-feedback) catalyzed by hubs:\t' + str(counter2) + '\tout of ' + str(counter1) + ' valid regulations\n') contcounter = 0 hubcontcounter = 0 tpluscount = 0 tminuscount = 0 flowregcounter = 0 with open('./results/' + organism + '/logfiles/HUBirrev.log', 'w') as out1: with open('./results/' + organism + '/logfiles/HUBStat.log', 'w') as out2: out1.write( '# This file contains a list of all reactions that are irreversible and use a hub as driving force\n# Structure of file:\tREACTION-NAME\tINNAMES\tOUTNAMES\n\n' ) out2.write( '# This file contains a list of all reactions that are regulated by hubs, indicating if the regulation is stabilizing or destabilizing\n\n' ) for r in dic.rlst: # hubs as substrates if intersection(r.innames, HUB) != [] and intersection( r.outnames, HUB) != [] and r.reversible == False: out1.write( str(r.name) + '\t' + str(r.innames) + '\t' + str(r.outnames) + '\n') flowregcounter += 1 # control through hubs if len(r.elst) != 0: contcounter += 1 pluscount = 0 minuscount = 0 hubelst = [ e for e in r.elst if intersection([c.name for c in e.cs], HUB) != [] ] if len(hubelst) != 0: hubcontcounter += 1 out2.write('\nReaction name:\t' + r.name + '\t(Reversible: ' + str(r.reversible) + ', common name: ' + ','.join(map(str, r.commname)) + ')\nIN-PWY: ' + ','.join(map(str, r.inpath)) + '\nIN/OUT:\t' + str(r.innames) + '\t' + str(r.outnames) + '\n') for e in hubelst: if e.stab() in [True, False]: out2.write( 'Act: ' + str(e.activation) + '\tStab: ' + str(e.stab) + '\t' + ','.join(map(str, [c.name for c in e.cs])) + '\n') if e.stab() == True: pluscount += 1 else: minuscount += 1 out2.write('TOTAL [#stabilizing,#destabilizing]:\t' + str([pluscount, minuscount])) tpluscount += pluscount tminuscount += minuscount print('\n# of HUB-driven irreversible reactions: \t' + str(flowregcounter) + '\tout of\t' + str(len([1 for r in dic.rlst if r.reversible == False])) + ' irreversible reactions\n') print('\n# of HUB-regulated reactions:\t' + str(hubcontcounter) + '\tout of\t' + str(contcounter) + ' regulated reactions\n\t\t\tstabilizing:\t' + str(tpluscount) + '\n\t\t\tdestabilizing:\t' + str(tminuscount)) #creation of the HUB-graph gr = Graph(0, directed=True) gr.add_vertices(HUB) for r in dic.rlst: if intersection(r.innames, HUB) != [] or intersection(r.outnames, HUB) != []: gr.add_vertices([r.name]) for h in intersection(r.innames, HUB): gr.add_edges([(h, r.name)]) for h in intersection(r.outnames, HUB): gr.add_edges([(r.name, h)]) if r.reversible == True: for h in intersection(r.innames, HUB): gr.add_edges([(r.name, h)]) for h in intersection(r.outnames, HUB): gr.add_edges([(h, r.name)]) GO.write_hub_gml(gr, [ e for e in dic.elst if intersection([c.name for c in e.cs], HUB) != [] ], './results/' + organism + '/graphs/HUB_rct_graph.gml') #creation of the pathway HUB-graph #coupling di reazioni attraverso pathways, ma come? il problema e che reazioni diverse devono essere accoppiate #guardare grafo senza hub #this graph has as nodes the hubs and the pathways connecting them. #the connection pathways, that can be seen as reactions, are chosen if in at least one reaction in the pathway there is an intersection between the principal in elements and the hublist AND an intersection between the principal out elements and the hubs (in practice, if there is a reaction that is hub driven). gp = Graph(0, directed=True) gp.add_vertices(HUB) for p in dic.plst: inlst = [] outlst = [] rlst = [] if p.substrates != [] and p.byproducts != []: inlst = intersection([c.name for c in p.substrates if c != None], HUB) outlst = intersection([c.name for c in p.byproducts if c != None], HUB) if intersection(inlst, HUB) != [] and intersection(outlst, HUB) != []: print p.name print inlst print outlst print '\n' gp.add_vertices([p.name]) for h in inlst: gp.add_edges([(h, p.name)]) for h in outlst: gp.add_edges([(p.name, h)]) GO.write_hub_gml(gp, [ e for e in dic.elst if intersection([c.name for c in e.cs], HUB) != [] ], './results/' + organism + '/graphs/HUB_path_graph.gml') #the connection pathways, that can be seen as reactions, are chosen if in at least one reaction in the pathway there is an intersection between the principal in elements and the hublist OR an intersection between the principal out elements and the hubs (so these are pathways that couple weakly hubs). gp = Graph(0, directed=True) gp.add_vertices(HUB) for p in dic.plst: inlst = [] outlst = [] rlst = [] for i, prim in enumerate(p.primlst): if intersection([c.name for c in prim[0]], HUB) != [] or intersection( [c.name for c in prim[1]], HUB) != []: inlst.extend(intersection([c.name for c in prim[0]], HUB)) outlst.extend(intersection([c.name for c in prim[1]], HUB)) rlst.append(p.rlst[i]) if rlst != []: gp.add_vertices([p.name]) for h in inlst: gp.add_edges([(h, p.name)]) for h in outlst: gp.add_edges([(p.name, h)]) GO.write_hub_gml( gp, [ e for e in dic.elst if intersection([c.name for c in e.cs], HUB) != [] ], './results/' + organism + '/graphs/HUB_path_weak_graph.gml')