Ejemplo n.º 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': []
    }
Ejemplo n.º 2
0
    def __init__(self, model, enzyme_reaction_prefix="R_ENZYME_DELIVERY_"):
        """SMomentModel an extension of REFRAMED CBModel for sMOMENT models.

        :param model: a path to a CBM xml file or an instance of REFRAMED SBModel
        :param enzyme_reaction_prefix: str enzyme prefix
                   GECKO_ANALOGON: "R_ENZYME_DELIVERY_"
                   GECKO: "R__TG_ER_"

        """
        if isinstance(model, str):
            from reframed.io.sbml import load_cbmodel
            model = load_cbmodel(model)
        elif not isinstance(model, CBModel):
            raise ValueError("The model should be a path or a CBModel")

        super(SMomentModel, self).__init__(model.id)
        self.enzyme_prefix = enzyme_reaction_prefix
        # import CBModel's data
        self.compartments = copy.deepcopy(model.compartments)
        self.metabolites = copy.deepcopy(model.metabolites)
        self.reactions = copy.deepcopy(model.reactions)
        self.genes = copy.deepcopy(model.genes)
        self.enzymes = []
        for rx in self.reactions:
            if rx.startswith(self.enzyme_prefix):
                self.enzymes.append(rx[len(self.enzyme_prefix):])
Ejemplo n.º 3
0
 def setUp(self):
     """Sets up the the model
     """
     from reframed.io.sbml import load_cbmodel
     self.model = load_cbmodel(EC_CORE_MODEL)
     from mewpy.optimization.settings import set_default_population_size
     set_default_population_size(10)
     from mewpy.optimization import set_default_engine
     set_default_engine('jmetal')
Ejemplo n.º 4
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'
Ejemplo n.º 5
0
def ec_gecko_ko(compound, display=False, filename=None):
    """ GECKO enzyme deletion example.
    It runs a multi objective optimization for the increased production of a certain compound on E. Coli.
    The GECKO model is the yeast model companion from the GECKO paper "Improving the phenotype predictions
    of a yeast genome‐scale metabolic model by incorporating enzymatic
    constraints" https://doi.org/10.15252/msb.20167411.
    Runs over the MEWpy implementation.

    :param compound: A target reaction identifier.
    :param display: Prints the best solution.
    :param filename: If given, saves the results as csv to filename.

    """

    import os
    dir_path = os.path.dirname(os.path.realpath(__file__))
    PATH = os.path.join(dir_path, '../../../examples/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})

    envcond = OrderedDict()

    # the evaluation (objective) functions

    evaluator_1 = BPCY("R_BIOMASS_Ec_iML1515_core_75p37M",
                       compound,
                       method=SimulationMethod.lMOMA)
    evaluator_2 = WYIELD("R_BIOMASS_Ec_iML1515_core_75p37M", compound)
    # The optimization problem
    problem = GeckoKOProblem(model,
                             fevaluation=[evaluator_1, evaluator_2],
                             envcond=envcond,
                             prot_prefix='R_draw_prot_',
                             candidate_max_size=6)

    # A new instance of the EA optimizer
    ea = EA(problem, max_generations=ITERATIONS)
    # runs the optimization
    final_pop = ea.run()
    # optimization results
    if display:
        individual = max(final_pop)
        best = list(problem.decode(individual.candidate).keys())
        print('Best Solution: \n{0}'.format(str(best)))
    # save final population to file
    if filename:
        print("Simplifying and saving solutions to file")
        population_to_csv(problem, final_pop, filename, simplify=False)
Ejemplo n.º 6
0
def load_sbml_simulator(filename, flavor='reframed', envcond=None):
    if flavor == 'reframed':
        from reframed.io.sbml import load_cbmodel
        model = load_cbmodel(filename, flavor='cobra')
    elif flavor == 'cobra':
        from cobra.io import read_sbml_model
        model = read_sbml_model(filename)
    else:
        raise ValueError(f"{flavor} is not a recognized flavor")
    simul = get_simulator(model, envcond=envcond)
    return simul
Ejemplo n.º 7
0
def load_sbml_container(filename, flavor='reframed'):
    if flavor == 'reframed':
        from reframed.io.sbml import load_cbmodel
        model = load_cbmodel(filename, flavor='cobra')
    elif flavor == 'cobra':
        from cobra.io import read_sbml_model
        model = read_sbml_model(filename)
    else:
        raise ValueError(f"{flavor} is not a recognized flavor")
    container = get_container(model)
    return container
Ejemplo n.º 8
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()
Ejemplo n.º 9
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
    }
