def test_basic_gecko_adjustment(): """Tests basic adjustments """ in_model = { 'P00549': 0.1, 'P31373': 0.1, 'P31382': 0.1, 'P39708': 0.1, 'P39714': 0.1, 'P39726': 0.1, 'Q01574': 0.1 } not_in_model = {'P10591': 0.1, 'P31383': 0.1, 'P32471': 0.1} measurements = pd.concat([pd.Series(in_model), pd.Series(not_in_model)]) model = GeckoModel('multi-pool') model.limit_proteins(fractions=pd.Series(measurements)) simul = GeckoSimulation(model) sol = simul.simulate() assert sol.objective_value > 0.05 assert len(model.proteins) - len(model.pool_proteins) - len(in_model) == 0 assert all(model.reactions[rxn].ub > 0 for rxn in model.individual_protein_exchanges)
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)
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)
)) return jobs if __name__ == '__main__': # Run the study output_directory = 'data' # Configure the experiments from mewpy.model.gecko import GeckoModel from collections import OrderedDict compound = 'r_1913' model = GeckoModel('single-pool', biomass_reaction_id='r_2111') model.set_objective({'r_2111': 1.0, 'r_4041': 0.0}) envcond = OrderedDict() from mewpy.optimization.evaluation import BPCY, WYIELD from mewpy.simulation import SimulationMethod # the evaluation (objective) functions evaluator_1 = BPCY("r_2111", compound, method=SimulationMethod.lMOMA) evaluator_2 = WYIELD("r_2111", compound) from mewpy.problems import GeckoOUProblem p = GeckoOUProblem(model, fevaluation=[evaluator_1, evaluator_2], candidate_max_size=candidate_max_size)
def ec_gecko_ou(compound, display=False, filename=None): """ GECKO enzyme over/under expression 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. """ # define the default solver # from reframed.solvers import set_default_solver # set_default_solver('gurobi') 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}) # change protein pool bound (suggested by Leslie) model.reactions['R_prot_pool_exchange'].ub = 0.26 # define environmental consitions envcond = OrderedDict() # the evaluation (objective) functions evaluator_1 = BPCY("R_BIOMASS_Ec_iML1515_core_75p37M", compound, method=SimulationMethod.MOMA) # FVA MAX is strangely very high... changing the default alpha (0.3) to compensate.. evaluator_2 = WYIELD("R_BIOMASS_Ec_iML1515_core_75p37M", compound, alpha=0.01) evaluator_3 = TargetFlux(compound) # The optimization problem problem = GeckoOUProblem( model, fevaluation=[evaluator_1, evaluator_2, evaluator_3], envcond=envcond, prot_prefix='R_draw_prot_', candidate_max_size=30) # A new instance of the EA optimizer ea = EA(problem, max_generations=ITERATIONS, mp=True) # 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)
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)
def setUp(self): from mewpy.model.gecko import GeckoModel model = GeckoModel('single-pool') from mewpy.simulation import get_simulator self.simul = get_simulator(model)
def test_simulator(self): from mewpy.model.gecko import GeckoModel model = GeckoModel('single-pool') from mewpy.simulation import get_simulator get_simulator(model)
def test_gecko(self): from mewpy.model.gecko import GeckoModel GeckoModel('single-pool')