Closed bdelepine closed 4 years ago
Across two different solutions I would only expect the objective value and fairly closely the in-fluxes to be equal. However, as you demonstrate, this is not the case. I will try to reproduce these but it looks quite problematic.
Another thing that pops out is that in many cases FLUX_MIN > FLUX_MAX
...
I recently noticed that the flux_min/flux_max returned by FVA had the same issue--the cobrapy version I'm using for this project is 0.14.2, so the problem might be quite old.
@gregmedlock I can't reproduce this bug with FVA alone. Could you make a new bug report with a reproducible example and indicate which solver you are using? Thanks!
The problem with here is that model.summary()
does not actually return a string representation of the summary but a Summary object that does nothing initially. The summary gets calculated when ans1
is printed and not in the with block. You can easily see that when printing ans1-ans3 within the with block which will give you correct results.
In your case ans1 uses the model after reset when print is called thus giving the unconstrained model. ans2 is using the solution from within the with block which is correct, thus everything works. ans3 uses the solution from within the with block which is correct but runs FVA on the model thus the discrepancy.
I feel like this is very odd behavior. I would expect summaries to be immutable. They should be calculated on call and not on print which can create all kinds of problems. Preferably Summary objects should be a one-shot thing. They only get calculated on init and then just store the results without any chance of re-computation.
Ah, thank you for investigating that Christian :smiley: That is actually what I proposed to do with my additional changes to the summary PR. So I guess it's urgent that I finish up that work.
Do we have planned fixes for this? This has been broken since several releases so might be a good idea to at least do a workaround.
Sorry, completely dropped off my radar. Please poke me again in mid May if I haven't submitted anything by then.
Sure thing. Thank you!
Sorry, completely dropped off my radar. Please poke me again in mid May if I haven't submitted anything by then.
Maybe a hint because it seems to work fine in the old version, please see below with version 0.15.4:
import cobra
import cobra.test
# With context
model = cobra.test.create_test_model("ecoli")
with model as m:
m.reactions.EX_glc_e.bounds = (0, 1000)
m.reactions.EX_ac_e.bounds = (-10, 1000)
solution = m.optimize()
ans1 = m.summary()
ans2 = m.summary(solution=solution)
ans3 = m.summary(solution=solution, fva=0.95)
# Without context
m = cobra.test.create_test_model("ecoli")
m.reactions.EX_glc_e.bounds = (0, 1000)
m.reactions.EX_ac_e.bounds = (-10, 1000)
solution = m.optimize()
ans11 = m.summary()
ans22 = m.summary(solution=solution)
ans33 = m.summary(solution=solution, fva=0.95)
#
print(ans1, ans11)
print(ans2, ans22)
print(ans3, ans33)
Output
ERROR:root:'M_sertrna[sec]_c' is not a valid SBML 'SId'.
IN FLUXES OUT FLUXES OBJECTIVES
----------------- ------------ ----------------------
ac_e 10 h2o_e 16.4 Ec_biomass_i... 0.247
o2_e 9.33 co2_e 9.85
h_e 7.73
nh4_e 2.67
pi_e 0.238
so4_e 0.0623
k_e 0.0483
fe2_e 0.00397
mg2_e 0.00214
ca2_e 0.00129
cl_e 0.00129
cu2_e 0.000175
mn2_e 0.000171
zn2_e 8.43e-05
ni2_e 7.98e-05
mobd_e 3.19e-05
IN FLUXES OUT FLUXES OBJECTIVES
----------------- ------------ ----------------------
ac_e 10 h2o_e 16.4 Ec_biomass_i... 0.247
o2_e 9.33 co2_e 9.85
h_e 7.73
nh4_e 2.67
pi_e 0.238
so4_e 0.0623
k_e 0.0483
fe2_e 0.00397
mg2_e 0.00214
ca2_e 0.00129
cl_e 0.00129
cu2_e 0.000175
mn2_e 0.000171
zn2_e 8.43e-05
ni2_e 7.98e-05
mobd_e 3.19e-05
IN FLUXES OUT FLUXES OBJECTIVES
--------------------------------------- ------------------------------------- ----------------------
id Flux Range id Flux Range Ec_biomass_i... 0.247
------ --------- -------------------- --------------- ------ ------------
ac_e 10 [9.53, 10] h2o_e 16.4 [15.2, 514]
o2_e 9.33 [8.91, 258] co2_e 9.85 [8.97, 10.4]
h_e 7.73 [6.43, 1e+03] fe3_e 0 [-1.25, 994]
nh4_e 2.67 [2.54, 3.62] for_e 0 [0, 1.39]
pi_e 0.238 [0.227, 0.37] urea_e 0 [0, 0.54]
so4_e 0.0623 [0.0592, 0.356] glyclt_e 0 [0, 0.475]
k_e 0.0483 [0.0458, 0.0483] gly_e 0 [0, 0.376]
fe2_e 0.00397 [-1.25, 994] acald_e 0 [0, 0.33]
mg2_e 0.00214 [0.00204, 0.00214] pyr_e 0 [0, 0.33]
ca2_e 0.00129 [0.00122, 0.00129] h2s_e 0 [0, 0.297]
cl_e 0.00129 [0.00122, 0.00129] ala__L_e 0 [0, 0.276]
cu2_e 0.000175 [0.000167, 0.000175] etoh_e 0 [0, 0.276]
mn2_e 0.000171 [0.000162, 0.000171] glyc__R_e 0 [0, 0.276]
zn2_e 8.4e-05 [8e-05, 8.4e-05] lac__D_e 0 [0, 0.276]
ni2_e 8e-05 [7.6e-05, 8e-05] ser__L_e 0 [0, 0.27]
mobd_e 3.2e-05 [3e-05, 3.2e-05] asp__L_e 0 [0, 0.247]
mal__L_e 0 [0, 0.237]
asn__L_e 0 [0, 0.228]
ura_e 0 [0, 0.228]
lac__L_e 0 [0, 0.223]
succ_e 0 [0, 0.22]
dha_e 0 [0, 0.216]
glyald_e 0 [0, 0.216]
alltn_e 0 [0, 0.191]
glyc_e 0 [0, 0.191]
akg_e 0 [0, 0.188]
ala__D_e 0 [0, 0.185]
hom__L_e 0 [0, 0.177]
12ppd__R_e 0 [0, 0.177]
12ppd__S_e 0 [0, 0.177]
etha_e 0 [0, 0.175]
4abut_e 0 [0, 0.172]
thr__L_e 0 [0, 0.172]
glu__L_e 0 [0, 0.17]
3hpp_e 0 [0, 0.165]
cit_e 0 [0, 0.163]
acser_e 0 [0, 0.16]
xan_e 0 [0, 0.154]
glyc3p_e 0 [0, 0.143]
thym_e 0 [0, 0.143]
hxan_e 0 [0, 0.141]
gua_e 0 [0, 0.138]
val__L_e 0 [0, 0.138]
pro__L_e 0 [0, 0.136]
ade_e 0 [0, 0.135]
cys__L_e 0 [0, 0.135]
ptrc_e 0 [0, 0.129]
orn_e 0 [0, 0.128]
agm_e 0 [0, 0.116]
arg__L_e 0 [0, 0.115]
leu__L_e 0 [0, 0.11]
his__L_e 0 [0, 0.104]
15dap_e 0 [0, 0.104]
lys__L_e 0 [0, 0.104]
hxa_e 0 [0, 0.103]
ile__L_e 0 [0, 0.0997]
quin_e 0 [0, 0.0955]
alaala_e 0 [0, 0.092]
g3pe_e 0 [0, 0.0913]
cgly_e 0 [0, 0.0897]
uri_e 0 [0, 0.0826]
g3pg_e 0 [0, 0.0802]
cytd_e 0 [0, 0.0778]
xtsn_e 0 [0, 0.0708]
tyr__L_e 0 [0, 0.0689]
ins_e 0 [0, 0.068]
phe__L_e 0 [0, 0.0662]
adn_e 0 [0, 0.0661]
thymd_e 0 [0, 0.0661]
indole_e 0 [0, 0.0656]
gthrd_e 0 [0, 0.059]
trp__L_e 0 [0, 0.0544]
LalaDgluMdap_e 0 [0, 0.0427]
LalaDgluMdap... 0 [0, 0.0367]
5mtr_e 0 [0, 0.0354]
spmd_e 0 [0, 0.0354]
anhgm_e 0 [0, 0.033]
enter_e 0 [0, 0.0216]
feenter_e 0 [0, 0.0216]
pheme_e 0 [0, 0.0185]
kdo2lipid4_e 0 [0, 0.00703]
lipa_e 0 [0, 0.00533]
enlipa_e 0 [0, 0.0052]
lipa_cold_e 0 [0, 0.00514]
colipa_e 0 [0, 0.00343]
acolipa_e 0 [0, 0.00333]
colipap_e 0 [0, 0.00249]
eca4colipa_e 0 [0, 0.0023]
ERROR:root:'M_sertrna[sec]_c' is not a valid SBML 'SId'.
IN FLUXES OUT FLUXES OBJECTIVES
----------------- ------------ ----------------------
ac_e 10 h2o_e 16.4 Ec_biomass_i... 0.247
o2_e 9.33 co2_e 9.85
h_e 7.73
nh4_e 2.67
pi_e 0.238
so4_e 0.0623
k_e 0.0483
fe2_e 0.00397
mg2_e 0.00214
ca2_e 0.00129
cl_e 0.00129
cu2_e 0.000175
mn2_e 0.000171
zn2_e 8.43e-05
ni2_e 7.98e-05
mobd_e 3.19e-05
IN FLUXES OUT FLUXES OBJECTIVES
----------------- ------------ ----------------------
ac_e 10 h2o_e 16.4 Ec_biomass_i... 0.247
o2_e 9.33 co2_e 9.85
h_e 7.73
nh4_e 2.67
pi_e 0.238
so4_e 0.0623
k_e 0.0483
fe2_e 0.00397
mg2_e 0.00214
ca2_e 0.00129
cl_e 0.00129
cu2_e 0.000175
mn2_e 0.000171
zn2_e 8.43e-05
ni2_e 7.98e-05
mobd_e 3.19e-05
IN FLUXES OUT FLUXES OBJECTIVES
--------------------------------------- ------------------------------------- ----------------------
id Flux Range id Flux Range Ec_biomass_i... 0.247
------ --------- -------------------- --------------- ------ ------------
ac_e 10 [9.53, 10] h2o_e 16.4 [15.2, 514]
o2_e 9.33 [8.91, 258] co2_e 9.85 [8.97, 10.4]
h_e 7.73 [6.43, 1e+03] fe3_e 0 [-1.25, 994]
nh4_e 2.67 [2.54, 3.62] for_e 0 [0, 1.39]
pi_e 0.238 [0.227, 0.37] urea_e 0 [0, 0.54]
so4_e 0.0623 [0.0592, 0.356] glyclt_e 0 [0, 0.475]
k_e 0.0483 [0.0458, 0.0483] gly_e 0 [0, 0.376]
fe2_e 0.00397 [-1.25, 994] acald_e 0 [0, 0.33]
mg2_e 0.00214 [0.00204, 0.00214] pyr_e 0 [0, 0.33]
ca2_e 0.00129 [0.00122, 0.00129] h2s_e 0 [0, 0.297]
cl_e 0.00129 [0.00122, 0.00129] ala__L_e 0 [0, 0.276]
cu2_e 0.000175 [0.000167, 0.000175] etoh_e 0 [0, 0.276]
mn2_e 0.000171 [0.000162, 0.000171] glyc__R_e 0 [0, 0.276]
zn2_e 8.4e-05 [8e-05, 8.4e-05] lac__D_e 0 [0, 0.276]
ni2_e 8e-05 [7.6e-05, 8e-05] ser__L_e 0 [0, 0.27]
mobd_e 3.2e-05 [3e-05, 3.2e-05] asp__L_e 0 [0, 0.247]
mal__L_e 0 [0, 0.237]
asn__L_e 0 [0, 0.228]
ura_e 0 [0, 0.228]
lac__L_e 0 [0, 0.223]
succ_e 0 [0, 0.22]
dha_e 0 [0, 0.216]
glyald_e 0 [0, 0.216]
alltn_e 0 [0, 0.191]
glyc_e 0 [0, 0.191]
akg_e 0 [0, 0.188]
ala__D_e 0 [0, 0.185]
hom__L_e 0 [0, 0.177]
12ppd__R_e 0 [0, 0.177]
12ppd__S_e 0 [0, 0.177]
etha_e 0 [0, 0.175]
4abut_e 0 [0, 0.172]
thr__L_e 0 [0, 0.172]
glu__L_e 0 [0, 0.17]
3hpp_e 0 [0, 0.165]
cit_e 0 [0, 0.163]
acser_e 0 [0, 0.16]
xan_e 0 [0, 0.154]
glyc3p_e 0 [0, 0.143]
thym_e 0 [0, 0.143]
hxan_e 0 [0, 0.141]
gua_e 0 [0, 0.138]
val__L_e 0 [0, 0.138]
pro__L_e 0 [0, 0.136]
ade_e 0 [0, 0.135]
cys__L_e 0 [0, 0.135]
ptrc_e 0 [0, 0.129]
orn_e 0 [0, 0.128]
agm_e 0 [0, 0.116]
arg__L_e 0 [0, 0.115]
leu__L_e 0 [0, 0.11]
his__L_e 0 [0, 0.104]
15dap_e 0 [0, 0.104]
lys__L_e 0 [0, 0.104]
hxa_e 0 [0, 0.103]
ile__L_e 0 [0, 0.0997]
quin_e 0 [0, 0.0955]
alaala_e 0 [0, 0.092]
g3pe_e 0 [0, 0.0913]
cgly_e 0 [0, 0.0897]
uri_e 0 [0, 0.0826]
g3pg_e 0 [0, 0.0802]
cytd_e 0 [0, 0.0778]
xtsn_e 0 [0, 0.0708]
tyr__L_e 0 [0, 0.0689]
ins_e 0 [0, 0.068]
phe__L_e 0 [0, 0.0662]
adn_e 0 [0, 0.0661]
thymd_e 0 [0, 0.0661]
indole_e 0 [0, 0.0656]
gthrd_e 0 [0, 0.059]
trp__L_e 0 [0, 0.0544]
LalaDgluMdap_e 0 [0, 0.0427]
LalaDgluMdap... 0 [0, 0.0367]
5mtr_e 0 [0, 0.0354]
spmd_e 0 [0, 0.0354]
anhgm_e 0 [0, 0.033]
enter_e 0 [0, 0.0216]
feenter_e 0 [0, 0.0216]
pheme_e 0 [0, 0.0185]
kdo2lipid4_e 0 [0, 0.00703]
lipa_e 0 [0, 0.00533]
enlipa_e 0 [0, 0.0052]
lipa_cold_e 0 [0, 0.00514]
colipa_e 0 [0, 0.00343]
acolipa_e 0 [0, 0.00333]
colipap_e 0 [0, 0.00249]
eca4colipa_e 0 [0, 0.0023]
None None
None None
None None
@Midnighter quick reminder.
I started working on this this morning :wink: Must be telepathy.
Problem description
Hello,
I want to use a context to safely change the C source, compute an FBA and then display the summary. I was surprised to see that the changes introduced in the context were ignored by the summary. I think this unexpected behavior because 1/ this is different than the behavior without using context, 2/ this leads to meaningless values if we additionally ask for FVA in the summary.
++
Code Sample
Actual Output
ans1 and ans11 are different:
ans2 and ans22 are equivalent:
ans3 and ans33 are different. ans3 is incoherent:
Expected Output
I would have expected that the summary with and without context to be equivalent.
Dependency Information