Example #1
0
 def getFluxModel(self,configFileName,modelNames):
     gconfigParser = GeneralMultiConfigParser()
     gconfigs = gconfigParser.parse(configFileName)
     modelParser = FluxModelFlatFileParser()
     modelParser.setWrapper("\'")
     
     fluxModel = None
     pName = ''
     iFluxModel = LinearModel()
     for mName in modelNames:
         if mName != '':
             gconfig = gconfigs[mName]
             iFluxModel = modelParser.parseGenConfig(gconfig, mName)
             if fluxModel == None:
                 fluxModel = iFluxModel
                 pName = fluxModel.objectives.keys()[0]
             else:
                 fluxModel.extend(pName,mName,iFluxModel)
     
     #---------------------------
     # Parse Linear Model
     #---------------------------
     
     modelName = modelNames[0]
     modelMaker = CreateLinearModel()
     modelMaker.setScale(1)
     modelMatrix = modelMaker.fromFluxModel(fluxModel, modelName)
     
     #-------------------------    
     #Set Filter Target List
     #------------------------
     nonTargets = []
     targetList = fluxModel.getMetabolicNetwork().getAnnotation("ValidTarget")
     for name in targetList.keys():
         value = targetList[name]
         if value =="FALSE":
             nonTargets.append(name)
     
     return (fluxModel,modelMatrix,nonTargets)
Example #2
0
 def parseModel(self,modelNames):
     '''
     Generate linear optimization model object
     using names from configuration set in ModelFactory
     @var modelNames: list of the names of the metabolic models
     @type modelNames: [String]
       
     '''
     modelConfig = ReflectionConfig()
     modelConfig.readfp(open(self.modelConfigFile))
     
     fluxModel = None
     #fluxModel = FluxModel()
     pName = ''
     annotation = {}
     for mName in modelNames:
         if mName != '':
             lmParser = MetabolicNetworkParser()
             modelConfig.reflect(mName,lmParser)
             #xFluxModel = lmParser.generateModel(mName)
             
             modelParser = FluxModelFlatFileParser()
             modelParser.setWrapper("\'")
             modelConfig.reflect(mName, modelParser)
             jFluxModel = modelParser.generateModel(mName)
             
             if fluxModel == None:
                 fluxModel = jFluxModel
                 pName = fluxModel.objectives.keys()[0]
             else:
                 fluxModel.extend(pName,mName,jFluxModel)
                 pass
             if modelConfig.has_option(mName, "annotationFiles"):
                 annotationFiles = modelConfig.get(mName,"annotationfiles")
                 annotationFiles = eval(annotationFiles)
                 iAnnotation = self.parseAnnotationFiles(annotationFiles)
                 annotation = self.joinAnnotation(annotation, iAnnotation)
                             
     #---------------------------
     # Parse Linear Model
     #---------------------------
     
     modelName = modelNames[0]
     modelMaker = CreateLinearModel()
     model = modelMaker.fromFluxModel(fluxModel, modelName)
     model.annotation = annotation
     model.modelName = ",".join(modelNames)
     
     #---------------------------
     # Select subsections
     #---------------------------
     if self.subSections != '':
         subSections = self.subSections.split(',')
         subValues= fluxModel.getMetabolicNetwork().getAnnotation("Section")
         for (name,subValue) in subValues.items():
             if subValue != None and subValue not in subSections:
                 if self.verbose: print "removing %s" % (name)
                 model.removeColumn(name)
                 
     validColumns = model.getColumnNames()
                         
     #-------------------------    
     #Set Filter Target List
     #------------------------
     targets = []
     nonTargets = []
     
     targetTags = fluxModel.getMetabolicNetwork().getAnnotation("ValidTarget")
     for (name,value) in targetTags.items():
         if value == "TRUE":
             targets.append(name)
         if value =="FALSE":
             nonTargets.append(name)
     
     targets = set(validColumns).intersection(targets) 
             
     model.targets = targets
     
     return (fluxModel,model)