Skip to content

Commit b05193d

Browse files
authored
Merge pull request #505 from SysBioChalmers/develop
RAVEN 2.8.4
2 parents 0a180fe + a09ece3 commit b05193d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+4096
-3751
lines changed

core/addExchangeRxns.m

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,4 +89,7 @@
8989
if isfield(model,'rxnConfidenceScores')
9090
model.rxnConfidenceScores=[model.rxnConfidenceScores;NaN(numel(J),1)];
9191
end
92+
if isfield(model,'rxnDeltaG')
93+
model.rxnDeltaG=[model.rxnDeltaG;NaN(numel(J),1)];
94+
end
9295
end

core/addMets.m

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@
2929
% metMiriams cell array with MIRIAM structures (opt,
3030
% default [])
3131
% metCharges metabolite charge (opt, default NaN)
32+
% metDeltaG Gibbs free energy of formation at
33+
% biochemical standard condition in kJ/mole
34+
% (opt, default NaN)
3235
% metNotes cell array with metabolite notes as strings
3336
% (opt, default '')
3437
% copyInfo when adding metabolites to a compartment where it previously
@@ -261,6 +264,27 @@
261264
end
262265
end
263266

267+
if isfield(metsToAdd,'metDeltaG')
268+
if numel(metsToAdd.metDeltaG)~=nMets
269+
EM='metsToAdd.metDeltaG must have the same number of elements as metsToAdd.mets';
270+
dispEM(EM);
271+
end
272+
if ~isnumeric(metsToAdd.metDeltaG)
273+
EM='metsToAdd.metDeltaG must be of type "double"';
274+
dispEM(EM);
275+
end
276+
if ~isfield(newModel,'metDeltaG')
277+
newModel.metDeltaG=NaN(numel(largeFiller),1);
278+
end
279+
newModel.metDeltaG=[newModel.metDeltaG;metsToAdd.metDeltaG(:)];
280+
else
281+
%Add default
282+
if isfield(newModel,'metDeltaG')
283+
newModel.metDeltaG=[newModel.metDeltaG;NaN(numel(filler),1)];
284+
end
285+
end
286+
287+
264288
if isfield(metsToAdd,'metNotes')
265289
metsToAdd.metNotes=convertCharArray(metsToAdd.metNotes);
266290
if numel(metsToAdd.metNotes)==1 && numel(metsToAdd.mets)>1
@@ -345,6 +369,9 @@
345369
if isfield(newModel,'metCharges')
346370
newModel.metCharges(I(i))=newModel.metCharges(J(i));
347371
end
372+
if isfield(newModel,'metDeltaG')
373+
newModel.metDeltaG(I(i))=newModel.metDeltaG(J(i));
374+
end
348375
end
349376
end
350377
end

core/addRxns.m

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@
5252
% model.comps) (opt, default {})
5353
% rxnNotes cell array with reaction notes (opt,
5454
% default '')
55+
% rxnDeltaG Gibbs free energy at biochemical standard
56+
% condition in kJ/mole (opt, default NaN)
5557
% rxnReferences cell array with reaction references (opt,
5658
% default '')
5759
% rxnConfidenceScores vector with reaction confidence scores
@@ -504,8 +506,6 @@
504506
%Fill with standard if it doesn't exist
505507
if ~isfield(newModel,'rxnConfidenceScores')
506508
newModel.rxnConfidenceScores=NaN(nOldRxns,1);
507-
EM='Adding reactions with confidence scores without such information. All existing reactions will have confidence scores as NaNs';
508-
dispEM(EM,false);
509509
end
510510
newModel.rxnConfidenceScores=[newModel.rxnConfidenceScores;rxnsToAdd.rxnConfidenceScores(:)];
511511
else
@@ -515,6 +515,23 @@
515515
end
516516
end
517517

518+
if isfield(rxnsToAdd,'rxnDeltaG')
519+
if numel(rxnsToAdd.rxnDeltaG)~=nRxns
520+
EM='rxnsToAdd.rxnDeltaG must have the same number of elements as rxnsToAdd.rxns';
521+
dispEM(EM);
522+
end
523+
%Fill with standard if it doesn't exist
524+
if ~isfield(newModel,'rxnDeltaG')
525+
newModel.rxnDeltaG=NaN(nOldRxns,1);
526+
end
527+
newModel.rxnDeltaG=[newModel.rxnDeltaG;rxnsToAdd.rxnDeltaG(:)];
528+
else
529+
%Fill with standard if it doesn't exist
530+
if isfield(newModel,'rxnDeltaG')
531+
newModel.rxnDeltaG=[newModel.rxnDeltaG;NaN(nRxns,1)];
532+
end
533+
end
534+
518535

