Skip to content

Commit

Permalink
feat: use alternative ProgressBar function
Browse files Browse the repository at this point in the history
works both when parfor is run in parallel or in serial, without any further changes to the code
  • Loading branch information
edkerk committed Apr 11, 2024
1 parent f2b4a23 commit 8918962
Show file tree
Hide file tree
Showing 10 changed files with 118 additions and 130 deletions.
2 changes: 1 addition & 1 deletion core/parallelPoolRAVEN.m
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
else
pool = gcp('nocreate');
if isempty(pool)
parpool(IdleTimeout=120);
parpool('IdleTimeout',120)
end
end
end
Expand Down
6 changes: 2 additions & 4 deletions core/runDynamicFBA.m
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
biomassVec = biomass;
timeVec(1) = 0;
[~,hsSol]=solveLP(model,1);
fprintf('Running dynamic FBA analysis... 0%% complete');
PB = ProgressBar2(nSteps,'Running dynamic FBA analysis','cli');
for stepNo = 1:nSteps
% Run FBA
[sol,hsSol] = solveLP(model,1,[],hsSol);
Expand Down Expand Up @@ -107,10 +107,8 @@
model.lb(excInd) = -uptakeBound;
timeVec(stepNo+1) = stepNo*timeStep;

progress=pad(num2str(floor(stepNo/nSteps*100)),3,'left');
fprintf('\b\b\b\b\b\b\b\b\b\b\b\b\b%s%% complete',progress);
count(PB);
end
fprintf('\b\b\b\b\b\b\b\b\b\b\b\b\bCOMPLETE\n');

selNonZero = any(concentrationMatrix>0,2);
concentrationMatrix = concentrationMatrix(selNonZero,:);
Expand Down
5 changes: 2 additions & 3 deletions core/runPhenotypePhasePlane.m
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,8 @@
shadowPrices2 = zeros(nPts);
[~,hsSol] = solveLP(model);
% Calulate points
fprintf('Running PhPP analysis... 0%% complete');
PB = ProgressBar2(nPts,'Running PhPP analysis','cli');
for i = 1:nPts %ind1
progress=pad(num2str(floor(i/nPts*100)),3,'left');
fprintf('\b\b\b\b\b\b\b\b\b\b\b\b\b%s%% complete',progress);
for j = 1:nPts %ind2
model1 = setParam(model,'eq',controlRxn1,-1*ind1(i));
model1 = setParam(model1,'eq',controlRxn2,-1*ind2(j));
Expand All @@ -63,6 +61,7 @@
shadowPrices2(j,i) = fbasol.sPrice(metID2);
end
end
count(PB);
end
fprintf('\b\b\b\b\b\b\b\b\b\b\b\b\bCOMPLETE\n');

Expand Down
6 changes: 2 additions & 4 deletions core/runProductionEnvelope.m
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,10 @@
targetUpperBound = nan(1,numel(biomassValues));
targetLowerBound = nan(1,numel(biomassValues));

fprintf('Creating production envelope... 0%% complete');
PB = ProgressBar2(length(biomassValues),'Creating production envelope','cli');
% Max/min for target production
model = setParam(model,'obj',targetRxn,1);
for i = 1:length(biomassValues)
progress=pad(num2str(floor(i/numel(biomassValues)*100)),3,'left');
fprintf('\b\b\b\b\b\b\b\b\b\b\b\b\b%s%% complete',progress);
model1 = setParam(model,'eq',biomassRxn,biomassValues(i));
sol = solveLP(model1,0,[],hsSol);
if (sol.stat > 0)
Expand All @@ -53,8 +51,8 @@
else
targetLowerBound(i) = NaN;
end
count(PB);
end
fprintf('\b\b\b\b\b\b\b\b\b\b\b\b\bCOMPLETE\n');

% Plot results
plot([biomassValues fliplr(biomassValues)],[targetUpperBound fliplr(targetLowerBound)],'blue','LineWidth',2);
Expand Down
7 changes: 3 additions & 4 deletions core/runRobustnessAnalysis.m
Original file line number Diff line number Diff line change
Expand Up @@ -50,16 +50,15 @@
redCost = zeros(nPoints,1);
controlFlux = linspace(solMin,solMax,nPoints)';

