def testRun(self): model = load_sbml_model(SMALL_TEST_MODEL, kind=GPR_CONSTRAINED) save_sbml_model(model, TEST_MODEL_COPY) model_copy = load_sbml_model(TEST_MODEL_COPY, kind=GPR_CONSTRAINED) self.assertEqual(model.id, model_copy.id) self.assertListEqual(model.metabolites.keys(), model_copy.metabolites.keys()) self.assertListEqual(model.reactions.keys(), model_copy.reactions.keys()) self.assertDictEqual(model.stoichiometry, model_copy.stoichiometry) self.assertDictEqual(model.bounds, model_copy.bounds) self.assertListEqual(model.genes.keys(), model_copy.genes.keys()) self.assertDictEqual(model.rules, model_copy.rules)
def testRun(self): model = load_sbml_model(SMALL_TEST_MODEL, kind=GPR_CONSTRAINED) fix_bigg_model(model) simplify(model) solution = FBA(model) self.assertEqual(solution.status, Status.OPTIMAL) self.assertAlmostEqual(solution.fobj, GROWTH_RATE, places=2)
def testRun(self): model = load_sbml_model(SMALL_TEST_MODEL, kind=GPR_CONSTRAINED) fix_bigg_model(model) solution = gene_deletion(model, ROOM_GENE_KO, 'ROOM') self.assertEqual(solution.status, Status.OPTIMAL) self.assertAlmostEqual(solution.values[model.detect_biomass_reaction()], ROOM_GROWTH_RATE, 3) self.assertAlmostEqual(solution.values['R_EX_succ_e'], ROOM_SUCC_EX, 3)
def testRun(self): model = load_sbml_model(SMALL_TEST_MODEL, kind=GPR_CONSTRAINED) fix_bigg_model(model) make_irreversible(model) self.assertTrue(all([not reaction.reversible for reaction in model.reactions.values()])) solution = FBA(model) self.assertEqual(solution.status, Status.OPTIMAL) self.assertAlmostEqual(solution.fobj, GROWTH_RATE, places=2)
def testRun(self): model = load_sbml_model(SMALL_TEST_MODEL, kind=CONSTRAINT_BASED) fix_bigg_model(model) write_model_to_file(model, PLAIN_TEXT_COPY) model_copy = read_model_from_file(PLAIN_TEXT_COPY, kind=CONSTRAINT_BASED) solution = FBA(model_copy) self.assertEqual(solution.status, Status.OPTIMAL) self.assertAlmostEqual(solution.fobj, GROWTH_RATE, places=2)
def benchmark_methods(modelpath): model = load_sbml_model(modelpath, GPR_CONSTRAINED) fix_bigg_model(model) benchmark_method('FBA', model) benchmark_method('pFBA', model) benchmark_method('qpFBA', model) benchmark_method('MOMA', model) benchmark_method('lMOMA', model) benchmark_method('ROOM', model)
def test_gapFind_glpk_core_sbml_b005(self): solver = GlpkSolverLazy() model = '../../../examples/models/gapFill/ecoli_core_model_test.xml' reactionsDB = '../../../examples/models/gapFill/ecoli_core_model.xml' self.model = load_sbml_model(model, kind=CONSTRAINT_BASED) fix_bigg_model(self.model) framed_result = GapFill(self.model, reactionsDB, solver, "R_Biomass_Ecoli_core_w_GAM", 0.05, 'sbml') self.assertEquals(framed_result[1], ['R_PGK', 'R_PGM', 'R_PYK'])
def testRun(self): model = load_sbml_model(SMALL_TEST_MODEL, kind=CONSTRAINT_BASED) write_model_to_file(model, PLAIN_TEXT_COPY) model_copy = read_model_from_file(PLAIN_TEXT_COPY, kind=CONSTRAINT_BASED) self.assertListEqual(sorted(model.metabolites.keys()), sorted(model_copy.metabolites.keys())) self.assertListEqual(model.reactions.keys(), model_copy.reactions.keys()) self.assertDictEqual(dict(model.stoichiometry), dict(model_copy.stoichiometry)) self.assertDictEqual(model.bounds, model_copy.bounds)
def testRun(self): model = load_sbml_model(SMALL_TEST_MODEL, kind=GPR_CONSTRAINED) fix_bigg_model(model) r_id1 = 'R_PGI' r_id2 = 'R_G6PDH2r' ratio = 2.0 add_ratio_constraint(model, r_id1, r_id2, ratio) solution = FBA(model, get_shadow_prices=True, get_reduced_costs=True) self.assertEqual(solution.status, Status.OPTIMAL) self.assertEqual(solution.values[r_id1] / solution.values[r_id2], ratio)
def testRun(self): model = load_sbml_model(SMALL_TEST_MODEL, kind=GPR_CONSTRAINED) fix_bigg_model(model) simplify(model) make_irreversible(model) simplify(model) #remove directionally blocked reactions model2 = load_sbml_model(SMALL_TEST_MODEL, kind=GPR_CONSTRAINED) fix_bigg_model(model2) make_irreversible(model2) simplify(model2) self.assertEqual(model.id, model2.id) self.assertListEqual(model.metabolites.keys(), model2.metabolites.keys()) self.assertListEqual(model.reactions.keys(), model2.reactions.keys()) self.assertDictEqual(model.stoichiometry, model2.stoichiometry) self.assertDictEqual(model.bounds, model2.bounds) self.assertListEqual(model.genes.keys(), model2.genes.keys()) self.assertDictEqual(model.rules, model2.rules)
def benchmark_build_problem(modelpath, n=10): model = load_sbml_model(modelpath, GPR_CONSTRAINED) fix_bigg_model(model) print 'benchmarking build problem for', n, 'instances:', tstart = time() for i in range(n): solver = solver_instance() solver.build_problem(model) tend = time() print 'took', tend - tstart
def test_gapFind_glpk_full_sbml_b087(self): solver = GlpkSolver() model = '../../../examples/models/gapFill/ecoli_core_model_test.xml' reactionsDB = '../../../examples/models/gapFill/iAF1260.xml' self.model = load_sbml_model(model, kind=CONSTRAINT_BASED) fix_bigg_model(self.model) framed_result = GapFill(self.model, reactionsDB, solver, "R_Biomass_Ecoli_core_w_GAM", 0.87, 'sbml') # R_Htex is required to produce M_h_p, which is a reactant in R_ATPS4rpp self.assertEquals(framed_result[1], ['R_ATPS4rpp', 'R_Htex', 'R_PGK', 'R_PGM'])
def testRun(self): model = load_sbml_model(SMALL_TEST_MODEL, kind=GPR_CONSTRAINED) fix_bigg_model(model) solution1 = qpFBA(model) solution2 = FBA(model) self.assertEqual(solution1.status, Status.OPTIMAL) self.assertEqual(solution2.status, Status.OPTIMAL) growth1 = solution1.values[model.detect_biomass_reaction()] growth2 = solution2.values[model.detect_biomass_reaction()] self.assertAlmostEqual(growth1, growth2, places=4) norm1 = sum([abs(solution1.values[r_id]) for r_id in model.reactions]) norm2 = sum([abs(solution2.values[r_id]) for r_id in model.reactions]) self.assertLessEqual(norm1, norm2 + 1e-6)
def benchmark_solving_stage(modelpath, n=10): model = load_sbml_model(modelpath, GPR_CONSTRAINED) fix_bigg_model(model) print 'benchmarking solving stage for', n, 'repetitions:', solver = solver_instance() solver.build_problem(model) tstart = time() for i in range(n): FBA(model, solver=solver) tend = time() print 'took', tend - tstart
def test_gapFind_glpk_lazy(self): """ Finds gaps in 7 models using Glpk """ for i in range(1,8): solver = GlpkSolverLazy(tol_int="default") model = '../../../examples/models/gapFind/ecoli_core_model' + str(i) + '.xml' self.model = load_sbml_model(model, kind=CONSTRAINT_BASED) fix_bigg_model(self.model) framed_result = GapFind(self.model, solver) COBRA_mets_result_filename = '../../../examples/models/gapFind/gapFind_results/ecoli0' + str(i) + '_mets_glpk.txt' COBRA_rxns_result_filename = '../../../examples/models/gapFind/gapFind_results/ecoli0' + str(i) + '_rxns_glpk.txt' result = self.compare_to_COBRA(framed_result, COBRA_mets_result_filename, COBRA_rxns_result_filename) self.assertTrue(result)
def test_gapFind_gurobi(self): """ Finds gaps in 7 models using Gurobi """ for i in range(1,8): if i == 6: continue solver = GurobiSolver() model = '../../../examples/models/gapFind/ecoli_core_model' + str(i) + '.xml' self.model = load_sbml_model(model, kind=CONSTRAINT_BASED) fix_bigg_model(self.model) framed_result = GapFind(self.model, solver) COBRA_mets_result_filename = '../../../examples/models/gapFind/gapFind_results/ecoli0' + str(i) + '_mets_gurobi.txt' COBRA_rxns_result_filename = '../../../examples/models/gapFind/gapFind_results/ecoli0' + str(i) + '_rxns_gurobi.txt' result = self.compare_to_COBRA(framed_result, COBRA_mets_result_filename, COBRA_rxns_result_filename) self.assertTrue(result)
def testRun(self): model = load_sbml_model(SMALL_TEST_MODEL, kind=GPR_CONSTRAINED) fix_bigg_model(model) variability = FVA(model) self.assertTrue(all([lb <= ub if lb is not None and ub is not None else True for lb, ub in variability.values()]))
def testRun(self): model = load_sbml_model(SMALL_TEST_MODEL, kind=GPR_CONSTRAINED) fix_bigg_model(model) solution = FBA(model, get_shadow_prices=True, get_reduced_costs=True) self.assertEqual(solution.status, Status.OPTIMAL) self.assertAlmostEqual(solution.fobj, GROWTH_RATE, places=2)
def update(self): BR = self.environment # calculating and updating the glucose uptake constraint rid = BR.metabolites.index('R_EX_glc_e') vlb_glc = float(-10 * BR.S[rid] / (BR.S[rid] + 1)) self.fba_constraints['R_EX_glc_e'] = (vlb_glc, 0) # ideal aerobic condition self.fba_constraints['R_EX_o2_e'] = (-15, None) ### Setup EC_1260_MODEL = 'models/Ec_iAF1260_gene_names.xml' ec1260 = load_sbml_model(EC_1260_MODEL, kind=CONSTRAINT_BASED) fix_bigg_model(ec1260) # Add 1-3-PDO pathway add_reaction_from_str(ec1260, 'R_glycerol_dehydratase: M_glyc_c + M_nadh_c + M_h_c --> M_1_3_pdo_c + M_nad_c') add_reaction_from_str(ec1260, 'R_1_3_PDOtr: M_1_3_pdo_c <-> M_1_3_pdo_e') add_reaction_from_str(ec1260, 'R_EX_1_3_pdo_e: M_1_3_pdo_e -->') ec = Ecoli(ec1260, id='ecoli') # make envelope strains r_substrate, r_target1, r_target2, r_oxygen = 'R_EX_glc_e', 'R_EX_1_3_pdo_e', 'R_EX_3_hp_e', 'R_EX_o2_e' aerobic_constraints = {r_substrate: (-10, 0), r_oxygen: (-15, None)} strains = dyssco.make_envelope_strains(ec, 'R_EX_glc_e', 'R_EX_1_3_pdo_e', N=5, constraints=aerobic_constraints)
def testRun(self): model = load_sbml_model(SMALL_TEST_MODEL, kind=GPR_CONSTRAINED) fix_bigg_model(model) essential = essential_genes(model) self.assertListEqual(essential, ESSENTIAL_GENES)
def setUp(self): self.model = load_sbml_model(SMALL_TEST_MODEL, kind=CONSTRAINT_BASED) fix_bigg_model(self.model)
@Author: Kai Zhuang """ __author__ = 'kaizhuang' import matplotlib.pyplot as plt from framed.io_utils.sbml import load_sbml_model, CONSTRAINT_BASED from framed.core.fixes import fix_bigg_model from framed.bioreactor import * from framed.bioreactor.bioreactors import * ### Basic Setup SMALL_TEST_MODEL = 'models/ecoli_core_model.xml' ec_core_model = load_sbml_model(SMALL_TEST_MODEL, kind=CONSTRAINT_BASED) fix_bigg_model(ec_core_model) ### Defining the Ecoli class # In the Ecoli class, the method update(), which is an abstract method in the superclass Organism, is defined. # The update() method describes how Ecoli will respond to changes in metabolite concentrations in its environment. # Usually, the relevant FBA uptake constraints are calculated and updated in the update() method. class Ecoli(Organism): def update(self): BR = self.environment # calculating and updating the glucose uptake constraint rid = BR.metabolites.index('R_EX_glc_e')
""" __author__ = 'kaizhuang' import matplotlib.pyplot as plt from framed.io_utils.sbml import load_sbml_model, CONSTRAINT_BASED from framed.core.fixes import fix_bigg_model from framed.analysis.dfba import * from framed.bioreactor.bioreactors import * from framed.bioreactor import * ### Basic Setup SMALL_TEST_MODEL = 'models/Ec_iAF1260_gene_names.xml' ec1260 = load_sbml_model(SMALL_TEST_MODEL, kind=CONSTRAINT_BASED) fix_bigg_model(ec1260) ### Defining the Ecoli class # In the Ecoli class, the method update(), which is an abstract method in the superclass Organism, is defined. # The update() method describes how Ecoli will respond to changes in metabolite concentrations in its environment. # Usually, the relevant FBA uptake constraints are calculated and updated in the update() method. class Ecoli(Organism): def update(self): BR = self.environment # calculating and updating the glucose uptake constraint rid = BR.metabolites.index('R_EX_glc_e') vlb_glc = float(-10 * BR.S[rid] / (BR.S[rid] + 1))