cobrapy icon indicating copy to clipboard operation
cobrapy copied to clipboard

Acess to coupling constraints in Harvey Model

Open Ilhem36 opened this issue 2 years ago • 10 comments

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.

image

Context

Ilhem36 avatar Jul 14 '22 10:07 Ilhem36

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.

cdiener avatar Jul 14 '22 15:07 cdiener

Yes I'm reading .mat file and yeah I mean C which is the C : image 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 ?

Ilhem36 avatar Jul 14 '22 15:07 Ilhem36

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])

cdiener avatar Jul 17 '22 22:07 cdiener

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

Ilhem36 avatar Jul 18 '22 15:07 Ilhem36

Sorry, my bad. I fixed the code example. v is the flux for the reaction you want to couple.

cdiener avatar Jul 18 '22 21:07 cdiener

Thank you for your answer : please how to deal with reactions that have an id begins with number like this in cobrapy: image

Ilhem36 avatar Jul 18 '22 21:07 Ilhem36

By using, model.reactions.get_by_id("30AS9M10__Streptococcus_parasanguinis").

cdiener avatar Jul 19 '22 16:07 cdiener

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 !

Ilhem36 avatar Jul 22 '22 08:07 Ilhem36

It would be model.constraints.coupling or you can do list(model.constraints) and check the output.

cdiener avatar Jul 22 '22 17:07 cdiener

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 : image

but when I want to check if the constraints are inserted in the model I'm getting this error

image Do you have please any idea on how to solve this ? or to check that constraints are correctly inserted in the model

Ilhem36 avatar Jul 22 '22 23:07 Ilhem36