fprintf('Running robustness analysis... 0%% complete');

PB = ProgressBar2(length(controlFlux),'Running robustness analysis','cli');
for i=1:length(controlFlux)
progress=pad(num2str(floor(i/numel(controlFlux)*100)),3,'left');
fprintf('\b\b\b\b\b\b\b\b\b\b\b\b\b%s%% complete',progress);
modelControlled = setParam(baseModel,'eq',controlRxnIdx,controlFlux(i));
solControlled = solveLP(modelControlled);
objFlux(i) = solControlled.x(logical(modelControlled.c));
redCost(i) = solControlled.rCost(controlRxnIdx);
count(PB);
end
fprintf('\b\b\b\b\b\b\b\b\b\b\b\b\bCOMPLETE\n');

if plotRedCost
yyaxis right
Expand Down
4 changes: 2 additions & 2 deletions doc/core/parallelPoolRAVEN.html
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ <h2><a name="_cross"></a>CROSS-REFERENCE INFORMATION <a href="#_top"><img alt="^
</ul>
This function is called by:
<ul style="list-style-image:url(../matlabicon.gif)">
<li><a href="findGeneDeletions.html" class="code" title="function [genes, fluxes, originalGenes, details, grRatioMuts]=findGeneDeletions(model,testType,analysisType,refModel,oeFactor)">findGeneDeletions</a> findGeneDeletions</li><li><a href="getAllowedBounds.html" class="code" title="function [minFluxes, maxFluxes, exitFlags]=getAllowedBounds(model,rxns,runParallel)">getAllowedBounds</a> getAllowedBounds</li><li><a href="randomSampling.html" class="code" title="function [solutions, goodRxns]=randomSampling(model,nSamples,replaceBoundsWithInf,supressErrors,runParallel,goodRxns,minFlux)">randomSampling</a> randomSampling</li></ul>
<li><a href="getAllowedBounds.html" class="code" title="function [minFluxes, maxFluxes, exitFlags]=getAllowedBounds(model,rxns,runParallel)">getAllowedBounds</a> getAllowedBounds</li><li><a href="randomSampling.html" class="code" title="function [solutions, goodRxns]=randomSampling(model,nSamples,replaceBoundsWithInf,supressErrors,runParallel,goodRxns,minFlux)">randomSampling</a> randomSampling</li></ul>
<!-- crossreference -->


