Analysis#
MATLAB functions in RAVEN/src/analysis of the RAVEN toolbox.
Functions#
Function |
Summary |
|---|---|
Compare flux change significance with expression change. |
|
Find the most significant flux changes between two conditions. |
|
Delete genes and track the resulting fluxes. |
|
Flux Scanning based on Enforced Objective Flux. |
|
Return the minimal and maximal fluxes through reactions. |
|
Get all metabolic subgraphs in a model. |
|
Calculate the essential reactions for a solvable model. |
|
Calculate Z scores between two sets of random flux distributions. |
|
Find the minimal set of uptake reactions for growth. |
|
Check which reactions can carry a flux. |
|
Sample the flux solution space (entry point for all samplers). |
|
Identify metabolites around which transcriptional changes occur. |
|
Perform dynamic FBA using the static optimization approach. |
|
Run phenotype phase plane analysis and plot the results. |
|
Calculate the byproduct secretion envelope. |
|
Perform robustness analysis for a reaction and objective. |
|
Simple OptKnock for growth-coupled production. |
|
Artificially Centered Hit-and-Run flux sampling. |
|
Centre of the largest ball inscribed in a polytope. |
|
Coordinate Hit-and-Run with Rounding flux sampling. |
|
Maximum-volume inscribed ellipsoid of a polytope. |
|
FVA warmup vertices for ACHR sampling. |
|
Find the highest-flux-fraction path between two reactions. |
|
Interactively navigate a flux distribution reaction by reaction. |
Reference#
analyzeSampling#
function scores=analyzeSampling(Tex, df, solutionsA, solutionsB, varargin)
Compare flux change significance with expression change.
Compares the significance of change in flux between two conditions with the significance of change in gene expression.
Parameters
Tex: doublea vector of t-scores for the change in gene expression for each reaction. This score could be the Student t between the two conditions, or you can calculate it from a p-value (by computing the inverse of the so called error function). If you choose the second alternative you should be aware that the transcripts that increased in expression level should have positive values and those who decreased in expression level should have negative values (the p-values only tell you if the fluxes changed or not but not in which direction).
df: doublethe degrees of freedom in the t-test.
solutionsA: doublerandom solutions for the reference condition (as generated by randomSampling).
solutionsB: doublerandom solutions for the test condition (as generated by randomSampling).
Name-Value Arguments
printResults: logicalprints the most significant reactions in each category (default false).
Returns
scores: doublea Nx3 column matrix with the probabilities of a reaction:
changing both in flux and expression in the same direction
changing in expression but not in flux
changing in flux but not in expression or changing in opposed directions in flux and expression
Examples
scores = analyzeSampling(Tex, df, solutionsA, solutionsB, ...
printResults);
compareFluxes#
function result = compareFluxes(model, fluxes1, fluxes2, varargin)
Find the most significant flux changes between two conditions.
Compares two flux vectors from the same model and returns all reactions that changed, sorted by absolute flux difference. Classifies reactions as turned on, turned off, reversed direction, or changed magnitude.
Parameters
model: structRAVEN model structure.
fluxes1: doublereference flux vector (condition A, e.g. wild-type).
fluxes2: doublecomparison flux vector (condition B, e.g. mutant or knockin).
Name-Value Arguments
cutoff: doubleminimum |flux| to consider a reaction active (default 1e-8).
metaboliteList: cellcell array of metabolite names. Only reactions involving at least one of these metabolites are compared; every other reaction is left out of the result entirely. Matching is against model.metNames and is case insensitive. A name that matches no metabolite is reported as a warning rather than an error (default all reactions).
nMax: doublemaximum rows printed in the summary table (default 20).
verbose: logicalprint the summary table (default true).
Returns
result: struct.turnedOn — cell, rxn IDs newly active in fluxes2 .turnedOff — cell, rxn IDs silenced in fluxes2 .flipped — cell, rxn IDs that reversed sign between conditions .changed — struct with fields (all reactions with |dflux|>cutoff, sorted by |dflux| descending): .rxn — cell of reaction IDs .flux1 — double, flux in condition A .flux2 — double, flux in condition B .absDelta — double, |flux2 - flux1| .relChange — double, (flux2-flux1)/|flux1|; NaN when flux1 is near-zero (reaction emerged) .type — cell, 'on'|'off'|'flip'|'' per reaction
Examples
solA = solveLP(model);
modelAna = setParam(model, 'ub', 'O2exchange', 0);
solB = solveLP(modelAna);
result = compareFluxes(model, solA.x, solB.x)
result = compareFluxes(model, solA.x, solB.x, 'nMax', 50)
result = compareFluxes(model, solA.x, solB.x, 'metaboliteList', {'ATP','NADH'})
See also
walkFluxes, traceFluxPath, modelSummary
findGeneDeletions#
function [genes, fluxes, originalGenes, details, grRatioMuts]=findGeneDeletions(model,varargin)
Delete genes and track the resulting fluxes.
Deletes genes, optimizes the model by FBA, and keeps track of the resulting fluxes. This is used for identifying gene deletion targets.
Parameters
model: structa model structure.
Name-Value Arguments
testType: charsingle/double gene deletion (default "sgd"):
"sgd" : single gene deletion
"dgd" : double gene deletion
Returns
genes: doublea matrix with the genes that were deleted in each optimization (the gene indexes in originalGenes). Each row corresponds to a column in fluxes.
fluxes: doublea matrix with the resulting fluxes. Double deletions that result in an unsolvable problem have all zero flux. Single deletions that result in an unsolvable problem are indicated in details instead.
originalGenes: cellsimply the genes in the input model. Included for simple presentation of the output.
details: doublenot all genes will be deleted in all analyses. It is for example not necessary to delete genes for dead end reactions. This is a vector with details about each gene in originalGenes and why or why not it was deleted:
1 : was deleted, and the problem was solved (a lethal deletion with zero growth also gets 1)
2 : the single-deletion problem had no optimal solution (infeasible or failed); fluxes and grRatioMuts are 0
3 : redundant, no longer used
4 : involved in dead-end reaction
grRatioMuts: doublegrowth rate ratio between mutated strain and wild type, matching the originalGenes(genes) mutants. Note that this does not directly map to model.genes, as is the case for COBRA getEssentialGenes. However, this can be obtained by afterwards running:
grRatio=zeros(1,numel(model.genes)); grRatio(genes)=grRatioMuts;
Examples
[genes, fluxes, originalGenes, details, grRatioMuts]=...
findGeneDeletions(model,testType);
FSEOF#
function targets=FSEOF(model,biomassRxn,targetRxn,varargin)
Flux Scanning based on Enforced Objective Flux.
Implements the Flux Scanning based on Enforced Objective Flux algorithm. This function writes a tab-delimited file or prints to the command window. If an output has been specified (targets), it will also generate a structure indicating for each model reaction whether it is identified by FSEOF as a target and the slope of the reaction when switching from biomass formation to product formation.
Parameters
model: structa model structure.
biomassRxn: charreaction ID of the biomass formation or growth reaction.
targetRxn: charreaction ID of the target reaction.
Name-Value Arguments
iterations: doublenumber of iterations (default 10).
coefficient: doubleratio of optimal target reaction flux, must be less than 1 (default 0.9).
outputFile: charoutput filename (default prints to command window).
corrThreshold: doubleminimum absolute Pearson correlation coefficient between a reaction absolute flux and the enforced product flux for the reaction to be selected as a target. Values in [0, 1]; higher values require a more linear response and suppress LP alternative- optima noise (default 0.9).
Returns
targets: structstructure with information for identified targets, with fields:
logical : logical array, true for amplification targets (backward compatible alias for amplify).
amplify : logical array, reactions whose absolute flux increases with enforced product flux.
knockdown : logical array, reactions driven toward but not to zero.
knockout : logical array, reactions driven to zero at max product.
slope : numeric array with per-reaction regression slopes of absolute flux versus enforced product flux (all reactions, not just targets).
Examples
targets = FSEOF(model, biomassRxn, targetRxn, iterations, ...
coefficient, outputFile);
getAllowedBounds#
function [minFluxes, maxFluxes, exitFlags]=getAllowedBounds(model,varargin)
Return the minimal and maximal fluxes through reactions.
Parameters
model: structa model structure.
Name-Value Arguments
rxns: cell or logical or doubleeither a cell array of reaction IDs, a logical vector with the same number of elements as reactions in the model, or a vector of reaction indexes (default model.rxns).
runParallel: logicalspeed up calculations by parallel processing. This is not beneficial if allowed bounds are calculated for only a few reactions, as the overhead of parallel processing will take longer. It requires MATLAB Parallel Computing Toolbox. If this is not installed, the calculations will not be parallelized, regardless of what is indicated as runParallel (default true).
Returns
minFluxes: doubleminimal allowed fluxes.
maxFluxes: doublemaximal allowed fluxes.
exitFlags: doubleexit flags for min/max for each of the reactions. True if it was possible to calculate a flux.
Notes
In cases where no solution can be calculated, NaN is returned.
Examples
[minFluxes, maxFluxes, exitFlags] = getAllowedBounds(model, rxns, runParallel);
getAllSubGraphs#
function subGraphs=getAllSubGraphs(model)
Get all metabolic subgraphs in a model.
Two metabolites are connected if they share a reaction.
Parameters
model: structa model structure.
Returns
subGraphs: logicala boolean matrix where the rows correspond to the metabolites and the columns to which subgraph they are assigned to. The columns are ordered so that larger subgraphs come first.
Examples
subGraphs = getAllSubGraphs(model);
getEssentialRxns#
function [essentialRxns, essentialRxnsIndexes]=getEssentialRxns(model,varargin)
Calculate the essential reactions for a solvable model.
Parameters
model: structa model structure.
Name-Value Arguments
ignoreRxns: cellcell array of reaction IDs which should not be checked (default {}).
Returns
essentialRxns: cellcell array with the IDs of the essential reactions.
essentialRxnsIndexes: doublevector with the indexes of the essential reactions.
Notes
Essential reactions are those which, when constrained to 0, result in an infeasible problem.
Examples
[essentialRxns, essentialRxnsIndexes] = getEssentialRxns(model, ignoreRxns);
getFluxZ#
function Z=getFluxZ(solutionsA, solutionsB)
Calculate Z scores between two sets of random flux distributions.
Parameters
solutionsA: doublerandom solutions for the reference condition (as generated by randomSampling).
solutionsB: doublerandom solutions for the test condition (as generated by randomSampling).
Returns
Z: doublea vector with Z-scores that tells you for each reaction how likely it is for its flux to have increased (positive sign) or decreased (negative sign) in the second condition with respect to the first.
Examples
Z = getFluxZ(solutionsA, solutionsB);
See also
randomSampling
getMinimalMedium#
function [medium, mediumIdx] = getMinimalMedium(model, varargin)
Find the minimal set of uptake reactions for growth.
Uses MILP to find the smallest set of exchange reactions that can carry uptake flux (lb < 0) while still allowing the model to achieve a target growth rate. Unlike iterative heuristics, the MILP formulation finds the globally minimal medium.
Parameters
model: structRAVEN model structure.
Name-Value Arguments
minGrowth: doubleminimum objective value (growth rate) the medium must support. Defaults to 10 % of the unconstrained optimum computed automatically. Set explicitly to avoid an extra FBA call (e.g. 'minGrowth', 0.1).
verbose: logicalprint the resulting minimal medium (default true).
Returns
medium: cellcell array of reaction IDs that form the minimal medium. Empty if no feasible medium can support the requested growth.
mediumIdx: doublecolumn vector of reaction indices corresponding to medium.
Examples
[med, idx] = getMinimalMedium(model)
[med, idx] = getMinimalMedium(model, 'minGrowth', 0.05)
[med, idx] = getMinimalMedium(model, 'verbose', false)
Notes
Only exchange reactions with lb < 0 are considered as candidate uptake reactions. Exchange reactions that are always secretion-only (lb >= 0) or that are completely blocked are not included.
The MILP formulation: minimise sum(y_i) s.t. S v = 0 c' v >= minGrowth v_i >= lb_i * y_i for each candidate uptake reaction i lb_j <= v_j <= ub_j for all reactions j y_i in {0, 1}
A y_i = 0 forces reaction i to carry non-negative flux (no net uptake); y_i = 1 allows it to carry flux as low as lb_i.
The minimal number of uptakes is guaranteed, but the medium itself need not be unique: when several media of the same size support the growth rate, the solver returns one of them, and another solver or solver version can return a different one.
The MILP is solved with the solver set by setRavenSolver. RAVEN's bundled GLPK solves it for small models (with a RAVEN:glpkMILP warning); for larger models Gurobi is much faster and more reliable (setRavenSolver('gurobi')).
haveFlux#
function I=haveFlux(model,varargin)
Check which reactions can carry a flux.
Checks which reactions can carry a (positive or negative) flux under the model's current bounds; other media or bounds are not explored. Is used as a faster version of getAllowedBounds if it is only interesting whether the reactions can carry a flux or not.
Parameters
model: structa model structure.
Name-Value Arguments
cutOff: doublethe flux value that a reaction has to carry to be identified as positive (default 10^-6).
rxns: cell or logical or doubleeither a cell array of IDs, a logical vector with the same number of elements as metabolites in the model, or a vector of indexes (default model.rxns).
seed: doubleseed for the random number generator used to shuffle the order in which reactions are tested, so that order is reproducible across runs (default: current rng state is left untouched).
Returns
I: logicallogical array with true if the corresponding reaction can carry a flux under the tested bounds.
Examples
I = haveFlux(model, cutOff, rxns);
Notes
If a model has +/- Inf bounds then those are replaced with an arbitary large value of +/- 10000 prior to solving.
Dead-end reactions are removed (simplifyModel) before solving. A dead-end reaction with a forced flux (lb > 0 or ub < 0) makes the model infeasible, but it is removed like any other dead end, so the remaining reactions are tested as if it were absent. A forced flux elsewhere in an infeasible model gives false for all reactions.
randomSampling#
function [solutions, goodRxns, info]=randomSampling(model,varargin)
Sample the flux solution space (entry point for all samplers).
Dispatches to one of three sampling methods via the 'method' argument: 'achr' (default) Artificially Centered Hit-and-Run; near-uniform MCMC sampling of the polytope interior (see sampleACHR). 'chrr' Coordinate Hit-and-Run with Rounding; near-uniform MCMC with maximum-volume-ellipsoid rounding, for better mixing on thin/ill-conditioned polytopes such as enzyme- constrained models (see sampleCHRR). 'randomObjective' the random-objective vertex method of Bordel et al. (2010) PLoS Comput Biol (doi:10.1371/journal.pcbi.1000859): each sample maximises a small random objective, returning a polytope vertex.
The 'achr'/'chrr' methods draw the (near-)uniform interior distribution; the 'randomObjective' method draws diverse vertices. Arguments below marked [randomObjective] apply only to that method; 'thinning'/'nBurnin' apply only to the MCMC methods.
Parameters
model: structa model structure.
Name-Value Arguments
nSamples: doublethe number of solutions to return (default 1000).
method: charsampling method: 'achr' (default), 'chrr', or 'randomObjective'.
thinning: doubleMCMC steps between recorded samples for 'achr'/'chrr' (default 100).
nBurnin: doubleburn-in steps discarded before the first sample for 'chrr' (default 1000).
replaceBoundsWithInf: logical[randomObjective] replace the largest upper bounds with Inf and the smallest lower bounds with -Inf. This is needed to get solutions without loops if your model has, for example, 1000/-1000 as arbitrarily large bounds. If your model only has "biologically relevant" bounds, then set this to false (default true).
supressErrors: logicalthe program will halt if it has problems finding non-zero solutions which are not involved in loops. This could be because the constraints on the model are too relaxed (such as unlimited glucose uptake) or too strict (such as too many and too narrow constraints) (default false).
runParallel: logicalspeed up calculations by parallel processing. Requires the MATLAB Parallel Computing Toolbox. If this is not installed, the calculations will not be parallelized, regardless of what is indicated as runParallel (default true).
goodRxns: doublevector of indexes of those reactions that are not involved in loops and can be used as random objective functions, as generated by a previous run of randomSampling on the same model (default empty).
minFlux: logicaldetermines if a second optimization should be performed for each random sample, to minimize the number of fluxes and thereby prevent loops. Typically, loops are averaged out when a large number of samples are taken, but this is not always the case (default false).
nObjectives: doublenumber of reactions included in the random objective function per sample iteration (default 2).
seed: doublerandom seed for reproducibility. If empty, the current MATLAB random state is used (default empty).
Returns
solutions: doublematrix with the solutions.
goodRxns: double[randomObjective] vector of indexes of those reactions that are not involved in loops or always carry zero flux and can be used as random objective functions. Empty ([]) for the 'achr' and 'chrr' methods.
info: struct[chrr] the diagnostics from sampleCHRR, including mveConverged (whether the maximum-volume ellipsoid rounding reached tolerance). Empty ([]) for the 'achr' and 'randomObjective' methods.
Notes
With 'randomObjective', the solutions are generated by maximizing (with random weights) for a random set of nObjectives reactions (default 2). For reversible reactions it randomly chooses between maximizing and minimizing. The default 'achr' and the 'chrr' methods use no random objectives; they take hit-and-run steps through the interior of the solution space.
If the model is a GECKO v3+ ecModel, then usage_prot reactions are not selected for sampling, instead focusing on sampling from the metabolic aspects that form the solution space.
Examples
% Near-uniform interior sampling (default, ACHR):
solutions = randomSampling(model, 1000);
% Coordinate hit-and-run with rounding:
solutions = randomSampling(model, 1000, 'method', 'chrr', 'seed', 1);
% Historical random-objective vertex method:
solutions = randomSampling(model, 1000, 'method', 'randomObjective');
See also
sampleACHR, sampleCHRR, sampleMaxVolEllipse
reporterMetabolites#
function repMets=reporterMetabolites(model,genes,genePValues,varargin)
Identify metabolites around which transcriptional changes occur.
The Reporter Metabolites algorithm for identifying metabolites around which transcriptional changes occur.
Parameters
model: structa model structure.
genes: cella cell array of gene names (should match with model.genes).
genePValues: doubleP-values for differential expression of the genes.
Name-Value Arguments
printResults: logicaltrue if the top 20 Reporter Metabolites should be printed to the screen (default false).
outputFile: charthe results are printed to this file (default none).
geneFoldChanges: doublelog-fold changes for the genes. If supplied, then Reporter Metabolites are calculated for only up/down-regulated genes in addition to the full test (default none).
Returns
repMets: structan array of structures with the following fields:
test : a string that describes the genes used to calculate the Reporter Metabolites ("all", "only up", or "only down"). The two latter structures are only calculated if geneFoldChanges are supplied.
mets : a cell array of metabolite IDs for the metabolites for which a score could be calculated.
metZScores : background-corrected Z-scores for differential expression around each metabolite in "mets". The entries of all fields are sorted by this score, highest first.
metPValues : one-sided (upper-tail) P-values of "metZScores".
metNGenes : number of neighbouring genes for each metabolite in "mets".
meanZ : average Z-scores for the genes around each metabolite in "mets".
stdZ : standard deviations of the Z-scores around each metabolite in "mets".
Examples
repMets = reporterMetabolites(model, genes, genePValues, ...
printResults, outputFile, geneFoldChanges);
Notes
For details about the algorithm, see Patil KR, Nielsen J, Uncovering transcriptional regulation of metabolism by using metabolic network topology. Proc. Natl Acad. Sci. USA 2005;102:2685-2689.
The background correction uses the closed-form mean and standard deviation of the aggregate Z-score of n genes drawn at random from all scored genes, so the results are deterministic.
runDynamicFBA#
function [concentrationMatrix, excRxnNames, timeVec, biomassVec] = runDynamicFBA(model, substrateRxns, initConcentrations, initBiomass, timeStep, nSteps, plotRxns, exclUptakeRxns)
Perform dynamic FBA using the static optimization approach.
Parameters
model: structa model structure.
substrateRxns: cellcell array with exchange reaction identifiers for substrates that are initially in the media, whose concentration may change (e.g. not h2o or co2).
initConcentrations: doubleinitial concentrations of substrates (matching substrateRxns).
initBiomass: doubleinitial biomass (must be non-zero).
timeStep: doubletime step size.
nSteps: doublemaximum number of time steps.
plotRxns: cellcell array with exchange reaction identifiers for substrates whose concentration should be plotted.
exclUptakeRxns: cellcell array with exchange reaction identifiers for substrates whose concentration does not change (e.g. co2, o2, h2o, h).
Returns
concentrationMatrix: doublematrix with extracellular metabolite concentrations.
excRxnNames: cellcell array with exchange reaction identifiers that match the metabolites included in the concentrationMatrix.
timeVec: doublevector of time points.
biomassVec: doublevector with biomass concentrations.
Examples
[concentrationMatrix, excRxnNames, timeVec, biomassVec] = ...
runDynamicFBA(model, substrateRxns, initConcentrations, ...
initBiomass, timeStep, nSteps, plotRxns, exclUptakeRxns);
Notes
If no initial concentration is given for a substrate that has an open uptake in the model (i.e. model.lb < 0) the concentration is assumed to be high enough to not be limiting. If the uptake rate for a nutrient is calculated to exceed the maximum uptake rate for that nutrient specified in the model and the max uptake rate specified is > 0, the maximum uptake rate specified in the model is used instead of the calculated uptake rate.
Modified from COBRA Toolbox dynamicFBA.m.
runPhenotypePhasePlane#
function [growthRates, shadowPrices1, shadowPrices2] = runPhenotypePhasePlane(model, controlRxn1, controlRxn2, varargin)
Run phenotype phase plane analysis and plot the results.
Runs phenotype phase plane analysis and plots the results. The first plot is a 3D surface plot showing the phenotype phase plane, the other two plots show the shadow prices of the metabolites from the two control reactions, which define the phases.
Parameters
model: structa model structure.
controlRxn1: charreaction identifier of the first reaction to be plotted.
controlRxn2: charreaction identifier of the second reaction to be plotted.
Name-Value Arguments
nPts: doublethe number of points to plot in each dimension (default 50).
range1: doublethe range [from 0 to range1] of reaction 1 to plot (default 20).
range2: doublethe range [from 0 to range2] of reaction 2 to plot (default 20).
Returns
growthRates: doublea matrix of maximum growth rates.
shadowPrices1: doublea matrix with shadow prices for reaction 1.
shadowPrices2: doublea matrix with shadow prices for reaction 2.
Examples
[growthRates, shadowPrices1, shadowPrices2] = ...
runPhenotypePhasePlane(model, controlRxn1, controlRxn2, nPts, ...
range1, range2);
Notes
Modified from COBRA Toolbox phenotypePhasePlane.m.
runProductionEnvelope#
function [biomassValues, targetValues] = runProductionEnvelope(model, targetRxn, biomassRxn, varargin)
Calculate the byproduct secretion envelope.
Parameters
model: structa model structure.
targetRxn: charidentifier of target metabolite production reaction.
biomassRxn: charidentifier of biomass reaction.
Name-Value Arguments
nPts: doublenumber of points in the plot (default 20).
Returns
biomassValues: doublebiomass values for plotting.
targetValues: doubletarget upper and lower bounds for plotting.
Examples
[biomassValues, targetValues] = runProductionEnvelope(model, ...
targetRxn, biomassRxn, nPts);
Notes
Modified from COBRA Toolbox productionEnvelope.m.
runRobustnessAnalysis#
function [controlFlux, objFlux] = runRobustnessAnalysis(model, controlRxn, varargin)
Perform robustness analysis for a reaction and objective.
Performs robustness analysis for a reaction of interest and an objective of interest.
Parameters
model: structa model structure.
controlRxn: charreaction of interest whose value is to be controlled.
Name-Value Arguments
nPoints: doublenumber of points to show on plot (default 20).
objRxn: charreaction identifier of objective to be maximized (default uses the objective defined in the model).
plotRedCost: logicalwhether reduced cost should also be plotted (default false).
Returns
controlFlux: doubleflux values of the reaction of interest, ranging from its minimum to its maximum value.
objFlux: doubleoptimal values of objective reaction at each control reaction flux value.
Examples
[controlFlux, objFlux] = runRobustnessAnalysis(model, controlRxn, ...
nPoints, objRxn);
Notes
Modified from COBRA Toolbox robustnessAnalysis.m.
runSimpleOptKnock#
function out = runSimpleOptKnock(model, targetRxn, biomassRxn, varargin)
Simple OptKnock for growth-coupled production.
Simple OptKnock algorithm that checks all gene or reaction deletions for growth-coupled metabolite production, by testing all possible combinations. This is not defined as MILP, and is therefore slow (but simple).
Parameters
model: structa model structure.
targetRxn: charidentifier of target reaction.
biomassRxn: charidentifier of biomass reaction.
Name-Value Arguments
deletions: cellcell array with gene or reaction identifiers that should be considered for knockout (default model.rxns).
genesOrRxns: charstring indicating whether deletions parameter is given with 'genes' or 'rxns' identifiers (default 'rxns').
maxNumKO: doublemaximum number of simultaneous knockouts (default 1).
minGrowth: doubleminimum growth rate (default 0.05).
Returns
out: structstructure with deletion strategies that result in growth-coupled production, with fields:
KO : cell array with gene(s) or reaction(s) to be deleted.
growthRate : vector with growth rates after deletion.
prodRate : vector with production rates after deletion.
Examples
out = runSimpleOptKnock(model, targetRxn, biomassRxn, deletions, ...
genesOrRxns, maxNumKO, minGrowth);
sampleACHR#
function solutions = sampleACHR(model, nSamples, thinning, warmup, seed)
Artificially Centered Hit-and-Run flux sampling.
Draws nSamples flux vectors approximately uniformly from the flux polytope {v : S*v = 0, lb <= v <= ub}, using the ACHR algorithm (Kaufman & Smith 1998). No rounding is performed, so on strongly elongated polytopes (e.g. enzyme-constrained models) mixing is slower than sampleCHRR; prefer CHRR there.
Parameters
model: structa RAVEN model structure.
nSamples: doublenumber of flux vectors to return (default 1000).
thinning: doubleMarkov-chain steps between recorded samples (default 100).
warmup: doublenPoints-by-nRxns warmup vertices (default: generated by sampleWarmupPoints).
seed: doublerandom seed for reproducibility (default: current RNG state).
Returns
solutions: doublenRxns-by-nSamples matrix of sampled flux distributions.
See also
randomSampling, sampleCHRR, sampleWarmupPoints
sampleChebyshevCenter#
function x0 = sampleChebyshevCenter(A, b)
Centre of the largest ball inscribed in a polytope.
Solves the LP max r s.t. a_i'*x + ||a_i||r <= b_i, r >= 0, giving a strictly interior point of {x : Ax <= b}. Used to initialise the interior-point MVE solver (sampleMaxVolEllipse) inside sampleCHRR.
Parameters
A: doublem-by-n constraint matrix.
b: doublem-by-1 right-hand side.
Returns
x0: doublen-by-1 Chebyshev centre (strictly interior point).
See also
sampleMaxVolEllipse, sampleCHRR
sampleCHRR#
function [solutions, info] = sampleCHRR(model, nSamples, thinning, nBurnin, seed, fixedWidthTol)
Coordinate Hit-and-Run with Rounding flux sampling.
Draws nSamples flux vectors approximately uniformly from the flux polytope {v : S*v = 0, lb <= v <= ub}, using the CHRR algorithm (Haraldsdottir et al. 2017, Bioinformatics 33:1741). The polytope is rounded before sampling, so mixing stays fast even on strongly elongated polytopes (e.g. enzyme-constrained models), unlike sampleACHR.
Set any constraints you want to condition on (e.g. a biomass lower bound or measured exchange fluxes) on the model before calling.
Parameters
model: structa RAVEN model structure.
nSamples: doublenumber of flux vectors to return (default 1000).
thinning: doubleMarkov-chain steps between recorded samples (default 100).
nBurnin: doubleburn-in steps discarded before the first recorded sample (default 1000).
seed: doublerandom seed for reproducibility (default: current RNG state).
fixedWidthTol: doublea reaction whose allowed flux range is narrower than this is treated as stoichiometrically fixed and folded into the equality system, keeping the reduced polytope full-dimensional (default 1e-7).
Returns
solutions: doublenRxns-by-nSamples matrix of sampled flux distributions.
info: struct.nDimensions — dimension of the sampled flux polytope .mveConverged — whether MVE rounding reached tolerance .fixedRxns — IDs of reactions folded in as fixed
See also
randomSampling, sampleACHR, sampleMaxVolEllipse
sampleMaxVolEllipse#
function [x, E, converged] = sampleMaxVolEllipse(A, b, x0, maxiter, tol, reg)
Maximum-volume inscribed ellipsoid of a polytope.
Solves max log det E over centre x and SPD matrix E such that the ellipsoid {x + Es : ||s||_2 <= 1} is contained in the polytope {z : Az <= b}, using the Zhang & Gao (2003) primal-dual interior-point method (the regularised variant used in COBRA's CHRR sampler). This is the rounding step of sampleCHRR: the returned transform E maps the polytope to a well-conditioned body in which coordinate hit-and-run mixes rapidly.
This function is pure linear algebra (no LP solver) except when x0 is empty, in which case a Chebyshev centre is obtained via sampleChebyshevCenter.
Parameters
A: doublem-by-n constraint matrix of the polytope {z : A*z <= b}. Requires m >= n+1 and a non-empty interior.
b: doublem-by-1 right-hand side.
x0: double (optional)a strictly interior point (A*x0 < b). If empty, computed by sampleChebyshevCenter(A, b).
maxiter: double (optional)maximum interior-point iterations (default 150).
tol: double (optional)convergence tolerance (default 1e-6).
reg: double (optional)diagonal / Levenberg regularisation keeping the Newton solves well-conditioned (default 1e-8).
Returns
x: doublen-by-1 ellipsoid centre.
E: doublen-by-n lower-triangular rounding transform with EE' = E2 (the SPD ellipsoid matrix). The rounding substitution is z = x + Ey.
converged: logicalwhether tol was reached within maxiter. A false value is not fatal — the last iterate is still a valid (if looser) rounding.
Notes
Validated against analytic cases: a box maps to the unit ball (E = I); a sheared box {z : -1 <= Mz <= 1} gives EE' = inv(M)*inv(M)'; a triangle gives its Steiner inellipse.
Based on Y. Zhang & L. Gao (2003), SIAM J. Optim. 14:53-76; as used in Haraldsdottir et al. (2017) Bioinformatics 33:1741 (CHRR).
See also
sampleCHRR, sampleChebyshevCenter, randomSampling
sampleWarmupPoints#
function warmup = sampleWarmupPoints(model,varargin)
FVA warmup vertices for ACHR sampling.
Generates warmup points for sampleACHR by maximising and minimising each reaction in turn and storing the full flux distribution at each optimum. These vertices span the flux polytope and seed the hit-and-run directions.
Parameters
model: structa RAVEN model structure.
Name-Value Arguments
runParallel: logicalspeed up calculations by parallel processing, as in getAllowedBounds, which solves the same per-reaction min/max LPs (default true).
Returns
warmup: doublenPoints-by-nRxns matrix; each row is a vertex flux distribution. Duplicate rows are removed.
See also
sampleACHR, randomSampling, getAllowedBounds
traceFluxPath#
function [pathRxns, pathMets, cumFrac] = traceFluxPath(model, fluxes, fromRxn, toRxn, varargin)
Find the highest-flux-fraction path between two reactions.
Traces how flux flows from one reaction to another through the metabolic network, quantifying what fraction of the source reaction's flux reaches the target. At each metabolite junction the flux is split proportionally among all consuming reactions; the path with the highest cumulative fraction is returned and printed.
By default the search excludes currency metabolites (ATP, NAD, H2O, etc.) so the returned path represents material (carbon-skeleton) flow rather than cofactor shortcuts. Set traceMaterial=false to disable this.
Parameters
model: structRAVEN model structure.
fluxes: doubleflux vector (length = numel(model.rxns)).
fromRxn: charsource reaction ID.
toRxn: chartarget reaction ID.
Name-Value Arguments
cutoff: doubleminimum |flux| for a reaction to be considered flux-carrying (default 1e-8).
maxHops: doublemaximum number of reactions in the path; longer paths are pruned (default 30).
verbose: logicalprint the path to the command window (default true).
traceMaterial: logicalexclude common currency/cofactor metabolites (ATP, ADP, NAD, NADH, H2O, CoA, Pi, CO2, …) so the path follows material (carbon-skeleton) flux rather than energy-carrier shortcuts (default true).
carbonOnly: logicaladditionally require each intermediate metabolite to contain at least one carbon atom, inferred from model.metFormulas. Drops H+, H2O, Pi, O2, NH3, CO2 that are not already caught by the currency list. Silently ignored when model.metFormulas is absent (default false).
excludeMets: cell of charextra metabolite names or IDs (after stripping compartment suffix) to exclude, in addition to the built-in currency list (default {}).
Returns
pathRxns: cellcell array of reaction IDs on the best path, including fromRxn and toRxn. Empty if no path is found.
pathMets: cellmetabolite IDs at each junction (numel = numel(pathRxns)-1).
cumFrac: doublefraction of fromRxn's flux that routes through this exact path (0 = no path found, 1 = all flux reaches toRxn directly).
Examples
[p, m, f] = traceFluxPath(model, sol.x, 'PFK', 'ATPS4rpp')
% disable material filter to see all connections including ATP/ADP:
[p, m, f] = traceFluxPath(model, sol.x, 'PFK', 'ATPS4rpp', 'traceMaterial', false)
% add model-specific cofactors to the exclusion list:
[p, m, f] = traceFluxPath(model, sol.x, 'PFK', 'CS', 'excludeMets', {'acetyl-CoA'})
Notes
The algorithm follows metabolites in the forward direction only: it traces the metabolites that fromRxn PRODUCES and finds which consuming reactions eventually reach toRxn. If fromRxn and toRxn are not connected in the forward flux direction (e.g. they are in parallel branches), an empty path is returned. A best-first (greedy) search ensures the highest-fraction path is found efficiently; a visited set prevents revisiting reactions.
walkFluxes#
function walkFluxes(model, fluxes, startRxn, varargin)
Interactively navigate a flux distribution reaction by reaction.
Starting from a chosen reaction, displays all flux-carrying reactions connected through shared metabolites, grouped by metabolite and labelled with each neighbour's role (produces / consumes). Select a neighbour by number to step to it; build a history and rewind with 'b'.
Parameters
model: structRAVEN model structure.
fluxes: doubleflux vector (length = numel(model.rxns)).
startRxn: char or doublestarting reaction ID (string) or column index.
Name-Value Arguments
cutoff: doubleminimum |flux| to display a reaction as a neighbour (default 1e-8).
maxPerMet: doublemaximum neighbour reactions displayed per metabolite (default 8).
Examples
sol = solveLP(model);
walkFluxes(model, sol.x, 'BIOMASS_Ec_iJO1366_core_53p95M')
walkFluxes(model, sol.x, 'PFK', 'cutoff', 1e-6)
Notes
Navigation commands:
This function is interactive and reads from the terminal at every step; it errors immediately under -batch, in deployed code, or otherwise without a real terminal, rather than blocking forever waiting for input that will never arrive.