{
"cells": [
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"# Low level API"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"Most users will use the `create_script_from_data()` to create the INCAScript, but if one wants more control over the script it is good to known the how the underlying api works."
]
},
{
"cell_type": "code",
"execution_count": 26,
"metadata": {},
"outputs": [],
"source": [
"import pandas as pd\n",
"import pathlib\n",
"from incawrapper import (\n",
" define_flux_measurements, \n",
" define_ms_data, \n",
" define_experiment, \n",
" define_model, \n",
" define_tracers, \n",
" define_options, \n",
" define_runner,\n",
" define_reactions,\n",
" INCAScript,\n",
" run_inca\n",
")\n",
"import ast\n",
"data_folder = pathlib.Path(\"./examples/Literature data/simple model\")"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"To illustrate how to use the INCAWrapper, we will use a small toy model with 5 reactions original used as a test model in [1,2]. As described in the Input data notebook, the INCAWrapper takes inputs in the form of pandas dataframes, which has to obey specific structure schema's. Let's have a look at the reactions data of our simple model."
]
},
{
"cell_type": "code",
"execution_count": 27,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"
\n",
"\n",
"
\n",
" \n",
" \n",
" | \n",
" model | \n",
" rxn_id | \n",
" rxn_eqn | \n",
"
\n",
" \n",
" \n",
" \n",
" | 0 | \n",
" simple_model | \n",
" R1 | \n",
" A (abc) -> B (abc) | \n",
"
\n",
" \n",
" | 1 | \n",
" simple_model | \n",
" R2 | \n",
" B (abc) <-> D (abc) | \n",
"
\n",
" \n",
" | 2 | \n",
" simple_model | \n",
" R3 | \n",
" B (abc) -> C (bc) + E (a) | \n",
"
\n",
" \n",
" | 3 | \n",
" simple_model | \n",
" R4 | \n",
" B (abc) + C (de) -> D (bcd) + E (a) + E (e) | \n",
"
\n",
" \n",
" | 4 | \n",
" simple_model | \n",
" R5 | \n",
" D (abc) -> F (abc) | \n",
"
\n",
" \n",
"
\n",
"
"
],
"text/plain": [
" model rxn_id rxn_eqn\n",
"0 simple_model R1 A (abc) -> B (abc)\n",
"1 simple_model R2 B (abc) <-> D (abc)\n",
"2 simple_model R3 B (abc) -> C (bc) + E (a)\n",
"3 simple_model R4 B (abc) + C (de) -> D (bcd) + E (a) + E (e)\n",
"4 simple_model R5 D (abc) -> F (abc)"
]
},
"execution_count": 27,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"reactions_data = pd.read_csv(data_folder / \"reactions.csv\")\n",
"reactions_data.head()"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"We see that the simple toy model consist of 5 reactions each defined with an atom map and has a unique identifier. Lets move on to the tracer data."
]
},
{
"cell_type": "code",
"execution_count": 28,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"\n",
"\n",
"
\n",
" \n",
" \n",
" | \n",
" experiment_id | \n",
" met_id | \n",
" tracer_id | \n",
" atom_ids | \n",
" ratio | \n",
" atom_mdv | \n",
" enrichment | \n",
"
\n",
" \n",
" \n",
" \n",
" | 0 | \n",
" exp1 | \n",
" A | \n",
" [2-13C]A | \n",
" [2] | \n",
" 1.0 | \n",
" [0, 1] | \n",
" 1 | \n",
"
\n",
" \n",
" | 1 | \n",
" exp2 | \n",
" A | \n",
" [1,2-13C]A | \n",
" [1, 2] | \n",
" 0.5 | \n",
" [0.05, 0.95] | \n",
" 1 | \n",
"
\n",
" \n",
"
\n",
"
"
],
"text/plain": [
" experiment_id met_id tracer_id atom_ids ratio atom_mdv enrichment\n",
"0 exp1 A [2-13C]A [2] 1.0 [0, 1] 1\n",
"1 exp2 A [1,2-13C]A [1, 2] 0.5 [0.05, 0.95] 1"
]
},
"execution_count": 28,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"tracers_data = pd.read_csv(data_folder / \"tracers.csv\", converters={'atom_ids': ast.literal_eval, 'atom_mdv':ast.literal_eval}) # remove id, add prurity\n",
"tracers_data.head()"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"Our data set contains two experiments each carried out with a different labelled substrate of metabolite A. In this data set we had measurements of exchange fluxes and ms data of some metabolites. Notice that we use the converters argument to properly read some the data (see XX for more information)."
]
},
{
"cell_type": "code",
"execution_count": 29,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"\n",
"\n",
"
\n",
" \n",
" \n",
" | \n",
" experiment_id | \n",
" rxn_id | \n",
" flux | \n",
" flux_std_error | \n",
"
\n",
" \n",
" \n",
" \n",
" | 0 | \n",
" exp1 | \n",
" R1 | \n",
" 10.0 | \n",
" 0.00001 | \n",
"
\n",
" \n",
"
\n",
"
"
],
"text/plain": [
" experiment_id rxn_id flux flux_std_error\n",
"0 exp1 R1 10.0 0.00001"
]
},
"execution_count": 29,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"flux_data = pd.read_csv(data_folder / \"flux_measurements.csv\")\n",
"ms_data = pd.read_csv(data_folder / \"ms_measurements.csv\", \n",
" converters={'labelled_atom_ids': ast.literal_eval, 'idv': ast.literal_eval, 'idv_std_error': ast.literal_eval}\n",
")\n",
"flux_data.head()"
]
},
{
"cell_type": "code",
"execution_count": 30,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"\n",
"\n",
"
\n",
" \n",
" \n",
" | \n",
" experiment_id | \n",
" met_id | \n",
" ms_id | \n",
" measurement_replicate | \n",
" labelled_atom_ids | \n",
" unlabelled_atoms | \n",
" mass_isotope | \n",
" intensity | \n",
" intensity_std_error | \n",
" time | \n",
"
\n",
" \n",
" \n",
" \n",
" | 0 | \n",
" exp1 | \n",
" F | \n",
" F1 | \n",
" 1 | \n",
" [1, 2, 3] | \n",
" NaN | \n",
" 0 | \n",
" 0.0001 | \n",
" 0.000002 | \n",
" 0 | \n",
"
\n",
" \n",
" | 1 | \n",
" exp1 | \n",
" F | \n",
" F1 | \n",
" 1 | \n",
" [1, 2, 3] | \n",
" NaN | \n",
" 1 | \n",
" 0.8008 | \n",
" 0.016016 | \n",
" 0 | \n",
"
\n",
" \n",
" | 2 | \n",
" exp1 | \n",
" F | \n",
" F1 | \n",
" 1 | \n",
" [1, 2, 3] | \n",
" NaN | \n",
" 2 | \n",
" 0.1983 | \n",
" 0.003966 | \n",
" 0 | \n",
"
\n",
" \n",
" | 3 | \n",
" exp1 | \n",
" F | \n",
" F1 | \n",
" 1 | \n",
" [1, 2, 3] | \n",
" NaN | \n",
" 3 | \n",
" 0.0009 | \n",
" 0.000018 | \n",
" 0 | \n",
"
\n",
" \n",
" | 4 | \n",
" exp2 | \n",
" F | \n",
" F1 | \n",
" 1 | \n",
" [1, 2, 3] | \n",
" NaN | \n",
" 0 | \n",
" 0.0002 | \n",
" 0.000002 | \n",
" 0 | \n",
"
\n",
" \n",
"
\n",
"
"
],
"text/plain": [
" experiment_id met_id ms_id measurement_replicate labelled_atom_ids \\\n",
"0 exp1 F F1 1 [1, 2, 3] \n",
"1 exp1 F F1 1 [1, 2, 3] \n",
"2 exp1 F F1 1 [1, 2, 3] \n",
"3 exp1 F F1 1 [1, 2, 3] \n",
"4 exp2 F F1 1 [1, 2, 3] \n",
"\n",
" unlabelled_atoms mass_isotope intensity intensity_std_error time \n",
"0 NaN 0 0.0001 0.000002 0 \n",
"1 NaN 1 0.8008 0.016016 0 \n",
"2 NaN 2 0.1983 0.003966 0 \n",
"3 NaN 3 0.0009 0.000018 0 \n",
"4 NaN 0 0.0002 0.000002 0 "
]
},
"execution_count": 30,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"ms_data.head()"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"## Generate the MATLAB script\n",
"To prepare a model and data for 13C-MFA in INCA, we need to write a matlab script, which specifies to the model, the tracers and the measured data. The script is constructed incrementally, line by line, within an INCAScript object. When the INCAWrapper executes INCA, it essentially runs this script within the MATLAB environment. \n",
"\n",
"To ensure the orderly execution of the MATLAB code, the structure of the INCAScript object is organized into discrete code blocks. Throughout this workflow, users progressively populate these code blocks one at a time until the script is fully formed. The central mechanism for this procedure involves employing the .add_to_block() method of the INCAScript object, in combination with a function that generates the corresponding MATLAB code string.\n",
"\n",
"Now, let's delve into the process of defining the model within the INCAScript. To achieve this, we make use of a script-writing function named define_reactions(). This function operates on a dataframe detailing the reactions and outputs a MATLAB code string that effectively defines the reactions within an INCA model."
]
},