Skip to content

Commit

Permalink
#29 update example to show that assignment will work when mapping is …
Browse files Browse the repository at this point in the history
…defined
  • Loading branch information
fbergmann committed Dec 13, 2022
1 parent 51008a5 commit 7a31e79
Showing 1 changed file with 174 additions and 23 deletions.
197 changes: 174 additions & 23 deletions docs/notebooks/Editing_Kinetics.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"cells": [
{
"cell_type": "markdown",
"id": "ac7fdcca",
"id": "86d5d8a5",
"metadata": {},
"source": [
"## Editing reaction kinetics\n",
Expand All @@ -12,7 +12,7 @@
{
"cell_type": "code",
"execution_count": 1,
"id": "51e4b06a",
"id": "ec398d0f",
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -21,7 +21,7 @@
},
{
"cell_type": "markdown",
"id": "624e263a",
"id": "719e97a5",
"metadata": {},
"source": [
"now lets create a new model: "
Expand All @@ -30,7 +30,7 @@
{
"cell_type": "code",
"execution_count": 2,
"id": "03e06c2e",
"id": "bff10872",
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -39,7 +39,7 @@
},
{
"cell_type": "markdown",
"id": "8ccddfb5",
"id": "bd513ab6",
"metadata": {},
"source": [
"we know we can create a reaction, by using the `add_reaction` command. It requires at the very least two arguments: \n",
Expand All @@ -53,7 +53,7 @@
{
"cell_type": "code",
"execution_count": 3,
"id": "6fb13e49",
"id": "0d2daeaa",
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -62,7 +62,7 @@
},
{
"cell_type": "markdown",
"id": "a759d106",
"id": "eaea42a1",
"metadata": {},
"source": [
"creates the reaction `R1`, species `A` and `B` and a local parameter `(R1).k1`. With `get_reactions` we can have a look at what was created: "
Expand All @@ -71,7 +71,7 @@
{
"cell_type": "code",
"execution_count": 4,
"id": "f4105b56",
"id": "9a201872",
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -134,7 +134,7 @@
},
{
"cell_type": "markdown",
"id": "153c334b",
"id": "f64abc5a",
"metadata": {},
"source": [
"here I want to point out, the `mapping` column. It shows that the parameter `k1` is a local one, as it is mapped to a value. And that the substrate of the function is mapped to `A`. We can specify the mapping directly in the `add_reaction` call, or we can specify it using `set_reaction`. So for example, if we wanted to modify the reaction, to map the reactions `k1` parameter to a global quantity `global_k`, we could to that as follows: "
Expand All @@ -143,7 +143,7 @@
{
"cell_type": "code",
"execution_count": 5,
"id": "96f852a4",
"id": "b9e54bdd",
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -154,7 +154,7 @@
{
"cell_type": "code",
"execution_count": 6,
"id": "63ecea1e",
"id": "d2265200",
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -217,7 +217,7 @@
},
{
"cell_type": "markdown",
"id": "bb2b7277",
"id": "5321d797",
"metadata": {},
"source": [
"next let us assume, i wanted to use a kinetic from the function database, that includes inhibition for the reaction. Using `get_functions` we can filter the functiondatabase, for suitable functions for our reaction, and then filter for ones that contain inhibition: "
Expand All @@ -226,7 +226,7 @@
{
"cell_type": "code",
"execution_count": 7,
"id": "7b433631",
"id": "b0ef53ab",
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -327,7 +327,7 @@
},
{
"cell_type": "markdown",
"id": "6aceb40d",
"id": "b550042e",
"metadata": {},
"source": [
"let us use `Allosteric inhibition (MWC)` here, lets have a look at the formula and the mapping table: "
Expand All @@ -336,7 +336,7 @@
{
"cell_type": "code",
"execution_count": 8,
"id": "39678fd6",
"id": "2faf9910",
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -364,7 +364,7 @@
},
{
"cell_type": "markdown",
"id": "2e21b9e9",
"id": "b2aadc12",
"metadata": {},
"source": [
"since this function requires a modifier, we also change the reaction scheme to include a modifier. This is done by adding a semicolon at the end of the reaction scheme, and listing the modifiers space separated there. Then we an assign that function directly. "
Expand All @@ -373,7 +373,7 @@
{
"cell_type": "code",
"execution_count": 9,
"id": "3573e0d7",
"id": "a44ab0c2",
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -441,7 +441,7 @@
},
{
"cell_type": "markdown",
"id": "5e67bcbb",
"id": "6666b360",
"metadata": {},
"source": [
"*Note:* that here, the mapping is not necessary, as the function has only one modifier, had we multiple modifiers defined, then we'd want to specify the mapping dictionary and map the `Inhibitor` to the respective modifier in our reaction scheme: "
Expand All @@ -450,7 +450,7 @@
{
"cell_type": "code",
"execution_count": 10,
"id": "97c24b0b",
"id": "e588d15a",
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -518,16 +518,16 @@
},
{
"cell_type": "markdown",
"id": "a36fb78b",
"id": "111ed9d0",
"metadata": {},
"source": [
"*Note:* Assigning a function that uses modifiers, *requires* that modifiers are present in the reaction scheme. So assigning the function above would fail with error, if no modifier is declared: "
"*Note:* Assigning a function that uses modifiers, *requires* that modifiers are present in the reaction scheme, or that *all modifiers* are specified in the mapping parameter. So assigning the function above would fail with error, if no modifier is declared: "
]
},
{
"cell_type": "code",
"execution_count": 11,
"id": "2b86b131",
"id": "e4fd7589",
"metadata": {},
"outputs": [
{
Expand All @@ -536,10 +536,161 @@
"text": [
"ERROR:root:the mapping for reaction \"error\" with function \"Allosteric inhibition (MWC)\" is not valid and cannot be applied.\n"
]
},
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>scheme</th>\n",
" <th>function</th>\n",
" <th>mapping</th>\n",
" </tr>\n",
" <tr>\n",
" <th>name</th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>R1</th>\n",
" <td>A -&gt; B; D</td>\n",
" <td>Allosteric inhibition (MWC)</td>\n",
" <td>{'substrate': 'A', 'Inhibitor': 'D', 'V': 0.1,...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>error</th>\n",
" <td>A -&gt; B</td>\n",
" <td>Mass action (irreversible)</td>\n",
" <td>{'k1': 0.1, 'substrate': 'A'}</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" scheme function \\\n",
"name \n",
"R1 A -> B; D Allosteric inhibition (MWC) \n",
"error A -> B Mass action (irreversible) \n",
"\n",
" mapping \n",
"name \n",
"R1 {'substrate': 'A', 'Inhibitor': 'D', 'V': 0.1,... \n",
"error {'k1': 0.1, 'substrate': 'A'} "
]
},
"execution_count": 11,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"add_reaction('error', scheme='A -> B', function='Allosteric inhibition (MWC)');"
"add_reaction('error', scheme='A -> B', function='Allosteric inhibition (MWC)');\n",
"get_reactions()[['scheme', 'function', 'mapping']]"
]
},
{
"cell_type": "markdown",
"id": "fca16b2a",
"metadata": {},
"source": [
"However, it will succeeed, if the modifier is specified. in the mapping parameter: "
]
},
{
"cell_type": "code",
"execution_count": 12,
"id": "359b2f58",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>scheme</th>\n",
" <th>function</th>\n",
" <th>mapping</th>\n",
" </tr>\n",
" <tr>\n",
" <th>name</th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>R1</th>\n",
" <td>A -&gt; B; D</td>\n",
" <td>Allosteric inhibition (MWC)</td>\n",
" <td>{'substrate': 'A', 'Inhibitor': 'D', 'V': 0.1,...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>now_it_works</th>\n",
" <td>A -&gt; B; D</td>\n",
" <td>Allosteric inhibition (MWC)</td>\n",
" <td>{'substrate': 'A', 'Inhibitor': 'D', 'V': 0.1,...</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" scheme function \\\n",
"name \n",
"R1 A -> B; D Allosteric inhibition (MWC) \n",
"now_it_works A -> B; D Allosteric inhibition (MWC) \n",
"\n",
" mapping \n",
"name \n",
"R1 {'substrate': 'A', 'Inhibitor': 'D', 'V': 0.1,... \n",
"now_it_works {'substrate': 'A', 'Inhibitor': 'D', 'V': 0.1,... "
]
},
"execution_count": 12,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"set_reaction('error', new_name='now_it_works', function='Allosteric inhibition (MWC)', mapping={'Inhibitor': 'D'})\n",
"get_reactions()[['scheme', 'function', 'mapping']]"
]
}
],
Expand Down

0 comments on commit 7a31e79

Please sign in to comment.