示例#1
0
def test_measurements_adapter(iJO1366):
    iJO1366, biomass_reaction, is_ec_model = iJO1366
    uptake_secretion_rates = [
        {
            "name": "Foo",
            "identifier": "CHEBI:42758",
            "namespace": "chebi",
            "measurement": -9.0,
            "uncertainty": 0,
        },
        {
            "name": "Foo",
            "identifier": "CHEBI:16236",
            "namespace": "chebi",
            "measurement": 4.9,
            "uncertainty": 0,
        },
    ]
    fluxomics = [
        {
            "name": "Foo",
            "identifier": "PFK",
            "namespace": "bigg.reaction",
            "measurement": 4.8,
            "uncertainty": 0,
        },
        {
            "name": "Foo",
            "identifier": "PGK",
            "namespace": "bigg.reaction",
            "measurement": 5,
            "uncertainty": 0,
        },
    ]
    proteomics = {
        "identifier": "P0A8V2",
        "measurement": 5.03e-6,
        "uncertainty": 0
    }
    operations, warnings, errors = apply_measurements(
        iJO1366,
        biomass_reaction,
        is_ec_model,
        fluxomics,
        [],
        proteomics,
        uptake_secretion_rates,
        [],
        None,
    )
    # 4 operations (2 rates + 2 fluxomics) + 1 warning (not an ecModel) are expected:
    assert len(operations) == 4
    assert len(warnings) == 1
    assert len(errors) == 0
示例#2
0
def test_measurements_adapter_ec_model(eciML1515):
    # successfully flexibilize -> apply kinetics + growth rate + only 1 protein
    eciML1515, biomass_reaction, is_ec_model = eciML1515
    proteomics = [
        {
            "identifier": "P0AFG8",
            "measurement": 8.2e-3,  # very high value (should be kept)
            "uncertainty": 8.2e-6,
        },
        {
            "identifier": "P15254",
            "measurement": 6.54e-8,  # very low value (should be removed)
            "uncertainty": 0,
        },
    ]
    uptake_secretion_rates = [
        {
            "name": "glucose",
            "identifier": "MNXM41",
            "namespace": "metanetx.chemical",
            "measurement": -9.8,
            "uncertainty": 0.3,
        },
        {
            "name": "ethanol",
            "identifier": "MNXM303",
            "namespace": "metanetx.chemical",
            "measurement": 0.5,
            "uncertainty": 0,
        },
    ]
    growth_rate = {"measurement": 0.1, "uncertainty": 0.01}
    operations, warnings, errors = apply_measurements(
        eciML1515,
        biomass_reaction,
        is_ec_model,
        [],
        [],
        proteomics,
        uptake_secretion_rates,
        [],
        growth_rate,
    )
    # 4 operations (1 protein + 1 uptake + 1 secretion + growth rate) + 1 warning
    # (removed protein due to flexibilization) are expected:
    assert len(operations) == 4
    assert len(warnings) == 1
    assert len(errors) == 0
示例#3
0
def test_measurements_adapter(iJO1366):
    iJO1366, biomass_reaction = iJO1366
    uptake_secretion_rates = [
        {
            "name": "Foo",
            "identifier": "CHEBI:42758",
            "namespace": "chebi",
            "measurement": -9.0,
            "uncertainty": 0,
        },
        {
            "name": "Foo",
            "identifier": "CHEBI:16236",
            "namespace": "chebi",
            "measurement": 4.9,
            "uncertainty": 0,
        },
    ]
    fluxomics = [
        {
            "name": "Foo",
            "identifier": "PFK",
            "namespace": "bigg.reaction",
            "measurement": 4.8,
            "uncertainty": 0,
        },
        {
            "name": "Foo",
            "identifier": "PGK",
            "namespace": "bigg.reaction",
            "measurement": 5,
            "uncertainty": 0,
        },
    ]
    operations, warnings, errors = apply_measurements(iJO1366,
                                                      biomass_reaction,
                                                      fluxomics, [],
                                                      uptake_secretion_rates,
                                                      [], None)
    assert len(operations) == 4
    assert len(errors) == 0
示例#4
0
def test_measurements_adapter_ec_model_skip(eciML1515):
    # skip flexibilization (no growth rate provided) + skip unmatched protein
    eciML1515, biomass_reaction, is_ec_model = eciML1515
    proteomics = [
        {
            "identifier": "P15254",
            "measurement": 6.54e-8,  # protein in model (should be kept)
            "uncertainty": 0,
        },
        {
            "identifier": "P0A8V2",  # protein not in model (should be skipped)
            "measurement": 5.03e-6,
            "uncertainty": 0,
        },
    ]
    operations, warnings, errors = apply_measurements(eciML1515,
                                                      biomass_reaction,
                                                      is_ec_model, [], [],
                                                      proteomics, [], [], [])
    # 1 operation (kept protein) + 1 warning (skipped protein) are expected:
    assert len(operations) == 1
    assert len(warnings) == 1
    assert len(errors) == 0
示例#5
0
def test_measurements_adapter_errors(iJO1366):
    # record unmatched metabolites and reactions as errors
    iJO1366, biomass_reaction, is_ec_model = iJO1366
    uptake_secretion_rates = [
        {
            "name": "not a match",
            "identifier": "CHEBI:123456789",  # non-existing id
            "namespace": "chebi",
            "measurement": 4.9,
            "uncertainty": 0,
        },
    ]
    fluxomics = [
        {
            "name": "not a match",
            "identifier": "ASDFGHJKL",  # non-existing id
            "namespace": "bigg.reaction",
            "measurement": 5,
            "uncertainty": 0,
        },
    ]
    operations, warnings, errors = apply_measurements(
        iJO1366,
        biomass_reaction,
        is_ec_model,
        fluxomics,
        [],
        [],
        uptake_secretion_rates,
        [],
        None,
    )
    # 2 errors (metabolite not found + reaction not found) are expected:
    assert len(operations) == 0
    assert len(warnings) == 0
    assert len(errors) == 2
示例#6
0
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}