diff --git a/release-notes/next-release.md b/release-notes/next-release.md index 287813643..e761c5b2f 100644 --- a/release-notes/next-release.md +++ b/release-notes/next-release.md @@ -9,6 +9,7 @@ of SBO:0000633 (see https://sourceforge.net/p/sbo/term-request/113/) * Correct reading and writing of subsystem in mat. * General cleanup of code in mat.py +* Fixed issue 673 (problem when copying reaction from a different model) ## Other diff --git a/src/cobra/core/model.py b/src/cobra/core/model.py index a3fe5b588..fe71e5047 100644 --- a/src/cobra/core/model.py +++ b/src/cobra/core/model.py @@ -863,13 +863,13 @@ def remove_reactions( reaction._model = None for met in reaction.metabolites: - if reaction in met.reactions: + if reaction in met._reaction: met.reaction_remove(reaction, context) if remove_orphans and len(met.reactions) == 0: self.remove_metabolites(met) for gene in reaction.genes: - if reaction in gene.reactions: + if reaction in gene._reaction: gene.reaction_remove(reaction, context) if remove_orphans and len(gene.reactions) == 0: diff --git a/src/cobra/core/species.py b/src/cobra/core/species.py index 3ea9cef63..658b5d55a 100644 --- a/src/cobra/core/species.py +++ b/src/cobra/core/species.py @@ -58,13 +58,15 @@ def reactions(self) -> FrozenSet: A frozenset that includes the reactions of the species. """ if self.model and self.__class__.__name__ == "Gene": - return self.model.reactions.query(lambda x: self in x, "genes") + return frozenset(self.model.reactions.query(lambda x: self in x, "genes")) elif self.model and self.__class__.__name__ == "Metabolite": - return self.model.reactions.query(lambda x: self in x, "metabolites") + return frozenset( + self.model.reactions.query(lambda x: self in x, "metabolites") + ) return frozenset(self._reaction) def reaction_add( - self, reaction: Reaction, context: Optional[HistoryManager] = None + self, reaction: "Reaction", context: Optional[HistoryManager] = None ) -> None: """Add reaction to .reaction field, with context. @@ -81,7 +83,7 @@ def reaction_add( context(partial(self._reaction.remove, reaction)) def reaction_remove( - self, reaction: Reaction, context: Optional[HistoryManager] = None + self, reaction: "Reaction", context: Optional[HistoryManager] = None ) -> None: """Remove reaction from .reaction field, with context.