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) print transformationCenter[6] redundantDict,patternDictList = extractRedundantContext(rules,transformationCenter,transformationContext) print redundantDict[(('Prot(iMod~U)',), ('Prot(egfr)', 'EGFR(prot)'))] #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 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
def createContactMap(fileName): rules = extractRulesfromBNGL(fileName) transformationCenter = [] transformationContext = [] transformationProduct = [] actionNames = [] atomicArray = [] for idx, rule in enumerate(rules): tatomicArray, ttransformationCenter, ttransformationContext, tproductElements, tactionNames, tlabelArray = extractAtomic.extractTransformations( [rule] ) transformationCenter.append(ttransformationCenter) transformationContext.append(ttransformationContext) actionNames.append(tactionNames) atomicArray.append(tatomicArray) transformationProduct.append(tproductElements) # tatomicArray, ttransformationCenter, ttransformationContext, \ # tproductElements,tactionNames,tlabelArray = extractAtomic.extractTransformations(rules) redundantDict, patternDictList = contextAnalyzer.extractRedundantContext( rules, transformationCenter, transformationContext ) reverseRedundantDict = reverseLookup(redundantDict) for idx in range(0, len(rules)): redundantPattern = [] if idx in reverseRedundantDict: for key in reverseRedundantDict[idx]: redundantPattern.append(patternDictList[key[0]][key[1]]) redundantPatternCounter = dictionaryToCounter(redundantPattern) createMap(rules[idx], transformationProduct[idx], redundantPatternCounter, "conImg/contatMap{0}".format(idx))
def extractCenterContext(rules): transformationCenter = [] transformationContext = [] transformationProduct = [] atomicArray = [] actionNames = [] for idx, rule in enumerate(rules): tatomicArray, ttransformationCenter, ttransformationContext, tproductElements, tactionNames, tlabelArray = extractAtomic.extractTransformations( [rule] ) transformationCenter.append(ttransformationCenter) transformationContext.append(ttransformationContext) actionNames.append(tactionNames) atomicArray.append(tatomicArray) transformationProduct.append(tproductElements) return transformationCenter, transformationContext, transformationProduct, atomicArray, actionNames