def postAnalyzeFile(outputFile, bngLocation, database): """ Performs a postcreation file analysis based on context information """ #print('Transforming generated BNG file to BNG-XML representation for analysis') consoleCommands.setBngExecutable(bngLocation) outputDir = os.sep.join(outputFile.split(os.sep)[:-1]) if outputDir != '': retval = os.getcwd() os.chdir(outputDir) consoleCommands.bngl2xml(outputFile.split(os.sep)[-1]) if outputDir != '': os.chdir(retval) bngxmlFile = '.'.join(outputFile.split('.')[:-1]) + '.xml' #print('Sending BNG-XML file to context analysis engine') contextAnalysis = postAnalysis.ModelLearning(bngxmlFile) # analysis of redundant bonds deleteBonds = contextAnalysis.analyzeRedundantBonds(database.assumptions['redundantBonds']) modificationFlag = True for molecule in database.assumptions['redundantBondsMolecules']: if molecule[0] in deleteBonds: for bond in deleteBonds[molecule[0]]: database.translator[molecule[1]].deleteBond(bond) logMess('INFO:Atomization', 'Used context information to determine that the bond {0} in species {1} is not likely'.format(bond,molecule[1])) returnArray = analyzeHelper(database.document, database.reactionDefinitions, database.useID, outputFile, database.speciesEquivalence, database.atomize, database.translator) with open(outputFile, 'w') as f: f.write(returnArray.finalString) # recompute bng-xml file consoleCommands.bngl2xml(outputFile) bngxmlFile = '.'.join(outputFile.split('.')[:-1]) + '.xml' # recompute context information contextAnalysis = postAnalysis.ModelLearning(bngxmlFile) # get those species patterns that follow uncommon motifs motifSpecies, motifDefinitions = contextAnalysis.processContextMotifInformation(database.assumptions['lexicalVsstoch'], database) #motifSpecies, motifDefinitions = contextAnalysis.processAllContextInformation() if len(motifDefinitions) > 0: logMess('WARNING:ContextAnalysis', 'Species with suspect context information were found. Information is being dumped to {0}_context.log'.format(outputFile)) with open('{0}_context.log'.format(outputFile), 'w') as f: pprint.pprint(dict(motifSpecies), stream=f) pprint.pprint(motifDefinitions, stream=f)
def postAnalysisHelper(outputFile, bngLocation, database): consoleCommands.setBngExecutable(bngLocation) outputDir = os.sep.join(outputFile.split(os.sep)[:-1]) if outputDir != '': retval = os.getcwd() os.chdir(outputDir) consoleCommands.bngl2xml(outputFile.split(os.sep)[-1]) if outputDir != '': os.chdir(retval) bngxmlFile = '.'.join(outputFile.split('.')[:-1]) + '.xml' #print('Sending BNG-XML file to context analysis engine') contextAnalysis = postAnalysis.ModelLearning(bngxmlFile) # analysis of redundant bonds deleteBonds = contextAnalysis.analyzeRedundantBonds(database.assumptions['redundantBonds']) for molecule in database.assumptions['redundantBondsMolecules']: if molecule[0] in deleteBonds: for bond in deleteBonds[molecule[0]]: database.translator[molecule[1]].deleteBond(bond) logMess('INFO:CTX002', 'Used context information to determine that the bond {0} in species {1} is not likely'.format(bond,molecule[1]))