コード例 #1
0
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,
                }
            )
コード例 #2
0
def test_tmy_result(e_coli_core, objective):
    e_coli_core, biomass_reaction = e_coli_core
    to_return = ["fluxes", "tmy", "model", "growth-rate", "removed-reactions"]
    result = simulate(
        e_coli_core, biomass_reaction, "fba", None, None, [objective], to_return
    )
    assert set(result) == set(to_return)
コード例 #3
0
def test_simulation_methods(e_coli_core, method):
    e_coli_core, biomass_reaction = e_coli_core
    for method in METHODS:
        fluxes, growth_rate = simulate(
            e_coli_core, biomass_reaction, method, None, None
        )
        if method not in {"fva", "pfba-fva"}:
            reactions_ids = [i.id for i in e_coli_core.reactions]
            assert set(fluxes) == set(reactions_ids)