519536
%***Start parsing the equations and adding the info to the S matrix The
520537
%mets are matched to model.mets

core/addRxnsGenesMets.m

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -116,21 +116,24 @@
116116
if isfield(sourceModel,'metFormulas')
117117
metsToAdd.metFormulas=sourceModel.metFormulas(metIdx);
118118
end
119-
if isfield(sourceModel,'metCharge')
120-
metsToAdd.metCharge=sourceModel.metCharge(metIdx);
119+
if isfield(sourceModel,'metCharges')
120+
metsToAdd.metCharges=sourceModel.metCharges(metIdx);
121121
end
122122
if isfield(sourceModel,'metMiriams')
123123
metsToAdd.metMiriams=sourceModel.metMiriams(metIdx);
124124
end
125-
if isfield(sourceModel,'metFormulas')
126-
metsToAdd.metFormulas=sourceModel.metFormulas(metIdx);
125+
if isfield(sourceModel,'metNotes')
126+
metsToAdd.metNotes=sourceModel.metNotes(metIdx);
127127
end
128128
if isfield(sourceModel,'inchis')
129129
metsToAdd.inchis=sourceModel.inchis(metIdx);
130130
end
131131
if isfield(sourceModel,'metSmiles')
132132
metsToAdd.metSmiles=sourceModel.metSmiles(metIdx);
133133
end
134+
if isfield(sourceModel,'metDeltaG')
135+
metsToAdd.metDeltaG=sourceModel.metDeltaG(metIdx);
136+
end
134137

135138
metsToAdd.compartments=strtrim(cellstr(num2str(sourceModel.metComps(metIdx)))); % Convert from compartment string to compartment number
136139
[~,idx]=ismember(metsToAdd.compartments,strsplit(num2str(1:length(sourceModel.comps)))); % Match compartment number to compartment abbreviation
@@ -164,6 +167,9 @@
164167
dispEM(EM, true);
165168
end
166169
rxnToAdd.rxnConfidenceScores(:)=confidence;
170+
if isfield(sourceModel,'rxnDeltaG')
171+
rxnToAdd.rxnDeltaG=sourceModel.rxnDeltaG(rxnIdx);
172+
end
167173
if isfield(sourceModel,'subSystems')
168174
rxnToAdd.subSystems=sourceModel.subSystems(rxnIdx);
169175
end

core/addTransport.m

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,9 @@
167167
if isfield(model,'rxnConfidenceScores')
168168
model.rxnConfidenceScores=[model.rxnConfidenceScores;ones(nRxns,1)];
169169
end
170+
if isfield(model,'rxnDeltaG')
171+
model.rxnDeltaG=[model.rxnDeltaG;zeros(nRxns,1)];
172+
end
170173
addedRxns = [addedRxns; addedRxnsID];
171174
end
172175
end

core/changeRxns.m

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,9 @@
129129
if isfield(model,'rxnConfidenceScores')
130130
rxnsToChange.rxnConfidenceScores=model.rxnConfidenceScores(J);
131131
end
132+
if isfield(model,'rxnDeltaG')
133+
rxnsToChange.rxnDeltaG=model.rxnDeltaG(J);
134+
end
132135
if isfield(model,'pwys')
133136
rxnsToChange.pwys=model.pwys(J);
134137
end

core/checkModelStruct.m

Lines changed: 44 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,12 @@ function checkModelStruct(model,throwErrors,trimWarnings)
151151
dispEM(EM,throwErrors);
152152
end
153153
end
154+
if isfield(model,'metDeltaG')
155+
if ~isnumeric(model.metDeltaG)
156+
EM='The "metDeltaG" field must be a double';
157+
dispEM(EM,throwErrors);
158+
end
159+
end
154160
if isfield(model,'subSystems')
155161
for i=1:numel(model.subSystems)
156162
if ~iscell(model.subSystems{i,1})
@@ -189,6 +195,12 @@ function checkModelStruct(model,throwErrors,trimWarnings)
189195
dispEM(EM,throwErrors);
190196
end
191197
end
198+
if isfield(model,'rxnDeltaG')
199+
if ~isnumeric(model.rxnDeltaG)
200+
EM='The "rxnDeltaG" field must be a double';
201+
dispEM(EM,throwErrors);
202+
end
203+
end
192204

