-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
DOC: Expand documentation for ORACLE/MCA/MA and dynamic simulations
- Loading branch information
Showing
4 changed files
with
231 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,78 @@ | ||
Non-linear dynamic simulations | ||
============================== | ||
|
||
Dynamic simulations can directly be perform by importing a model that contains | ||
parameter values. For large-scale kinetic models though it is recommended to | ||
parametrize the initial-conditions to a known / assumed reference steady-state | ||
as high dimensional non-linear often exhibit multiple steady-states. | ||
|
||
|
||
.. code-block:: python | ||
from pytfa.io.json import load_json_model | ||
from skimpy.io.yaml import load_yaml_model | ||
from skimpy.analysis.oracle.load_pytfa_solution import load_concentrations, load_fluxes | ||
from skimpy.core.parameters import ParameterValues | ||
from skimpy.utils.namespace import * | ||
# Units of the parameters are muM and hr | ||
CONCENTRATION_SCALING = 1e6 | ||
TIME_SCALING = 1 # 1hr to 1min | ||
DENSITY = 1200 # g/L | ||
GDW_GWW_RATIO = 0.3 # Assumes 70% Water | ||
kmodel = load_yaml_model('./../../models/varma_strain_1.yml') | ||
tmodel = load_json_model('./../../models/tfa_varma.json') | ||
# Reference steady-state data | ||
ref_solution = pd.read_csv('./../../data/tfa_reference_strains.csv', | ||
index_col=0).loc['strain_1',:] | ||
ref_concentrations = load_concentrations(ref_solution, tmodel, kmodel, | ||
concentration_scaling=CONCENTRATION_SCALING) | ||
To run dynamic simulations the model need to contain compiled ODE expressions, by calling ``kmodel.prepare()`` | ||
and ``kmodel.compile_ode()``. To compute fluxes at specific time points it can be useful | ||
to build a ``FluxFunction`` using the ``make_flux_fun(kmodel, QSSA)`` function. | ||
|
||
.. code-block:: python | ||
kmodel.compile_ode(sim_type=QSSA,ncpu=8) | ||
# make function to calculate the fluxes | ||
flux_fun = make_flux_fun(kmodel, QSSA) | ||
for k in kmodel.initial_conditions: | ||
kmodel.initial_conditions[k] = ref_concentrations[k] | ||
desings = {'vmax_forward_LDH_D': 2.0, | ||
'vmax_forward_GAPD': 2.0} | ||
fluxes = [] | ||
for p,v in desings.items(): | ||
kmodel.parameters = parameter_values | ||
# Implement parameter desing | ||
kmodel.parameters[p].value = kmodel.parameters[p].value*v | ||
sol = kmodel.solve_ode(np.logspace(-9,0, 1000), | ||
solver_type='cvode') | ||
# Calculate fluxes: | ||
this_fluxes = [] | ||
for i, concentrations in sol.concentrations.iterrows(): | ||
t_fluxes = flux_fun(concentrations, parameters=parameter_values) | ||
this_fluxes.append(t_fluxes) | ||
# Make it a DataFrame | ||
this_fluxes = pd.DataFrame(this_fluxes)/ref_fluxes | ||
this_fluxes.index = sol.time | ||
fluxes.append(this_fluxes) | ||
ldh_fluxes = np.array([fluxes[0]['LDH_D'].values, fluxes[1]['LDH_D'].values ]).T | ||
timetrace_plot(sol.time,ldh_fluxes , | ||
filename='ldh_flux.html', | ||
legend=['2 x [LDH]','2 x [GAPD]'], | ||
backend='svg' | ||
) | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,77 @@ | ||
Metabolic control analysis | ||
=========================== | ||
|
||
|
||
Further we need to compute the steady state concentrations and fluxes for the steady-state | ||
we aim to perform the MCA for. Here we use the concentrations and fluxes | ||
from we used for the respective ORACLE parametrization. | ||
|
||
.. code-block:: python | ||
from pytfa.io.json import load_json_model | ||
from skimpy.io.yaml import load_yaml_model | ||
from skimpy.analysis.oracle.load_pytfa_solution import load_concentrations, load_fluxes | ||
from skimpy.core.parameters import ParameterValues | ||
from skimpy.utils.namespace import * | ||
# Units of the parameters are muM and hr | ||
CONCENTRATION_SCALING = 1e6 | ||
TIME_SCALING = 1 # 1hr to 1min | ||
DENSITY = 1200 # g/L | ||
GDW_GWW_RATIO = 0.3 # Assumes 70% Water | ||
kmodel = load_yaml_model('./../../models/varma_strain_1.yml') | ||
tmodel = load_json_model('./../../models/tfa_varma.json') | ||
# Reference steady-state data | ||
ref_solution = pd.read_csv('./../../data/tfa_reference_strains.csv', | ||
index_col=0).loc['strain_1',:] | ||
ref_concentrations = load_concentrations(ref_solution, tmodel, kmodel, | ||
concentration_scaling=CONCENTRATION_SCALING) | ||
ref_fluxes = load_fluxes(ref_solution, tmodel, kmodel, | ||
density=DENSITY, | ||
ratio_gdw_gww=GDW_GWW_RATIO, | ||
concentration_scaling=CONCENTRATION_SCALING, | ||
time_scaling=TIME_SCALING) | ||
# Extract the current parameter set from the model | ||
parameter_values = {p.symbol:p.value for p in kmodel.parameters.values()} | ||
parameter_values = ParameterValues(parameter_values, kmodel) | ||
With a set of parameters, fluxes and concentration we can then calculate the control coefficients. | ||
To perform metabolic control analysis the control-coeffcient expressions | ||
need to be compiled by calling ``kmodel.prepare()`` and ``kmodel.compile_mca(parameter_list=parameter_list)``, | ||
where ``parameter_list`` is a TabDict contaning the symbols of the parameters we | ||
want to the control-coeffcients for. Here we calculate the control-coeffcients with respect | ||
to all maximal enzyme rates ``V_max``. | ||
|
||
|
||
.. code-block:: python | ||
from skimpy.utils.tabdict import TabDict | ||
from skimpy.viz.controll_coefficients import plot_control_coefficients | ||
# Compile mca with parameter elasticities with respect to Vmaxes | ||
parameter_list = TabDict([(k, p.symbol) for k, p in | ||
kmodel.parameters.items() if | ||
p.name.startswith('vmax_forward')]) | ||
kmodel.compile_mca(sim_type=QSSA,ncpu=8, parameter_list=parameter_list) | ||
flux_control_coeff = kmodel.flux_control_fun(ref_fluxes, | ||
ref_concentrations, | ||
[parameter_values, ]) | ||
lac_control_coeff = flux_control_coeff.slice_by('sample',0).loc['LDH_D', :] | ||
lac_control_coeff.index = [v.replace('vmax_forward_','') | ||
for v in lac_control_coeff.index ] | ||
plot_control_coefficients(lac_control_coeff, | ||
filename='lac_control_coeff.html', | ||
backend='svg', | ||
) | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,55 @@ | ||
Modal analysis | ||
=========================== | ||
|
||
Modal analysis allows to get insight into the dynamics close the the steady state. | ||
The modal matrix provides information on which eigenvalues contribute to the | ||
dynamics of each concentration. Similar to MCA, Modal analysis is conducted around a steady-state | ||
therefore modal analysis requieres to compute or import a valid set of steady-state concentrations: | ||
|
||
.. code-block:: python | ||
from pytfa.io.json import load_json_model | ||
from skimpy.io.yaml import load_yaml_model | ||
from skimpy.analysis.oracle.load_pytfa_solution import load_concentrations, load_fluxes | ||
from skimpy.analysis.modal import modal_matrix | ||
from skimpy.core.parameters import ParameterValues | ||
from skimpy.utils.namespace import * | ||
from skimpy.utils.tabdict import TabDict | ||
from skimpy.viz.modal import plot_modal_matrix | ||
# Units of the parameters are muM and hr | ||
CONCENTRATION_SCALING = 1e6 | ||
TIME_SCALING = 1 # 1hr to 1min | ||
DENSITY = 1200 # g/L | ||
GDW_GWW_RATIO = 0.3 # Assumes 70% Water | ||
kmodel = load_yaml_model('./../../models/varma_strain_1.yml') | ||
tmodel = load_json_model('./../../models/tfa_varma.json') | ||
# Reference steady-state data | ||
ref_solution = pd.read_csv('./../../data/tfa_reference_strains.csv', | ||
index_col=0).loc['strain_1',:] | ||
ref_concentrations = load_concentrations(ref_solution, tmodel, kmodel, | ||
concentration_scaling=CONCENTRATION_SCALING) | ||
parameter_values = {p.symbol:p.value for p in kmodel.parameters.values()} | ||
parameter_values = ParameterValues(parameter_values, kmodel) | ||
To compute the modal-matrix the model needs to have compiled Jacobian expressions, they are build by calling ``kmodel.prepare()`` and ``kmodel.compile_jacobian()``. | ||
|
||
.. code-block:: python | ||
kmodel.prepare() | ||
kmodel.compile_jacobian(sim_type=QSSA,ncpu=8) | ||
M = modal_matrix(kmodel,ref_concentrations,parameter_values) | ||
plot_modal_matrix(M,filename='modal_matrix.html', | ||
plot_width=800, plot_height=600, | ||
clustered=True, | ||
backend='svg', | ||
) |