6. Sampling thermodynamics and fluxes

Thermodynamics and Flux Sampling (TFS) allows to sample steady state reaction energies, standard reaction energies, metabolite concentrations and fluxes in a metabolic network.

TFS consists in two main steps:

  1. Sample reaction energies and orthants (sets of reaction directions in the model).

  2. Sample standard reaction energies, metabolite concentrations and reaction fluxes conditioned on the sampled reaction energies and orthants.

6.1. Sampling reaction energies

The first step is to sample reaction energies and estimate the probability of the orthants of the thermodynamic space:

1# Wrap a cobrapy model and the corresponding thermodynamic space in a single object.
2tfs_model = pta.TFSModel(model, thermodynamic_space)
3
4# Sample the thermodynamic space.
5result = pta.sample_drg(tfs_model)

The result object contains the following fields:

  • samples: Pandas data frame containing the samples of reaction energies.

  • orthants: Pandas data frame containing the signs (-1 / +1) of the sampled orthants. An additional column weight stores the weight of each orthant.

  • psrf Pandas series containing the Potential Scale Reduction Factor (PSRF) of each reaction energy. This is only used to assess convergence of the sampling procedure.

Note that the space of steady state reaction energies is generally non-convex and disconnected, thus convergence can take a high number of steps. While PTA tries to automatically choose a good number of steps, this may not be sufficient for challenging models and you may get a warning that sampling did not converge. In this case you should manually tell sample_drg() to use more steps using the num_steps option.

6.2. Sampling the conditionals

The remaining quantities can be sampled from the reaction energies:

 1# Sample the natural logarithm of the metabolite concentrations. This function draws
 2# one concentration sample for each reaction energy sample.
 3log_conc = sample_log_conc_from_drg(thermodynamic_space, result.samples)
 4
 5# Sample the standard reaction energies. This function draws one standard reaction
 6# energy sample for each reaction energy sample.
 7drg0 = sample_drg0_from_drg(thermodynamic_space, result.samples)
 8
 9# Sample reaction fluxes. For each unique orthant represented by the reaction energy
10# samples this function draws a number of flux samples proportional to the weight of
11# the orthant.
12fluxes = sample_fluxes_from_drg(model, result.samples, result.orthants)

Each function returns a Pandas data frame containing the samples. For concentrations and standard reaction energies, PTA can use an analytical expression of the conditional probability, which makes sampling very fast. However, for fluxes we need to run uniform sampling on each orthant separately, which can take a long time for medium-large models. If sampling fluxes takes too long, pass fewer reaction energy samples to reduce the number of orthants sampled.