6.1.1.1. pytfa.analysis
¶
6.1.1.1.1. Submodules¶
6.1.1.1.2. Package Contents¶
6.1.1.1.2.1. Classes¶
The abstract base class for hit-and-run samplers. |
|
The abstract base class for hit-and-run samplers. |
|
The abstract base class for hit-and-run samplers. |
|
Class to represent a DeltaG |
|
Class to represent a forbidden net flux directionality profile |
|
Class to represent a forward use variable, a type of binary variable used to |
6.1.1.1.2.2. Functions¶
|
Sample valid flux distributions from a thermo cobra_model. |
|
Returns the active use variables in a solution. Use Variables are binary |
|
Sets up a logger that outputs INFO+ messages on stdout and DEBUG+ messages |
|
Returns the ids of reactions that can both carry net flux in the forward or |
|
Takes a ThermoModel and performs enumeration of the directionality profiles |
|
turns a list of booleans into a string |
|
|
|
Performs variability analysis, gicven a variable type |
|
WIP. |
|
|
|
Applies the VA results as bounds for the reactions of a cobra_model |
|
Reactions a dealt with cobra, but the other variables added use pytfa's |
|
Takes a flux solution and transfers its reaction directionality as |
6.1.1.1.2.3. Attributes¶
- class pytfa.analysis.GeneralizedHRSampler(model, thinning, nproj=None, seed=None)[source]¶
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.analysis.GeneralizedACHRSampler(model, thinning=100, seed=None)[source]¶
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.analysis.GeneralizedOptGPSampler(model, processes, thinning=100, seed=None)[source]¶
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.analysis.sample(model, n, method='optgp', thinning=100, processes=1, seed=None)[source]¶
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
- ‘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
‘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
- class pytfa.analysis.DeltaG(reaction, **kwargs)¶
Bases:
ReactionVariable
Class to represent a DeltaG
- prefix = DG_¶
- class pytfa.analysis.ForbiddenProfile(model, expr, id_, **kwargs)¶
Bases:
GenericConstraint
Class to represent a forbidden net flux directionality profile Looks like: FU_rxn_1 + BU_rxn_2 + … + FU_rxn_n <= n-1
- prefix = FP_¶
- pytfa.analysis.get_direction_use_variables(tmodel, solution)¶
Returns the active use variables in a solution. Use Variables are binary variables that control the directionality of the reaction The difference with get_active_use_variables is that variables with both UseVariables at 0 will return as going forwards. This is to ensure that the output size of the function is equal to the number of FDPs
ex: FU_ACALDt BU_PFK
- Parameters
tmodel (pytfa.core.ThermoModel) –
solution –
- Returns
- class pytfa.analysis.ForwardUseVariable(reaction, **kwargs)¶
Bases:
ReactionVariable
,BinaryVariable
Class to represent a forward use variable, a type of binary variable used to enforce forward directionality in reaction net fluxes
- prefix = FU_¶
- pytfa.analysis.get_bistream_logger(name)¶
Sets up a logger that outputs INFO+ messages on stdout and DEBUG+ messages in the log file
- Parameters
name – a class __name__ attribute
- Returns
- pytfa.analysis.find_bidirectional_reactions(va, tolerance=1e-08)[source]¶
Returns the ids of reactions that can both carry net flux in the forward or backward direction.
- Parameters
va –
- A variability analysis, pandas Dataframe like so:
maximum minimum
6PGLter -8.330667e-04 -8.330667e-04 ABUTt2r 0.000000e+00 0.000000e+00 ACALDt 0.000000e+00 0.000000e+00
- Returns
- pytfa.analysis.find_directionality_profiles(tmodel, bidirectional, max_iter=10000.0, solver='optlang-glpk')[source]¶
Takes a ThermoModel and performs enumeration of the directionality profiles
- Parameters
tmodel –
max_iter –
- Returns
- pytfa.analysis._bool2str(bool_list)[source]¶
turns a list of booleans into a string
- Parameters
bool_list – ex: ‘[False True False False True]’
- Returns
‘01001’
- pytfa.analysis.variability_analysis(tmodel, kind='reactions', proc_num=BEST_THREAD_RATIO)[source]¶
Performs variability analysis, gicven a variable type
- Parameters
tmodel –
kind –
proc_num –
- Returns
- pytfa.analysis.parallel_variability_analysis(tmodel, kind='reactions', proc_num=BEST_THREAD_RATIO)[source]¶
WIP.
- Parameters
tmodel –
kind –
proc_num –
- Returns
- pytfa.analysis.apply_reaction_variability(tmodel, va, inplace=True)[source]¶
Applies the VA results as bounds for the reactions of a cobra_model :param inplace: :param tmodel: :param va: :return: