Exemple #1
0
def load_yeast():
    """Loads a configuration for optimizations on yeast model iMM904SL_v6,
    including the model, environmental conditions, non targets for modifications,
    the biomass equation ID, and wild type reference flux values.

    Returns: A dictionary constaining the configuration.
    """
    DIR = os.path.dirname(os.path.realpath(__file__))
    PATH = os.path.join(DIR, '../models/yeast/')
    DATA_FILE = os.path.join(PATH, "iMM904SL_v6.xml")
    BIOMASS_ID = 'R_biomass_SC5_notrace'
    O2 = 'R_EX_o2_e_'
    GLC = 'R_EX_glc_e_'

    model = load_cbmodel(DATA_FILE, flavor='cobra')

    old_obj = model.get_objective().keys()
    obj = {key: 0 for key in old_obj if key != BIOMASS_ID}
    obj[BIOMASS_ID] = 1
    model.set_objective(obj)

    envcond = OrderedDict()
    envcond.update({GLC: (-10.0, 999999.0), O2: (-12.25, 100000.0)})

    simulation = get_simulator(model, envcond=envcond)
    res = simulation.simulate(method=SimulationMethod.pFBA)
    reference = res.fluxes

    return {
        'model': model,
        'biomass': BIOMASS_ID,
        'envcond': envcond,
        'reference': reference,
        'non_target': []
    }
Exemple #2
0
def load_gecko():
    """Loads yeast GECKO model using REFRAMED
    """
    from mewpy.model.gecko import GeckoModel
    model = GeckoModel('single-pool')
    simul = get_simulator(model)
    simul.summary()
Exemple #3
0
 def setUp(self):
     """Set up
     Loads a model
     """
     from reframed.io.sbml import load_cbmodel
     model = load_cbmodel(EC_CORE_MODEL)
     from mewpy.simulation import get_simulator
     self.simul = get_simulator(model)
     self.BIOMASS_ID = model.biomass_reaction
     self.SUCC = 'R_EX_succ_e'
Exemple #4
0
 def setUp(self):
     """Set up
     Loads a model
     """
     from cobra.io.sbml import read_sbml_model
     model = read_sbml_model(EC_CORE_MODEL)
     from mewpy.simulation import get_simulator
     self.simul = get_simulator(model)
     k = list(self.simul.objective.keys())
     self.BIOMASS_ID = k[0]
     self.SUCC = 'EX_succ_e'
Exemple #5
0
def load_cobra():
    """Load a model using COBRApy
    """
    DIR = os.path.dirname(os.path.realpath(__file__))
    PATH = os.path.join(DIR, '../models/optram/')
    DATA_FILE = os.path.join(PATH, "yeast_7.6-optram.xml")

    from cobra.io import read_sbml_model
    model = read_sbml_model(DATA_FILE)
    simul = get_simulator(model)
    simul.summary()
Exemple #6
0
def test1(compound='R_EX_tyr__L_e'):
    """
    AutoPACMEN, "Automatic construction of metabolic models with enzyme constraints"
    (https://doi.org/10.1186/s12859-019-3329-9), is able to construct GECKO like models.
    This example optimizes the production of a compound using the E. coli autoPACMEN model
    where enzymes are defined as pseudo reactants.

    """
    DIR = os.path.dirname(os.path.realpath(__file__))
    PATH = os.path.join(DIR, '../models/autopacmen/')
    DATA_FILE = os.path.join(PATH, "iJO1366_2019_06_25_GECKO.xml")

    model = SMomentModel(DATA_FILE, enzyme_reaction_prefix='R__TG_ER_')

    print(model.proteins)

    sim = get_simulator(model)
    sim.set_objective("R_BIOMASS_Ec_iJO1366_core_53p95M")
    solution = sim.simulate()
    print(solution)
    print('Wild type tyrosine production :', solution.fluxes['R_EX_tyr__L_e'])

    from mewpy.optimization.evaluation import BPCY, WYIELD
    from mewpy.simulation import SimulationMethod
    from collections import OrderedDict

    envcond = OrderedDict()
    envcond.update({'R_EX_glc__D_e': (-10.0, 100000.0)})

    # the evaluation (objective) functions
    evaluator_1 = BPCY("R_BIOMASS_Ec_iJO1366_core_53p95M",
                       compound,
                       method=SimulationMethod.lMOMA)
    evaluator_2 = WYIELD("R_BIOMASS_Ec_iJO1366_core_53p95M", compound)

    problem = GeckoOUProblem(model,
                             fevaluation=[evaluator_1, evaluator_2],
                             envcond=envcond,
                             candidate_max_size=6,
                             prot_prefix='R__TG_ER_')

    # A new instance of the EA optimizer
    from mewpy.optimization import EA
    ea = EA(problem, max_generations=500)
    # runs the optimization
    final_pop = ea.run()

    from mewpy.util.io import population_to_csv
    from time import time

    millis = int(round(time() * 1000))
    filename = "sMOMEMT{}_OU_{}.csv".format(compound, millis)
    population_to_csv(problem, final_pop, filename, simplify=False)
