diff --git a/src/cobra/core/gene.py b/src/cobra/core/gene.py index 56733ec46..5c0d90963 100644 --- a/src/cobra/core/gene.py +++ b/src/cobra/core/gene.py @@ -221,6 +221,19 @@ def __init__(self, id: str = None, name: str = "", functional: bool = True) -> N super().__init__(id=id, name=name) self._functional = functional + @property + def id(self) -> str: + return super().id + + @id.setter + def id(self, new_id) -> None: + warnings.warn( + "Direct modification of gene.id is discouraged and can lead to unexpected gene duplications. " + "Use cobra.manipulation.modify.rename_genes to safely rename genes.", + UserWarning + ) + super(Gene, self.__class__).id.fset(self, new_id) + @property def functional(self) -> bool: """Flag indicating if the gene is functional.