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
예제 #3
0
"""

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()
    ids = list(set(lp.getColumnIDs()) - set(lp.getTransporters()))
    print ids