예제 #1
0
파일: geckoopt.py 프로젝트: pg42862/mewpy
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)
예제 #2
0
파일: geneopt.py 프로젝트: pg42862/mewpy
def cb_ou(product, chassis='ec', display=False, filename=None):
    """Defines and run a gene over/under expression problem.

    Args:
        product (str): the ID of the compound reaction exchange to be optimized
        chassis (str, optional): The chassis, 'ec'(E.coli iJO1366Sl) , 'ec2' (E.coli iML1515) or 'ys' (yeast).
                                 Defaults to 'ec'.
        display (bool, optional): [description]. Defaults to False.
        filename ([type], optional): [description]. Defaults to None.
    """
    if chassis == 'ec2':
        conf = load_ec2()
    elif chassis == 'ys':
        conf = load_yeast()
    else:
        conf = load_ec()

    BIOMASS_ID = conf['biomass']
    PRODUCT_ID = product
    model = conf['model']
    envcond = conf['envcond']
    reference = conf['reference']

    evaluator_1 = BPCY(BIOMASS_ID, PRODUCT_ID, method=SimulationMethod.lMOMA)
    evaluator_2 = WYIELD(BIOMASS_ID, PRODUCT_ID)
    # Favors deletion and under expression modifications
    evaluator_3 = ModificationType()

    from mewpy.problems import GOUProblem
    problem = GOUProblem(model,
                         fevaluation=[evaluator_1, evaluator_2, evaluator_3],
                         envcond=envcond,
                         reference=reference,
                         candidate_min_size=4,
                         candidate_max_size=6,
                         operators=("lambda x,y: min(x,y)",
                                    "lambda x,y: max(x,y)"),
                         product=PRODUCT_ID)

    ea = EA(problem,
            max_generations=ITERATIONS,
            visualizer=False,
            algorithm='NSGAIII')
    final_pop = ea.run()

    if display:
        individual = max(final_pop)
        best = list(problem.decode(individual.candidate).keys())
        print('Best Solution: \n{0}'.format(str(best)))

    if filename:
        print("Simplifying and saving solutions to file")
        population_to_csv(problem, final_pop, filename, simplify=False)
예제 #3
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)
예제 #4
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)
예제 #5
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)
예제 #6
0
파일: geneopt.py 프로젝트: pg42862/mewpy
def cb_ko(product, chassis='ec', display=False, filename=None):
    """Defines and run a gene deletion problem.

    Args:
        product (str): the ID of the compound reaction exchange to be optimized
        chassis (str, optional): The chassis, 'ec'(E.coli iJO1366Sl) , 'ec2' (E.coli iML1515) or 'ys' (yeast).
                                 Defaults to 'ec'.
        display (bool, optional): [description]. Defaults to False.
        filename ([type], optional): [description]. Defaults to None.
    """
    if chassis == 'ec':
        conf = load_ec()
    elif chassis == 'ys':
        conf = load_yeast()
    else:
        raise ValueError

    BIOMASS_ID = conf['biomass']
    PRODUCT_ID = product
    model = conf['model']
    non_target = conf['non_target']
    envcond = conf['envcond']
    reference = conf['reference']

    evaluator_1 = BPCY(BIOMASS_ID, PRODUCT_ID, method=SimulationMethod.lMOMA)
    evaluator_2 = WYIELD(BIOMASS_ID, PRODUCT_ID)
    from mewpy.problems.genes import GKOProblem
    problem = GKOProblem(model,
                         fevaluation=[evaluator_1, evaluator_2],
                         non_target=non_target,
                         envcond=envcond,
                         reference=reference)

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

    if display:
        individual = max(final_pop)
        best = list(problem.decode(individual.candidate).keys())
        print('Best Solution: \n{0}'.format(str(best)))

    if filename:
        print("Simplifying and saving solutions to file")
        population_to_csv(problem, final_pop, filename, simplify=False)
예제 #7
0
파일: geckoopt.py 프로젝트: pg42862/mewpy
def yeast_gecko_ou(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.

    """

    model = GeckoModel('single-pool')
    BIOMASS = 'r_2111'
    envcond = envcond = {'r_1714_REV': (-10, 100000)}

    # the evaluation (objective) functions

    evaluator_1 = BPCY(BIOMASS, compound, method='lMOMA')
    evaluator_2 = WYIELD(BIOMASS, compound)
    # The optimization problem
    problem = GeckoOUProblem(model,
                             fevaluation=[evaluator_1, evaluator_2],
                             envcond=envcond,
                             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)