Skip to content
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

Fix 673 #1264

Open
wants to merge 6 commits into
base: devel
Choose a base branch
from
Open

Fix 673 #1264

wants to merge 6 commits into from

Conversation

akaviaLab
Copy link
Contributor

@akaviaLab akaviaLab commented Aug 10, 2022

Copy link
Member

@cdiener cdiener left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks mostly good to me.

The necessity to add so many sync functions just to ensure Species._reactions mirrors what is defined in Model makes it really clear that it would be much easier with a "single source of truth" design where Species.reactions only looks through reactions in the models for whether they contain the species and returns an error if the Species in not part of a Model (where that function does not make much sense since that is a 1:1 mapping anyway for reactions that are not part of a model).

src/cobra/core/model.py Outdated Show resolved Hide resolved
src/cobra/core/model.py Outdated Show resolved Hide resolved
src/cobra/core/model.py Show resolved Hide resolved
@@ -828,21 +862,17 @@ def remove_reactions(
self.reactions.remove(reaction)
reaction._model = None

for met in reaction._metabolites:
for met in reaction.metabolites:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is slower though since it creates a copy of the metabolite list. It's not great to access hidden attributes bu here it creates a large memory overhead not to do that.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should I change all other places where I access reaction.metabolites? I don't think so, but I'm not sure

src/cobra/core/model.py Outdated Show resolved Hide resolved
src/cobra/core/species.py Outdated Show resolved Hide resolved
src/cobra/core/species.py Outdated Show resolved Hide resolved
src/cobra/core/species.py Outdated Show resolved Hide resolved
src/cobra/core/species.py Outdated Show resolved Hide resolved
src/cobra/core/species.py Outdated Show resolved Hide resolved
uri.akavia added 5 commits August 10, 2022 15:39
added species.py functions to set ._reaction field
made metabolites a settable property, and used that to simplify bits of model (including copy and add_reaction)
@akaviaLab
Copy link
Contributor Author

Fixed almost everything. If I remove context from species/remove_reaction, species/add_reaction almost everything works, which is simpler.

However, test_remove_genes_with_context() breaks. Can you help me fix that? I'm not good with contexts. The previous version would not try to update contexts when calling add_reaction or remove_reaction from _associate_gene/__dissociate_gene and that would work.

@akaviaLab
Copy link
Contributor Author

@cdiener - can you help me fix test_remove_genes_with_context() please

@cdiener cdiener added the stale The issue or pull request lacks activity. label Apr 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stale The issue or pull request lacks activity.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Adding reactions from another model does not reset the reactions their metabolites refer to
2 participants