6.1.1.1.1.3. pytfa.analysis.sampling

Sampling wrappers for pytfa models

6.1.1.1.1.3.1. Module Contents

6.1.1.1.1.3.1.1. Classes

GeneralizedHRSampler

The abstract base class for hit-and-run samplers.

GeneralizedACHRSampler

The abstract base class for hit-and-run samplers.

GeneralizedOptGPSampler

The abstract base class for hit-and-run samplers.

6.1.1.1.1.3.1.2. Functions

sample(model, n, method='optgp', thinning=100, processes=1, seed=None)

Sample valid flux distributions from a thermo cobra_model.

class pytfa.GeneralizedHRSampler(model, thinning, nproj=None, seed=None)

Bases: cobra.sampling.HRSampler

The abstract base class for hit-and-run samplers.

New samplers should derive from this class where possible to provide a uniform interface.

modelcobra.Model

The cobra model from which to generate samples.

thinningint

The thinning factor of the generated sampling chain. A thinning of 10 means samples are returned every 10 steps.

nprojint > 0, optional

How often to reproject the sampling point into the feasibility space. Avoids numerical issues at the cost of lower sampling. If you observe many equality constraint violations with sampler.validate you should lower this number (default None).

seedint > 0, optional

Sets the random number seed. Initialized to the current time stamp if None (default None).

feasibility_tol: float

The tolerance used for checking equalities feasibility.

bounds_tol: float

The tolerance used for checking bounds feasibility.

n_samplesint

The total number of samples that have been generated by this sampler instance.

retriesint

The overall of sampling retries the sampler has observed. Larger values indicate numerical instabilities.

problemProblem

A NamedTuple whose attributes define the entire sampling problem in matrix form.

warmupnumpy.matrix

A numpy matrix with as many columns as reactions in the model and more than 3 rows containing a warmup sample in each row. None if no warmup points have been generated yet.

fwd_idxnumpy.array

A numpy array having one entry for each reaction in the model, containing the index of the respective forward variable.

rev_idxnumpy.array

A numpy array having one entry for each reaction in the model, containing the index of the respective reverse variable.

generate_fva_warmup(self)

Generate the warmup points for the sampler.

Generates warmup points by setting each flux as the sole objective and minimizing/maximizing it. Also caches the projection of the warmup points into the nullspace for non-homogeneous problems (only if necessary).

class pytfa.GeneralizedACHRSampler(model, thinning=100, seed=None)

Bases: GeneralizedHRSampler, cobra.sampling.ACHRSampler

The abstract base class for hit-and-run samplers.

New samplers should derive from this class where possible to provide a uniform interface.

modelcobra.Model

The cobra model from which to generate samples.

thinningint

The thinning factor of the generated sampling chain. A thinning of 10 means samples are returned every 10 steps.

nprojint > 0, optional

How often to reproject the sampling point into the feasibility space. Avoids numerical issues at the cost of lower sampling. If you observe many equality constraint violations with sampler.validate you should lower this number (default None).

seedint > 0, optional

Sets the random number seed. Initialized to the current time stamp if None (default None).

feasibility_tol: float

The tolerance used for checking equalities feasibility.

bounds_tol: float

The tolerance used for checking bounds feasibility.

n_samplesint

The total number of samples that have been generated by this sampler instance.

retriesint

The overall of sampling retries the sampler has observed. Larger values indicate numerical instabilities.

problemProblem

A NamedTuple whose attributes define the entire sampling problem in matrix form.

warmupnumpy.matrix

A numpy matrix with as many columns as reactions in the model and more than 3 rows containing a warmup sample in each row. None if no warmup points have been generated yet.

fwd_idxnumpy.array

A numpy array having one entry for each reaction in the model, containing the index of the respective forward variable.

rev_idxnumpy.array

A numpy array having one entry for each reaction in the model, containing the index of the respective reverse variable.

class pytfa.GeneralizedOptGPSampler(model, processes, thinning=100, seed=None)

Bases: GeneralizedHRSampler, cobra.sampling.OptGPSampler

The abstract base class for hit-and-run samplers.

New samplers should derive from this class where possible to provide a uniform interface.

modelcobra.Model

The cobra model from which to generate samples.

thinningint

The thinning factor of the generated sampling chain. A thinning of 10 means samples are returned every 10 steps.

nprojint > 0, optional

How often to reproject the sampling point into the feasibility space. Avoids numerical issues at the cost of lower sampling. If you observe many equality constraint violations with sampler.validate you should lower this number (default None).

seedint > 0, optional

Sets the random number seed. Initialized to the current time stamp if None (default None).

feasibility_tol: float

The tolerance used for checking equalities feasibility.

bounds_tol: float

The tolerance used for checking bounds feasibility.

n_samplesint

The total number of samples that have been generated by this sampler instance.

retriesint

The overall of sampling retries the sampler has observed. Larger values indicate numerical instabilities.

problemProblem

A NamedTuple whose attributes define the entire sampling problem in matrix form.

warmupnumpy.matrix

A numpy matrix with as many columns as reactions in the model and more than 3 rows containing a warmup sample in each row. None if no warmup points have been generated yet.

fwd_idxnumpy.array

A numpy array having one entry for each reaction in the model, containing the index of the respective forward variable.

rev_idxnumpy.array

A numpy array having one entry for each reaction in the model, containing the index of the respective reverse variable.

pytfa.sample(model, n, method='optgp', thinning=100, processes=1, seed=None)

Sample valid flux distributions from a thermo cobra_model.

Function adapted from cobra.flux_analysis.sample to display all solver variables

Documentation adapted from cobra.flux_analysis.sample

  1. ‘optgp’ (default) which uses the OptGPSampler that supports parallel

    analysis 1. Requires large numbers of samples to be performant (n < 1000). For smaller samples ‘achr’ might be better suited.

or

  1. ‘achr’ which uses artificial centering hit-and-run. This is a single process method with good convergence 2.

modelpytfa.core.ThermoModel

The cobra_model from which to sample variables.

nint

The number of samples to obtain. When using ‘optgp’ this must be a multiple of processes, otherwise a larger number of samples will be returned.

methodstr, optional

The analysis algorithm to use.

thinningint, optional

The thinning factor of the generated analysis chain. A thinning of 10 means samples are returned every 10 steps. Defaults to 100 which in benchmarks gives approximately uncorrelated samples. If set to one will return all iterates.

processesint, optional

Only used for ‘optgp’. The number of processes used to generate samples.

seedpositive integer, optional

The random number seed to be used. Initialized to current time stamp if None.

pandas.DataFrame

The generated flux samples. Each row corresponds to a sample of the fluxes and the columns are the reactions.

The samplers have a correction method to ensure equality feasibility for long-running chains, however this will only work for homogeneous models, meaning models with no non-zero fixed variables or constraints ( right-hand side of the equalities are zero).

1

Megchelenbrink W, Huynen M, Marchiori E (2014) optGpSampler: An Improved Tool for Uniformly Sampling the Solution-Space of Genome-Scale Metabolic Networks. PLoS ONE 9(2): e86587.

2

Direction Choice for Accelerated Convergence in Hit-and-Run Sampling David E. Kaufman Robert L. Smith Operations Research 199846:1 , 84-95