-
Notifications
You must be signed in to change notification settings - Fork 218
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
#652[Feature request] Provide compartments as objects #696
Conversation
Codecov Report
@@ Coverage Diff @@
## devel #696 +/- ##
==========================================
+ Coverage 81.72% 81.76% +0.04%
==========================================
Files 36 37 +1
Lines 3644 3691 +47
Branches 832 843 +11
==========================================
+ Hits 2978 3018 +40
- Misses 472 477 +5
- Partials 194 196 +2
Continue to review full report at Codecov.
|
All TravisCI tests are now working. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One concern about the files changed for the tests. Did you intentionally and (more or less) manually change the mini_cobra.xml and mini_fbc*.xml? And why did the textbook* solutions change? If this all happened due to the update script then I would ask you please to checkout the previous versions of the solutions. Simply to ensure that there are no changes creeping in over time.
I want to look at the compartment class a little more but it looks like great work!
@Midnighter I only used the update_pickles.py script. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
model.comaprtments
should assemble a list of compartments dynamically from the metabolites in the model like before. For instance the following is now working incorrectly:
In [2]: from cobra.test import create_test_model
In [3]: mod = create_test_model("textbook")
In [5]: mod.compartments
Out[5]: [<Compartment c at 0x7f4d164bf048>, <Compartment e at 0x7f4d164bf0b8>]
In [6]: mod.metabolites.ac_e.compartment = "m"
In [7]: mod.metabolites.ac_e.compartment
Out[7]: 'm'
In [8]: mod.compartments
Out[8]: [<Compartment c at 0x7f4d164bf048>, <Compartment e at 0x7f4d164bf0b8>]
This should include a compartment "m" with an empty name.
Also we will need to maintain backwards compatibility so compartments should be optional in JSON and YAML.
cobra/core/model.py
Outdated
@@ -161,32 +166,6 @@ def get_metabolite_compartments(self): | |||
return {met.compartment for met in self.metabolites | |||
if met.compartment is not None} | |||
|
|||
@property | |||
def compartments(self): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this should not be removed see general comment.
compartment_list = [x for x in compartment_list | ||
if x.id not in self.compartments] | ||
|
||
bad_ids = [m for m in compartment_list |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
spaces should probably be disallowed as well since we will get problems with optlang otherwise.
cobra/io/json.py
Outdated
}, | ||
"notes": {"type": "object"}, | ||
"annotation": {"type": "object"}, | ||
}, | ||
"required": ["id", "reactions", "metabolites", "genes"], | ||
"required": ["id", "reactions", "metabolites", "genes", "compartments"], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need to maintain backwards compatibility so compartments should be optional for all input formats.
"c": "cytosol", | ||
"e": "extracellular" | ||
}, | ||
"compartments": [ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should also include a version ("mini_legacy.json") without those to test backwards compatibility.
cobra/test/data/mini.yml
Outdated
@@ -1143,6 +1143,10 @@ | |||
- name: G_s0001 | |||
- id: mini_textbook | |||
- compartments: | |||
e: extracellular | |||
c: cytosol | |||
- !!omap |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That looks a bit weird. What was wrong with the old notation?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The ordered map is introduced by the YAML IO automatically but I agree, let's keep the old format of id: name
.
cobra/test/test_io.py
Outdated
try: | ||
reference_model = load(infile) | ||
except UnicodeDecodeError: | ||
reference_model = load(infile, encoding='latin1') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why that? I think we should not include any files with latin-1. Everything should be unicode.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree, please store files in utf-8 format.
@@ -182,7 +185,7 @@ def compare_models(cls, name, model1, model2): | |||
|
|||
@classmethod | |||
def extra_comparisons(cls, name, model1, model2): | |||
assert model1.compartments == model2.compartments | |||
assert len(model1.compartments) == len(model2.compartments) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should also check if they contain the same IDs.
cobra/util/version_info.py
Outdated
@@ -12,6 +12,8 @@ | |||
|
|||
import pkg_resources | |||
|
|||
import pkg_resources |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for that trick!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please revert the changes to this file since the issue was addressed in #697.
cobra/core/compartment.py
Outdated
""" | ||
def __init__(self, id=None, name=""): | ||
Object.__init__(self, id, name) | ||
self._model = None |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think it needs a back-ref to the model. That just creates problems.
Thanks for all the work! Sorry that there are so many comments but for new features we have to ensure that nothing breaks. Cheers! |
|
Appveyor seems to work again. |
Dear @MaxGreil, I'm very sorry to be doing this but we need to move things along right now. Thus I took your branch, rebased it on the current devel and will take over development on that new branch. Thank you very much for contribution and I hope this is not offending you. Please see #725 for the new PR. |
Hi @Midnighter, I didn't have the time to continue working on this issue. |
That's completely understandable. Would you like to finish it up, though? |
I would still like to. What is left to be done? |
#652
Implemented model.compartments as objects, therefore added new class compartment in cobra.core.
EDIT 20.04.:
EDIT 21.04.: