Sensitivity Analysis

This notebook demonstrates how to use sensitivity analysis using basico.

We start as always by importing basico, and loading a model. Here I load the brusselator model from the examples.

[1]:
from basico import *
[2]:
load_example('brusselator');
get_reactions()[['scheme']]
[2]:
scheme
name
R1 A -> X
R2 2 * X + Y -> 3 * X
R3 X + B -> Y + D
R4 X -> E

Settings

The settings for the sensitivities task are controlled using the functions get_sensitivity_settings() and set_sensitivity_settings(). The core attributes to change here would be:

  • the subtask to use (can be one of ‘Evaluation’, ‘Steady State’, ‘Time Series’, ‘Parameter Estimation’, ‘Optimization’, ‘Cross Section’). They are available in the SENS_ST constant class.

  • effect: this specifies the element (or elements that we want to observe)

  • cause and secondary_cause: these are the elements to be varied, that we expect to have an effect on the observed element.

If we look at the current settings, we see that the steady state subtask is run to observe what happens to non-constant concentratiosn of species when parameter values are varied.

[3]:
get_sensitivity_settings()
[3]:
{'scheduled': False,
 'update_model': False,
 'method': {'Delta factor': 0.001,
  'Delta minimum': 1e-12,
  'name': 'Sensitivities Method'},
 'report': {'filename': '',
  'report_definition': 'Sensitivities',
  'append': True,
  'confirm_overwrite': False},
 'sub_task': 'Steady State',
 'effect': 'Non-Constant Concentrations of Species',
 'cause': 'All Parameter Values',
 'secondary_cause': 'Not Set'}

Valid values for cause and effect are either a specific element, specified by using either the display name or the CN of an element. Or an element from the SENS constant class.

Running the Analysis

run_sensitivities() will run the sensitivity task, after which the result is available by calling:

  • get_scaled_sensitivities()

  • get_unscaled_sensitivities()

  • get_summarized_sensitivities()

[4]:
run_sensitivities()
[5]:
get_scaled_sensitivities()
[5]:
(R1).k1 (R2).k1 (R3).k1 (R4).k1
[X] 1.000000 0.000000 4.440893e-13 -0.999001
[Y] -0.999001 -0.999001 1.000000e+00 1.000000
[6]:
get_unscaled_sensitivities()
[6]:
(R1).k1 (R2).k1 (R3).k1 (R4).k1
[X] 0.500000 0.000000 2.220446e-13 -0.499500
[Y] -5.993999 -5.993999 5.999993e+00 5.999993
[7]:
get_summarized_sensitivities()
[7]:
0
(R1).k1 1.413507
(R2).k1 0.999001
(R3).k1 1.000000
(R4).k1 1.413507

Convenience overloads exist, so that the settings can directly be passed on to the run method. If run_first=True is given to the functions retrieving the result, the sensitivities will be computed before obtaining the result.

So for example, if we just wanted to see how the initial concentration of A would affect the transient concentration of X, we could directly call:

[8]:
get_scaled_sensitivities(run_first=True, settings={'effect': '[X]', 'cause': '[A]_0'})
[8]:
1.0000000000004075

To see what effect it would have on all metabolite concentrations:

[9]:
get_scaled_sensitivities(run_first=True,
                         settings={'effect': SENS.NON_CONST_METAB_CONCENTRATIONS,
                                   'cause': '[A]_0'})
[9]:
0
[X] 1.000000
[Y] -0.999001

The changed settings of the last run will persist, so that it can be reproduced in the COPASI user interface as well:

[10]:
get_sensitivity_settings()
[10]:
{'scheduled': False,
 'update_model': False,
 'method': {'Delta factor': 0.001,
  'Delta minimum': 1e-12,
  'name': 'Sensitivities Method'},
 'report': {'filename': '',
  'report_definition': 'Sensitivities',
  'append': True,
  'confirm_overwrite': False},
 'sub_task': 'Steady State',
 'effect': 'Non-Constant Concentrations of Species',
 'cause': '[A]_0',
 'secondary_cause': 'Not Set'}