Skip to content

Commit

Permalink
Merge pull request #615 from opencobra/fix-metric
Browse files Browse the repository at this point in the history
fix: add parametrized metric
  • Loading branch information
Midnighter committed Feb 21, 2019
2 parents 46ed257 + 2871f49 commit 28a7b57
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 22 deletions.
1 change: 1 addition & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ History

Next Release
------------
* Add missing parametrized metric on ``test_biomass_open_production``.

0.9.4 (2019-02-20)
------------------
Expand Down
43 changes: 21 additions & 22 deletions memote/suite/tests/test_biomass.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,13 @@ def test_biomass_presence(model):
ann = test_biomass_presence.annotation
ann["data"] = [
rxn.id for rxn in helpers.find_biomass_reaction(model)]
ann["metric"] = 1.0 - float(len(ann["data"]) > 0)
outcome = len(ann["data"]) > 0
ann["metric"] = 1.0 - float(outcome)
ann["message"] = wrapper.fill(
"""In this model {} the following biomass reactions were
identified: {}""".format(
len(ann["data"]), truncate(ann["data"])))
assert len(ann["data"]) > 0, ann["message"]
assert outcome, ann["message"]


@pytest.mark.biomass
Expand Down Expand Up @@ -113,11 +114,11 @@ def test_biomass_consistency(model, reaction_id):
which is outside of the 1e-03 margin from 1 mmol / g[CDW] / h.
""".format(reaction_id, ann["data"][reaction_id])
)
test_outcome = (1 - 1e-03) < ann["data"][reaction_id] < (1 + 1e-06)
ann["metric"][reaction_id] = 1.0 - float(test_outcome)
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 test_outcome, ann["message"][reaction_id]
assert outcome, ann["message"][reaction_id]


@pytest.mark.biomass
Expand All @@ -138,14 +139,14 @@ def test_biomass_default_production(model, reaction_id):
"""
ann = test_biomass_default_production.annotation
ann["data"][reaction_id] = helpers.run_fba(model, reaction_id)
test_outcome = ann["data"][reaction_id] > 1E-07
ann["metric"][reaction_id] = 1.0 - float(test_outcome)
outcome = ann["data"][reaction_id] > 1E-07
ann["metric"][reaction_id] = 1.0 - float(outcome)
ann["message"][reaction_id] = wrapper.fill(
"""Using the biomass reaction {} this is the growth rate (1/h) that
can be achieved when the model is simulated on the provided
default medium: {}
""".format(reaction_id, ann["data"][reaction_id]))
assert test_outcome, ann["message"][reaction_id]
assert outcome, ann["message"][reaction_id]


@pytest.mark.biomass
Expand All @@ -167,14 +168,14 @@ def test_biomass_open_production(model, reaction_id):
ann = test_biomass_open_production.annotation
helpers.open_boundaries(model)
ann["data"][reaction_id] = helpers.run_fba(model, reaction_id)
test_outcome = ann["data"][reaction_id] > 1E-07
ann["metric"] = 1.0 - float(test_outcome)
outcome = ann["data"][reaction_id] > 1E-07
ann["metric"][reaction_id] = 1.0 - float(outcome)
ann["message"][reaction_id] = wrapper.fill(
"""Using the biomass reaction {} this is the growth rate that can be
achieved when the model is simulated on a complete medium i.e.
with all the boundary reactions unconstrained: {}
""".format(reaction_id, ann["data"][reaction_id]))
assert test_outcome, ann["message"][reaction_id]
assert outcome, ann["message"][reaction_id]


@pytest.mark.biomass
Expand Down Expand Up @@ -312,19 +313,18 @@ def test_gam_in_biomass(model, reaction_id):
"""
ann = test_gam_in_biomass.annotation
reaction = model.reactions.get_by_id(reaction_id)
test_outcome = biomass.gam_in_biomass(model, reaction)
ann["data"][reaction_id] = test_outcome
test_outcome = ann["data"][reaction_id]
ann["metric"][reaction_id] = 1.0 - float(test_outcome)
if test_outcome:
outcome = biomass.gam_in_biomass(model, reaction)
ann["data"][reaction_id] = outcome
ann["metric"][reaction_id] = 1.0 - float(outcome)
if outcome:
ann["message"][reaction_id] = wrapper.fill(
"""Yes, {} contains a term for growth-associated maintenance.
""".format(reaction_id))
else:
ann["message"][reaction_id] = wrapper.fill(
"""No, {} does not contain a term for growth-associated
maintenance.""".format(reaction_id))
assert test_outcome, ann["message"][reaction_id]
assert outcome, ann["message"][reaction_id]


@pytest.mark.biomass
Expand All @@ -351,10 +351,9 @@ def test_fast_growth_default(model, reaction_id):
"""
ann = test_fast_growth_default.annotation
test_outcome = helpers.run_fba(model, reaction_id) > 2.81
ann["data"][reaction_id] = test_outcome
ann["metric"][reaction_id] = 1.0 - float(test_outcome)

outcome = helpers.run_fba(model, reaction_id) > 2.81
ann["data"][reaction_id] = outcome
ann["metric"][reaction_id] = 1.0 - float(outcome)
if ann["data"][reaction_id]:
ann["message"][reaction_id] = wrapper.fill(
"""Using the biomass reaction {} and when the model is simulated on
Expand All @@ -368,7 +367,7 @@ def test_fast_growth_default(model, reaction_id):
the provided default medium the growth rate is *lower* than that
of the fastest bacteria. This is to be expected for
a majority of organisms.""".format(reaction_id))
assert test_outcome, ann["message"][reaction_id]
assert outcome, ann["message"][reaction_id]


@pytest.mark.biomass
Expand Down

0 comments on commit 28a7b57

Please sign in to comment.