193205
%Empty strings
194206
if isempty(model.id)
@@ -364,38 +376,38 @@ function checkModelStruct(model,throwErrors,trimWarnings)
364376
dispEM(EM,false,allInchis(hasMultiple),trimWarnings);
365377
end
366378

367-
%Check if there are metabolites with different names but the same SMILES
368-
if isfield(model,'metSmiles')
369-
metSmiles=containers.Map();
370-
for i=1:numel(model.mets)
371-
if ~isempty(model.metSmiles{i})
372-
%Get existing metabolite indexes
373-
if isKey(metSmiles,model.metSmiles{i})
374-
existing=metSmiles(model.metSmiles{i});
375-
else
376-
existing=[];
377-
end
378-
metSmiles(model.metSmiles{i})=[existing;i];
379-
end
380-
end
381-
382-
%Get all keys
383-
allmetSmiles=keys(metSmiles);
384-
385-
hasMultiple=false(numel(metSmiles),1);
386-
for i=1:numel(metSmiles)
387-
if numel(metSmiles(metSmiles{i}))>1
388-
%Check if they all have the same name
389-
if numel(unique(model.metNames(metSmiles(allmetSmiles{i}))))>1
390-
hasMultiple(i)=true;
391-
end
392-
end
393-
end
394-
395-
%Print output
396-
EM='The following metSmiles strings are associated to more than one unique metabolite name:';
397-
dispEM(EM,false,allmetSmiles(hasMultiple),trimWarnings);
398-
end
379+
% %Check if there are metabolites with different names but the same SMILES
380+
% if isfield(model,'metSmiles')
381+
% metSmiles=containers.Map();
382+
% for i=1:numel(model.mets)
383+
% if ~isempty(model.metSmiles{i})
384+
% %Get existing metabolite indexes
385+
% if isKey(metSmiles,model.metSmiles{i})
386+
% existing=metSmiles(model.metSmiles{i});
387+
% else
388+
% existing=[];
389+
% end
390+
% metSmiles(model.metSmiles{i})=[existing;i];
391+
% end
392+
% end
393+
%
394+
% %Get all keys
395+
% allmetSmiles=keys(metSmiles);
396+
%
397+
% hasMultiple=false(numel(metSmiles),1);
398+
% for i=1:numel(metSmiles)
399+
% if numel(metSmiles(metSmiles{i}))>1
400+
% %Check if they all have the same name
401+
% if numel(unique(model.metNames(metSmiles(allmetSmiles{i}))))>1
402+
% hasMultiple(i)=true;
403+
% end
404+
% end
405+
% end
406+
%
407+
% %Print output
408+
% EM='The following metSmiles strings are associated to more than one unique metabolite name:';
409+
% dispEM(EM,false,allmetSmiles(hasMultiple),trimWarnings);
410+
% end
399411
end
400412

401413
function I=duplicates(strings)

core/convertToIrrev.m

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,9 @@
9696
if isfield(irrevModel,'rxnConfidenceScores')
9797
irrevModel.rxnConfidenceScores=[irrevModel.rxnConfidenceScores;irrevModel.rxnConfidenceScores(revIndexes)];
9898
end
99+
if isfield(irrevModel,'rxnDeltaG')
100+
irrevModel.rxnDeltaG=[irrevModel.rxnDeltaG;-irrevModel.rxnDeltaG(revIndexes)]; % Invert dG for reversed rxns
101+
end
99102
if isfield(irrevModel,'rxnReferences')
100103
irrevModel.rxnReferences=[irrevModel.rxnReferences;irrevModel.rxnReferences(revIndexes)];
101104
end

