def __init__(self, path2model="", medium={}, include={}, objective=None, optimizationRoutine='pFBA', koQ=True, *args, **kwargs):
     self.koQ = koQ
     self.optimizationRoutine = optimizationRoutine
     self.objective = objective
     self.lp = Metabolism(ImportCplex(path2model))
     self.path2model = path2model
     if objective:
         self.lp.setReactionObjective(self.objective)
     self.preMed = dict([(r, (-1000., 0)) for r in self.lp.getTransporters()])
     self.preMed.update(include)
     self.lp.modifyColumnBounds(self.preMed)
     self.lp.modifyColumnBounds(dict([(r, (0., 1000.)) for r in self.lp.getReactions()]))
     self.lp.modifyColumnBounds(medium)
     self.lp.eraseHistory()
예제 #2
0
 def __prepareProblem(self, lp):
     """Prepares the lp construct for analysis
     
     Transposes the stoichiometric matrix S_ij -> S^T
     Columns(Reactions) become rows and rows(Metabolites) become columns
     Previous column, now row bounds are set to 0
     Previous row, now column bounds are set to > 0
     """
     oldProb = Metabolism(lp)
     biomR = [r for r in oldProb.getColumnIDs() if re.search(".*.*", r, re.IGNORECASE)][0]
     print biomR
     oldProb.deleteReactionsFromStoich([biomR])
     oldProb.eraseHistory()
     newProb = Metabolism(glp_create_prob())
     for elem in range(1, oldProb.getNumCols() + 1):
         columnsDict = dict()
         identifier = glp_get_col_name(oldProb.lp, elem)
         colCoefList = oldProb.getColumnCoef(elem)
         columnsDict[identifier] = (0, 0, colCoefList)
         newProb.addRows(columnsDict)
     for elem in range(1, oldProb.getNumRows() + 1):
         rowsDict = dict()
         identifier = glp_get_row_name(oldProb.lp, elem)
         rowCoefList = oldProb.getRowCoef(elem)
         rowsDict[identifier] = (0, 10000, rowCoefList)
         newProb.addColumns(rowsDict)
     newProb.eraseHistory()
     return newProb.lp
def solveMedium(path2model="", medium={}, include={}, objective=None, optimizationRoutine='pFBA', koQ=True, *args, **kwargs):
    """doc"""
    lp = Metabolism(ImportCplex(path2model))
    if objective:
        lp.setReactionObjective(objective)
    preMed = dict([(r, (-1000., 0)) for r in lp.getTransporters()])
    preMed.update(include)
    lp.modifyColumnBounds(preMed)
    lp.modifyColumnBounds(medium)
    lp.modifyColumnBounds(dict([(r, (0., 1000.)) for r in lp.getReactions()]))
    lp.eraseHistory()
    # print lp.cplex()
    f = lp.pFBA()
    # simulationStorage = generateStorageObject(outputfile, lp)
    knockoutEffects = dict()
    wt = f[objective]
    print wt
    if koQ and wt > 0.:
        knockoutEffects = lp.singleKoAnalysis(f.getActiveReactions())
        for k in knockoutEffects:
            knockoutEffects[k] = knockoutEffects[k] / wt
    lp.initialize()
    # print knockoutEffects
    return FBAsimulationResult(f, knockoutEffects, lp.getColumnBounds(),
                                            lp.getObjectiveFunction(),
                                            time.time(), path2model, "Test")
class SolveMedium(object):
    
    def __init__(self, path2model="", medium={}, include={}, objective=None, optimizationRoutine='pFBA', koQ=True, *args, **kwargs):
        self.koQ = koQ
        self.optimizationRoutine = optimizationRoutine
        self.objective = objective
        self.lp = Metabolism(ImportCplex(path2model))
        self.path2model = path2model
        if objective:
            self.lp.setReactionObjective(self.objective)
        self.preMed = dict([(r, (-1000., 0)) for r in self.lp.getTransporters()])
        self.preMed.update(include)
        self.lp.modifyColumnBounds(self.preMed)
        self.lp.modifyColumnBounds(dict([(r, (0., 1000.)) for r in self.lp.getReactions()]))
        self.lp.modifyColumnBounds(medium)
        self.lp.eraseHistory()

    def run(self, *args, **kwargs):
        """docstring for run"""

        f = getattr(self.lp, self.optimizationRoutine)()
        knockoutEffects = dict()
        wt = f[self.objective]
        if self.koQ and wt > 0.:
            knockoutEffects = self.lp.singleKoAnalysis(f.getActiveReactions())
            for k in knockoutEffects:
                knockoutEffects[k] = knockoutEffects[k] / wt
        self.lp.undo()
        return FBAsimulationResult(f, knockoutEffects, self.lp.getColumnBounds(),
                                                self.lp.getObjectiveFunction(),
                                                time.time(), self.path2model, "Test")

    def __del__(self):
        """docstring for __del__"""
        glp_delete_prob(self.lp.lp) # FIXME this is a dirty hack
        del self
예제 #5
0
Created by Nikolaus Sonnenschein on 2010-03-02.
Copyright (c) 2010 . All rights reserved.
"""

import sys
import os


if __name__ == '__main__':
    from ifba.GlpkWrap.metabolism import Metabolism
    from ifba.GlpkWrap.util import ImportCplex, WriteCplex
    from ifba.fluxVariability.fluxVariability import Variability
    import random
    import pickle
    
    lp = Metabolism(ImportCplex('../../ifba/models/iAF1260template_minimalMed_noCarb.lp'))
    print len(lp.getColumnIDs())
    lp.modifyColumnBounds({'R("MglcDb_Transp")':(0, 20), 'R("Mo2b_Transp")':(-20, 20)})
    lp.modifyColumnBounds({'R("R_Ec_biomass_iAF1260_core_59p81M")': (1., 100.)})
    lp.eraseHistory()
    if os.path.exists('blocked.pcl'):
        blocked = pickle.load(open('blocked.pcl'))
    else:
        # blocked = Variability(lp).getBlocked(['R("R_Ec_biomass_iAF1260_core_59p81M")', 'R("R_AGPR")'])
        blocked = Variability(lp).getBlocked()
        sys.exit()
        pickle.dump(blocked, open('blocked.pcl', 'w'))
    print blocked
    print len(blocked)
    lp.deleteReactionsFromStoich(blocked)
    lp.eraseHistory()