-
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
refactor: turn compartments into objects #725
base: devel
Are you sure you want to change the base?
Conversation
Codecov Report
@@ Coverage Diff @@
## devel #725 +/- ##
=========================================
+ Coverage 82.98% 83.48% +0.5%
=========================================
Files 40 42 +2
Lines 3890 4008 +118
Branches 891 920 +29
=========================================
+ Hits 3228 3346 +118
+ Misses 463 462 -1
- Partials 199 200 +1
Continue to review full report at Codecov.
|
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.
Looks good to me.
In the example file "GENE_ASSOCIATION" changed to "GENE ASSOCIATION". Not sure where this is coming from, or some unwanted side effect.
Probably the example notebooks must be updated also.
Sorry, didn't have time to test the branch but for me the most important parts would be the following two:
If those two are met I think the PR is ready to go 😄 |
I'll try to summarize what is still required for this to be 'done':
|
cobra/util/util.py
Outdated
len(string) < 1 or string is ' ' |
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.
Actually, any space anywhere in an identifier is nasty for us (and optlang will complain for sure). Which we would test with: any(c.isspace() for c in string)
. string
is also the name of a Python stdlib package so maybe change it to identifier
.
This should be good to go now. Please let me know if anything is unclear. I'm looking forward to comments and feedback. |
Wondering if we could address #747 with that at once (see last comments there). If we could add a way to mark a compartment as external I could integrate that into the media module. |
33f8efd
to
4229da9
Compare
This represents the state of the work done by @MaxGreil. refactor: add methods feat: mimic previous behaviour when comparing compartments with strings fix: use compartment IDs instead of objects when converting model to dict fix: ensure backwards compatibility when importing JSON following the previous schema fix: add importlib-resources to setup chore: regenerate pickle models and fix SBML and mat importer fix: update compartment handling on mat and sbml input fix: change version type in json schema from int to str fix: satisfy flake8 fix: better checking for sane IDs chore: update pickels again fix: update documentation notebooks building_model and getting_started test: add tests for compartments and metabolites fix: flake8 is a cruel mistress style: add blank line in test_compartment
4229da9
to
37d33c8
Compare
What's a use case for the |
Hi all, |
We have a use case for it; just posted here: #760 (comment) I'm happy to give more details! |
Hi all, I have a need for the compartment objects and was wondering when they would be integrated into the stable/master branch of COBRApy. Additionally, I noticed that current compartment class does not have a |
Same here. Also have a need for compartment objects. Would be great to have these in cobrapy
|
Hi all, Best Matthias |
I also want this feature a lot. The complications that have been blocking this are:
|
Hi all, Is there a timeline associated with the completion and integration of the compartment class that can be shared? I could use really use compartment objects for constraint-based/dynamic modeling workflows, and would be happy to help out in any way I can. Best, Zack |
Hey @z-haiman, I can't give you an exact timeline since we don't have any full time developers. We're getting some important things done recently, though, so this is becoming feasible to do and I've put this on our roadmap. |
Would you like me to try and tackle updating this? |
The main thing I got stuck on was to come up with a good design for our "undo" functionality, i.e., when you modify a model in a context, those actions are undone again upon leaving the context. This is more complicated with compartments when you add a compartment from one model to another one. Does that mean you also add all metabolites & reactions in that compartment from the other model? I'm probably overthinking this a bit but didn't have the chance to discuss different design choices so far. If you want to take this on, I suggest we have an online meeting and come up with a good design. |
Hi @Midnighter |
|
Maybe this should be discussed at a dev meeting? @cdiener wanted to schedule one soon.
Should it? I mean, it could be super convenient to say, copy mitochondrion from one model to another. Of course, it's not hard to loop over compartment contents and add those. Maybe
Not directly, for MEMOTE we looked at the metabolites of a reaction to figure it out. How are transport reactions handled in SBML using this? |
For the transport reactions you just add a compartment such as I agree, copying of the complete compartment is nice to have, but should not be the default behavior. Dev meeting would be great. Would be happy to participate. |
Sorry forgot. There are also many membrane bound reactions which catalyze on one side of the compartment. I.e. the enymes are associated with the membrane, but all the metabolites involved are on one side of the membrane. Inferring compartments from metabolites gives incorrect compartments here. |
I don't see yet how this gives the wrong information. If an enzyme is membrane bound but carries out the reaction only in one compartment, that is where the reaction happens, right? |
Agree with @Midnighter here. Reaction is a bit of an abstract concept but if you go by physical chemistry it is a collision that passes an energy threshold so it requires physical contact. So the actual reaction would still take place where the substrate is located. For channels the initial adsorption/entry takes place on one side of the membrane and secretion/export on the other side. The substrate and product would have different compartments and the reaction would have two compartments due to the multi-step nature. Which is how it is handled in cobrapy right now. If you want to specifically model what happens with the molecule inside the channel you have to add a species in the membrane compartment as well. I totally get that enzymes can have a single location in that case but reactions are not exactly the same thing. |
Okay. I'd be happy to participate in some kind of debate in a developer meeting if you'll let me know when it is. I've also been thinking a bit about the computational format of compartments, and my approach, based on my biological knowledge and intuition is
That should comply with what @cdiener and @Midnighter pointed out. |
@cdiener and @Midnighter: For scaling of reaction bounds based on RNA or protein data the incorrect compartment will give the incorrect scaling. I.e. proteins (reactions) in the membrane should be scaled based on Area, not volume. For this to work the reactions should be assigned the correct location, i.e. it happens at the membrane.
This is a big issue when using Data to set bounds for reactions, or also to just account for dilution with cell growth (e.g. in approaches such as RBA). Because cobrapy is meant as a core library on which other packages can build more complex analysis the correct handling of this cases would be important. If cobrapy is just a simple tool for FBA, never mind. Similar issues exist for visualization algorithms using the information in SBML. The important information about the localization of the reaction at the membrane is lost and the network is visualized incorrectly. |
@matthiaskoenig if the reaction happens in the membrane I think everybody agrees. But the argument from the paper seems incomplete as only one component is bound to the membrane but the other may still diffuse freely in the cytosol. If you scale the cell volume up this would still enter as a volumetric measure for that second freely diffusible component. And regarding the scope of cobrapy: as the name implies we provide infrastructure for constraint-based modeling which is admittedly not very well defined but I would say that kinetic models and (general) visualization would generally not fall within that scope. However, I do agree that information should not be dropped and we could save that either in the annotations or a separate attribute. Though it would be nice if SBML could support multiple compartments for an enzyme since membrane-bound components or channels do have parts embedded in several compartments. I am also not super eager of allowing that reactions may involve metabolites that have no overlap with the enzyme compartment now. Having a reaction assigned to the nucleus using metabolites from the extracellular space does not look right to me. |
@cdiener @matthiaskoenig
|
@akaviaLab you are wrong. Please just look at the SBML specification. You definitely did not look in the document. Reactions have compartments. So the main question is what to do if the |
@matthiaskoenig we can't remove the reaction compartments logic in cobrapy right now due to backwards compatibility. Also the interpretation is different and more correct in cobrapy IMO as it actually ensures that reaction compartments are compatible with metabolite compartments (but we can ask the community to decide). But we can definitely store the SBML-assigned compartment and have that assigned as a different attribute like But either way it's unrelated to the PR and can be addressed in a separate discussion. |
@matthiaskoenig @cdiener If both reactions and metabolites have compartments, I don't think it would make sense for genes to have compartments. Maybe in the future, if we want to do ME models (or similar stuff), there can be a protein that derives from gene and has compartments. Section 7.12 (p 137 of the standard). @cdiener and @Midnighter, do you agree genes shouldn't have compartments now? |
FBA and the LP do not depend on reaction compartments. What part of the code base depends on reaction compartments? What would break if we support custom assigned compartments? I don't get this part of the argument.
Basically if all metabolites are in a compartment the reaction is in the compartment. Okay? What does this help me? How is this better then fixing the compartment assignments in the few reactions where the heuristics is wrong. Yes, I agree this opens the issue for incorrect compartment assignments on reactions (but these can easily be detected by comparing actual vs. heuristics assignments) |
Moved the discussion about SBML reaction compartments here. @akaviaLab Right now only metabolites have compartments assigned and reaction compartments are generated on the fly as the set of all compartments of contained metabolites. So compartments only really need to keep track of metabolites for an initial PR. I think the original idea was just to have a simple compartment type which is just additional annotations for the name and only metabolites track which compartment they belong to. I do like the idea of a group-like object as well though but we probably want to track compartment assignment only in one place so that would mean dropping the compartment from metabolites and not allowing metabolites to be in a compartment without belonging to a model (would not be backward compatible). The advantage is that this would enable hierarchical compartments which might be useful. But yeah, either solutions sounds good for me... |
This is based on @MaxGreil's work. I simply rebased his branch onto the latest devel and added two methods. I did so because we need compartment objects soon in order to complete the work on the SBML I/O.
I'm not completely done with this but please add your suggestions here @cdiener and @matthiaskoenig.