Expand Down Expand Up @@ -115,7 +115,7 @@ <h2><a name="_source"></a>SOURCE CODE <a href="#_top"><img alt="^" border="0" sr
0046 <span class="keyword">else</span>
0047 pool = gcp(<span class="string">'nocreate'</span>);
0048 <span class="keyword">if</span> isempty(pool)
0049 parpool(IdleTimeout=120);
0049 parpool(<span class="string">'IdleTimeout'</span>,120)
0050 <span class="keyword">end</span>
0051 <span class="keyword">end</span>
0052 <span class="keyword">end</span>
Expand Down
52 changes: 25 additions & 27 deletions doc/core/runDynamicFBA.html
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ <h2><a name="_source"></a>SOURCE CODE <a href="#_top"><img alt="^" border="0" sr
0076 biomassVec = biomass;
0077 timeVec(1) = 0;
0078 [~,hsSol]=solveLP(model,1);
0079 fprintf(<span class="string">'Running dynamic FBA analysis... 0%% complete'</span>);
0079 PB = ProgressBar2(nSteps,<span class="string">'Running dynamic FBA analysis'</span>,<span class="string">'cli'</span>);
0080 <span class="keyword">for</span> stepNo = 1:nSteps
0081 <span class="comment">% Run FBA</span>
0082 [sol,hsSol] = solveLP(model,1,[],hsSol);
Expand Down Expand Up @@ -189,32 +189,30 @@ <h2><a name="_source"></a>SOURCE CODE <a href="#_top"><img alt="^" border="0" sr
0107 model.lb(excInd) = -uptakeBound;
0108 timeVec(stepNo+1) = stepNo*timeStep;
0109
0110 progress=pad(num2str(floor(stepNo/nSteps*100)),3,<span class="string">'left'</span>);
0111 fprintf(<span class="string">'\b\b\b\b\b\b\b\b\b\b\b\b\b%s%% complete'</span>,progress);
0112 <span class="keyword">end</span>
0113 fprintf(<span class="string">'\b\b\b\b\b\b\b\b\b\b\b\b\bCOMPLETE\n'</span>);
0114
0115 selNonZero = any(concentrationMatrix&gt;0,2);
0116 concentrationMatrix = concentrationMatrix(selNonZero,:);
0117 excRxnNames = excRxnNames(selNonZero);
0118 selPlot = ismember(excRxnNames,plotRxns);
0119
0120 <span class="comment">% Plot concentrations as a function of time</span>
0121 clf
0122 subplot(1,2,1);
0123 plot(timeVec,biomassVec);
0124 axis tight
0125 title(<span class="string">'Biomass'</span>);
0126 xlabel(<span class="string">'Time (h)'</span>);
0127 ylabel(<span class="string">'Concentration (g/L)'</span>);
0128 subplot(1,2,2);
0129 plot(timeVec,concentrationMatrix(selPlot,:));
0130 axis tight
0131 title(<span class="string">'Substrates and/or products'</span>);
0132 xlabel(<span class="string">'Time (h)'</span>);
0133 ylabel(<span class="string">'Concentration (mmol/L)'</span>);
0134 legend(strrep(excRxnNames(selPlot),<span class="string">'EX_'</span>,<span class="string">''</span>));
0135 <span class="keyword">end</span></pre></div>
0110 count(PB);
0111 <span class="keyword">end</span>
0112
0113 selNonZero = any(concentrationMatrix&gt;0,2);
0114 concentrationMatrix = concentrationMatrix(selNonZero,:);
0115 excRxnNames = excRxnNames(selNonZero);
0116 selPlot = ismember(excRxnNames,plotRxns);
0117
0118 <span class="comment">% Plot concentrations as a function of time</span>
0119 clf
0120 subplot(1,2,1);
0121 plot(timeVec,biomassVec);
0122 axis tight
0123 title(<span class="string">'Biomass'</span>);
0124 xlabel(<span class="string">'Time (h)'</span>);
0125 ylabel(<span class="string">'Concentration (g/L)'</span>);
0126 subplot(1,2,2);
0127 plot(timeVec,concentrationMatrix(selPlot,:));
0128 axis tight
0129 title(<span class="string">'Substrates and/or products'</span>);
0130 xlabel(<span class="string">'Time (h)'</span>);
0131 ylabel(<span class="string">'Concentration (mmol/L)'</span>);
0132 legend(strrep(excRxnNames(selPlot),<span class="string">'EX_'</span>,<span class="string">''</span>));
0133 <span class="keyword">end</span></pre></div>
<hr><address>Generated by <strong><a href="http://www.artefact.tk/software/matlab/m2html/" title="Matlab Documentation in HTML">m2html</a></strong> &copy; 2005</address>
</body>
</html>
75 changes: 37 additions & 38 deletions doc/core/runPhenotypePhasePlane.html
Original file line number Diff line number Diff line change
Expand Up @@ -118,45 +118,44 @@ <h2><a name="_source"></a>SOURCE CODE <a href="#_top"><img alt="^" border="0" sr
0049 shadowPrices2 = zeros(nPts);
0050 [~,hsSol] = solveLP(model);
0051 <span class="comment">% Calulate points</span>
0052 fprintf(<span class="string">'Running PhPP analysis... 0%% complete'</span>);
0052 PB = ProgressBar2(nPts,<span class="string">'Running PhPP analysis'</span>,<span class="string">'cli'</span>);
0053 <span class="keyword">for</span> i = 1:nPts <span class="comment">%ind1</span>
0054 progress=pad(num2str(floor(i/nPts*100)),3,<span class="string">'left'</span>);
0055 fprintf(<span class="string">'\b\b\b\b\b\b\b\b\b\b\b\b\b%s%% complete'</span>,progress);
0056 <span class="keyword">for</span> j = 1:nPts <span class="comment">%ind2</span>
0057 model1 = <a href="setParam.html" class="code" title="function model=setParam(model, paramType, rxnList, params, var)">setParam</a>(model,<span class="string">'eq'</span>,controlRxn1,-1*ind1(i));
0058 model1 = <a href="setParam.html" class="code" title="function model=setParam(model, paramType, rxnList, params, var)">setParam</a>(model1,<span class="string">'eq'</span>,controlRxn2,-1*ind2(j));
0059 [fbasol,hsSol] = solveLP(model1,0,[],hsSol);
0060 <span class="keyword">try</span>
0061 growthRates(j,i) = fbasol.x(logical(model1.c));
0062 shadowPrices1(j,i) = fbasol.sPrice(metID1);
0063 shadowPrices2(j,i) = fbasol.sPrice(metID2);
0064 <span class="keyword">end</span>
0065 <span class="keyword">end</span>
0066 <span class="keyword">end</span>
0067 fprintf(<span class="string">'\b\b\b\b\b\b\b\b\b\b\b\b\bCOMPLETE\n'</span>);
0068
0069 <span class="comment">% Plot the points</span>
0070 figure(2);
0071 pcolor(ind1,ind2,shadowPrices1);
0072 xlabel(strrep(strcat(controlRxn1,<span class="string">' (mmol/g DW-hr)'</span>),<span class="string">'_'</span>,<span class="string">'\_'</span>)), ylabel(strrep(strcat(controlRxn2,<span class="string">' (mmol/g DW-hr)'</span>),<span class="string">'_'</span>,<span class="string">'\_'</span>)), zlabel(<span class="string">'growth rate (1/hr)'</span>);
0073 title([<span class="string">'Shadow price '</span> strrep(model.mets{metID1},<span class="string">'_'</span>,<span class="string">'-'</span>)]);
0074 colorbar();
0075 xticklabels(sprintfc(<span class="string">'%d'</span>, -xticks))
0076 yticklabels(sprintfc(<span class="string">'%d'</span>, -yticks))
0077 figure(3);
0078 pcolor(ind1,ind2,shadowPrices2);
0079 xlabel(strrep(strcat(controlRxn1,<span class="string">' (mmol/g DW-hr)'</span>),<span class="string">'_'</span>,<span class="string">'\_'</span>)), ylabel(strrep(strcat(controlRxn2,<span class="string">' (mmol/g DW-hr)'</span>),<span class="string">'_'</span>,<span class="string">'\_'</span>)), zlabel(<span class="string">'growth rate (1/hr)'</span>);
0080 title([<span class="string">'Shadow price '</span> strrep(model.mets{metID2},<span class="string">'_'</span>,<span class="string">'-'</span>)]);
0081 colorbar();
0082 xticklabels(sprintfc(<span class="string">'%d'</span>, -xticks))
0083 yticklabels(sprintfc(<span class="string">'%d'</span>, -yticks))
0084 figure(1);
0085 surfl(ind1,ind2,growthRates);
0086 xlabel(strrep(strcat(controlRxn1,<span class="string">' (mmol/g DW-hr)'</span>),<span class="string">'_'</span>,<span class="string">'\_'</span>)), ylabel(strrep(strcat(controlRxn2,<span class="string">' (mmol/g DW-hr)'</span>),<span class="string">'_'</span>,<span class="string">'\_'</span>)), zlabel(<span class="string">'growth rate (1/hr)'</span>);
0087 colormap(hsv(17));
0088 xticklabels(sprintfc(<span class="string">'%d'</span>, -xticks))
0089 yticklabels(sprintfc(<span class="string">'%d'</span>, -yticks))
0090 <span class="keyword">end</span></pre></div>
0054 <span class="keyword">for</span> j = 1:nPts <span class="comment">%ind2</span>
0055 model1 = <a href="setParam.html" class="code" title="function model=setParam(model, paramType, rxnList, params, var)">setParam</a>(model,<span class="string">'eq'</span>,controlRxn1,-1*ind1(i));
0056 model1 = <a href="setParam.html" class="code" title="function model=setParam(model, paramType, rxnList, params, var)">setParam</a>(model1,<span class="string">'eq'</span>,controlRxn2,-1*ind2(j));
0057 [fbasol,hsSol] = solveLP(model1,0,[],hsSol);
0058 <span class="keyword">try</span>
0059 growthRates(j,i) = fbasol.x(logical(model1.c));
0060 shadowPrices1(j,i) = fbasol.sPrice(metID1);
0061 shadowPrices2(j,i) = fbasol.sPrice(metID2);
0062 <span class="keyword">end</span>
0063 <span class="keyword">end</span>
0064 count(PB);
0065 <span class="keyword">end</span>
0066 fprintf(<span class="string">'\b\b\b\b\b\b\b\b\b\b\b\b\bCOMPLETE\n'</span>);
0067
0068 <span class="comment">% Plot the points</span>
0069 figure(2);
0070 pcolor(ind1,ind2,shadowPrices1);
0071 xlabel(strrep(strcat(controlRxn1,<span class="string">' (mmol/g DW-hr)'</span>),<span class="string">'_'</span>,<span class="string">'\_'</span>)), ylabel(strrep(strcat(controlRxn2,<span class="string">' (mmol/g DW-hr)'</span>),<span class="string">'_'</span>,<span class="string">'\_'</span>)), zlabel(<span class="string">'growth rate (1/hr)'</span>);
0072 title([<span class="string">'Shadow price '</span> strrep(model.mets{metID1},<span class="string">'_'</span>,<span class="string">'-'</span>)]);
0073 colorbar();
0074 xticklabels(sprintfc(<span class="string">'%d'</span>, -xticks))
0075 yticklabels(sprintfc(<span class="string">'%d'</span>, -yticks))
0076 figure(3);
0077 pcolor(ind1,ind2,shadowPrices2);
0078 xlabel(strrep(strcat(controlRxn1,<span class="string">' (mmol/g DW-hr)'</span>),<span class="string">'_'</span>,<span class="string">'\_'</span>)), ylabel(strrep(strcat(controlRxn2,<span class="string">' (mmol/g DW-hr)'</span>),<span class="string">'_'</span>,<span class="string">'\_'</span>)), zlabel(<span class="string">'growth rate (1/hr)'</span>);
0079 title([<span class="string">'Shadow price '</span> strrep(model.mets{metID2},<span class="string">'_'</span>,<span class="string">'-'</span>)]);
0080 colorbar();
0081 xticklabels(sprintfc(<span class="string">'%d'</span>, -xticks))
0082 yticklabels(sprintfc(<span class="string">'%d'</span>, -yticks))
0083 figure(1);
0084 surfl(ind1,ind2,growthRates);
0085 xlabel(strrep(strcat(controlRxn1,<span class="string">' (mmol/g DW-hr)'</span>),<span class="string">'_'</span>,<span class="string">'\_'</span>)), ylabel(strrep(strcat(controlRxn2,<span class="string">' (mmol/g DW-hr)'</span>),<span class="string">'_'</span>,<span class="string">'\_'</span>)), zlabel(<span class="string">'growth rate (1/hr)'</span>);
0086 colormap(hsv(17));
0087 xticklabels(sprintfc(<span class="string">'%d'</span>, -xticks))
0088 yticklabels(sprintfc(<span class="string">'%d'</span>, -yticks))
0089 <span class="keyword">end</span></pre></div>
<hr><address>Generated by <strong><a href="http://www.artefact.tk/software/matlab/m2html/" title="Matlab Documentation in HTML">m2html</a></strong> &copy; 2005</address>
</body>
</html>
52 changes: 25 additions & 27 deletions doc/core/runProductionEnvelope.html
Original file line number Diff line number Diff line change
Expand Up @@ -92,36 +92,34 @@ <h2><a name="_source"></a>SOURCE CODE <a href="#_top"><img alt="^" border="0" sr
0033 targetUpperBound = nan(1,numel(biomassValues));
0034 targetLowerBound = nan(1,numel(biomassValues));
0035
0036 fprintf(<span class="string">'Creating production envelope... 0%% complete'</span>);
0036 PB = ProgressBar2(length(biomassValues),<span class="string">'Creating production envelope'</span>,<span class="string">'cli'</span>);
0037 <span class="comment">% Max/min for target production</span>
0038 model = <a href="setParam.html" class="code" title="function model=setParam(model, paramType, rxnList, params, var)">setParam</a>(model,<span class="string">'obj'</span>,targetRxn,1);
0039 <span class="keyword">for</span> i = 1:length(biomassValues)
0040 progress=pad(num2str(floor(i/numel(biomassValues)*100)),3,<span class="string">'left'</span>);
0041 fprintf(<span class="string">'\b\b\b\b\b\b\b\b\b\b\b\b\b%s%% complete'</span>,progress);
0042 model1 = <a href="setParam.html" class="code" title="function model=setParam(model, paramType, rxnList, params, var)">setParam</a>(model,<span class="string">'eq'</span>,biomassRxn,biomassValues(i));
0043 sol = solveLP(model1,0,[],hsSol);
0044 <span class="keyword">if</span> (sol.stat &gt; 0)
0045 targetUpperBound(i) = sol.x(logical(model.c));
0046 <span class="keyword">else</span>
0047 targetUpperBound(i) = NaN;
0048 <span class="keyword">end</span>
0049 model1.c = -model1.c;
0050 sol = solveLP(model1,0,[],hsSol);
0051 <span class="keyword">if</span> (sol.stat &gt; 0)
0052 targetLowerBound(i) = sol.x(logical(model1.c));
0053 <span class="keyword">else</span>
0054 targetLowerBound(i) = NaN;
0055 <span class="keyword">end</span>
0056 <span class="keyword">end</span>
0057 fprintf(<span class="string">'\b\b\b\b\b\b\b\b\b\b\b\b\bCOMPLETE\n'</span>);
0058
0059 <span class="comment">% Plot results</span>
0060 plot([biomassValues fliplr(biomassValues)],[targetUpperBound fliplr(targetLowerBound)],<span class="string">'blue'</span>,<span class="string">'LineWidth'</span>,2);
0061 axis tight;
0062 ylabel([strrep(targetRxn,<span class="string">'_'</span>,<span class="string">'-'</span>) <span class="string">' (mmol/gDW h)'</span>]);
0063 xlabel(<span class="string">'Growth rate (1/h)'</span>);
0064 targetValues = [targetLowerBound; targetUpperBound];
0065 <span class="keyword">end</span></pre></div>
0040 model1 = <a href="setParam.html" class="code" title="function model=setParam(model, paramType, rxnList, params, var)">setParam</a>(model,<span class="string">'eq'</span>,biomassRxn,biomassValues(i));
0041 sol = solveLP(model1,0,[],hsSol);
0042 <span class="keyword">if</span> (sol.stat &gt; 0)
0043 targetUpperBound(i) = sol.x(logical(model.c));
0044 <span class="keyword">else</span>
0045 targetUpperBound(i) = NaN;
0046 <span class="keyword">end</span>
0047 model1.c = -model1.c;
0048 sol = solveLP(model1,0,[],hsSol);
0049 <span class="keyword">if</span> (sol.stat &gt; 0)
0050 targetLowerBound(i) = sol.x(logical(model1.c));
0051 <span class="keyword">else</span>
0052 targetLowerBound(i) = NaN;
0053 <span class="keyword">end</span>
0054 count(PB);
0055 <span class="keyword">end</span>
0056
0057 <span class="comment">% Plot results</span>
0058 plot([biomassValues fliplr(biomassValues)],[targetUpperBound fliplr(targetLowerBound)],<span class="string">'blue'</span>,<span class="string">'LineWidth'</span>,2);
0059 axis tight;
0060 ylabel([strrep(targetRxn,<span class="string">'_'</span>,<span class="string">'-'</span>) <span class="string">' (mmol/gDW h)'</span>]);
0061 xlabel(<span class="string">'Growth rate (1/h)'</span>);
0062 targetValues = [targetLowerBound; targetUpperBound];
0063 <span class="keyword">end</span></pre></div>
<hr><address>Generated by <strong><a href="http://www.artefact.tk/software/matlab/m2html/" title="Matlab Documentation in HTML">m2html</a></strong> &copy; 2005</address>
</body>
</html>
Loading

0 comments on commit 8918962

Please sign in to comment.