Ejemplo n.º 10
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)
Ejemplo n.º 11
0
def test():
    """ An example on to use OptRAM optimization problems to find
    regulatory modification for the increased production of tryptophan.
    """
    dir_path = os.path.dirname(os.path.realpath(__file__))
    PATH = os.path.join(dir_path, '../../../examples/models/optram/')
    gene_file = os.path.join(PATH, 'mgene.csv')
    ft_file = os.path.join(PATH, 'TFnames.csv')
    matrix_file = os.path.join(PATH, 'regnet.csv')
    model_file = os.path.join(PATH, 'yeast_7.6-optram.xml')

    BIOMASS_ID = 'r_2111'
    PRODUCT_ID = 'r_1912'
    GLC = 'r_1714'

    envcond = {GLC: (-10, 0)}

    # adds the prefix 'G_' to genes. Only for REFRAMED models
    regnet = load_optram(gene_file, ft_file, matrix_file, gene_prefix='G_')
    # the general objective is to maximize the target
    from reframed.io.sbml import load_cbmodel
    model = load_cbmodel(model_file)
    model.set_objective({BIOMASS_ID: 1})

    evaluator_1 = BPCY(BIOMASS_ID, PRODUCT_ID, method=SimulationMethod.lMOMA)
    evaluator_2 = WYIELD(BIOMASS_ID, PRODUCT_ID, parsimonious=True)

    # OptRAM problem
    problem = OptRamProblem(model, [evaluator_1, evaluator_2],
                            regnet,
                            envcond=envcond,
                            candidate_min_size=10,
                            candidate_max_size=30)

    print('Target List:', problem.target_list)
    print("\n\n")
    print('Metabolic Genes', problem.simulator.genes)
    print("\n\n")

    ea = EA(problem, max_generations=3, mp=True)
    final_pop = ea.run()
    from mewpy.util.io import population_to_csv
    millis = int(round(time() * 1000))
    filename = "OPTRAM{}_OU_{}.csv".format('TRP', millis)
    population_to_csv(problem, final_pop, filename, simplify=False)
Ejemplo n.º 12
0
    def __getitem__(self, item):
        """Get a bundled GECKO model.

        :param item: basestring. Either 'single-pool' for the single-protein pool ecYeastGEM model or
        'multi-pool' for individually modeled protein pools.

        """
        try:
            file_name = self.model_files[item]
        except KeyError:
            raise KeyError('model name must be one of {}'.format(', '.join(
                list(self.model_files))))
        if file_name not in self.models:
            model = load_cbmodel(
                os.path.join(os.path.dirname(__file__),
                             'data/{}'.format(file_name)))
            self.simplify_model(model)
            self.models[file_name] = model
        return self.models[file_name]
