Exemplo n.º 1
0
    def extractMoleculeTypes(self,ticket,bnglContents, bnglContents2):

        moleculeTypesList = []
        for element in [bnglContents, bnglContents2]:
            pointer = tempfile.mkstemp(suffix='.bngl', text=True)
            with open(pointer[1], 'w') as f:
                f.write(element)
            print pointer[1]
            consoleCommands.setBngExecutable(bngDistro)
            consoleCommands.bngl2xml(pointer[1])

            xmlFileName = pointer[1].split('.')[0] + '.xml'
            xmlFileName = xmlFileName.split(os.sep)[-1]
            moleculeTypes, _, _ = readBNGXML.parseXML(xmlFileName)
            moleculeTypesList.append(moleculeTypes)
            os.remove(xmlFileName)
        self.addToDict(ticket, moleculeTypesList)
        print 'success', ticket
Exemplo n.º 2
0
    def generateGraph(self, ticket, bnglContents, graphtype):
        print ticket
        pointer = tempfile.mkstemp(suffix='.bngl', text=True)
        with open(pointer[1], 'w') as f:
            f.write(bnglContents)
        try:
            if graphtype in ['regulatory', 'contactmap']:
                consoleCommands.setBngExecutable(bngDistro)
                consoleCommands.generateGraph(pointer[1], graphtype)
                name = pointer[1].split('.')[0].split('/')[-1]
                with open('{0}_{1}.gml'.format(name, graphtype), 'r') as f:
                    graphContent = f.read()

                gml = networkx.read_gml('{0}_{1}.gml'.format(name, graphtype))
                result = gml2cyjson(gml, graphtype=graphtype)
                jsonStr = json.dumps(result, indent=1, separators=(',', ': '))

                result = {'jsonStr': jsonStr, 'gmlStr': graphContent}
                self.addToDict(ticket, result)
                os.remove('{0}_{1}.gml'.format(name, graphtype))
                print 'success', ticket

            elif graphtype in ['sbgn_er']:
                consoleCommands.setBngExecutable(bngDistro)
                consoleCommands.generateGraph(pointer[1], 'contactmap')
                name = pointer[1].split('.')[0].split('/')[-1]
                # with open('{0}_{1}.gml'.format(name,'contactmap'),'r') as f:
                #   graphContent = f.read()
                graphContent = networkx.read_gml(
                    '{0}_{1}.gml'.format(name, 'contactmap'))
                sbgn = libsbgn.createSBNG_ER_gml(graphContent)
                self.addToDict(ticket, sbgn)
                os.remove('{0}_{1}.gml'.format(name, 'contactmap'))
                print 'success', ticket
            elif graphtype in ['std']:
                consoleCommands.setBngExecutable(bngDistro)
                consoleCommands.bngl2xml(pointer[1])
                xmlFileName = pointer[1].split('.')[0] + '.xml'
                xmlFileName = xmlFileName.split(os.sep)[-1]

                graph = stdgraph.generateSTDGML(xmlFileName)
                gmlGraph = networkx.generate_gml(graph)


                #os.remove('{0}.gml'.format(xmlFileName))
                result = gml2cyjson(graph, graphtype=graphtype)
                jsonStr = json.dumps(result, indent=1, separators=(',', ': '))

                result = {'jsonStr': jsonStr, 'gmlStr': ''.join(gmlGraph)}

                #self.addToDict(ticket, ''.join(gmlGraph))
                self.addToDict(ticket, result)
                print 'success', ticket
        except:
            import traceback
            traceback.print_exc()
            self.addToDict(ticket,-5)
            print 'failure',ticket
        finally:
            task.deferLater(reactor, 600,  freeQueue, ticket)
Exemplo n.º 3
0
    def compareFiles(self, ticket, bnglContents, bnglContents2, mappingFile):
        finalBNGLContent = []
        finalNamespace = []
        try:
            for mapInfo, bnglContent in zip(mappingFile['model'], [bnglContents, bnglContents2]):
                pointer = tempfile.mkstemp(suffix='.bngl', text=True)
                with open(pointer[1], 'w') as f:
                    f.write(bnglContent)

                print pointer[1]
                consoleCommands.setBngExecutable(bngDistro)
                consoleCommands.bngl2xml(pointer[1])

                xmlFileName = pointer[1].split('.')[0] + '.xml'
                xmlFileName = xmlFileName.split(os.sep)[-1]
                bnglNamespace = readBNGXML.parseFullXML(xmlFileName)
                normalizer.normalizeNamespace(bnglNamespace, mapInfo)
                
                finalBNGLContent.append(readBNGXML.createBNGLFromDescription(bnglNamespace))
                finalNamespace.append(bnglNamespace)



                # os.remove(pointer[1])
                os.remove(xmlFileName)

            similarity = modelComparison.evaluateSimilarity(finalNamespace[0], finalNamespace[1])
            self.addToDict(ticket, [finalBNGLContent, similarity])
            print 'success', ticket
        except:
            self.addToDict(ticket,-5)
            print 'failure',ticket
        finally:
            task.deferLater(reactor, 600,  freeQueue, ticket)
            


        pass
Exemplo n.º 4
0
 def generateGraph(self,ticket,bnglContents,graphtype):
     print ticket
     pointer = tempfile.mkstemp(suffix='.bngl',text=True)
     with open(pointer[1],'w' ) as f:
         f.write(bnglContents)
     #try:
     if graphtype in ['regulatory','contactmap']:
         consoleCommands.setBngExecutable(bngDistro)
         consoleCommands.generateGraph(pointer[1],graphtype)
         name = pointer[1].split('.')[0]
         with open('{0}_{1}.gml'.format(name,graphtype),'r') as f:
             graphContent = f.read()         
             self.addToDict(ticket,graphContent)
             print 'success',ticket
     elif graphtype in ['sbgn_er']:
         consoleCommands.setBngExecutable(bngDistro)
         consoleCommands.generateGraph(pointer[1],'contactmap')
         name = pointer[1].split('.')[0]
         #with open('{0}_{1}.gml'.format(name,'contactmap'),'r') as f:
         #   graphContent = f.read()
         graphContent = networkx.read_gml('{0}_{1}.gml'.format(name,'contactmap'))
         sbgn = libsbgn.createSBNG_ER_gml(graphContent)
         self.addToDict(ticket,sbgn)
         print 'success',ticket