In some datasets, I sometimes observe fixed flux ratios which I would like to incorporate into my simulations. How could I do this in CBMPy?
For example, I have the model from here and would now like to constrain the ratio of succinate efflux and pyruvate efflux to 2.0. I know how to set constraints on individual reactions:
import cbmpy
# downloaded from http://bigg.ucsd.edu/models/e_coli_core
ecoli = cbmpy.CBRead.readSBML3FBC('e_coli_core.xml')
ecoli.setReactionBounds('R_EX_pyr_e', 1.0, 1000.0)
ecoli.setReactionBounds('R_EX_succ_e', 2.0, 1000.0)
# solve the model
cbmpy.doFBA(ecoli)
# get all reaction values
solution = ecoli.getReactionValues()
print(solution['R_EX_pyr_e'])
print(solution['R_EX_succ_e'])
For this case the ratio is correct, but how can I add it as a constraint that it will be fulfilled for all conditions?
That is indeed a common approach in Flux Balance Analysis (FBA) and you can use the function
addUserConstraint
to accomplish this.The entire code sample could look like this (explanation below):
This will print
As you can see the ratio is
2.0
as desired.Bit more explanation:
The constraint is
which can be rewritten to
and finally
That's exactly what we pass to
fluxes
inaddUserConstraint
:You can check the user defined constraints by printing:
As this is a dictionary you can delete the constraint by simply doing:
but I highly recommend to create a clone everytime you introduce major changes to a model.