opencobra / cobrapy

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

pFBA and FBA do not return similar objective function values #518

Closed taylo5jm closed 7 years ago

taylo5jm commented 7 years ago

Hi all,

It seems that pFBA (cobra.flux_analysis.pfba(model)) does not return a similar objective function value to the one calculated with FBA (model.optimize()).

I am running cobrapy version 0.6.1 with Python version 3.5.2 inside of IPython version 5.3.0. My operating system is Fedora 25.

I briefly mentioned this issue in a different question on the Google group, but I figured it would be better to create a separate issue for it here. In the case I have shown below, I attempt to maximize the H2O transport reaction in RECON1 using the glpk solver. With FBA, I observe an objective function value of 999999. With pFBA, I observe an objective value of 2999997.

# coding: utf-8   
import cobra
model = cobra.io.load_json_model('data/models/RECON1.json')
model.objective = {}
model.objective = 'H2Ot'
model.solver = 'glpk'
model.objective.expression # check to see if objective is what I think it is
fba_soln = model.optimize()
pfba_soln = cobra.flux_analysis.pfba(model)
fba_soln.objective_value
pfba_soln.objective_value

Thanks, Justin

cdiener commented 7 years ago

Parsimonious FBA changes the objective to the minimum total flux objective (minimize sum_i abs(v_i)) and that is the one reported by the solution. The biomass reaction should have the same flux in both solutions, e.g. fba_soln["H2Ot"] ~ pfba_soln["H2Ot"]. I agree that this is not very obvious and it might make sense for pFBA to rather assign the previous objective value to solution.objective_value...

taylo5jm commented 7 years ago

Ah, thank you. I see that is indeed the case. It makes sense to me now why pFBA assigns the objective function value that it does. If the user wants to recover the previous objective function value, running model.optimize() may be the easiest route. Alternatively, the previous objective function value could just be calculated manually from the pFBA solution for more complex objective functions.

hredestig commented 7 years ago

Happy to read you find the current behaviour acceptable, saving solutions and fetching fluxes or indeed the actual objective value appears to the most explicit way to go in my opinion. Please re-open the issue if you think there is more to be done / discussed here.

BhushanDhamale commented 7 years ago

@cdiener How can I compute the total flux objective using FBA?

cdiener commented 7 years ago

@BhushanDhamale as mentioned in gitter with sol.fluxes.abs().sum().