7.1.1.2.1.4. pta.sampling.tfs

Thermodynamics-based sampling of free energies, concentrations and fluxes.

7.1.1.2.1.4.1. Module Contents

class pta.sampling.tfs.TFSModel(network: Union[cobra.Model, pta.flux_space.FluxSpace], thermodynamic_space: pta.thermodynamic_space.ThermodynamicSpace, thermodynamic_space_basis: pta.thermodynamic_space.ThermodynamicSpaceBasis = None, confidence_level: float = 0.95, min_drg: float = 0.1, max_drg: float = 1000, solver: Optional[str] = None, solver_options: dict = None)[source]

Bases: pta.sampling.commons.SamplerInterface

Object holding the information necessary to run TFS.

Parameters:
  • network (Union[cobra.Model, FluxSpace]) – Cobra model or FluxSpace object describing the flux space of the metabolic network.

  • thermodynamic_space (ThermodynamicSpace) – Description of the thermodynamic space of the metabolic network.

  • thermodynamic_space_basis (ThermodynamicSpaceBasis, optional) – A basis for the thermodynamic space. If specified, m will be defined in this basis.

  • objective (Callable[ [PmoProblem], cp.problems.objective.Objective], optional) – A function used to set the optimization objective. By default the probability of in thermodynamic space is maximized.

  • confidence_level (float, optional) – Confidence level (in the range \([0.0, 1.0[\)) on the joint of the thermodynamic variables, by default 0.95.

  • min_drg (float, optional) – Minimum magnitude for the reaction energy of each reaction, by default 1e-1.

  • max_drg (float, optional) – Maximum magnitude for the reaction energy of each reaction, by default 1000.

  • solver (Optional[str], optional) – Name of the solver to use, this can be any of the solvers supported by CVXPY, by default None.

  • solver_options (dict, optional) – Dictionary specifying additional options for the solver.

property T: pta.thermodynamic_space.ThermodynamicSpace[source]

Gets the thermodynamic space used for sampling.

property F: pta.flux_space.FluxSpace[source]

Gets the flux space used for sampling.

property B: pta.thermodynamic_space.ThermodynamicSpaceBasis[source]

Gets the basis of the thermodynamic space used for sampling.

property pmo_args[source]

Gets the arguments used to construct PMO problems.

property dimensionality: int[source]

Gets the dimensionality of the basis of the thermodynamic space.

property confidence_radius[source]

Gets the radius of the selected confidence region.

property drg_epsilon[source]

Gets the minimum magnitude of the reaction energy of irreversible reactions.

property reversible_rxn_ids[source]

Gets the identifiers of the reversible reactions in the thermodynamic space.

get_reversible_reactions_ids_T() List[source]

Get the ids of the reversible reactions in the thermodynamic space

Returns:

The corresponding reactions ids

Return type:

List

to_drg(value: numpy.ndarray) numpy.ndarray[source]

Transform a point or matrix from the the basis to reaction energies.

Parameters:

value (np.ndarray) – Input values in the basis.

Returns:

The corresponding reaction energies.

Return type:

np.ndarray

simulate(settings: _pta_python_binaries.SamplerSettings, initial_points: numpy.ndarray, directions_transform: numpy.ndarray) _pta_python_binaries.TFSResult[source]

Run the sampler with the given parameters.

Parameters:
  • settings (pb.SamplerSettings) – Sampling settings.

  • initial_points (np.ndarray) – The initial points for the chains.

  • directions_transform (np.ndarray) – The transform for the directions sampler.

compute_psrf(result: _pta_python_binaries.TFSResult) pandas.Series[source]

Compute the potential scale reduction factors for the variables of interest on a given set of chains.

Parameters:

result (pb.TFSResult) – The result of the sampling function.

Returns:

The computed potential scale reduction factors.

Return type:

pd.Series

get_chains(result: _pta_python_binaries.TFSResult) numpy.ndarray[source]

Extract the simulated chains from a given result.

Parameters:

result (pb.TFSResult) – The result of the native sampling function.

Returns:

The simulated chains.

Return type:

np.ndarray

get_initial_points(num_points: int) numpy.ndarray[source]

Gets initial points for sampling reaction energies.

Parameters:

num_points (int) – Number of initial points to generate.

Returns:

Array containing the initial points.

Return type:

np.ndarray

class pta.sampling.tfs.FreeEnergiesSamplingResult(samples: pandas.DataFrame, psrf: pandas.Series, orthants: pandas.DataFrame, basis_samples: pandas.DataFrame = None, chains: numpy.ndarray = None)[source]

Bases: pta.sampling.commons.SamplingResult

Encapsulates the result of sampling reaction energies.

Parameters:
  • samples (pd.DataFrame) – Data frame containing the free energy samples.

  • psrf (pd.Series) – The Potential Scale Reduction Factors of each variable.

  • orthants (pd.DataFrame) – Data frame containing the signs of the reversible reactions for each orthants. Contains an additional column (“weight”) describing the weight of the orthant.

  • basis_samples (pd.DataFrame, optional) – The samples in the basis.

  • chains (np.ndarray, optional) – The simulated chains.

property orthants: pandas.DataFrame[source]

Gets a data frame containing the sampled orthants. Contains an additional column (“weight”) describing the weight of the orthant.

pta.sampling.tfs.sample_drg(model: TFSModel, num_samples: int = default_num_samples, num_direction_samples: int = default_num_samples, max_steps: int = -1, max_psrf: float = default_max_psrf, num_chains: int = -1, initial_points: numpy.ndarray = None, num_initial_steps: int = -1, feasibility_cache_size: int = tfs_default_feasibility_cache_size, min_rel_region_length: float = tfs_default_min_rel_region_length, max_threads: int = default_max_threads, convergence_manager: pta.sampling.convergence_manager.ConvergenceManager = None) FreeEnergiesSamplingResult[source]

Sample reaction energies under steady state flux constraints in the given model.

Parameters:
  • model (TFSModel) – The model to sample.

  • num_samples (int, optional) – Number of samples to draw.

  • num_direction_samples (int, optional) – Number of orthant samples to collect.

  • max_steps (int, optional) – The maximum number fo steps to simulate.

  • max_psrf (float, optional) – Maximum value of the PSRFs for convergence.

  • num_chains (int, optional) – The number of chains to simulate.

  • initial_points (np.ndarray, optional) – The initial points for the chains.

  • num_initial_steps (int, optional) – Initial chains length.

  • feasibility_cache_size (int, optional) – Maximum size of the cache storing the feasibility of the orthants encountered during the random walk.

  • min_rel_region_length (float, optional) – Minimum length (relative to the length of the entire ray) of a segment in order to consider it for sampling.

  • max_threads (int, optional) – The maximum number of parallel threads to use.

  • convergence_manager (ConvergenceManager, optional) – The object to use to monitor and improve convergence.

Returns:

The sampling result.

Return type:

FreeEnergiesSamplingResult

Raises:

SamplingException – If sampling fails.

pta.sampling.tfs.sample_log_conc_from_drg(thermodynamic_space: pta.thermodynamic_space.ThermodynamicSpace, drg_samples: pandas.DataFrame, min_eigenvalue: float = default_min_eigenvalue_tds_basis) pandas.DataFrame[source]

Sample the natural logarithm of the metabolite concentrations conditioned on samples of free energies. This function draws one sample for each sample of reaction energies.

Parameters:
  • thermodynamic_space (ThermodynamicSpace) – The thermodynamic space of the network.

  • drg_samples (pd.DataFrame) – Data frame containing the samples of reaction energies.

  • min_eigenvalue (float, optional) – Minimum eigenvalue to keep when performing the truncated SVD of the covariance of the conditional probability.

Returns:

Data frame containing the log-concentration samples.

Return type:

pd.DataFrame

pta.sampling.tfs.sample_drg0_from_drg(thermodynamic_space: pta.thermodynamic_space.ThermodynamicSpace, drg_samples: pandas.DataFrame, min_eigenvalue: float = default_min_eigenvalue_tds_basis) pandas.DataFrame[source]

Sample standard reaction energies conditioned on samples of reaction energies. This function draws one sample for each sample of reaction energies.

Parameters:
  • thermodynamic_space (ThermodynamicSpace) – The thermodynamic space of the network.

  • drg_samples (pd.DataFrame) – Data frame containing the samples of reaction energies.

  • min_eigenvalue (float, optional) – Minimum eigenvalue to keep when performing the truncated SVD of the covariance of the conditional probability.

Returns:

Data frame containing the standard reaction energy samples.

Return type:

pd.DataFrame

pta.sampling.tfs.sample_fluxes_from_drg(model: cobra.Model, drg_samples: pandas.DataFrame, orthants: pandas.DataFrame, num_approx_samples: int = default_num_samples) pandas.DataFrame[source]

Sample the flux space using the samples of orthant of reaction energies and orthants as prior. For each unique orthant implied by the reaction energy samples, this function draws a number of uniform flux samples proportional to the probability of the orthant in the thermodynamic space.

Parameters:
  • model (cobra.Model) – cobrapy model describing the flux space.

  • drg_samples (pd.DataFrame) – The input reaction energy samples.

  • orthants (pd.DataFrame) – Data frame containing the sampled orthants and their weights.

  • num_approx_samples (int, optional) – Approximate number of samples to draw.

Returns:

Data frame containing the flux samples.

Return type:

pd.DataFrame