
{
"cell_type": "code",
"execution_count": 31,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"% Create reactions\n",
"r = [...\n",
"reaction('A (abc) -> B (abc)', 'id', 'R1'),...\n",
"reaction('B (abc) <-> D (abc)', 'id', 'R2'),...\n",
"reaction('B (abc) -> C (bc) + E (a)', 'id', 'R3'),...\n",
"reaction('B (abc) + C (de) -> D (bcd) + E (a) + E (e)', 'id', 'R4'),...\n",
"reaction('D (abc) -> F (abc)', 'id', 'R5'),...\n",
"];\n"
]
}
],
"source": [
"print(define_reactions(reactions_data))"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"To add the reaction definition to the `INCAScript` we use the `.add_to_block()` method."
]
},
{
"cell_type": "code",
"execution_count": 32,
"metadata": {},
"outputs": [],
"source": [
"script = INCAScript()\n",
"script.add_to_block('reactions', define_reactions(reactions_data))"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"We can view the reactions block in the `INCAScript`."
]
},
{
"cell_type": "code",
"execution_count": 16,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"% REACTION BLOCK\n",
"% Create reactions\n",
"r = [...\n",
"reaction('A (abc) -> B (abc)', 'id', 'R1'),...\n",
"reaction('B (abc) <-> D (abc)', 'id', 'R2'),...\n",
"reaction('B (abc) -> C (bc) + E (a)', 'id', 'R3'),...\n",
"reaction('B (abc) + C (de) -> D (bcd) + E (a) + E (e)', 'id', 'R4'),...\n",
"reaction('D (abc) -> F (abc)', 'id', 'R5'),...\n",
"];\n"
]
}
],
"source": [
"print(script.blocks['reactions'])"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"There are similar script writing functions to generate the other parts of the Matlab script. The experimental data is added to the `INCAScript` on a per experiment basis. Thus, the functions which adds experimental data also takes a argument for the experiment id. One example is the `define_tracers`:"
]
},
{
"cell_type": "code",
"execution_count": 17,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"% define tracers used in exp1\n",
"t_exp1 = tracer({...\n",
"'[2-13C]A: A @ 2',...\n",
"});\n",
"t_exp1.frac = [1.0 ];\n",
"t_exp1.atoms.it(:,1) = [0,1];\n",
"\n"
]
}
],
"source": [
"print(define_tracers(tracers_data, 'exp1'))"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"Because the `.add_to_block()` appends to the code block is best practice to include the `INCAScript` instantiation and the `.add_to_block()` calls within the same Jupyter-notebook cell. This will avoid adding the same code multiple times, when working a Jupyter-notebook file. In the following we add tracers, flux measurements, and ms measurements from the experiment with experiment id exp1."
]
},
{
"cell_type": "code",
"execution_count": 18,
"metadata": {},
"outputs": [],
"source": [
"script = INCAScript()\n",
"script.add_to_block('reactions', define_reactions(reactions_data))\n",
"script.add_to_block('tracers', define_tracers(tracers_data, 'exp1'))\n",
"script.add_to_block('fluxes', define_flux_measurements(flux_data, 'exp1'))\n",
"script.add_to_block('ms_fragments', define_ms_data(ms_data, 'exp1'))\n",
"script.add_to_block('experiments', define_experiment('exp1', measurement_types=['data_flx', 'data_ms']))"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"Notice that that addition of data is a two step procedure. First, the data is added to the script and second the data is added to the experiment using the `define_experiment()` function. This function takes the experiment id and a list of what measurement types are associated with this experiment. \n",
"\n",
"We can view the script that we have build by simply printing the script object."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"clear functions\n",
"\n",
"% REACTION BLOCK\n",
"% Create reactions\n",
"r = [...\n",
"reaction('A (abc) -> B (abc)', ['id'], ['R1']),...\n",
"reaction('B (abc) <-> D (abc)', ['id'], ['R2']),...\n",
"reaction('B (abc) -> C (bc) + E (a)', ['id'], ['R3']),...\n",
"reaction('B (abc) + C (de) -> D (bcd) + E (a) + E (e)', ['id'], ['R4']),...\n",
"reaction('D (abc) -> F (abc)', ['id'], ['R5']),...\n",
"];\n",
"\n",
"% TRACERS BLOCK\n",
"% define tracers used in exp1\n",
"t_exp1 = tracer({...\n",
"'[1-13C]A: A @ 1',...\n",
"});\n",
"t_exp1.frac = [1.0 ];\n",
"t_exp1.atoms.it(:,1) = [0,1];\n",
"\n",
"\n",
"% FLUXES BLOCK\n",
"\n",
"% define flux measurements for experiment exp1\n",
"f_exp1 = [...\n",
"data('R1', 'val', 10.0, 'std', 1e-05),...\n",
"];\n",
"\n",
"\n",
"% MS_FRAGMENTS BLOCK\n",
"\n",
"% define mass spectrometry measurements for experiment exp1\n",
"ms_exp1 = [...\n",
"msdata('F1: F @ 1 2 3', 'more', 'C3H5O1'),...\n",
"];\n",
"\n",
"% define mass spectrometry measurements for experiment exp1\n",
"ms_exp1{'F1'}.idvs = idv([[0.01;0.8;0.1;0.0009]], 'id', {'exp1_F1_0_0_1'}, 'std', [[0.0003;0.003;0.0008;0.001]], 'time', 0.0)\n",
"\n",
"\n",
"% EXPERIMENTAL_DATA BLOCK\n",
"e_exp1 = experiment(t_exp1, 'id', 'exp1', 'data_flx', f_exp1, 'data_ms', ms_exp1);\n",
"\n",
"\n",
"% MODEL BLOCK\n",
"\n",
"\n",
"% OPTIONS BLOCK\n",
"\n",
"\n",
"m.rates.flx.val = mod2stoich(m); % make sure the fluxes are feasible\n",
"\n",
"% RUNNER BLOCK\n",
"\n"
]
}
],
"source": [
"print(script)"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"We see that the three last blocks model, options and runner, have not been populated yet. To populate the model block we need to define what experiments should be included in the model. In the options block, we can changes the options/settings which influence how INCA is run, for example we can increase the number of restarts during the flux estimation procedure and turn off the natural abundance correction. Finally, the runner defines what algorithms INCA should run on the model. In this example we will run the estimation and the simulation algorithm."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# same as previous code\n",
"script = INCAScript()\n",
"script.add_to_block('reactions', define_reactions(reactions_data))\n",
"script.add_to_block('tracers', define_tracers(tracers_data, 'exp1'))\n",
"script.add_to_block('fluxes', define_flux_measurements(flux_data, 'exp1'))\n",
"script.add_to_block('ms_fragments', define_ms_data(ms_data, 'exp1'))\n",
"script.add_to_block('experiments', define_experiment('exp1', ['data_flx', 'data_ms']))\n",
"\n",
"# new code to define model, options and runner\n",
"script.add_to_block('model', define_model(['exp1']))\n",
"script.add_to_block('options', define_options(fit_starts=20, sim_na=False))\n",
"script.add_to_block('runner', define_runner(\"/path/to/output/file.mat\", run_estimate=True, run_simulation=True))"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"clear functions\n",
"\n",
"% REACTION BLOCK\n",
"% Create reactions\n",
"r = [...\n",
"reaction('A (abc) -> B (abc)', ['id'], ['R1']),...\n",
"reaction('B (abc) <-> D (abc)', ['id'], ['R2']),...\n",
"reaction('B (abc) -> C (bc) + E (a)', ['id'], ['R3']),...\n",
"reaction('B (abc) + C (de) -> D (bcd) + E (a) + E (e)', ['id'], ['R4']),...\n",
"reaction('D (abc) -> F (abc)', ['id'], ['R5']),...\n",
"];\n",
"\n",
"% TRACERS BLOCK\n",
"% define tracers used in exp1\n",
"t_exp1 = tracer({...\n",
"'[1-13C]A: A @ 1',...\n",
"});\n",
"t_exp1.frac = [1.0 ];\n",
"t_exp1.atoms.it(:,1) = [0,1];\n",
"\n",
"\n",
"% FLUXES BLOCK\n",
"\n",
"% define flux measurements for experiment exp1\n",
"f_exp1 = [...\n",
"data('R1', 'val', 10.0, 'std', 1e-05),...\n",
"];\n",
"\n",
"\n",
"% MS_FRAGMENTS BLOCK\n",
"\n",
"% define mass spectrometry measurements for experiment exp1\n",
"ms_exp1 = [...\n",
"msdata('F1: F @ 1 2 3', 'more', 'C3H5O1'),...\n",
"];\n",
"\n",
"% define mass spectrometry measurements for experiment exp1\n",
"ms_exp1{'F1'}.idvs = idv([[0.01;0.8;0.1;0.0009]], 'id', {'exp1_F1_0_0_1'}, 'std', [[0.0003;0.003;0.0008;0.001]], 'time', 0.0)\n",
"\n",
"\n",
"% EXPERIMENTAL_DATA BLOCK\n",
"e_exp1 = experiment(t_exp1, 'id', 'exp1', 'data_flx', f_exp1, 'data_ms', ms_exp1);\n",
"\n",
"\n",
"% MODEL BLOCK\n",
"m = model(r, 'expts', [e_exp1]);\n",
"\n",
"\n",
"% OPTIONS BLOCK\n",
"m.options = option('fit_starts', 20, 'sim_na', false)\n",
"\n",
"m.rates.flx.val = mod2stoich(m); % make sure the fluxes are feasible\n",
"\n",
"% RUNNER BLOCK\n",
"f = estimate(m);\n",
"s=simulate(m);\n",
"filename = '/path/to/output/file.mat';\n",
"save(filename, 'f', 's', 'm');\n",
"\n"
]
}
],
"source": [
"print(script)"
]
},