Example #1
0
def test_biomass_consistency(read_only_model, reaction_id, store):
    """Expect biomass components to sum up to 1 g[CDW]."""
    store["biomass_sum"] = store.get("biomass_sum", list())
    reaction = read_only_model.reactions.get_by_id(reaction_id)
    component_sum = biomass.sum_biomass_weight(reaction)
    store["biomass_sum"].append(component_sum)
    assert np.isclose(component_sum, 1.0, atol=1e-03), \
        "{}'s components sum up to {} which is too far from " \
        "1 mmol / g[CDW] / h".format(reaction.id, component_sum)
Example #2
0
def test_biomass_weight_production(model, expected):
    """
    Expect that the sum of total mass of all biomass components equals 1.

    Allow for an absolute tolerance of 1e-03.
    """
    biomass_rxns = helpers.find_biomass_reaction(model)
    for rxn in biomass_rxns:
        control_sum = biomass.sum_biomass_weight(rxn)
        assert np.isclose(1, control_sum, atol=1e-03) is expected
Example #3
0
def test_biomass_weight_production(model, expected):
    """
    Expect that the sum of total mass of all biomass components equals 1.

    Allow for an absolute tolerance of 1e-03.
    """
    biomass_rxns = helpers.find_biomass_reaction(model)
    for rxn in biomass_rxns:
        control_sum = biomass.sum_biomass_weight(rxn)
        assert np.isclose(1, control_sum, atol=1e-03) == expected
Example #4
0
def test_biomass_consistency(read_only_model, reaction_id):
    """
    Expect biomass components to sum up to 1 g[CDW].

    The molecular weight of the biomass reaction in metabolic models is
    defined to be equal to 1 g/mmol. Conforming to this is essential in order
    to be able to reliably calculate growth yields, to cross-compare models,
    and to obtain valid predictions when simulating microbial consortia. A
    deviation by 1e-03 is accepted.
    """
    ann = test_biomass_consistency.annotation
    reaction = read_only_model.reactions.get_by_id(reaction_id)
    ann["data"][reaction_id] = biomass.sum_biomass_weight(reaction)
    ann["message"][reaction_id] = wrapper.fill(
        """The component molar mass of the biomass reaction {} sums up to {}
        which is outside of the 1e-03 margin from 1 mmol / g[CDW] / h.
        """.format(reaction_id, ann["data"][reaction_id]))
    assert np.isclose(ann["data"][reaction_id], 1.0,
                      atol=1e-03), ann["message"][reaction_id]
Example #5
0
def test_biomass_consistency(model, reaction_id):
    """
    Expect biomass components to sum up to 1 g[CDW].

    This test only yields sensible results if all biomass precursor
    metabolites have chemical formulas assigned to them.
    The molecular weight of the biomass reaction in metabolic models is
    defined to be equal to 1 g/mmol. Conforming to this is essential in order
    to be able to reliably calculate growth yields, to cross-compare models,
    and to obtain valid predictions when simulating microbial consortia. A
    deviation from 1 - 1E-03 to 1 + 1E-06 is accepted.

    Implementation:
    Multiplies the coefficient of each metabolite of the biomass reaction with
    its molecular weight calculated from the formula, then divides the overall
    sum of all the products by 1000.

    """
    ann = test_biomass_consistency.annotation
    reaction = model.reactions.get_by_id(reaction_id)
    try:
        ann["data"][reaction_id] = biomass.sum_biomass_weight(reaction)
    except TypeError:
        ann["data"][reaction_id] = None
        ann["message"][reaction_id] = wrapper.fill(
            """One or more of the biomass components do not have a defined
            formula or contain unspecified chemical groups.""")
    else:
        ann["message"][reaction_id] = wrapper.fill(
            """The component molar mass of the biomass reaction {} sums up to {}
            which is outside of the 1e-03 margin from 1 mmol / g[CDW] / h.
            """.format(reaction_id, ann["data"][reaction_id]))
    outcome = (1 - 1e-03) < ann["data"][reaction_id] < (1 + 1e-06)
    ann["metric"][reaction_id] = 1.0 - float(outcome)
    # To account for numerical inaccuracies, a range from 1-1e0-3 to 1+1e-06
    # is implemented in the assertion check
    assert outcome, ann["message"][reaction_id]