def model_simulate(model_id, method, objective_id, objective_direction, operations): try: model_wrapper = storage.get(model_id) except Unauthorized as error: abort(401, error.message) except Forbidden as error: abort(403, error.message) except ModelNotFound as error: abort(404, error.message) model = model_wrapper.model # Use the context manager to undo all modifications to the shared model instance on # completion. with model: apply_operations(model, operations) try: flux_distribution, growth_rate = simulate( model, model_wrapper.biomass_reaction, method, objective_id, objective_direction, ) except OptimizationError: return jsonify({"status": model.solver.status}) else: return jsonify( { "status": model.solver.status, "flux_distribution": flux_distribution, "growth_rate": growth_rate, } )
def test_add_reaction(e_coli_core): e_coli_core, biomass_reaction, is_ec_model = e_coli_core assert not e_coli_core.reactions.has_id("FOOBAR") apply_operations( e_coli_core, [{ "operation": "add", "type": "reaction", "data": { "id": "FOOBAR", "name": "Foo Bar", "metabolites": { "accoa_c": -1.0, "cit_c": 1.0, "coa_c": 1.0, "h2o_c": -1.0, "h_c": 1.0, "oaa_c": -1.0, }, "lower_bound": 0.0, "upper_bound": 1000.0, "gene_reaction_rule": "b0720", }, }], ) assert e_coli_core.reactions.FOOBAR.bounds == (0.0, 1000.0)
def test_knockout_reaction(e_coli_core): e_coli_core, biomass_reaction, is_ec_model = e_coli_core assert e_coli_core.reactions.CS.bounds != (0.0, 0.0) apply_operations(e_coli_core, [{ "operation": "knockout", "type": "reaction", "id": "CS" }]) assert e_coli_core.reactions.CS.bounds == (0.0, 0.0)
def test_knockout_gene(e_coli_core): e_coli_core, biomass_reaction, is_ec_model = e_coli_core assert e_coli_core.genes.b4025.functional assert all( [r.bounds != (0.0, 0.0) for r in e_coli_core.genes.b4025.reactions]) apply_operations(e_coli_core, [{ "operation": "knockout", "type": "gene", "id": "b4025" }]) assert not e_coli_core.genes.b4025.functional assert all( [r.bounds == (0.0, 0.0) for r in e_coli_core.genes.b4025.reactions])
def test_modify_reaction(e_coli_core): e_coli_core, biomass_reaction, is_ec_model = e_coli_core assert e_coli_core.reactions.CS.bounds == (0.0, 1000.0) apply_operations( e_coli_core, [{ "operation": "modify", "type": "reaction", "id": "CS", "data": { "id": "CS", "lower_bound": -20.0, "upper_bound": 20.0 }, }], ) assert e_coli_core.reactions.CS.bounds == (-20.0, 20)
def test_add_reaction_unknown_metabolites(e_coli_core): e_coli_core, biomass_reaction, is_ec_model = e_coli_core assert not e_coli_core.metabolites.has_id("foo_c") assert not e_coli_core.metabolites.has_id("bar_c") apply_operations( e_coli_core, [{ "operation": "add", "type": "reaction", "data": { "id": "FOOBAR", "name": "Foo Bar", "metabolites": { "foo_c": -1.0, "bar_c": 1.0 }, "lower_bound": -1000.0, "upper_bound": 1000.0, "gene_reaction_rule": "", }, }], ) assert e_coli_core.metabolites.has_id("foo_c") assert e_coli_core.metabolites.has_id("bar_c")