
{
"cell_type": "code",
"execution_count": 33,
"metadata": {},
"outputs": [],
"source": [
"# replace fake path with actual path, this is just to hide my actual path from being displayed in the docs.\n",
"# It is not necessary in the actual workflow\n",
"script.blocks['runner'] = script.blocks['runner'].replace(\"'/path/to/output/file.mat'\", \"'\" + str((data_folder / 'simple_model_inca_from_low_level_api.mat').resolve()) + \"'\")"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"Now we are ready to run the flux estimation algorithm in INCA."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"INCA script saved to /var/folders/z6/mxpxh4k56tv0h0ff41vmx7gdwtlpvp/T/tmpvymjjsts/inca_script.m.\n",
"Starting MATLAB engine...\n",
" \n",
"ms_exp1 = 1x1 msdata object\n",
" \n",
"fields: atoms id [idvs] more on state \n",
" \n",
"F1\n",
" \n",
" \n",
"m = 1x1 model object\n",
" \n",
"fields: [expts] [mets] notes [options] [rates] [states] \n",
" \n",
"\t5 reactions (6 fluxes) \n",
"\t6 states (3 balanced, 1 source, 2 sink and 0 unbalanced)\n",
"\t6 metabolites \n",
"\t1 experiments \n",
" \n",
"\n",
" Directional \n",
" Iteration Residual Step-size derivative Lambda\n",
" 0 9.99461e+11\n",
" 1 9.97934e+11 0.000764 -9.99e+11 1.60177\n",
" 2 1.42897e+06 1 -3.06e+06 1.60177\n",
" 3 80454.8 1 -1.92e+05 0.533923\n",
" 4 8606.5 1 -4.85e+03 0.177974\n",
" 5 8153.72 1 -3.28 0.0593248\n",
" \n",
" Optimization terminated: Constrained optimum found.\n",
" Parameters converged to within tolerance. \n",
"\n",
" Directional \n",
" Iteration Residual Step-size derivative Lambda\n",
" 0 9.99276e+11\n",
" 1 9.96908e+11 0.00119 -9.98e+11 2.99791\n",
" 2 2.82654e+06 1 -2.71e+06 2.99791\n",
" 3 206220 1 -4.07e+05 0.999304\n",
" 4 10942.2 1 -1.83e+04 0.364917\n",
" 5 8154.58 1 -47.9 0.121639\n",
" 6 8153.7 1 -0.00032 0.0405463\n",
" \n",
" Optimization terminated: Constrained optimum found.\n",
" Norm of gradient less than tolerance. \n",
"\n",
" Directional \n",
" Iteration Residual Step-size derivative Lambda\n",
" 0 9.99496e+11\n",
" 1 9.97013e+11 0.00124 -9.98e+11 8.25557\n",
" 2 7.49812e+11 0.133 -8.65e+11 8.25557\n",
" 3 1.72508e+06 1 -3.54e+04 8.25557\n",
" 4 198278 1 -2.51e+05 2.75186\n",
" 5 31932.4 1 -2.07e+04 1.35509\n",
" 6 10888.2 0.68 748 0.451696\n",
" 7 9267.69 1 -0.00839 0.451696\n",
" \n",
" Optimization terminated: Constrained optimum found.\n",
" Norm of gradient less than tolerance. \n",
"\n",
" Directional \n",
" Iteration Residual Step-size derivative Lambda\n",
" 0 9.99592e+11\n",
" 1 9.97293e+11 0.00115 -9.98e+11 0.256206\n",
" 2 9263.85 1 -1.4e+05 0.256206\n",
" 3 8153.7 1 2.63 0.0854019\n",
" \n",
" Optimization terminated: Constrained optimum found.\n",
" Parameters converged to within tolerance. \n",
"\n",
" Directional \n",
" Iteration Residual Step-size derivative Lambda\n",
" 0 9.99754e+11\n",
" 1 9.9861e+11 0.000573 -9.98e+11 3.17144\n",
" 2 3.05221e+06 1 -1.37e+07 3.17144\n",
" 3 201540 1 -4.43e+05 1.05715\n",
" 4 10824.2 1 -1.77e+04 0.353927\n",
" 5 8154.51 1 -45 0.117976\n",
" 6 8153.7 1 -0.000282 0.0393252\n",
" \n",
" Optimization terminated: Constrained optimum found.\n",
" Norm of gradient less than tolerance. \n",
"\n",
" Directional \n",
" Iteration Residual Step-size derivative Lambda\n",
" 0 9.99757e+11\n",
" 1 9.98946e+11 0.000406 -9.99e+11 4.83394\n",
" 2 1.82069e+06 1 -3.57e+07 4.83394\n",
" 3 18373.2 1 -1.19e+05 1.61131\n",
" 4 8164.33 1 -309 0.537104\n",
" 5 8153.7 1 -0.0134 0.179035\n",
" \n",
" Optimization terminated: Constrained optimum found.\n",
" Parameters converged to within tolerance. \n",
"\n",
" Directional \n",
" Iteration Residual Step-size derivative Lambda\n",
" 0 9.99103e+11\n",
" 1 9.97131e+11 0.000987 -9.98e+11 0.592389\n",
" 2 203195 1 -5.81e+05 0.592389\n",
" 3 10931.3 1 -1.8e+04 0.197463\n",
" 4 8154.57 1 -47.6 0.065821\n",
" 5 8153.7 1 -0.000303 0.0219403\n",
" \n",
" Optimization terminated: Constrained optimum found.\n",
" Norm of gradient less than tolerance. \n",
"\n",
" Directional \n",
" Iteration Residual Step-size derivative Lambda\n",
" 0 9.99644e+11\n",
" 1 9.97232e+11 0.00121 -9.95e+11 13.1605\n",
" 2 9.83399e+11 0.00696 -9.9e+11 13.1605\n",
" 3 2.42944e+11 0.503 -4.89e+11 13.1605\n",
" 4 2.13269e+06 1 -12.5 13.1605\n",
" 5 1.10561e+06 1 -3.68e+05 4.38683\n",
" 6 117851 1 -1.58e+05 2.40399\n",
" 7 28352.2 1 -9.65e+03 1.02639\n",
" 8 10233.5 0.747 -41.7 0.342129\n",
" 9 9267.69 1 -0.00379 0.342129\n",
" \n",
" Optimization terminated: Constrained optimum found.\n",
" Norm of gradient less than tolerance. \n",
"\n",
" Directional \n",
" Iteration Residual Step-size derivative Lambda\n",
" 0 9.99422e+11\n",
" 1 9.97065e+11 0.00118 -9.97e+11 6.62877\n",
" 2 9.50368e+11 0.0237 -9.73e+11 6.62877\n",
" 3 2.43406e+11 0.494 -4.81e+11 6.62877\n",
" 4 2.13269e+06 1 -6.35 6.62877\n",
" 5 790061 1 -4.06e+05 2.20959\n",
" 6 82008.8 1 -1.1e+05 1.41421\n",
" 7 27252.5 1 -5.16e+03 0.531876\n",
" 8 9614.73 0.839 594 0.177292\n",
" 9 9267.69 1 -0.000705 0.177292\n",
" \n",
" Optimization terminated: Constrained optimum found.\n",
" Norm of gradient less than tolerance. \n",
"\n",
" Directional \n",
" Iteration Residual Step-size derivative Lambda\n",
" 0 9.98733e+11\n",
" 1 9.98153e+11 0.00029 -9.98e+11 2.63162\n",
" 2 2.18933e+06 1 -6.31e+06 2.63162\n",
" 3 142395 1 -3.08e+05 0.877207\n",
" 4 9549.51 1 -1.1e+04 0.292402\n",
" 5 8153.92 1 -17.3 0.0974675\n",
" 6 8153.7 1 -4.39e-05 0.0324892\n",
" \n",
" Optimization terminated: Constrained optimum found.\n",
" Norm of gradient less than tolerance. \n",
"\n",
" Directional \n",
" Iteration Residual Step-size derivative Lambda\n",
" 0 9.99412e+11\n",
" 1 9.96285e+11 0.00157 -9.98e+11 7.87281\n",
" 2 3.80862e+11 0.382 -6.16e+11 7.87281\n",
" 3 925902 1 -1.39e+05 7.87281\n",
" 4 96902.3 1 -1.31e+05 2.62427\n",
" 5 27664.8 1 -6.98e+03 1.05019\n",
" 6 9905.18 0.79 147 0.350062\n",
" 7 9267.69 1 -0.00256 0.350062\n",
" \n",
" Optimization terminated: Constrained optimum found.\n",
" Norm of gradient less than tolerance. \n",
"\n",
" Directional \n",
" Iteration Residual Step-size derivative Lambda\n",
" 0 9.99643e+11\n",
" 1 9.9789e+11 0.000878 -9.98e+11 6.90612\n",
" 2 3.57725e+11 0.401 -5.97e+11 6.90612\n",
" 3 847758 1 -1.41e+05 6.90612\n",
" 4 88226.1 1 -1.19e+05 2.30204\n",
" 5 27416.3 1 -5.91e+03 0.890441\n",
" 6 9740.78 0.816 361 0.296814\n",
" 7 9267.69 1 -0.00161 0.296814\n",
" \n",
" Optimization terminated: Constrained optimum found.\n",
" Norm of gradient less than tolerance. \n",
"\n",
" Directional \n",
" Iteration Residual Step-size derivative Lambda\n",
" 0 9.99477e+11\n",
" 1 9.97624e+11 0.000928 -9.99e+11 0.759894\n",
" 2 631059 1 -1.1e+06 0.759894\n",
" 3 27938.5 1 -7.5e+04 0.253298\n",
" 4 8193.37 1 -808 0.0844327\n",
" 5 8153.7 1 -0.0873 0.0281442\n",
" \n",
" Optimization terminated: Constrained optimum found.\n",
" Parameters converged to within tolerance. \n",
"\n",
" Directional \n",
" Iteration Residual Step-size derivative Lambda\n",
" 0 9.99804e+11\n",
" 1 9.98903e+11 0.000451 -9.99e+11 1.5183\n",
" 2 1.22163e+06 1 -1.01e+07 1.5183\n",
" 3 64389.6 1 -1.61e+05 0.506101\n",
" 4 8438.17 1 -3.45e+03 0.1687\n",
" 5 8153.71 1 -1.64 0.0562334\n",
" \n",
" Optimization terminated: Constrained optimum found.\n",
" Parameters converged to within tolerance. \n",
"\n",
" Directional \n",
" Iteration Residual Step-size derivative Lambda\n",
" 0 9.99437e+11\n",
" 1 9.96992e+11 0.00122 -9.98e+11 3.72851\n",
" 2 3.68594e+06 1 -3.8e+06 3.72851\n",
" 3 287827 1 -5.43e+05 1.24284\n",
" 4 13241.8 1 -2.82e+04 0.48519\n",
" 5 8156.57 1 -115 0.16173\n",
" 6 8153.7 1 -0.00182 0.05391\n",
" \n",
" Optimization terminated: Constrained optimum found.\n",
" Norm of gradient less than tolerance. \n",
"\n",
" Directional \n",
" Iteration Residual Step-size derivative Lambda\n",
" 0 9.99732e+11\n",
" 1 9.98354e+11 0.00069 -9.98e+11 6.9614\n",
" 2 7.60754e+11 0.127 -8.71e+11 6.9614\n",
" 3 1.59821e+06 1 -2.86e+04 6.9614\n",
" 4 180930 1 -2.32e+05 2.32047\n",
" 5 31050.2 1 -1.82e+04 1.11703\n",
" 6 10798.5 0.688 494 0.372343\n",
" 7 9267.69 1 -0.00654 0.372343\n",
" \n",
" Optimization terminated: Constrained optimum found.\n",
" Norm of gradient less than tolerance. \n",
"\n",
" Directional \n",
" Iteration Residual Step-size derivative Lambda\n",
" 0 9.99245e+11\n",
" 1 9.96412e+11 0.00142 -9.98e+11 1.30251\n",
" 2 1.40943e+06 1 -8.68e+05 1.30251\n",
" 3 79523.6 1 -1.9e+05 0.434169\n",
" 4 8595.83 1 -4.77e+03 0.144723\n",
" 5 8153.72 1 -3.16 0.048241\n",
" \n",
" Optimization terminated: Constrained optimum found.\n",
" Parameters converged to within tolerance. \n",
"\n",
" Directional \n",
" Iteration Residual Step-size derivative Lambda\n",
" 0 9.99414e+11\n",
" 1 1.8588e+06 1 -5.85e+07 2.52112\n",
" 2 99555.8 1 -2.53e+05 0.840374\n",
" 3 8849.47 1 -6.64e+03 0.280125\n",
" 4 8153.75 1 -6.2 0.0933749\n",
" \n",
" Optimization terminated: Constrained optimum found.\n",
" Parameters converged to within tolerance. \n",
"\n",
" Directional \n",
" Iteration Residual Step-size derivative Lambda\n",
" 0 9.99534e+11\n",
" 1 9.98138e+11 0.000698 -9.99e+11 0.446625\n",
" 2 216198 1 -1.04e+06 0.446625\n",
" 3 11271.7 1 -1.96e+04 0.148875\n",
" 4 8154.8 1 -56.4 0.049625\n",
" 5 8153.7 1 -0.000418 0.0165417\n",
" \n",
" Optimization terminated: Constrained optimum found.\n",
" Norm of gradient less than tolerance. \n",
"\n",
" Directional \n",
" Iteration Residual Step-size derivative Lambda\n",
" 0 9.99578e+11\n",
" 1 9.98277e+11 0.000651 -9.99e+11 4.39459\n",
" 2 2.9496e+06 1 -1.24e+07 4.39459\n",
" 3 183948 1 -4.25e+05 1.46486\n",
" 4 10407.4 1 -1.57e+04 0.488288\n",
" 5 8154.28 1 -35.1 0.162763\n",
" 6 8153.7 1 -0.000181 0.0542543\n",
" \n",
" Optimization terminated: Constrained optimum found.\n",
" Norm of gradient less than tolerance. \n",
"\n",
" Directional \n",
" Iteration Residual Step-size derivative Lambda\n",
" 0 8153.7\n",
" 1 8153.7 1 -1.83e-15 0.000211752\n",
" \n",
" Optimization terminated: Constrained optimum found.\n",
" Norm of gradient less than tolerance. \n",
"\n",
"\tEstimation completed in 11.4100 seconds.\n",
"\n",
"\tPreprocessing time: 7.3100 s\n",
"\n",
"\tComputation time: 3.9600 s\n",
"\n",
"\tPostprocessing time: 0.1400 s\n",
"\n",
"Warning: Network is ill-conditioned.\n",
"\n",
"\tSimulation completed in 0.1000 seconds.\n",
"\n",
"\tPreprocessing time: 0.0900 s\n",
"\n",
"\tComputation time: 0.0100 s\n",
"\n",
"\tPostprocessing time: 0.0000 s\n",
"\n",
"--- 21.26518416404724 seconds -\n"
]
}
],
"source": [
"import dotenv\n",
"inca_directory = pathlib.Path(dotenv.get_key(dotenv.find_dotenv(), \"INCA_base_directory\")) # Simply replace this with the path to your INCA installation\n",
"run_inca(script, INCA_base_directory=inca_directory)"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"INCA has now done flux estimation on our model and saved it to a .mat file, which was specified in the `INCAScript` (here simple_model_inca.mat). This file can be open using the `INCAResults` workflow described in a later notebook or directly in the INCA GUI using \"Open fluxmap\"."
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"### Note about opening models in INCA GUI\n",
"There are multiple ways to open models in the INCA GUI: \"Open model\", \"Open fluxmap\". Both methods opens the .mat file with is generated by `run_inca()`. \"Open model\" will open the model with any associated experiments and data, but it will not include the results of flux estimation. To get the results of the estimate, continuation or monte carlo algorithms use the \"Open fluxmap\" instead. This will load both the model and the results of the algorithms which were applied. One thing to know is that \"Open fluxmap\" in the INCA GUI fails if there is no simulation in the .mat file. Thus, to be able to open the results in the INCA GUI it is required to set `run_simulation=True` in the `define_runner()`."
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"## References\n",
"[1] M. R. Antoniewicz, J. K. Kelleher, and G. Stephanopoulos, “Determination of confidence intervals of metabolic fluxes estimated from stable isotope measurements,” Metabolic Engineering, vol. 8, no. 4, pp. 324–337, Jul. 2006, doi: 10.1016/j.ymben.2006.01.004.\n",
"\n",
"[2] M. R. Antoniewicz, J. K. Kelleher, and G. Stephanopoulos, “Elementary metabolite units (EMU): A novel framework for modeling isotopic distributions,” Metabolic Engineering, vol. 9, no. 1, pp. 68–86, Jan. 2007, doi: 10.1016/j.ymben.2006.09.001.\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "bfair-testing",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.8"
},
"vscode": {
"interpreter": {
"hash": "820c70ec08a0eb018d8ec3c5d089748cbb2d1e243fbedf0a7cbeb7c8948c3b84"
}
}
},
"nbformat": 4,
"nbformat_minor": 4
}