cobrapy icon indicating copy to clipboard operation
cobrapy copied to clipboard

[Feature request] Provide compartments as objects like all other model components

Open ChristianLieven opened this issue 7 years ago • 6 comments

Problem description

To future-proof cobrapy it migh make sense to offer compartments not just as a dictionary but as objects like all the other model components. While adding little overhead in terms of performance (the larges model I've seen had 14 compartments), I think this would have a lot of benefits such as allowing users to store information on compartment size (pH, molecular size potentially relevant for ME-model-esque calculations) and compartment-specific annotation (type of compartment, SBO terms, literature reference and whatnot).

Code Sample in Jupyter Notebook

IN[1]: model.compartment.c
OUT[1]: 
"""
Compartment identifier | c
-- | --
Name | Cytosol
Memory address | 0x011c852e90
pH | 6.7
Contains 4 metabolites| pyr_c, g6p_c, g3p_c, f6p_c
"""

IN[2]: model.compartment.c.annotation
OUT[2]: 
{'SBO': 'SBO:0000247',
'ImaginaryCompDB':'SpecificCompIdentifier'}

ChristianLieven avatar Jan 19 '18 08:01 ChristianLieven

I fully support the idea but don't really see us implementing it until a cobrapy 1.0 or so.

Midnighter avatar Jan 22 '18 14:01 Midnighter

The other question would be the degree of compatibility with the various SBML specs... I.e., I don't think they have an annotation field.

Could be nice to have compartment.reactions / compartment.metabolites methods as well.

pstjohn avatar Jan 22 '18 16:01 pstjohn

Just for clarification: Compartments are like all other SMBL objects sub classes of SBase. This means they have the same

  • sbo term
  • annotation
  • id
  • metaid fields like all other SBML objects, e.g., Species and Reactions.

So completely compatible with Species and Reactions, you can even use the same parser code to read the information for annotations from all the different objects.

Yes, please add compartments as first class cobra citizens. These are very important.

matthiaskoenig avatar Jan 23 '18 09:01 matthiaskoenig

I have no objections. The proposed API looks good to me. So basically model.compartment would be container of lightweight objects (might even be NamedTuples). That would be pretty simple to add. Just have to adjust the JSON and YAML schema as well.

cdiener avatar Jan 23 '18 18:01 cdiener

Can somebody implement this? This should not be a too big change, but just changing how the compartments are stored (dict of compartment objects instead of dict of compartment strings). Providing all the annotations on the compartments is then just one line of code in the sbml parser. I just need to be able to set

c.annotation

on a compartment object.

matthiaskoenig avatar Mar 23 '18 08:03 matthiaskoenig

I can have a look at this issue.

MaxGreil avatar Mar 28 '18 16:03 MaxGreil