Exemple #7
0
def load_reframed():
    """
    Loads a model with REFRAMED
    """
    DIR = os.path.dirname(os.path.realpath(__file__))
    PATH = os.path.join(DIR, '../models/optram/')
    DATA_FILE = os.path.join(PATH, "yeast_7.6-optram.xml")

    from reframed.io.sbml import load_cbmodel
    model = load_cbmodel(DATA_FILE, flavor='cobra')
    model.summary()
    simul = get_simulator(model)
    simul.summary()
Exemple #8
0
def load_ec2():
    """Loads a configuration for optimizations on E.coli model iML1515,
    including the model, environmental conditions, non targets for modifications,
    the biomass equation ID, and wild type reference flux values.

    Returns: A dictionary constaining the configuration.
    """
    DIR = os.path.dirname(os.path.realpath(__file__))
    PATH = os.path.join(DIR, '../models/ec/')
    DATA_FILE = os.path.join(PATH, "iML1515.xml")
    NON_TARGET_FILE = os.path.join(
        PATH, "nontargets#RK#iJO1366SL#[lim-aerobic#glucose].txt")
    BIOMASS_ID = 'R_BIOMASS_Ec_iML1515_core_75p37M'
    O2 = 'R_EX_o2_e'
    GLC = 'R_EX_glc__D_e'

    model = load_cbmodel(DATA_FILE, flavor='cobra')

    old_obj = model.get_objective().keys()
    obj = {key: 0 for key in old_obj if key != BIOMASS_ID}
    obj[BIOMASS_ID] = 1
    model.set_objective(obj)

    non_target = [O2, GLC, 'R_ATPM']
    with open(NON_TARGET_FILE) as f:
        line = f.readline()
        while line:
            non_target.append(line.strip())
            line = f.readline()

    envcond = OrderedDict()
    envcond.update({GLC: (-10.0, 100000.0), O2: (-9.66, 100000.0)})

    simulation = get_simulator(model, envcond=envcond)
    res = simulation.simulate(method=SimulationMethod.pFBA)
    reference = res.fluxes

    res = simulation.simulate()
    print(res)

    return {
        'model': model,
        'biomass': BIOMASS_ID,
        'envcond': envcond,
        'reference': reference,
        'non_target': non_target
    }
Exemple #9
0
def test2(compoud='R_EX_tyr__L_e', filename=None):
    """
    AutoPACMEN, "Automatic construction of metabolic models with enzyme constraints"
    (https://doi.org/10.1186/s12859-019-3329-9), is able to construct GECKO like models.
    This example optimizes the production of a compound using the E. coli autoPACMEN model
    where enzymes are defined as pseudo reactants.
    The model defines a linear constraint over the protein pool as reactant, by adding the
    protein pool as a metabolite in the stochiometric matrix.
    Therefore, the model may be treated as a regular GSM.

    """
    DIR = os.path.dirname(os.path.realpath(__file__))
    PATH = os.path.join(DIR, '../models/autopacmen/')
    DATA_FILE = os.path.join(PATH, "iJO1366_sMOMENT_2019_06_25.xml")
    from reframed.io.sbml import load_cbmodel
    model = load_cbmodel(DATA_FILE)
    sim = get_simulator(model)
    s = sim.simulate()
    print(s)
    # print(s.fluxes)
    print('Wildtype tyrosine production :', s.fluxes['R_EX_tyr__L_e'])
    print('Pool:', s.fluxes['R_ER_pool_TG_'])

    fva = sim.FVA(reactions=['R_ER_pool_TG_'])
    print(fva)

    # implements a knockout over genes that encode enzymes
    BIOMASS_ID = 'R_BIOMASS_Ec_iJO1366_WT_53p95M'
    PRODUCT_ID = compoud
    from mewpy.optimization.evaluation import BPCY, WYIELD
    from mewpy.simulation import SimulationMethod
    evaluator_1 = BPCY(BIOMASS_ID, PRODUCT_ID, method=SimulationMethod.lMOMA)
    evaluator_2 = WYIELD(BIOMASS_ID, PRODUCT_ID)
    # evaluator_3 = TargetFlux(PRODUCT_ID)
    from mewpy.problems.genes import GOUProblem
    problem = GOUProblem(model,
                         fevaluation=[evaluator_1, evaluator_2],
                         max_candidate_size=30)
    print(problem.target_list)
    from mewpy.optimization import EA
    ea = EA(problem, max_generations=20, mp=True)
    final_pop = ea.run()
    if filename:
        print("Simplifying and saving solutions to file")
        population_to_csv(problem, final_pop, filename, simplify=False)