Ejemplo n.º 13
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)
Ejemplo n.º 14
0
def framed_imc1010_model():
    """

    SRFBA FRAMED Ecoli iMC1010 model from Covert et al. 2004 at https://doi.org/10.1038/nature02456
    This model uses the E. coli metabolic model iJR904 available at https://www.ebi.ac.uk/biomodels/MODEL1507180060
    and published at https://doi.org/10.1186/gb-2003-4-9-r54

    Some rules had to be adjusted though
    iJR904 had to be adjusted, as it didn't match SR_FBA original publication or had errors

    The following reactions were added as in the original publication:
        - h2so: 2 o2_c + h2s_c -> (0, 999999) so4_c + 2 h_c
        - h2st: h2s_e <-> (-999999, 999999) h2s_c
        - h2s_ext: h2s_e -> (0, 999999)
        - 5dglcn_ext: 5dglcn_e -> (0, 999999)
        - btn_ext: btn_e -> (0, 999999)
        - cbi_ext: cbi_e -> (0, 999999)
        - h2o2_ext: h2o2_e -> (0, 999999)
        - ppa_ext: ppa_e -> (0, 999999)
        - thym_ext: thym_e-> (0, 999999)

    The following reactions were removed from iJR904, as they were duplicated or wrong
        - GALU (duplicated GALUi (correct GPR))

    The following reactions were removed from SR-FBA orginal publication model, as they were duplicated or wrong:
        - ptrca (duplicated PTRCTA)
        - indolet (unbalanced and duplicated indolet2r)

    The following indirect mappings were found:

        cbiat, R_CBIAT_DELETE
        cblat, R_CBLAT_DELETE
        d-lact2, R_D_LACt2
        dhptdc, R_DHPTDCs
        l-lacd2, R_L_LACD2
        l-lact2r, R_L_LACt2r
        lcar, R_LCARS
        nh3t, R_NH4t
        l-lacd3, R_L_LACD3
        test_akgdh, R_AKGDH
        test_nadtrhd, R_NADTRHD
        trpas1, CYSDS

    Others:
        - iJR904 has an additional reaction to ptrcta, namely ORNTA


    :return: srfba model
    """

    from reframed.io.sbml import load_cbmodel
    from mewpy.simulation.reframed import Simulation

    DIR = os.path.dirname(os.path.realpath(__file__))
    cbm_model_f = os.path.join(DIR, "../models/iJR904_srfba.xml")
    reg_model_f = os.path.join(DIR, '../models/regulation/imc1010_v6.csv')
    aliases_f = os.path.join(DIR,
                             '../models/regulation/imc1010_srfba_aliases.csv')

    _BIOMASS_ID = 'R_BiomassEcoli'
    _O2 = 'R_EX_o2_e'
    _GLC = 'R_EX_glc_DASH_D_e'
    _CO2 = 'R_EX_co2_e'
    _FE2 = "R_EX_fe2_e"
    _H = "R_EX_h_e"
    _H2O = "R_EX_h2o_e"
    _K = "R_EX_k_e"
    _NA1 = "R_EX_na1_e"
    _NH4 = "R_EX_nh4_e"
    _PI = "R_EX_pi_e"
    _SO4 = "R_EX_so4_e"
    _SUCC = "R_EX_succ_e"

    t0 = time.time()
    model = load_cbmodel(cbm_model_f)
    model.set_objective({_BIOMASS_ID: 1})

    # envcond = {_GLC: (-10.0, 100000.0),
    #            _O2: (-100.0, 100000.0),
    #            _CO2: (-100.0, 100000.0),
    #            _FE2: (-100.0, 100000.0),
    #            _H: (-100.0, 100000.0),
    #            _H2O: (-100.0, 100000.0),
    #            _K: (-100.0, 100000.0),
    #            _NA1: (-100.0, 100000.0),
    #            _NH4: (-100.0, 100000.0),
    #            _PI: (-100.0, 100000.0),
    #            _SO4: (-100.0, 100000.0)}

    envcond = {
        _GLC: (-10.0, 100000.0),
        _SUCC: (0.0, 100000.0),
        _NH4: (-10.0, 100000.0),
        _O2: (-10.0, 100000.0),
        _CO2: (-15.0, 100000.0),
        _PI: (-15.0, 100000.0),
        _SO4: (-10.0, 100000.0),
        _H: (-10.0, 100000.0),
        _H2O: (-55.0, 100000.0)
    }

    simulation = Simulation(model, envcond=envcond)
    t1 = time.time()

    print(t1 - t0)

    t0 = time.time()
    srfba = SRFBAModel.from_tabular_format(reg_model_f,
                                           model,
                                           cbm_simulation_interface=simulation,
                                           sep=';',
                                           id_col=1,
                                           rule_col=4,
                                           aliases_cols=[0, 2, 3],
                                           header=0)
    srfba.update_aliases_from_tabular_format_file(aliases_f,
                                                  sep=';',
                                                  id_col=0,
                                                  aliases_cols=[1])
    t1 = time.time()

    print(t1 - t0)

    m_initial_state = {i.id: 1 for i in srfba.metabolic_regulatory_genes_gen()}

    initial_state = {'Growth': 1, 'pH': 7}

    initial_state.update(m_initial_state)

    srfba.initial_state = initial_state

    t0 = time.time()
    srfba.simulate()
    t1 = time.time()

    print(t1 - t0)

    return srfba