core/expandModel.m

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,9 @@
7171
if isfield(model,'rxnConfidenceScores')
7272
model.rxnConfidenceScores=[model.rxnConfidenceScores;model.rxnConfidenceScores(cpyIndices)];
7373
end
74+
if isfield(model,'rxnDeltaG')
75+
model.rxnDeltaG=[model.rxnDeltaG;model.rxnDeltaG(cpyIndices)];
76+
end
7477

7578
%now expand the more complex fields - will be filled in later
7679
model.rxns=[model.rxns;cell(toAdd,1)];

core/getAllowedBounds.m

Lines changed: 37 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,42 @@
1-
function [minFluxes, maxFluxes, exitFlags]=getAllowedBounds(model,rxns)
1+
function [minFluxes, maxFluxes, exitFlags]=getAllowedBounds(model,rxns,runParallel)
22
% getAllowedBounds
33
% Returns the minimal and maximal fluxes through each reaction.
44
%
5-
% model a model structure
6-
% rxns either a cell array of reaction IDs, a logical vector with the
7-
% same number of elements as reactions in the model, or a vector
8-
% of reaction indexes (opt, default model.rxns)
5+
% Input:
6+
% model a model structure
7+
% rxns either a cell array of reaction IDs, a logical vector with the
8+
% same number of elements as reactions in the model, or a vector
9+
% of reaction indexes (opt, default model.rxns)
10+
% runParallel make use of MATLAB parallel pool to speed up calculations. Not
11+
% beneficial if only a limited number of reactions are simulated.
12+
% (opt, default true)
913
%
10-
% minFluxes minimal allowed fluxes
11-
% maxFluxes maximal allowed fluxes
12-
% exitFlags exit flags for min/max for each of the reactions. True if
13-
% it was possible to calculate a flux
14+
% Output:
15+
% minFluxes minimal allowed fluxes
16+
% maxFluxes maximal allowed fluxes
17+
% exitFlags exit flags for min/max for each of the reactions. True if it was
18+
% possible to calculate a flux
1419
%
1520
% NOTE: In cases where no solution can be calculated, NaN is returned.
1621
%
17-
% Usage: [minFluxes, maxFluxes, exitFlags]=getAllowedBounds(model,rxns)
22+
% Usage: [minFluxes, maxFluxes, exitFlags] = getAllowedBounds(model, rxns, runParallel)
1823

1924
if nargin<2
2025
rxns=1:numel(model.rxns);
2126
elseif ~islogical(rxns) && ~isnumeric(rxns)
2227
rxns=convertCharArray(rxns);
2328
rxns=getIndexes(model,rxns, 'rxns');
2429
end
30+
if nargin<3
31+
runParallel = true;
32+
end
33+
if runParallel
34+
addonList = matlab.addons.installedAddons;
35+
if ~any(strcmpi(addonList.Name,'Parallel Computing Toolbox'))
36+
disp('Cannot find MATLAB Parallel Computing Toolbox, process is not parallelized.')
37+
runParallel = false;
38+
end
39+
end
2540

2641
minFluxes=zeros(numel(rxns),1);
2742
maxFluxes=zeros(numel(rxns),1);
@@ -31,12 +46,9 @@
3146
N = numel(rxns);
3247
p = 1;
3348
h = waitbar(0, 'Please wait ...');
34-
35-
addonList = matlab.addons.installedAddons;
36-
if any(strcmpi(addonList.Name,'Parallel Computing Toolbox'))
49+
if runParallel
3750
D = parallel.pool.DataQueue;
38-
afterEach(D, @nUpdateWaitbar);
39-
51+
afterEach(D, @nUpdateWaitbarParallel);
4052
parfor i=1:N
4153
tmpModel=model;
4254
tmpModel.c=c;
@@ -84,14 +96,18 @@
8496
else
8597
maxFluxes(i)=NaN;
8698
end
87-
nUpdateWaitbar;
99+
nUpdateWaitbar(p,N,h);
88100
end
89101
end
90-
91102
close(h)
92103

93-
function nUpdateWaitbar(~)
94-
waitbar(p/N, h);
95-
p = p + 1;
96-
end
104+
function nUpdateWaitbarParallel(~)
105+
waitbar(p/N, h);
106+
p = p + 1;
107+
end
108+
109+
function nUpdateWaitbar(p,N,h)
110+
waitbar(p/N, h);
111+
p = p + 1;
112+
end
97113
end

0 commit comments

Comments
 (0)