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