opencobra / memote

memote – the genome-scale metabolic model test suite
https://memote.readthedocs.io/
Apache License 2.0
126 stars 26 forks source link

`memote report snapshot` raises `TypeError` exceptions #349

Closed siddC closed 6 years ago

siddC commented 6 years ago

Problem description

Running memote report snapshot -a "-vv" on the iJO 1366 model results in 8 TypeError exceptions. All the errors occur in test_biomass.py. The specific functions these exceptions occur for are:

The specific error messages given are:

E TypeError: 'float' object does not support item assignment

for test_biomass_precursors_default_production and test_biomass_precursors_open_production and:

E TypeError: unsupported format string passed to dict.__format__

for test_direct_metabolites_in_biomass and test_essential_precursors_not_in_biomass

The reactions for these TypeError exceptions occur for are BIOMASS_Ec_iJO1366_core_53p95M and BIOMASS_Ec_iJO1366_WT_53p95M

Raw terminal output: ~~~ _________ test_biomass_precursors_default_production[BIOMASS_Ec_iJO1366_WT_53p95M] __________ memote/suite/tests/test_biomass.py:156: in test_biomass_precursors_default_production ) / len(biomass.find_biomass_precursors(read_only_model, reaction)) E TypeError: 'float' object does not support item assignment _________ test_biomass_precursors_default_production[BIOMASS_Ec_iJO1366_core_53p95M] __________ memote/suite/tests/test_biomass.py:156: in test_biomass_precursors_default_production ) / len(biomass.find_biomass_precursors(read_only_model, reaction)) E TypeError: 'float' object does not support item assignment ___________ test_biomass_precursors_open_production[BIOMASS_Ec_iJO1366_WT_53p95M] ___________ memote/suite/tests/test_biomass.py:196: in test_biomass_precursors_open_production ann["metric"][reaction_id], E TypeError: 'float' object is not subscriptable __________ test_biomass_precursors_open_production[BIOMASS_Ec_iJO1366_core_53p95M] __________ memote/suite/tests/test_biomass.py:196: in test_biomass_precursors_open_production ann["metric"][reaction_id], E TypeError: 'float' object is not subscriptable ______________ test_direct_metabolites_in_biomass[BIOMASS_Ec_iJO1366_WT_53p95M] _______________ memote/suite/tests/test_biomass.py:285: in test_direct_metabolites_in_biomass ann["data"][reaction_id] E TypeError: unsupported format string passed to dict.__format__ ______________ test_direct_metabolites_in_biomass[BIOMASS_Ec_iJO1366_core_53p95M] _______________ memote/suite/tests/test_biomass.py:285: in test_direct_metabolites_in_biomass ann["data"][reaction_id] E TypeError: unsupported format string passed to dict.__format__ ___________ test_essential_precursors_not_in_biomass[BIOMASS_Ec_iJO1366_WT_53p95M] ____________ memote/suite/tests/test_biomass.py:331: in test_essential_precursors_not_in_biomass ann["data"][reaction_id] E TypeError: unsupported format string passed to dict.__format__ __________ test_essential_precursors_not_in_biomass[BIOMASS_Ec_iJO1366_core_53p95M] ___________ memote/suite/tests/test_biomass.py:331: in test_essential_precursors_not_in_biomass ann["data"][reaction_id] E TypeError: unsupported format string passed to dict.__format__ ~~~
siddC commented 6 years ago

For the following TypeError exceptions:

_______________ test_biomass_precursors_open_production[BIOMASS_Ec_iJO1366_WT_53p95M] _______________
memote/suite/tests/test_biomass.py:196: in test_biomass_precursors_open_production
    ann["metric"][reaction_id],
E   TypeError: 'float' object is not subscriptable
______________ test_biomass_precursors_open_production[BIOMASS_Ec_iJO1366_core_53p95M] ______________
memote/suite/tests/test_biomass.py:196: in test_biomass_precursors_open_production
    ann["metric"][reaction_id],
E   TypeError: 'float' object is not subscriptable

the issue seems to stem from test_biomass_precursors_open_production. As can be seen in the details tab, this function has an issue with ann["metric"][reaction_id] because ann["metric"][reaction_id] is not defined anywhere in the function at all.

~~~ def test_biomass_precursors_open_production(model, reaction_id): """ Expect precursor production in complete medium. Using flux balance analysis this test optimizes for the production of each metabolite that is a substrate of the biomass reaction with the exception of atp and h2o. Optimizations are carried out using a complete medium i.e. unconstrained boundary reactions. This is useful when reconstructing the precursor biosynthesis pathways of a metabolic model. To pass this test, the model should be able to synthesis all the precursors. """ ann = test_biomass_precursors_open_production.annotation helpers.open_boundaries(model) reaction = model.reactions.get_by_id(reaction_id) ann["data"][reaction_id] = get_ids( biomass.find_blocked_biomass_precursors(reaction, model) ) ann["message"][reaction_id] = wrapper.fill( """Using the biomass reaction {} and when the model is simulated in complete medium a total of {} precursors ({:.2%} of all precursors except h2o and atp) cannot be produced: {} """.format(reaction_id, len(ann["data"][reaction_id]), ann["metric"][reaction_id], ann["data"][reaction_id] )) assert len(ann["data"][reaction_id]) == 0, ann["message"][reaction_id] ~~~
Midnighter commented 6 years ago

The problem seems to be that the @annotate decorator is missing an argument metric=dict() which should definitely be set before using it in the message. Something like:

ann["metric"][reaction_id] = len(blocked_precursors) / len(all_precursors)