Exemple #10
0
def load_ec_gecko():
    """ Loads a GECKO like model from AUTOPACMEN
    """
    DIR = os.path.dirname(os.path.realpath(__file__))
    PATH = os.path.join(DIR, '../models/autopacmen/')
    DATA_FILE = os.path.join(PATH, "iJO1366_2019_06_25_GECKO.xml")

    from mewpy.model.gecko import GeckoModel
    from reframed.io.sbml import load_cbmodel
    cbmodel = load_cbmodel(DATA_FILE)
    # ='R_ER_pool_TG_'
    model = GeckoModel(cbmodel,
                       biomass_reaction_id='R_BIOMASS_Ec_iJO1366_WT_53p95M',
                       protein_reaction_id='R_PROTRS_TG_1',
                       common_protein_pool_id='M_prot_pool')

    simul = get_simulator(model)
    for rxn in simul.reactions:
        if "R_PROT" in rxn:
            print(rxn)
Exemple #11
0
    def setUp(self):
        import cobra.test
        model = cobra.test.create_test_model("textbook")
        _BIOMASS_ID = 'Biomass_Ecoli_core'

        envcond = {'EX_glc__D_e': (-10, 100000.0)}
        from mewpy.simulation import get_simulator
        sim = get_simulator(model, envcond=envcond)
        sim.objective = _BIOMASS_ID
        from mewpy.regulation import RFBAModel
        rfba = RFBAModel.from_tabular_format(OPTORF_REG, model, sim,
                                             sep=',', id_col=1, rule_col=2, aliases_cols=[0], header=0)
        rfba.update_aliases_from_tabular_format_file(OPTORF_ALIASES, id_col=1, aliases_cols=[0])

        initial_state = {var: 1 for var in rfba.targets}
        initial_state.update({_BIOMASS_ID: 0.1})
        rfba.initial_state = initial_state

        _PRODUCT_ID = "EX_succ_e"
        from mewpy.optimization.evaluation import BPCY, WYIELD
        evaluator_1 = BPCY(_BIOMASS_ID, _PRODUCT_ID, method='pFBA')
        evaluator_2 = WYIELD(_BIOMASS_ID, _PRODUCT_ID)
        from mewpy.regulation.optorf import OptOrfProblem
        self.problem = OptOrfProblem(model, [evaluator_1, evaluator_2], rfba, candidate_max_size=6)