Ejemplo n.º 15
0
 def setUp(self):
     from mewpy.regulation.optram import OptRamProblem, load_optram
     regnet = load_optram(OPTRAM_GENES, OPTRAM_TFS, OPTRAM_REGNET, gene_prefix='G_')
     from reframed.io.sbml import load_cbmodel
     model = load_cbmodel(OPTRAM_MODEL)
     self.problem = OptRamProblem(model, [], regnet)
Ejemplo n.º 16
0
 def setUp(self):
     from reframed.io.sbml import load_cbmodel
     model = load_cbmodel(EC_CORE_MODEL)
     from mewpy.problems import GOUProblem
     self.problem = GOUProblem(model, [])
Ejemplo n.º 17
0
def framed_imc1010_model(dynamic=True):
    """

    RFBA FRAMED Ecoli iMC1010 model from Covert et al. 2004 at https://doi.org/10.1038/nature02456
    This model uses the E. coli metabolic model iJR904 available at https://www.ebi.ac.uk/biomodels/MODEL1507180060
    and published at https://doi.org/10.1186/gb-2003-4-9-r54

    Some rules had to be adjusted though iJR904 had to be adjusted, as it didn't match SR_FBA original publication
    or had errors.

    The following reactions were added as in the original publication:

        - h2so: 2 o2_c + h2s_c -> (0, 999999) so4_c + 2 h_c
        - h2st: h2s_e <-> (-999999, 999999) h2s_c
        - h2s_ext: h2s_e -> (0, 999999)
        - 5dglcn_ext: 5dglcn_e -> (0, 999999)
        - btn_ext: btn_e -> (0, 999999)
        - cbi_ext: cbi_e -> (0, 999999)
        - h2o2_ext: h2o2_e -> (0, 999999)
        - ppa_ext: ppa_e -> (0, 999999)
        - thym_ext: thym_e-> (0, 999999)


    The following reactions were removed from iJR904, as they were duplicated or wrong:
        - GALU (duplicated GALUi (correct GPR))


    The following reactions were removed from SR-FBA orginal publication model, as they were duplicated or wrong:
        - ptrca (duplicated PTRCTA)
        - indolet (unbalanced and duplicated indolet2r)


    The following indirect mappings were found:

        cbiat, R_CBIAT_DELETE
        cblat, R_CBLAT_DELETE
        d-lact2, R_D_LACt2
        dhptdc, R_DHPTDCs
        l-lacd2, R_L_LACD2
        l-lact2r, R_L_LACt2r
        lcar, R_LCARS
        nh3t, R_NH4t
        l-lacd3, R_L_LACD3
        test_akgdh, R_AKGDH
        test_nadtrhd, R_NADTRHD
        trpas1, CYSDS

    Others:
        - iJR904 has an additional reaction to ptrcta, namely ORNTA


    Target genes with empty rules were set as ON in version 6. Alternatively, the state of all target genes can be set
    to 1 using the initial state setter.

    :return: rfba model

    """

    from reframed.io.sbml import load_cbmodel
    from mewpy.simulation.reframed import Simulation

    DIR = os.path.dirname(os.path.realpath(__file__))
    cbm_model_f = os.path.join(DIR, "../models/regulation/iJR904_srfba.xml")
    reg_model_f = os.path.join(DIR, '../models/regulation/imc1010_v6.csv')
    aliases_f = os.path.join(DIR, '../models/regulation/imc1010_rfba_aliases.csv')
    # env_cond_f = os.path.join(DIR,"../models/regulation/imc1010_env_cond.xlsx")

    _BIOMASS_ID = 'R_BiomassEcoli'
    _O2 = 'R_EX_o2_e'
    _GLC = 'R_EX_glc_DASH_D_e'
    _CO2 = 'R_EX_co2_e'
    _FE2 = "R_EX_fe2_e"
    _H = "R_EX_h_e"
    _H2O = "R_EX_h2o_e"
    _K = "R_EX_k_e"
    _NA1 = "R_EX_na1_e"
    _NH4 = "R_EX_nh4_e"
    _PI = "R_EX_pi_e"
    _SO4 = "R_EX_so4_e"
    _SUCC = "R_EX_succ_e"

    _GLY = "R_EX_gly_e"
    _DALA = "R_EX_ala_DASH_D_e"

    t0 = time.time()
    model = load_cbmodel(cbm_model_f)
    model.set_objective({_BIOMASS_ID: 1})

    # Wild-type
    # import pandas as pd
    # envcond = pd.read_excel(env_cond_f)
    # envcond = {j: (float(envcond.iloc[i, 1]), float(envcond.iloc[i, 2])) for i, j in enumerate(envcond.iloc[:, 0])}

    # envcond = {_GLC: (-10.0, 100000.0),
    #            _O2: (-10.0, 100000.0),
    #            _CO2: (-15.0, 100000.0),
    #            _FE2: (-10.0, 100000.0),
    #            _H: (-10.0, 100000.0),
    #            _H2O: (-55.0, 100000.0),
    #            _K: (-10.0, 100000.0),
    #            _NA1: (-10.0, 100000.0),
    #            _NH4: (-10.0, 100000.0),
    #            _PI: (-15.0, 100000.0),
    #            _SO4: (-10.0, 100000.0),
    #            _SUCC: (0.0, 100000.0)}

    envcond = {_GLC: (-10.0, 100000.0),
               _SUCC: (0.0, 100000.0),
               _NH4: (-10.0, 100000.0),
               _O2: (-10.0, 100000.0),
               _CO2: (-15.0, 100000.0),
               _PI: (-15.0, 100000.0),
               _SO4: (-10.0, 100000.0),
               _H: (-10.0, 100000.0),
               _H2O: (-55.0, 100000.0)}

    # envcond.update({_GLC: (-10.0, 100000.0),
    #                 _SUCC: (0.0, 100000.0),
    #                 _NH4: (-10.0, 100000.0),
    #                 _O2: (-10.0, 100000.0),
    #                 _CO2: (-15.0, 100000.0),
    #                 _PI: (-15.0, 100000.0),
    #                 _SO4: (-10.0, 100000.0),
    #                 _H: (-10.0, 100000.0),
    #                 _H2O: (-55.0, 100000.0)})

    # Paper analysis encoding: in vivo/FBA/RFBA;  (+ growth) (- no growth)

    # OD600 growth on Glycine + b3359 M ARGDR
    # In paper: -/-/-

    # envcond.update(
    #     {_GLC: (0.0, 100000.0),
    #      _GLY: (-10.0, 100000.0),
    #      'R_ACOTA': (0.0,0.0)}
    # )

    # OD600 growth on Glycine + b3572 M AVTA1
    # In paper: -/+/-

    # envcond.update(
    #     {_GLC: (0.0, 100000.0),
    #      _GLY: (-10.0, 100000.0),
    #      'R_VPAMT': (0.0,0.0)}
    # )

    # OD600 growth on Glycine + b3671 M ILVB1 b3671 M ILVB2
    # In paper: +/+/-

    # envcond.update(
    #     {_GLC: (0.0, 100000.0),
    #      _GLY: (-10.0, 100000.0)}
    # )

    # OD600 growth on D-Alanine + b3423 R GlpR
    # In paper: +/not observable/+
    # SET GlpR to false in csv

    # envcond.update(
    #     {_GLC: (0.0, 100000.0),
    #      _DALA: (-10.0, 100000.0)}
    # )

    # OD600 growth on D-Alanine + b3119 R TdcR
    # In paper: +/not observable/+
    # SET TdcR to false in csv

    # envcond.update(
    #     {_GLC: (0.0, 100000.0),
    #      _DALA: (-10.0, 100000.0)}
    # )

    # OD600 growth on D-Alanine + b3572 M AVTA1
    # In paper: +/not observable/+

    # envcond.update(
    #     {_GLC: (0.0, 100000.0),
    #      _DALA: (-10.0, 100000.0),
    #      'R_VPAMT': (0.0,0.0)}
    # )

    simulation = Simulation(model, envcond=envcond)
    t1 = time.time()

    print(t1 - t0)

    t0 = time.time()
    rfba = RFBAModel.from_tabular_format(reg_model_f, model, simulation,
                                         sep=';', id_col=1, rule_col=4, aliases_cols=[0, 2, 3], header=0)
    rfba.update_aliases_from_tabular_format_file(aliases_f, sep=';', id_col=0, aliases_cols=[1])
    t1 = time.time()

    print(t1 - t0)

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

    if dynamic:
        t0 = time.time()
        rfba.dynamic_simulate()
        t1 = time.time()

    else:

        t0 = time.time()
        rfba.simulate()
        t1 = time.time()

    print(t1 - t0)

    return rfba
