def test_medium_adapter_ec_model(eciML1515): eciML1515, biomass_reaction, is_ec_model = eciML1515 medium = [ { "name": "glc", "identifier": "MNXM41", "namespace": "metanetx.chemical" }, { "name": "nh4", "identifier": "MNXM15", "namespace": "metanetx.chemical" }, { "name": "o2", "identifier": "MNXM4", "namespace": "metanetx.chemical" }, ] operations, warnings, errors = apply_medium(eciML1515, is_ec_model, medium) # 2 warnings are expected: trace metals (CHEBI:25517 and CHEBI:25368) not found in # model, as eciML1515 does not have CHEBI ids. assert len(warnings) == 2 assert len(errors) == 0 assert set(eciML1515.medium) == { "EX_glc__D_e_REV", "EX_nh4_e_REV", "EX_o2_e_REV", } assert eciML1515.reactions.EX_glc__D_e_REV.upper_bound == +10 assert eciML1515.reactions.EX_nh4_e_REV.upper_bound == +1000 assert eciML1515.reactions.EX_o2_e_REV.upper_bound == +1000
def test_medium_adapter(iJO1366): iJO1366, biomass_reaction, is_ec_model = iJO1366 medium = [ { "name": "Foo", "identifier": "CHEBI:63041", "namespace": "chebi" }, { "name": "Bar", "identifier": "CHEBI:91249", "namespace": "chebi" }, { "name": "Baz", "identifier": "CHEBI:86244", "namespace": "chebi" }, { "name": "Goo", "identifier": "CHEBI:131387", "namespace": "chebi" }, ] operations, warnings, errors = apply_medium(iJO1366, is_ec_model, medium) # 30 warnings are expected; 29 unique compounds not found in the model and 1 # unmapped ion from the salts mapping assert len(warnings) == 30 assert len(errors) == 0 assert set(iJO1366.medium) == { "EX_fe2_e", "EX_fe3_e", "EX_h2o_e", "EX_mobd_e", "EX_nh4_e", "EX_so4_e", "EX_ni2_e", "EX_mn2_e", "EX_cl_e", } assert all( iJO1366.reactions.get_by_id(r).lower_bound == -1000 for r in iJO1366.medium)
def model_modify( model_id, medium, genotype, fluxomics, metabolomics, uptake_secretion_rates, molar_yields, growth_rate, ): if not request.is_json: abort(415, "Non-JSON request content is not supported") 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) # Use the context manager to undo all modifications to the shared model instance on # completion. with model_wrapper.model as model: # Build list of operations to perform on the model operations = [] warnings = [] errors = [] if medium: results = apply_medium(model, medium) operations.extend(results[0]) warnings.extend(results[1]) errors.extend(results[2]) if genotype: results = apply_genotype(model, genotype) operations.extend(results[0]) warnings.extend(results[1]) errors.extend(results[2]) if ( fluxomics or metabolomics or uptake_secretion_rates or molar_yields or growth_rate ): results = apply_measurements( model, model_wrapper.biomass_reaction, fluxomics, metabolomics, uptake_secretion_rates, molar_yields, growth_rate, ) operations.extend(results[0]) warnings.extend(results[1]) errors.extend(results[2]) if errors: # If any errors occured during modifications, discard generated operations # and return the error messages to the client for follow-up return {"errors": errors}, 400 else: return {"operations": operations, "warnings": warnings}