-
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
initial attempt at compartments #1193
Draft
akaviaLab
wants to merge
4
commits into
opencobra:devel
Choose a base branch
from
akaviaLab:refactor/compartments2
base: devel
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+201
−5
Draft
Changes from 1 commit
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev
Previous commit
some minor corrections
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -10,7 +10,7 @@ | |||||
|
||||||
class Compartment(Group): | ||||||
""" | ||||||
Manage groups via this implementation of the SBML group specification. | ||||||
Manage compartments via this implementation of the SBML group specification. | ||||||
|
||||||
`Compartment` is a class for holding information regarding a bounded space in | ||||||
which species are located. You can think of it as a location in a model, | ||||||
|
@@ -29,13 +29,14 @@ class Compartment(Group): | |||||
dimensions: float, optional | ||||||
Compartments can have dimensions defined, if they are volume (3 dimensions) or | ||||||
2 (a two-dimensional compartment, a surface, like a membrane). In theory, this | ||||||
can be 1 or 0 dimensions, and even partial dimensions, but that will needlessly | ||||||
complicate the math. The number of dimensions influences the size and units | ||||||
used. | ||||||
can be 1 or 0 dimensions, and even partial dimensions (fractal dimensions for | ||||||
trees and vessels). For almost every application in constraint based modeling | ||||||
this will be an integer. The number of dimensions influences the size and | ||||||
units used. | ||||||
""" | ||||||
def __init__(self, id: str, name: str = "", members: Optional[Iterable] = None, | ||||||
dimensions: Optional[float] = None): | ||||||
"""Initialize the group object. | ||||||
"""Initialize the Compartment object. | ||||||
|
||||||
id : str | ||||||
The identifier to associate with this group | ||||||
|
@@ -57,8 +58,8 @@ def __init__(self, id: str, name: str = "", members: Optional[Iterable] = None, | |||||
super().__init__(id, name, members) | ||||||
for x in members: | ||||||
if not isinstance(x, (Metabolite, Reaction)): | ||||||
raise(TypeError, f"Compartments should have only " | ||||||
f"reactions or metabolites. {x} is a {type(x)}.") | ||||||
raise(TypeError, f"Compartments should only have reactions or " | ||||||
f"metabolites as members. {x} is a {type(x)}.") | ||||||
self._members = DictList() if members is None else DictList(members) | ||||||
self._compartment_type = None | ||||||
self.__delattr__("kind") # Compartments don't have kind | ||||||
|
@@ -163,22 +164,6 @@ def assigned_reactions(self) -> FrozenSet[Reaction]: | |||||
""" | ||||||
return frozenset(self._members.query(lambda x: isinstance(x, Reaction))) | ||||||
|
||||||
@property | ||||||
def reactions(self) -> FrozenSet[Reaction]: | ||||||
"""Return the reactions who belong to this compartment. | ||||||
|
||||||
This is returned as a FrozenSet of reactions for each metabolite in the | ||||||
compartment, if any, and the reactions that were assigned to this compartment | ||||||
directly. | ||||||
|
||||||
Returns | ||||||
------- | ||||||
FrozenSet of cobra.Reactions | ||||||
Reactions that belong to this compartment, both assigned and inferred. | ||||||
""" | ||||||
assigned_reactions = set(self.assigned_reactions) | ||||||
return frozenset(assigned_reactions.union(self.inferred_reactions)) | ||||||
|
||||||
def __contains__(self, member: Union[Metabolite, Reaction]): | ||||||
return self.members.__contains__(member) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If we keep members then more pythonic would be
Suggested change
|
||||||
|
||||||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 know if inheriting from
Group
is really desirable or we should just have a similar class interface.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.
Another point in favor is that
.members
is a bit awkward here. We rather want attributes.reactions
and.metabolites
.