Ejemplo n.º 18
0
def optorf_imc():
    """

    From Kim, J., Reed, J.L. OptORF: Optimal metabolic and regulatory perturbations for metabolic engineering of
    microbial strains. BMC Syst Biol 4, 53 (2010). https://doi.org/10.1186/1752-0509-4-53

    In the simulations, we excluded transport reactions for acetate, carbon dioxide, formate, phosphate,
    and water from consideration as eliminating transport may be challenging. In addition, ATP synthase deletion was
    excluded from consideration since the deletion resulted in a high variability in ethanol production at the
    predicted optimal growth condition. Equivantly, the deletion of focA, focB, and atp operon were excluded from the
    OptORF simulations. The OptORF approach was applied to identify metabolic engineering strategies for
    overproduction of ethanol or higher alcohols (i.e. c j = 1 for j = desired alcohol secretion) in glucose minimal
    media. Maximum glucose uptake rate (GUR) and oxygen uptake rate (OUR) are specified in order to simulate
    anaerobic growth conditions (GUR = 18.5 mmol/gDW/hr, OUR = 0 mmol/gDW/hr) [21]. A minimal growth rate was set to
    0.1 hr-1 for all simulations.

    :return:
    """

    from reframed.io.sbml import load_cbmodel
    from mewpy.simulation.reframed import Simulation

    DIR = os.path.dirname(os.path.realpath(__file__))
    cbm_model_f = os.path.join(DIR, "../models/regulation/iJR904_srfba.xml")
    reg_model_f = os.path.join(DIR, '../models/regulation/imc1010_v6.csv')
    aliases_f = os.path.join(DIR, '../models/regulation/imc1010_rfba_aliases.csv')
    # env_cond_f = "../../../examples/models/regulation/imc1010_env_cond.xlsx"

    _BIOMASS_ID = 'R_BiomassEcoli'
    _O2 = 'R_EX_o2_e'
    _GLC = 'R_EX_glc_DASH_D_e'
    _CO2 = 'R_EX_co2_e'
    _FE2 = "R_EX_fe2_e"
    _H = "R_EX_h_e"
    _H2O = "R_EX_h2o_e"
    _K = "R_EX_k_e"
    _NA1 = "R_EX_na1_e"
    _NH4 = "R_EX_nh4_e"
    _PI = "R_EX_pi_e"
    _SO4 = "R_EX_so4_e"
    _SUCC = "R_EX_succ_e"
    _ETOH = "R_EX_etoh_e"

    _GLY = "R_EX_gly_e"
    _DALA = "R_EX_ala_DASH_D_e"

    model = load_cbmodel(cbm_model_f)
    model.set_objective({_BIOMASS_ID: 1})

    envcond = {_GLC: (-18.5, 100000.0),
               # _SUCC: (0.0, 100000.0),
               # _NH4: (-10.0, 100000.0),
               _O2: (0, 100000.0),
               # _CO2: (-15.0, 100000.0),
               # _PI: (-15.0, 100000.0),
               # _SO4: (-10.0, 100000.0),
               # _H: (-10.0, 100000.0),
               # _H2O: (-55.0, 100000.0)
               }

    simulation = Simulation(model, envcond=envcond)

    rfba = RFBAModel.from_tabular_format(reg_model_f, model, simulation,
                                         sep=';', id_col=1, rule_col=4, aliases_cols=[0, 2, 3], header=0)
    rfba.update_aliases_from_tabular_format_file(aliases_f, sep=';', id_col=0, aliases_cols=[1])

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

    _PRODUCT_ID = _ETOH

    evaluator_1 = BPCY(_BIOMASS_ID, _PRODUCT_ID, method=SimulationMethod.pFBA)
    evaluator_2 = WYIELD(_BIOMASS_ID, _PRODUCT_ID)

    problem = OptOrfProblem(model, [evaluator_1, evaluator_2], rfba, candidate_max_size=6)

    ea = EA(problem, max_generations=100, mp=True)
    final_pop = ea.run()

    import mewpy.utils.utilities as utl

    filename = "OPTORF{}_KO_{}.csv".format(_PRODUCT_ID, "iJR904_srfba")
    utl.population_to_csv(problem, final_pop, filename, simplify=False)
Ejemplo n.º 19
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)