You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am programatically manipulating some models
I thought I would set model.compartments using a dict,
then, as part of adding metabolites to it I would iterate the list of compartments.
(Basically for these metabolites i want to add one copy to each compartment).
However, when reading model.compartments it only returns compartments that have at least one metabolite in them already.
So you can set it, and it looks like nothing happens
Code sample
Code run:
In [83]: m=cobra.Model()
In [84]: m.compartments= {'a': "first compartment", 'b': "second compartment"}
In [85]: m.compartmentsOut[85]: {}
In [86]: m.add_metabolites(cobra.Metabolite("X", "mystery", compartment='b'))
In [87]: m.compartmentsOut[87]: {'b': 'second compartment'}
"""Get or set the dictionary of current compartment descriptions.
Assigning a dictionary to this property updates the model's
dictionary of compartment descriptions with the new values.
Parameters
----------
value : dict
Dictionary mapping compartments abbreviations to full names.
Examples
--------
>>> from cobra.io import load_model
>>> model = load_model("textbook")
>>> model.compartments = {'c': 'the cytosol'}
>>> model.compartments
{'c': 'the cytosol', 'e': 'extracellular'}
"""
self._compartments.update(value)
Anything else?
I think probably the most sensible thing would be to deprecate the setter for Model.compartments,
and replace it with a function update_compartments or add_compartments.
and maybe replace the read property with a occupied_compartments property?
The text was updated successfully, but these errors were encountered:
Sorry about that. Compartments were supposed to become objects at some point for better compatibility with SBML but this was abandoned half-way, that's why we have the odd Frankenstein implementation. There is a "single source of truth" implementation for most things in cobrapy so that you can't have conflicting information from two places (because that was the source of many bugs historically). You can specify compartments by assigning them to metabolites or you could set them directly on the Model. To have those not conflict the only source for compartments are the Metabolites so they are always only inferred from there. But at some point we also wanted descriptions/names so there is now a dictionary stored in the Model class that keeps those:
So it should probably be something along the lines of compartment_annotations or something. A modifier to return all declared compartments or only occupied ones also makes sense to me.
Is there an existing issue for this?
Problem description
I am programatically manipulating some models
I thought I would set
model.compartments
using a dict,then, as part of adding metabolites to it I would iterate the list of compartments.
(Basically for these metabolites i want to add one copy to each compartment).
However, when reading
model.compartments
it only returns compartments that have at least one metabolite in them already.So you can set it, and it looks like nothing happens
Code sample
Code run:
Environment
idk
but you can see the problem in the code here:
cobrapy/src/cobra/core/model.py
Lines 224 to 261 in 0e99b1d
Anything else?
I think probably the most sensible thing would be to deprecate the setter for
Model.compartments
,and replace it with a function
update_compartments
oradd_compartments
.and maybe replace the read property with a
occupied_compartments
property?The text was updated successfully, but these errors were encountered: