def extractCenterContext(rules, excludeReverse=False): transformationCenter = [] transformationContext = [] transformationProduct = [] atomicArray = [] actionNames = [] label = [] doubleModificationRules = [] for idx, rule in enumerate(rules): tatomicArray, ttransformationCenter, ttransformationContext, \ tproductElements, tactionNames, tlabelArray = extractAtomic.extractTransformations( [rule], True) if excludeReverse and '_reverse_' in rule[0].label and \ len([x for x in tactionNames if 'ChangeCompartment' not in x]) > 1: continue label.append(rule[0].label) if len([x for x in tactionNames if 'ChangeCompartment' not in x]) > 1: doubleModificationRules.append(rule[0].label) transformationCenter.append(ttransformationCenter) transformationContext.append(ttransformationContext) actionNames.append(tactionNames) atomicArray.append(tatomicArray) transformationProduct.append(tproductElements) return label, transformationCenter, transformationContext, \ transformationProduct, atomicArray, actionNames, doubleModificationRules
def askQuestions(inputfile, molecule, center, context=None): _, rules, _ = readBNGXML.parseXML(inputfile) transformationCenter = [] transformationContext = [] transformationProduct = [] atomicArray = [] actionNames = [] for idx, rule in enumerate(rules): tatomicArray, ttransformationCenter, ttransformationContext, \ tproductElements, tactionNames, tlabelArray = extractAtomic.extractTransformations( [rule],True) if any([ molecule in y and center in y for x in ttransformationCenter for y in x ]): if context: print str(rule[0]).split(':')[0] print[ y for x in ttransformationContext for y in x if context in y and molecule in y ] else: print rule
def main(): fileName = 'complex/output19.bngl' console.bngl2xml(fileName) species, rules, par = readBNGXML.parseXML('output19.xml') #print rules transformationCenter = [] transformationContext = [] #extract the context of such reactions for idx, rule in enumerate(rules): tatomicArray, ttransformationCenter, ttransformationContext, \ tproductElements,tactionNames,tlabelArray = extractAtomic.extractTransformations([rule]) #atomicArray.append(tatomicArray) transformationCenter.append(ttransformationCenter) transformationContext.append(ttransformationContext) redundantDict, patternDictList = extractRedundantContext( rules, transformationCenter, transformationContext) #print redundantDict #construct rule based patterns based on the reaction patterns they have to match and #the ones they have to discriminate for center in patternDictList: for rate in patternDictList[center]: match = patternDictList[center][rate] notContext = [] for cRate in [x for x in patternDictList[center] if x != rate]: notContext.append([ transformationContext[x] for x in redundantDict[center][cRate] ]) ruleSet = [rules[x] for x in redundantDict[center][rate]] createMetaRule(ruleSet, match) newRules = range(0, len(rules)) for center in redundantDict: for context in redundantDict[center]: for element in range(1, len(redundantDict[center][context])): newRules.remove(redundantDict[center][context][element]) #for element in newRules: # print str(rules[element][0]) newRulesArray = [] for element in newRules: newRulesArray.append('{0}\n'.format(str(rules[element][0]))) lines = readFile(fileName) startR = lines.index('begin reaction rules\n') endR = lines.index('end reaction rules\n') startP = lines.index('begin parameters\n') endP = lines.index('end parameters\n') newPar = findNewParameters(lines[startP + 1:endP], par) newLines = lines[0:endP] + newPar + lines[ endP:startR + 1] + newRulesArray + lines[endR:len(lines)] f = open(fileName + 'reduced.bngl', 'w') f.writelines(newLines) '''
def main(): fileName = 'complex/output19.bngl' console.bngl2xml(fileName) species,rules,par= readBNGXML.parseXML('output19.xml') #print rules transformationCenter = [] transformationContext = [] #extract the context of such reactions for idx,rule in enumerate(rules): tatomicArray, ttransformationCenter, ttransformationContext, \ tproductElements,tactionNames,tlabelArray = extractAtomic.extractTransformations([rule]) #atomicArray.append(tatomicArray) transformationCenter.append(ttransformationCenter) transformationContext.append(ttransformationContext) redundantDict,patternDictList = extractRedundantContext(rules,transformationCenter,transformationContext) #print redundantDict #construct rule based patterns based on the reaction patterns they have to match and #the ones they have to discriminate for center in patternDictList: for rate in patternDictList[center]: match = patternDictList[center][rate] notContext = [] for cRate in [x for x in patternDictList[center] if x != rate]: notContext.append([transformationContext[x] for x in redundantDict[center][cRate]]) ruleSet = [rules[x] for x in redundantDict[center][rate]] createMetaRule(ruleSet,match) newRules = range(0,len(rules)) for center in redundantDict: for context in redundantDict[center]: for element in range(1,len(redundantDict[center][context])): newRules.remove(redundantDict[center][context][element]) #for element in newRules: # print str(rules[element][0]) newRulesArray = [] for element in newRules: newRulesArray.append('{0}\n'.format(str(rules[element][0]))) lines = readFile(fileName) startR = lines.index('begin reaction rules\n') endR = lines.index('end reaction rules\n') startP = lines.index('begin parameters\n') endP = lines.index('end parameters\n') newPar = findNewParameters(lines[startP+1:endP],par) newLines = lines[0:endP] + newPar + lines[endP:startR+1] + newRulesArray + lines[endR:len(lines)] f = open(fileName + 'reduced.bngl','w') f.writelines(newLines) '''
def askQuestions(inputfile, molecule, center, context=None): _, rules, _ = readBNGXML.parseXML(inputfile) ruleArray = [] contextArray = [] for idx, rule in enumerate(rules): tatomicArray, ttransformationCenter, ttransformationContext, \ tproductElements, tactionNames, tlabelArray = extractAtomic.extractTransformations( [rule], True) if any([molecule in y and center in y for x in ttransformationCenter for y in x]): if context: ruleArray.append(str(rule[0]).split(':')[0]) contextArray.append([y for x in ttransformationContext for y in x if context in y and molecule in y]) else: print rule return ruleArray, contextArray
def extractCenterContext(rules): transformationCenter = [] transformationContext = [] transformationProduct = [] atomicArray = [] actionNames = [] for idx, rule in enumerate(rules): tatomicArray, ttransformationCenter, ttransformationContext, \ tproductElements, tactionNames, tlabelArray = extractAtomic.extractTransformations( [rule], True) transformationCenter.append(ttransformationCenter) transformationContext.append(ttransformationContext) actionNames.append(tactionNames) atomicArray.append(tatomicArray) transformationProduct.append(tproductElements) return transformationCenter, transformationContext, \ transformationProduct, atomicArray, actionNames
def extractStatistics(): number = 151 console.bngl2xml('complex/output{0}.bngl'.format(number)) species, rules, parameterDict = readBNGXML.parseXML( 'output{0}.xml'.format(number)) #print rules transformationCenter = [] transformationContext = [] k = [] actions = Counter() actionSet = Counter() for idx, rule in enumerate(rules): tatomicArray, ttransformationCenter, ttransformationContext, \ tproductElements,tactionNames,tlabelArray = extractAtomic.extractTransformations([rule]) #atomicArray.append(tatomicArray) transformationCenter.append(ttransformationCenter) transformationContext.append(ttransformationContext) k.append(len(rule[0].actions)) #if len(rule[0].actions) > 3: # print rule[0].reactants actions.update([x.action for x in rule[0].actions]) tmp = [x.action for x in rule[0].actions] tmp.sort() actionSet.update([tuple(tmp)]) #print actions #print actionSet print 'number of species', len(species) print 'avg number o actions', np.average(k), np.std(k) centerDict = groupByReactionCenter(transformationCenter) print 'singletons', len( {x: centerDict[x] for x in centerDict if len(centerDict[x]) == 1}) tmp = [[tuple(set(x)), len(centerDict[x])] for x in centerDict] #reactionCenterGraph(species,tmp) #tmp.sort(key=lambda x:x[1],reverse=True) print 'number of reaction centers', len(centerDict.keys()) print 'number of rules', len(rules) #print 'unique',[x for x in centerDict[element] if len(centerDict[element]) == 1] redundantDict = groupByReactionCenterAndRateAndActions(rules, centerDict) #print redundantDict tmp2 = [('$\\tt{{{0}}}$'.format(tuple(set(x))), tuple(set(y[:-1])), y[-1], len(redundantDict[x][y])) for x in redundantDict for y in redundantDict[x] if 'kr' not in y[-1]] tmp2 = set(tmp2) tmp2 = list(tmp2) tmp2.sort(key=lambda x: x[3], reverse=True) tmp2.sort(key=lambda x: x[0], reverse=True) tmp2 = [ '{0} & {1} & {2} & {3}\\\\\n'.format(element[0], element[1], element[2], element[3]) for element in tmp2 ] with open('table.tex', 'w') as f: f.write('\\begin{tabular}{|cccc|}\n') f.write('\\hline\n') f.write('Reaction Centers & Action & Score\\\\\\hline\n') for element in tmp2: f.write(element) f.write('\\hline\n') f.write('\\end{tabular}\n') #print redundantDict x = [len(centerDict[x]) for x in centerDict] #122,138 print 'average number of reactions with same rate and reaction cneter', np.average( x), np.std(x) print 'total number of clusters', len(x) print x
def extractStatistics(): number = 151 console.bngl2xml('complex/output{0}.bngl'.format(number)) species,rules,parameterDict= readBNGXML.parseXML('output{0}.xml'.format(number)) #print rules transformationCenter = [] transformationContext = [] k = [] actions = Counter() actionSet = Counter() for idx,rule in enumerate(rules): tatomicArray, ttransformationCenter, ttransformationContext, \ tproductElements,tactionNames,tlabelArray = extractAtomic.extractTransformations([rule]) #atomicArray.append(tatomicArray) transformationCenter.append(ttransformationCenter) transformationContext.append(ttransformationContext) k.append(len(rule[0].actions)) #if len(rule[0].actions) > 3: # print rule[0].reactants actions.update([x.action for x in rule[0].actions]) tmp = [x.action for x in rule[0].actions] tmp.sort() actionSet.update([tuple(tmp)]) #print actions #print actionSet print 'number of species',len(species) print 'avg number o actions',np.average(k),np.std(k) centerDict = groupByReactionCenter(transformationCenter) print 'singletons',len({x:centerDict[x] for x in centerDict if len(centerDict[x]) == 1}) tmp = [[tuple(set(x)),len(centerDict[x])] for x in centerDict] #reactionCenterGraph(species,tmp) #tmp.sort(key=lambda x:x[1],reverse=True) print 'number of reaction centers',len(centerDict.keys()) print 'number of rules',len(rules) #print 'unique',[x for x in centerDict[element] if len(centerDict[element]) == 1] redundantDict = groupByReactionCenterAndRateAndActions(rules,centerDict) #print redundantDict tmp2 = [('$\\tt{{{0}}}$'.format(tuple(set(x))),tuple(set(y[:-1])),y[-1],len (redundantDict[x][y])) for x in redundantDict for y in redundantDict[x] if 'kr' not in y[-1]] tmp2 = set(tmp2) tmp2 = list(tmp2) tmp2.sort(key=lambda x:x[3],reverse=True) tmp2.sort(key=lambda x:x[0],reverse=True) tmp2 = ['{0} & {1} & {2} & {3}\\\\\n'.format(element[0],element[1],element[2],element[3]) for element in tmp2] with open('table.tex','w') as f: f.write('\\begin{tabular}{|cccc|}\n') f.write('\\hline\n') f.write('Reaction Centers & Action & Score\\\\\\hline\n') for element in tmp2: f.write(element) f.write('\\hline\n') f.write('\\end{tabular}\n') #print redundantDict x = [len(centerDict[x]) for x in centerDict] #122,138 print 'average number of reactions with same rate and reaction cneter',np.average(x),np.std(x) print 'total number of clusters',len(x) print x