opencobra / cobrapy

COBRApy is a package for constraint-based modeling of metabolic networks.
http://opencobra.github.io/cobrapy/
GNU General Public License v2.0
467 stars 218 forks source link

Lower and upper bounds overwriting on save #1300

Closed ym2877 closed 1 year ago

ym2877 commented 2 years ago

https://github.com/opencobra/cobrapy/blob/4ef4d797d234e6b7153a1eabca0d9bc1d75a7d9e/src/cobra/io/sbml.py#L1281-L1286

Hi! I'm not sure if this is the intended behavior, but these lines of code are overwriting and replacing all absolute bounds that were changed prior to saving the model. So for example, if I have a model with the following reactions-

-1000 < reactionA  < 1000
-1000 < reactionB  < 1000
-1000 < reactionC  < 1000

If I were to try changing the bounds of just reaction C with reactionC.bounds = (-2000,4000), the bounds of all reactions upon saving the model (and subsequently reading it from file) would be-

-2000 < reactionA  < 4000
-2000 < reactionB  < 4000
-2000 < reactionC  < 4000

instead of

-1000 < reactionA  < 1000
-1000 < reactionB  < 1000
-2000 < reactionC  < 4000

If this is indeed the intended behavior, I'd argue it doesn't make much sense and entirely defeats the purpose of having a global configuration object altogether. It's especially strange considering these changes only kick in when trying to save a model a file. With the way the code is written now, the lower_bound and upper_bound configurations are entirely ignored once 1 reaction is added to the model.

Suggested fix is removing the first if clause like so-

min_value = config.lower_bound 
max_value = config.upper_bound 
cdiener commented 2 years ago

Yes that's true. Looks like strange behavior to me as well.

ym2877 commented 1 year ago

@cdiener any updates on this? Should I go ahead and make a PR with this fix?