Skip to content

Commit

Permalink
Remove deprecated manipulation2 (#1208)
Browse files Browse the repository at this point in the history
* removed removed get_compiled_gene_reaction_rules

* added knock_out_model_genes
removed find_gene_knockout_reactions from delete.py
removed _find_gene_knockout_reactions_fast, _gene_knockout_computation, _get_removed from test_delete.py

* Removed references to delete_model_genes() and undelete_model_genes

* removed trimmed from model.py since it is no longer used

* added deprecation warning

* Removed references to delete_model_genes() and undelete_model_genes

* fix according to comments

* some linting and tidying

* fix knock_out_model_genes()

* Apply suggestions from code review

Co-authored-by: Moritz E. Beber <midnighter@posteo.net>

* fix typing and use of set

* list comprehension

* fixed lint problems

* simplified knock_out_model_genes()
Added tests to make sure that int and cobra.Gene will work as well

Co-authored-by: uri.akavia <uri.akavia@mcgill.ca>
Co-authored-by: Moritz E. Beber <midnighter@posteo.net>
  • Loading branch information
3 people authored Apr 29, 2022
1 parent f5a1b96 commit b628572
Show file tree
Hide file tree
Showing 8 changed files with 162 additions and 351 deletions.
4 changes: 2 additions & 2 deletions documentation_builder/faq.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@
"source": [
"That depends on what precisely you mean by delete a gene.\n",
"\n",
"If you want to simulate the model with a gene knockout, use the `cobra.manipulation.delete_model_genes` function. The effects of this function are reversed by `cobra.manipulation.undelete_model_genes`."
"If you want to simulate the model with a gene knockout, use the `cobra.manipulation.knock_out_model_genes` function. The effects of this function are reversed when exiting a context."
]
},
{
Expand All @@ -157,7 +157,7 @@
"model = cobra.test.create_test_model()\n",
"PGI = model.reactions.get_by_id(\"PGI\")\n",
"print(\"bounds before knockout:\", (PGI.lower_bound, PGI.upper_bound))\n",
"cobra.manipulation.delete_model_genes(model, [\"STM4221\"])\n",
"cobra.manipulation.knock_out_model_genes(model, [\"STM4221\"])\n",
"print(\"bounds after knockouts\", (PGI.lower_bound, PGI.upper_bound))"
]
},
Expand Down
120 changes: 6 additions & 114 deletions documentation_builder/getting_started.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,7 @@
" <td>e_coli_core</td>\n",
" </tr><tr>\n",
" <td><strong>Memory address</strong></td>\n",
<<<<<<< HEAD
" <td>0x01158878d0</td>\n",
=======
" <td>0x010cb2d358</td>\n",
>>>>>>> origin/devel
" </tr><tr>\n",
" <td><strong>Number of metabolites</strong></td>\n",
" <td>72</td>\n",
Expand All @@ -109,11 +105,7 @@
" </table>"
],
"text/plain": [
<<<<<<< HEAD
"<Model e_coli_core at 0x1158878d0>"
=======
"<Model e_coli_core at 0x10cb2d358>"
>>>>>>> origin/devel
]
},
"execution_count": 3,
Expand Down Expand Up @@ -148,11 +140,7 @@
" <td><strong>Name</strong></td><td>L-Glutamate exchange</td>\n",
" </tr><tr>\n",
" <td><strong>Memory address</strong></td>\n",
<<<<<<< HEAD
" <td>0x011615e2e8</td>\n",
=======
" <td>0x0117a94898</td>\n",
>>>>>>> origin/devel
" </tr><tr>\n",
" <td><strong>Stoichiometry</strong></td>\n",
" <td>\n",
Expand All @@ -170,11 +158,7 @@
" "
],
"text/plain": [
<<<<<<< HEAD
"<Reaction EX_glu__L_e at 0x11615e2e8>"
=======
"<Reaction EX_glu__L_e at 0x117a94898>"
>>>>>>> origin/devel
]
},
"execution_count": 4,
Expand Down Expand Up @@ -209,31 +193,19 @@
" <td><strong>Name</strong></td><td>ATP</td>\n",
" </tr><tr>\n",
" <td><strong>Memory address</strong></td>\n",
<<<<<<< HEAD
" <td>0x01160d4630</td>\n",
=======
" <td>0x01179dae48</td>\n",
>>>>>>> origin/devel
" </tr><tr>\n",
" <td><strong>Formula</strong></td><td>C10H12N5O13P3</td>\n",
" </tr><tr>\n",
" <td><strong>Compartment</strong></td><td>c</td>\n",
" </tr><tr>\n",
" <td><strong>In 13 reaction(s)</strong></td><td>\n",
<<<<<<< HEAD
" PPS, ADK1, ATPS4r, GLNS, SUCOAS, GLNabc, PGK, ATPM, PPCK, ACKr, PFK, Biomass_Ecoli_core, PYK</td>\n",
=======
" PPCK, ATPS4r, ADK1, ATPM, GLNS, GLNabc, ACKr, PGK, PPS, PYK, SUCOAS, Biomass_Ecoli_core, PFK</td>\n",
>>>>>>> origin/devel
" </tr>\n",
" </table>"
],
"text/plain": [
<<<<<<< HEAD
"<Metabolite atp_c at 0x1160d4630>"
=======
"<Metabolite atp_c at 0x1179dae48>"
>>>>>>> origin/devel
]
},
"execution_count": 5,
Expand Down Expand Up @@ -302,11 +274,7 @@
" <td><strong>Name</strong></td><td>glucose-6-phosphate isomerase</td>\n",
" </tr><tr>\n",
" <td><strong>Memory address</strong></td>\n",
<<<<<<< HEAD
" <td>0x0116188e48</td>\n",
=======
" <td>0x0117afacc0</td>\n",
>>>>>>> origin/devel
" </tr><tr>\n",
" <td><strong>Stoichiometry</strong></td>\n",
" <td>\n",
Expand All @@ -324,11 +292,7 @@
" "
],
"text/plain": [
<<<<<<< HEAD
"<Reaction PGI at 0x116188e48>"
=======
"<Reaction PGI at 0x117afacc0>"
>>>>>>> origin/devel
]
},
"execution_count": 7,
Expand Down Expand Up @@ -658,31 +622,19 @@
" <td><strong>Name</strong></td><td>ATP</td>\n",
" </tr><tr>\n",
" <td><strong>Memory address</strong></td>\n",
<<<<<<< HEAD
" <td>0x01160d4630</td>\n",
=======
" <td>0x01179dae48</td>\n",
>>>>>>> origin/devel
" </tr><tr>\n",
" <td><strong>Formula</strong></td><td>C10H12N5O13P3</td>\n",
" </tr><tr>\n",
" <td><strong>Compartment</strong></td><td>c</td>\n",
" </tr><tr>\n",
" <td><strong>In 13 reaction(s)</strong></td><td>\n",
<<<<<<< HEAD
" PPS, ADK1, ATPS4r, GLNS, SUCOAS, GLNabc, PGK, ATPM, PPCK, ACKr, PFK, Biomass_Ecoli_core, PYK</td>\n",
=======
" PPCK, ATPS4r, ADK1, ATPM, GLNS, GLNabc, ACKr, PGK, PPS, PYK, SUCOAS, Biomass_Ecoli_core, PFK</td>\n",
>>>>>>> origin/devel
" </tr>\n",
" </table>"
],
"text/plain": [
<<<<<<< HEAD
"<Metabolite atp_c at 0x1160d4630>"
=======
"<Metabolite atp_c at 0x1179dae48>"
>>>>>>> origin/devel
]
},
"execution_count": 19,
Expand Down Expand Up @@ -814,17 +766,10 @@
{
"data": {
"text/plain": [
<<<<<<< HEAD
"frozenset({<Reaction Biomass_Ecoli_core at 0x1161337b8>,\n",
" <Reaction G6PDH2r at 0x1160a3a20>,\n",
" <Reaction GLCpts at 0x1160a3da0>,\n",
" <Reaction PGI at 0x116188e48>})"
=======
"frozenset({<Reaction Biomass_Ecoli_core at 0x117a71358>,\n",
" <Reaction G6PDH2r at 0x117a575f8>,\n",
" <Reaction GLCpts at 0x117a9d0f0>,\n",
" <Reaction PGI at 0x117afacc0>})"
>>>>>>> origin/devel
]
},
"execution_count": 24,
Expand Down Expand Up @@ -888,11 +833,7 @@
{
"data": {
"text/plain": [
<<<<<<< HEAD
"frozenset({<Gene b4025 at 0x11610a2b0>})"
=======
"frozenset({<Gene b4025 at 0x1179cec18>})"
>>>>>>> origin/devel
]
},
"execution_count": 26,
Expand Down Expand Up @@ -920,11 +861,7 @@
" <td><strong>Name</strong></td><td>pgi</td>\n",
" </tr><tr>\n",
" <td><strong>Memory address</strong></td>\n",
<<<<<<< HEAD
" <td>0x011610a2b0</td>\n",
=======
" <td>0x01179cec18</td>\n",
>>>>>>> origin/devel
" </tr><tr>\n",
" <td><strong>Functional</strong></td><td>True</td>\n",
" </tr><tr>\n",
Expand All @@ -934,11 +871,7 @@
" </table>"
],
"text/plain": [
<<<<<<< HEAD
"<Gene b4025 at 0x11610a2b0>"
=======
"<Gene b4025 at 0x1179cec18>"
>>>>>>> origin/devel
]
},
"execution_count": 27,
Expand Down Expand Up @@ -966,11 +899,7 @@
{
"data": {
"text/plain": [
<<<<<<< HEAD
"frozenset({<Reaction PGI at 0x116188e48>})"
=======
"frozenset({<Reaction PGI at 0x117afacc0>})"
>>>>>>> origin/devel
]
},
"execution_count": 28,
Expand All @@ -997,11 +926,7 @@
{
"data": {
"text/plain": [
<<<<<<< HEAD
"frozenset({<Gene eggs at 0x1160245c0>, <Gene spam at 0x116024080>})"
=======
"frozenset({<Gene eggs at 0x11793d6d8>, <Gene spam at 0x11793d748>})"
>>>>>>> origin/devel
]
},
"execution_count": 29,
Expand Down Expand Up @@ -1057,11 +982,7 @@
" <td><strong>Name</strong></td><td></td>\n",
" </tr><tr>\n",
" <td><strong>Memory address</strong></td>\n",
<<<<<<< HEAD
" <td>0x0116024080</td>\n",
=======
" <td>0x011793d748</td>\n",
>>>>>>> origin/devel
" </tr><tr>\n",
" <td><strong>Functional</strong></td><td>True</td>\n",
" </tr><tr>\n",
Expand All @@ -1071,11 +992,7 @@
" </table>"
],
"text/plain": [
<<<<<<< HEAD
"<Gene spam at 0x116024080>"
=======
"<Gene spam at 0x11793d748>"
>>>>>>> origin/devel
]
},
"execution_count": 31,
Expand All @@ -1091,7 +1008,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"The `delete_model_genes` function will evaluate the GPR and set the upper and lower bounds to 0 if the reaction is knocked out. This function can preserve existing deletions or reset them using the `cumulative_deletions` flag."
"The `knock_out_model_genes` function will evaluate the GPR and set the upper and lower bounds to 0 if the reaction is knocked out."
]
},
{
Expand All @@ -1109,45 +1026,20 @@
}
],
"source": [
"cobra.manipulation.delete_model_genes(\n",
" model, [\"spam\"], cumulative_deletions=True)\n",
"cobra.manipulation.knock_out_model_genes(\n",
" model, [\"spam\"])\n",
"print(\"after 1 KO: %4d < flux_PGI < %4d\" % (pgi.lower_bound, pgi.upper_bound))\n",
"\n",
"cobra.manipulation.delete_model_genes(\n",
" model, [\"eggs\"], cumulative_deletions=True)\n",
"cobra.manipulation.knock_out_model_genes(\n",
" model, [\"eggs\"])\n",
"print(\"after 2 KO: %4d < flux_PGI < %4d\" % (pgi.lower_bound, pgi.upper_bound))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The undelete_model_genes can be used to reset a gene deletion"
]
},
{
"cell_type": "code",
"execution_count": 33,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"-1000 < pgi < 1000\n"
]
}
],
"source": [
"cobra.manipulation.undelete_model_genes(model)\n",
"print(pgi.lower_bound, \"< pgi <\", pgi.upper_bound)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Making changes reversibly using models as contexts"
"When knocking out model genes in a context, it is reversed when leaving the context."
]
},
{
Expand Down
12 changes: 12 additions & 0 deletions release-notes/next-release.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## New features

Added knock_out_model_genes to simulate knock-outs, setting
reaction bounds of effected reactions to zero and returning a list
of reactions that were knocked-out. Replaces delete_model_genes and undelete_model_genes
since it is context sensitive.
Improve reading of matlab models, which will include metaboilte
and reaction annotations.

Expand All @@ -24,7 +28,15 @@ test_gpr_that_needs_two_replacements()

## Deprecated features

Deprecated delete_model_genes, undelete_model_genes.

## Backwards incompatible changes

removed find_gene_knockout_reactions from delete.py

removed _find_gene_knockout_reactions_fast,
_gene_knockout_computation, _get_removed
from test_delete.py
Removed pymatlib direct transfer of models to matlab process.
Please use save_matlab_model() and then read the model in matlab.

5 changes: 1 addition & 4 deletions src/cobra/core/gene.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from ast import parse as ast_parse
from copy import deepcopy
from keyword import kwlist
from typing import TYPE_CHECKING, FrozenSet, Iterable, Optional, Set, Tuple, Union
from typing import FrozenSet, Iterable, Optional, Set, Tuple, Union
from warnings import warn

import sympy.logic.boolalg as spl
Expand All @@ -30,9 +30,6 @@
from cobra.util.util import format_long_string


if TYPE_CHECKING:
from cobra import Model

# TODO - When https://github.com/symengine/symengine.py/issues/334 is resolved,
# change sympy.Symbol (above in imports) to optlang.symbolics.Symbol

Expand Down
3 changes: 0 additions & 3 deletions src/cobra/core/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,6 @@ def __init__(self, id_or_model=None, name=None):
self._solver = id_or_model.solver
else:
Object.__init__(self, id_or_model, name=name)
self._trimmed = False
self._trimmed_genes = []
self._trimmed_reactions = {}
self.genes = DictList()
self.reactions = DictList() # A list of cobra.Reactions
self.metabolites = DictList() # A list of cobra.Metabolites
Expand Down
4 changes: 1 addition & 3 deletions src/cobra/manipulation/__init__.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
from .annotate import add_SBO
from .delete import (
delete_model_genes,
find_gene_knockout_reactions,
get_compiled_gene_reaction_rules,
knock_out_model_genes,
prune_unused_metabolites,
prune_unused_reactions,
remove_genes,
undelete_model_genes,
)
from .modify import escape_ID, rename_genes
from .validate import check_mass_balance, check_metabolite_compartment_formula
Loading

0 comments on commit b628572

Please sign in to comment.