cobrapy
cobrapy copied to clipboard
Acess to coupling constraints in Harvey Model
Problem description
Please explain:
Problem description
Hello I'm trying to access to the coupling constraints of the whole body metabolism with cobrapy but I m getting this error . Is that another way to find coupling constraints with cobra py please?
Code Sample
Code Sample
Create a minimal, complete, verifiable example.
Context
Are you reading from the Matlab model? This field does not seem to be part of mat file specification. Maybe you meant the "C" field? That one is not supported by the COBRAPY parser for now.
Yes I'm reading .mat file and yeah I mean C which is the C :
In fact , I want to To enforce that flux through a microbial reaction only occurs when its biomass reaction has a non-zero value, by including coupling constraints. Is that possible in cobrapy by using another way please ?
Yep you can certainly do that manually. Coupling constraints are constraint of the form v >= c*biomass
which can be rewritten as v - c*biomass >= 0
. You can add this constraint to cobrapy model with
rxn = model.reactions.my_reaction
biomass = model.reactions.biomass_reaction
c = 20000
coupling = model.problem.Constraint(
rxn.flux_expression - c * biomass.flux_expression,
ub=0,
name="coupling_my_reaction"
)
model.add_cons_vars([coupling])
Thank you for your answer but can't undrestand how can I multiply biomass (which an rxn by an integer) ? biomass = model.reactions.get_by_id("") rxn = model.reactions.get_by_id("") c = 20000 coupling = model.problem.Constraint( rxn.flux_expression - c * biomass, ub=0, name="coupling_my_reaction" ) model.add_cons_vars([coupling])
I 'm not sure that I undrestand what I will put here in place of my_reaction and biomass_reaction, the id of each one ? and what do you mean by v(flux variable?) please ? rxn = model.reactions.my_reaction biomass = model.reactions.biomass_reaction Thank you
Sorry, my bad. I fixed the code example. v
is the flux for the reaction you want to couple.
Thank you for your answer : please how to deal with reactions that have an id begins with number like this in cobrapy:
By using, model.reactions.get_by_id("30AS9M10__Streptococcus_parasanguinis")
.
Thank you very much. Can you please how can I check if these constraints are successfully added to the model because I'm trying to do this model.problem.Constraint.coupling and it doesn't work !
It would be model.constraints.coupling
or you can do list(model.constraints)
and check the output.
Please I'm trying to loop over biomass list and rxns_id , to insert in every loop the biomass with the corresponding rxns using this code and I don't have error in the code because it's executing :
but when I want to check if the constraints are inserted in the model I'm getting this error
Do you have please any idea on how to solve this ? or to check that constraints are correctly inserted in the model