Exemple #12
0
def gecko_ec():
    import os
    dir_path = os.path.dirname(os.path.realpath(__file__))
    PATH = os.path.join(dir_path, '../models/gecko/')
    DATA_FILE = os.path.join(PATH, 'eciML1515_batch.xml')
    from reframed.io.sbml import load_cbmodel
    m = load_cbmodel(DATA_FILE)
    model = GeckoModel(m,
                       biomass_reaction_id='R_BIOMASS_Ec_iML1515_core_75p37M',
                       protein_pool_exchange_id='R_prot_pool_exchange',
                       reaction_prefix='R_')
    model.set_objective({'R_BIOMASS_Ec_iML1515_core_75p37M': 1.0})

    # change protein pool bound (suggested by Leslie)
    # model.reactions['R_prot_pool_exchange'].ub = 0.26
    from mewpy.simulation import get_simulator, SimulationMethod

    c = {
        'P32131': 0.125,
        'P45425': 32,
        'P0A6E1': 32,
        'P0A9I8': 0,
        'P52643': 4,
        'P37661': 0.125
    }

    from mewpy.optimization.evaluation import BPCY, WYIELD
    from mewpy.problems import GeckoOUProblem
    # the evaluation (objective) functions
    evaluator_1 = BPCY("R_BIOMASS_Ec_iML1515_core_75p37M",
                       'R_EX_tyr__L_e',
                       method=SimulationMethod.pFBA)
    # FVA MAX is strangely very high... changing the default alpha (0.3) to compensate..
    evaluator_2 = WYIELD("R_BIOMASS_Ec_iML1515_core_75p37M",
                         'R_EX_tyr__L_e',
                         alpha=0.01)

    # The optimization problem
    problem = GeckoOUProblem(model,
                             fevaluation=[evaluator_1, evaluator_2],
                             envcond={},
                             prot_prefix='R_draw_prot_',
                             candidate_max_size=30)

    # c1 = problem.translate(c,reverse=True)
    # print(c1)
    # c2 = problem.decode(c1)
    # print(c2)
    sim = get_simulator(model)

    # c2 = {'R_draw_prot_P0AFV4': 0.0, 'R_draw_prot_P67910': (0.0, 0.0), 'R_draw_prot_P02924': (0.0, 0.0),
    #       'R_draw_prot_P07639': (1.1271272290940493e-07, 10000), 'R_draw_prot_P39172': 0.0,
    #       'R_draw_prot_P0AER3': (0.0, 10000), 'R_draw_prot_P0A991': (0.0, 10000), 'R_draw_prot_P0ACD8': (0.0, 0.0),
    #       'R_draw_prot_P00805': (0.0, 10000), 'R_draw_prot_P28635': (0.0, 0.0), 'R_draw_prot_P33593': (0.0, 0.0),
    #       'R_draw_prot_P0A9H5': (0.0, 10000), 'R_draw_prot_P0A6L4': (0.0, 10000), 'R_draw_prot_P60560': (0.0, 10000),
    #       'R_draw_prot_P37001': 0.0, 'R_draw_prot_P37355': (0.0, 0.0), 'R_draw_prot_P0AEE5': (0.0, 0.0),
    #       'R_draw_prot_P0ABA0': (0.0, 0.0), 'R_draw_prot_P0ABK5': (0.0, 10000)}
    c2 = {
        'R_draw_prot_P69922': (0.0, 10000),
        'R_draw_prot_P32176': (0.0, 0.0),
        'R_draw_prot_P11349': (0.0, 10000),
        'R_draw_prot_P37646': 0.0,
        'R_draw_prot_P76577': (0.0, 0.0),
        'R_draw_prot_P77788': (0.0, 0.0),
        'R_draw_prot_P0AG20': (0.0, 10000),
        'R_draw_prot_P63224': 0.0,
        'R_draw_prot_P62623': (0.0, 3.28753677758505e-07),
        'R_draw_prot_P10907': (0.0, 0.0),
        'R_draw_prot_P0AER5': (0.0, 0.0),
        'R_draw_prot_P27254': (0.0, 10000),
        'R_draw_prot_P0A6E1': (4.0254906190734055e-05, 10000),
        'R_draw_prot_P0A924': 0.0,
        'R_draw_prot_P32055': (0.0, 10000),
        'R_draw_prot_P21179': 0.0,
        'R_draw_prot_P10378': 0.0
    }

    print("\nFBA")
    res = sim.simulate(method=SimulationMethod.FBA, constraints=c2)
    print(res)
    print("Biomass:", res.fluxes['R_BIOMASS_Ec_iML1515_core_75p37M'])
    print("TYR:", res.fluxes['R_EX_tyr__L_e'])

    print("\npFBA")
    res = sim.simulate(method=SimulationMethod.pFBA, constraints=c2)
    print(res)
    print("Biomass:", res.fluxes['R_BIOMASS_Ec_iML1515_core_75p37M'])
    print("TYR:", res.fluxes['R_EX_tyr__L_e'])

    print("\nlMOMA")
    res = sim.simulate(method=SimulationMethod.lMOMA, constraints=c2)
    print(res)
    print("Biomass:", res.fluxes['R_BIOMASS_Ec_iML1515_core_75p37M'])
    print("TYR:", res.fluxes['R_EX_tyr__L_e'])

    print("\nMOMA")
    res = sim.simulate(method=SimulationMethod.MOMA, constraints=c2)
    print(res)
    print("Biomass:", res.fluxes['R_BIOMASS_Ec_iML1515_core_75p37M'])
    print("TYR:", res.fluxes['R_EX_tyr__L_e'])

    print("\nFVA")
    res = sim.FVA(reactions=['R_EX_tyr__L_e'], constraints=c2)
    print(res)
Exemple #13
0
 def setUp(self):
     from mewpy.model.gecko import GeckoModel
     model = GeckoModel('single-pool')
     from mewpy.simulation import get_simulator
     self.simul = get_simulator(model)
Exemple #14
0
 def test_simulator(self):
     from mewpy.model.gecko import GeckoModel
     model = GeckoModel('single-pool')
     from mewpy.simulation import get_simulator
     get_simulator(model)