def processMDLR(self, mdlrPath): ''' main method. extracts species definition, creates bng-xml, creates mdl definitions ''' nautyDict = self.xml2HNautySpeciesDefinitions(mdlrPath) #append extended bng-xml to the bng-xml definition (the one that doesn't include seed information) bngxmlestr = writeBXe.mergeBXBXe(namespace.input + '_total.xml', namespace.input + '_extended.xml') with open(mdlrPath + '_total.xml', 'w') as f: f.write(bngxmlestr) xmlspec = readBNGXML.parseFullXML(namespace.input + '.xml') # write out the equivalent plain mdl stuffs mdlDict = writeMDL.constructMCell(xmlspec, namespace.input, finalName.split(os.sep)[-1], nautyDict) writeMDL.writeMDL(mdlDict, finalName)
def extractStatsFromFile(fileName): fileStats = {} structures = bxml.parseFullXML(fileName) fileStats['compression'] = 1 - len(structures['molecules'])*1.0/len(structures['observables']) \ if len(structures['observables']) > 0 else 0 fileStats['index'] = fileName.split('/')[-1].split('.')[0] fileStats['nreactions'] = len(structures['rules']) fileStats['nspecies'] = len(structures['observables']) if fileStats['nreactions'] > 0: fileStats['atomization'] = sum([ 1 for x in structures['rules'] if any([y.action not in ['Add', 'Delete'] for y in x[0].actions]) ]) * 1.0 / len(structures['rules']) else: fileStats['atomization'] = 0 return fileStats
normalizeMoleculeNamespace(molecule, moleculeSettings) for product in ruleDescription[0].products: for molecule in product.molecules: for moleculeSettings in normalizationSettings['molecules']: normalizeMoleculeNamespace(molecule, moleculeSettings) def defineConsole(): """ defines the program console line commands """ parser = argparse.ArgumentParser(description='SBML to BNGL translator') parser.add_argument('-n', '--normalize', type=str, help='normalization settings file', required=True) return parser if __name__ == "__main__": parser = defineConsole() namespace = parser.parse_args() with open(namespace.normalize) as f: normalizationSettings = yaml.load(f) for model in normalizationSettings['model']: bnglNamespace = readBNGXML.parseFullXML(model['name']) normalizeNamespace(bnglNamespace, model) bnglString = readBNGXML.createBNGLFromDescription(bnglNamespace) with open(model['name']+ '_norm.bngl','w') as f: f.write(bnglString)
normalizeMoleculeNamespace(molecule, moleculeSettings) def defineConsole(): """ defines the program console line commands """ parser = argparse.ArgumentParser(description='SBML to BNGL translator') parser.add_argument('-n', '--normalize', type=str, help='normalization settings file', required=True) return parser if __name__ == "__main__": parser = defineConsole() namespace = parser.parse_args() with open(namespace.normalize) as f: normalizationSettings = yaml.load(f) for model in normalizationSettings['model']: bnglNamespace = readBNGXML.parseFullXML(model['name']) normalizeNamespace(bnglNamespace, model) bnglString = readBNGXML.createBNGLFromDescription(bnglNamespace) with open(model['name'] + '_norm.bngl', 'w') as f: f.write(bnglString)
for element in [x for x in stdDictionary2[0] if x in intersectingNamespace]: for state in stdDictionary2[0][element]: intersectionSpace2[element].add(frozenset(x for x in state if x[0] in lowerIntersectionNamespace)) for element in intersectionSpace: scoreDict[element]['file2'] = len(intersectionSpace2[element]) for element in intersectionSpace: scoreDict[element]['intersection'] = [len(intersectionSpace[element] - intersectionSpace2[element]), len(intersectionSpace2[element] - intersectionSpace[element])] scoreDict[element]['score'] = 1 - scoreDict[element]['intersection'][0]*1.0/scoreDict[element]['file1'] scoreDict[element]['score2'] = 1 - scoreDict[element]['intersection'][1]*1.0/scoreDict[element]['file2'] return scoreDict def evaluateSimilarity(bnglNamespace, bnglNamespace2): similarity = {} similarity['structure'] = evaluateStructureSimilarity(bnglNamespace['molecules'], bnglNamespace2['molecules']) similarity['process'] = evaluateProcessSimilarity(bnglNamespace, bnglNamespace2) return similarity if __name__ == "__main__": parser = defineConsole() namespace = parser.parse_args() bnglNamespace = readBNGXML.parseFullXML(namespace.filename1) bnglNamespace2 = readBNGXML.parseFullXML(namespace.filename2) evaluateSimilarity(bnglNamespace, bnglNamespace2)
def reactionBasedAtomizationDistro(directory): ''' calculates a rection atomization based metric: ration of atomized reactions (non syndeg) in a model ''' syndelArray = [] atomizedDistro = [] nonAtomizedDistro = [] atomizationDB = pandas.DataFrame() # generate bng-xml # generateBNGXML(directory) print 'reading bng-xml files' xmlFiles = getValidFiles(directory, 'xml') print 'analyzing {0} bng-xml files'.format(len(xmlFiles)) progress = progressbar.ProgressBar() validFiles = 0 for i in progress(range(len(xmlFiles))): xml = xmlFiles[i] # for xml in xmlFiles: try: # console.bngl2xml('complex/output{0}.bngl'.format(element),timeout=10) try: structures = readBNGXML.parseFullXML(xml) rules = structures['rules'] observables = structures['observables'] molecules = structures['molecules'] except IOError: print xml continue atomizedProcesses, weight = reactionBasedAtomization(rules) ato, nonato = stoichiometryAnalysis(rules) atomizedDistro.extend(ato) nonAtomizedDistro.extend(nonato) # if (2,1) in nonato: # interesting.append(element) score = atomizedProcesses * 1.0 / weight if weight != 0 else 0 #totalRatomizedProcesses += atomizedProcesses #totalReactions += len(rules) #totalProcesses += weight # calculate yield activeMolecules = extractActiveMolecules(rules) activeMoleculeTypes = [x for x in molecules if x.name in activeMolecules] yieldValue = len([x for x in activeMoleculeTypes if len( x.components) > 0]) * 1.0 / len(activeMoleculeTypes) if len(activeMoleculeTypes) > 0 else 0 # syndel value syndelValue = 1 - (len(rules) - weight) * 1.0 / len(rules) if len(rules) > 0 else 0 atomizationDB.set_value(xml, 'score', score) atomizationDB.set_value(xml, 'weight', weight) atomizationDB.set_value(xml, 'length', len(rules)) atomizationDB.set_value(xml, 'yild', yieldValue) atomizationDB.set_value(xml, 'syndel', syndelValue) atomizationDB.set_value(xml, 'numspecies', len(observables)) validFiles += 1 except IOError: print 'io' continue print 'found {0} models i could extract info from'.format(validFiles) return atomizationDB
def getModelStructures(bngxml): structures = readBNGXML.parseFullXML(bngxml) return structures
normalizeMoleculeNamespace(molecule, moleculeSettings) def defineConsole(): """ defines the program console line commands """ parser = argparse.ArgumentParser(description="SBML to BNGL translator") parser.add_argument("-n", "--normalize", type=str, help="normalization settings file", required=True) return parser if __name__ == "__main__": parser = defineConsole() namespace = parser.parse_args() with open(namespace.normalize) as f: normalizationSettings = yaml.load(f) for model in normalizationSettings["model"]: bnglNamespace = readBNGXML.parseFullXML(model["name"]) normalizeNamespace(bnglNamespace, model) bnglString = readBNGXML.createBNGLFromDescription(bnglNamespace) with open(model["name"] + "_norm.bngl", "w") as f: f.write(bnglString)