opencobra / cobrapy

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

Presence of objective influences FVA result even if fraction_of_optimum=0.0 #1308

Closed axelvonkamp closed 1 year ago

axelvonkamp commented 1 year ago

To illustrate my issue I set up a simple model (without objective) and run a FVA:

from cobra import Model, Reaction, Metabolite
from cobra.flux_analysis import flux_variability_analysis
model = Model('FVA_bug')
model.add_metabolites([Metabolite('A'), Metabolite('B')])
r1 = Reaction('R1')
r2 = Reaction('R2')
r3 = Reaction('R3')
model.add_reactions([r1, r2, r3])
r1.build_reaction_from_string("<=> A")
r2.build_reaction_from_string("A <=> B")
r3.build_reaction_from_string("<=> B")
flux_variability_analysis(model)

I get the expected result:

  | minimum | maximum -- | -- | -- R1|-1000.0 | 1000.0 R2|-1000.0 | 1000.0 R3|-1000.0 | 1000.0

Then I add an objective and run the FVA again with the fraction_of_optimum parameter set to 0.0:

model.objective = r2
flux_variability_analysis(model, fraction_of_optimum=0.0)

Now I get a different result:

  | minimum | maximum -- | -- | -- R1|0.0 | 1000.0 R2|0.0 | 1000.0 R3|-1000.0 | 0.0

I would have expected the same result as before. This behaviour comes from the additional variables/constraints added for the situation that fraction_of_optimum > 0. As possible fix in variability.py would be to add the additional variables/constraints only if fraction_of_optimum > 0.

Midnighter commented 1 year ago

What is the objective function that you added? It looks like enforcing a semi-positive objective is constraining the directions in the system which is not necessarily incorrect.

gregmedlock commented 1 year ago

This is the expected result--by setting r2 as the objective prior to FVA, r2 is then constrained as positive in each iteration of the FVA min/max problems.

axelvonkamp commented 1 year ago

I think this behaviour is confusing. Why should an objective that is weighted with 0 affect the result? An objective weighted with zero should in my view be the same as the zero objective.

cdiener commented 1 year ago

What do you mean by zero objective? In FVA you enforce that obj >= fraction * max(obj) so if fraction is zero your objective is forced to be positive. If you want to constrain a particular direction of the Reaction you can also set the objective to only that direction...

cdiener commented 1 year ago

Closing due to inactivity. Feel free to reopen.