Open hongzhonglu opened 1 year ago
Dear Hongzhong, Thank you for your question.
Yes, in the current implmentation of ETFL you cannot change kcats after creating the model. To update a kcat, you can recreate a new model with the updated kcat. We are currently implementing change of kcats after creating a model, and it will be soon available in the new release of the code.
Best wishes, Omid
Thank you very much, Omid. Today I further think about it and found reusing function - apply_enzyme_catalytic_constraint may help to update the constraints on the condition that the old one is removed. I am looking forward to your new release.
Best wishes, Hongzhong
Good day Hongzhong,
Pierre here, the developer of ETFL. As Omid mentioned, so far the most secure way to change your kcat
is to rebuild the model. That is because kcat
values are used to scale the constraint so that the solver stays happy.
That being said, if you want to try to hot-swap the kcat
, the workaround you suggested is a good start. What is happening though, is that the solver interface sees you are trying to add a constraint with a name that already exists in its constraint list, so it silently fails.
Try to first remove the forward and backward catalytic constraints attached to this enzyme, and then reapply the catalytic constraint:
# Suggested code for 1 enzyme, not tested
rid = 'r_0962'
enz_id = 'YAL038W_enzyme'
r = yeast.reactions.get_by_id(rid)
e = yeast.enzymes.get_by_id('YAL038W_enzyme')
def check_reaction_coupling(the_rxn, the_enz)
# Getting the constraints
fwd_cons = yeast.forward_catalytic_constraints.get_by_id(the_rxn.id)
bwd_cons = yeast.backward_catalytic_constraints.get_by_id(the_rxn.id)
# Printing them to check current kcat
print('Scaled forward kcat :', fwd_cons.constraint.get_linear_coefficients([the_enz.variable]))
print('Scaled backward kcat :', bwd_cons.constraint.get_linear_coefficients([the_enz.variable]))
print('Scaled forward expression :', fwd_cons.expr)
print('Scaled backward expression :', bwd_cons.expr)
check_reaction_coupling(r,e)
# Remove the constraints
yeast.remove_constraint( yeast.forward_catalytic_constraints.get_by_id(the_rxn.id))
yeast.remove_constraint(yeast.backward_catalytic_constraints.get_by_id(the_rxn.id))
# Edit attributes
e.kcat = 123.4 # You can also edit individually kcat_fwd and kcat_bwd
yeast.apply_enzyme_catalytic_constraint(r)
yeast._push_queue()
yeast.regenerate_constraints()
yeast.regenerate_variables()
check_reaction_coupling(r,e)
# The solution will not necessarily change by changing the `kcat` so do not use this as a check
# And conversely a changing solution is not a guarantee that `kcat` changed
sol2 = yeast.optimize()
Hope this helps! Cheers, Pierre
Thanks a lot, Pierre. @psalvy It is very helpful.
Hello @oftadehomid, I am still trying to use ETFL model of yeast. I find it is difficult to update the kcat for specific enzyme using the following code:
yeast is the ETFL model
yeast.reactions.r_1714.lower_bound = -2 yeast.reactions.r_1714.upper_bound = 0 yeast.objective = growth_reaction_id yeast.objective.direction = 'max' sol = yeast.optimize()
yeast.enzymes.get_by_id('YAL038W_enzyme').kcat_fwd = 100 yeast.enzymes.get_by_id('YAL038W_enzyme').kcat_bwd = 100
yeast.enzymes.get_by_id('YOR347C_enzyme').kcat_fwd = 100 yeast.enzymes.get_by_id('YOR347C_enzyme').kcat_bwd = 100
update variable and constraints attributes?
rid = 'r_0962' r = yeast.reactions.get_by_id(rid) yeast.apply_enzyme_catalytic_constraint(r) yeast._push_queue() yeast.regenerate_constraints() yeast.regenerate_variables() sol2 = yeast.optimize()
Here, though I update the kcat for YOR347C_enzyme, however the related constraints information from the model is not updated. Could you give me some suggestions about this? Thanks a lot!
Best wishes, Hongzhong