Skip to content

Commit 166bc4f

Browse files
authored
fix: readYAMLmodel builds correct ec.rxnEnzMat (#568)
* fix: exportForGit correct neverPrefix option * feat: YAML I/O tests * fix: exportForGit do not test COBRA if not exist * fix: readYAMLmodel correct rxnEnzMat * fix: importExportTests less strict filesize test
1 parent 5dcec1c commit 166bc4f

16 files changed

+475
-364
lines changed

doc/installation/checkInstallation.html

Lines changed: 180 additions & 175 deletions
Large diffs are not rendered by default.

doc/io/exportForGit.html

Lines changed: 133 additions & 137 deletions
Large diffs are not rendered by default.

doc/io/exportModel.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ <h2><a name="_cross"></a>CROSS-REFERENCE INFORMATION <a href="#_top"><img alt="^
5353
<li><a href="checkFileExistence.html" class="code" title="function files=checkFileExistence(files,fullOrTemp,allowSpace,checkExist)">checkFileExistence</a> checkFileExistence</li><li><a href="exportModel.html" class="code" title="function exportModel(model,fileName,neverPrefix,supressWarnings,sortIds)">exportModel</a> exportModel</li><li><a href="sortIdentifiers.html" class="code" title="function newModel = sortIdentifiers(model)">sortIdentifiers</a> exportModel</li></ul>
5454
This function is called by:
5555
<ul style="list-style-image:url(../matlabicon.gif)">
56-
<li><a href="SBMLFromExcel.html" class="code" title="function SBMLFromExcel(fileName, outputFileName,toCOBRA,printWarnings)">SBMLFromExcel</a> SBMLFromExcel</li><li><a href="exportForGit.html" class="code" title="function out=exportForGit(model,prefix,path,formats,mainBranchFlag,subDirs,COBRAtext,COBRAstyle)">exportForGit</a> exportForGit</li><li><a href="exportModel.html" class="code" title="function exportModel(model,fileName,neverPrefix,supressWarnings,sortIds)">exportModel</a> exportModel</li></ul>
56+
<li><a href="SBMLFromExcel.html" class="code" title="function SBMLFromExcel(fileName, outputFileName,toCOBRA,printWarnings)">SBMLFromExcel</a> SBMLFromExcel</li><li><a href="exportForGit.html" class="code" title="function out=exportForGit(model,prefix,path,formats,mainBranchFlag,subDirs,COBRAtext,neverPrefixIDs)">exportForGit</a> exportForGit</li><li><a href="exportModel.html" class="code" title="function exportModel(model,fileName,neverPrefix,supressWarnings,sortIds)">exportModel</a> exportModel</li></ul>
5757
<!-- crossreference -->
5858

5959
<h2><a name="_subfunctions"></a>SUBFUNCTIONS <a href="#_top"><img alt="^" border="0" src="../up.png"></a></h2>

doc/io/exportToExcelFormat.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ <h2><a name="_cross"></a>CROSS-REFERENCE INFORMATION <a href="#_top"><img alt="^
5353
<li><a href="exportToTabDelimited.html" class="code" title="function exportToTabDelimited(model,path,sortIds)">exportToTabDelimited</a> exportToTabDelimited</li><li><a href="loadWorkbook.html" class="code" title="function workbook=loadWorkbook(fileName,createEmpty)">loadWorkbook</a> loadWorkbook</li><li><a href="sortIdentifiers.html" class="code" title="function newModel = sortIdentifiers(model)">sortIdentifiers</a> exportModel</li><li><a href="writeSheet.html" class="code" title="function wb=writeSheet(wb,sheetName,sheetPosition,captions,units,raw,isIntegers)">writeSheet</a> writeSheet</li></ul>
5454
This function is called by:
5555
<ul style="list-style-image:url(../matlabicon.gif)">
56-
<li><a href="exportForGit.html" class="code" title="function out=exportForGit(model,prefix,path,formats,mainBranchFlag,subDirs,COBRAtext,COBRAstyle)">exportForGit</a> exportForGit</li></ul>
56+
<li><a href="exportForGit.html" class="code" title="function out=exportForGit(model,prefix,path,formats,mainBranchFlag,subDirs,COBRAtext,neverPrefixIDs)">exportForGit</a> exportForGit</li></ul>
5757
<!-- crossreference -->
5858

5959

doc/io/getToolboxVersion.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ <h2><a name="_cross"></a>CROSS-REFERENCE INFORMATION <a href="#_top"><img alt="^
4949
</ul>
5050
This function is called by:
5151
<ul style="list-style-image:url(../matlabicon.gif)">
52-
<li><a href="exportForGit.html" class="code" title="function out=exportForGit(model,prefix,path,formats,mainBranchFlag,subDirs,COBRAtext,COBRAstyle)">exportForGit</a> exportForGit</li></ul>
52+
<li><a href="exportForGit.html" class="code" title="function out=exportForGit(model,prefix,path,formats,mainBranchFlag,subDirs,COBRAtext,neverPrefixIDs)">exportForGit</a> exportForGit</li></ul>
5353
<!-- crossreference -->
5454

5555
<h2><a name="_subfunctions"></a>SUBFUNCTIONS <a href="#_top"><img alt="^" border="0" src="../up.png"></a></h2>

doc/io/readYAMLmodel.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -682,7 +682,7 @@ <h2><a name="_source"></a>SOURCE CODE <a href="#_top"><img alt="^" border="0" sr
682682
0625 [~,enzIdx] = ismember(enzStoich(:,2),model.ec.enzymes);
683683
0626 coeffs = cell2mat(enzStoich(:,3));
684684
0627 model.ec.rxnEnzMat = zeros(numel(model.ec.rxns), numel(model.ec.genes));
685-
0628 linearIndices = sub2ind([max(rxnIdx), max(enzIdx)], rxnIdx, enzIdx);
685+
0628 linearIndices = sub2ind([numel(model.ec.rxns), numel(model.ec.genes)], rxnIdx, enzIdx);
686686
0629 model.ec.rxnEnzMat(linearIndices) = coeffs;
687687
0630 <span class="comment">%Parse ec-codes</span>
688688
0631 <span class="keyword">if</span> ~isempty(ecGecko)

doc/io/sortIdentifiers.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ <h2><a name="_cross"></a>CROSS-REFERENCE INFORMATION <a href="#_top"><img alt="^
4747
</ul>
4848
This function is called by:
4949
<ul style="list-style-image:url(../matlabicon.gif)">
50-
<li><a href="exportForGit.html" class="code" title="function out=exportForGit(model,prefix,path,formats,mainBranchFlag,subDirs,COBRAtext,COBRAstyle)">exportForGit</a> exportForGit</li><li><a href="exportModel.html" class="code" title="function exportModel(model,fileName,neverPrefix,supressWarnings,sortIds)">exportModel</a> exportModel</li><li><a href="exportToExcelFormat.html" class="code" title="function exportToExcelFormat(model,fileName,sortIds)">exportToExcelFormat</a> exportToExcelFormat</li><li><a href="exportToTabDelimited.html" class="code" title="function exportToTabDelimited(model,path,sortIds)">exportToTabDelimited</a> exportToTabDelimited</li><li><a href="writeYAMLmodel.html" class="code" title="function writeYAMLmodel(model,fileName,preserveQuotes,sortIds)">writeYAMLmodel</a> writeYAMLmodel</li></ul>
50+
<li><a href="exportForGit.html" class="code" title="function out=exportForGit(model,prefix,path,formats,mainBranchFlag,subDirs,COBRAtext,neverPrefixIDs)">exportForGit</a> exportForGit</li><li><a href="exportModel.html" class="code" title="function exportModel(model,fileName,neverPrefix,supressWarnings,sortIds)">exportModel</a> exportModel</li><li><a href="exportToExcelFormat.html" class="code" title="function exportToExcelFormat(model,fileName,sortIds)">exportToExcelFormat</a> exportToExcelFormat</li><li><a href="exportToTabDelimited.html" class="code" title="function exportToTabDelimited(model,path,sortIds)">exportToTabDelimited</a> exportToTabDelimited</li><li><a href="writeYAMLmodel.html" class="code" title="function writeYAMLmodel(model,fileName,preserveQuotes,sortIds)">writeYAMLmodel</a> writeYAMLmodel</li></ul>
5151
<!-- crossreference -->
5252

5353

doc/io/writeYAMLmodel.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ <h2><a name="_cross"></a>CROSS-REFERENCE INFORMATION <a href="#_top"><img alt="^
4949
<li><a href="sortIdentifiers.html" class="code" title="function newModel = sortIdentifiers(model)">sortIdentifiers</a> exportModel</li></ul>
5050
This function is called by:
5151
<ul style="list-style-image:url(../matlabicon.gif)">
52-
<li><a href="exportForGit.html" class="code" title="function out=exportForGit(model,prefix,path,formats,mainBranchFlag,subDirs,COBRAtext,COBRAstyle)">exportForGit</a> exportForGit</li></ul>
52+
<li><a href="exportForGit.html" class="code" title="function out=exportForGit(model,prefix,path,formats,mainBranchFlag,subDirs,COBRAtext,neverPrefixIDs)">exportForGit</a> exportForGit</li></ul>
5353
<!-- crossreference -->
5454

5555
<h2><a name="_subfunctions"></a>SUBFUNCTIONS <a href="#_top"><img alt="^" border="0" src="../up.png"></a></h2>

doc/testing/unit_tests/importExportTests.html

Lines changed: 46 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ <h2><a name="_cross"></a>CROSS-REFERENCE INFORMATION <a href="#_top"><img alt="^
4242

4343
<h2><a name="_subfunctions"></a>SUBFUNCTIONS <a href="#_top"><img alt="^" border="0" src="../../up.png"></a></h2>
4444
<ul style="list-style-image:url(../../matlabicon.gif)">
45-
<li><a href="#_sub1" class="code">function testExcelImport(testCase)</a></li><li><a href="#_sub2" class="code">function testSBMLImport(testCase)</a></li><li><a href="#_sub3" class="code">function testExcelExport(testCase)</a></li><li><a href="#_sub4" class="code">function testSBMLExport(testCase)</a></li></ul>
45+
<li><a href="#_sub1" class="code">function testExcelImport(testCase)</a></li><li><a href="#_sub2" class="code">function testSBMLImport(testCase)</a></li><li><a href="#_sub3" class="code">function testYAMLimport(testCase)</a></li><li><a href="#_sub4" class="code">function testExcelExport(testCase)</a></li><li><a href="#_sub5" class="code">function testSBMLExport(testCase)</a></li><li><a href="#_sub6" class="code">function testYAMLexport(testCase)</a></li></ul>
4646

4747
<h2><a name="_source"></a>SOURCE CODE <a href="#_top"><img alt="^" border="0" src="../../up.png"></a></h2>
4848
<div class="fragment"><pre>0001 <span class="comment">%run this test case with the command</span>
@@ -72,31 +72,52 @@ <h2><a name="_source"></a>SOURCE CODE <a href="#_top"><img alt="^" border="0" sr
7272
0025 verifyEqual(testCase,model,modelSBML)
7373
0026 <span class="keyword">end</span>
7474
0027
75-
0028 <a name="_sub3" href="#_subfunctions" class="code">function testExcelExport(testCase)</a>
75+
0028 <a name="_sub3" href="#_subfunctions" class="code">function testYAMLimport(testCase)</a>
7676
0029 sourceDir=fileparts(fileparts(fileparts(which(mfilename))));
77-
0030 load(fullfile(sourceDir,<span class="string">'testing'</span>,<span class="string">'unit_tests'</span>,<span class="string">'test_data'</span>,<span class="string">'ecoli_textbook.mat'</span>), <span class="string">'model'</span>);
78-
0031 exportToExcelFormat(model,fullfile(sourceDir,<span class="string">'testing'</span>,<span class="string">'unit_tests'</span>,<span class="string">'test_data'</span>,<span class="string">'_test.xlsx'</span>));
79-
0032 <span class="comment">%File will not be exactly equal as it contains the current date and time,</span>
80-
0033 <span class="comment">%so md5 or similar would not work. Just check whether file is reasonably</span>
81-
0034 <span class="comment">%sized.</span>
82-
0035 s = dir(fullfile(sourceDir,<span class="string">'testing'</span>,<span class="string">'unit_tests'</span>,<span class="string">'test_data'</span>,<span class="string">'_test.xlsx'</span>));
83-
0036 filesize = s.bytes;
84-
0037 verifyTrue(testCase,filesize&gt;17000);
85-
0038 delete(fullfile(sourceDir,<span class="string">'testing'</span>,<span class="string">'unit_tests'</span>,<span class="string">'test_data'</span>,<span class="string">'_test.xlsx'</span>));
86-
0039 <span class="keyword">end</span>
87-
0040
88-
0041 <a name="_sub4" href="#_subfunctions" class="code">function testSBMLExport(testCase)</a>
89-
0042 sourceDir=fileparts(fileparts(fileparts(which(mfilename))));
90-
0043 load(fullfile(sourceDir,<span class="string">'testing'</span>,<span class="string">'unit_tests'</span>,<span class="string">'test_data'</span>,<span class="string">'ecoli_textbook.mat'</span>), <span class="string">'model'</span>);
91-
0044 evalc(<span class="string">'exportModel(model,fullfile(sourceDir,''testing'',''unit_tests'',''test_data'',''_test.xml''))'</span>);
92-
0045 <span class="comment">%File will not be exactly equal as it contains the current date and time,</span>
93-
0046 <span class="comment">%so md5 or similar would not work. Just check whether file is reasonably</span>
94-
0047 <span class="comment">%sized.</span>
95-
0048 s = dir(fullfile(sourceDir,<span class="string">'testing'</span>,<span class="string">'unit_tests'</span>,<span class="string">'test_data'</span>,<span class="string">'_test.xml'</span>));
96-
0049 filesize = s.bytes;
97-
0050 verifyTrue(testCase,filesize&gt;18500);
98-
0051 delete(fullfile(sourceDir,<span class="string">'testing'</span>,<span class="string">'unit_tests'</span>,<span class="string">'test_data'</span>,<span class="string">'_test.xml'</span>));
99-
0052 <span class="keyword">end</span></pre></div>
77+
0030 yamlFile=fullfile(sourceDir,<span class="string">'tutorial'</span>,<span class="string">'empty.yml'</span>);
78+
0031 evalc(<span class="string">'model=readYAMLmodel(yamlFile)'</span>); <span class="comment">% Repress warnings</span>
79+
0032 load(fullfile(sourceDir,<span class="string">'testing'</span>,<span class="string">'unit_tests'</span>,<span class="string">'test_data'</span>,<span class="string">'importExportResults.mat'</span>), <span class="string">'modelYAML'</span>);
80+
0033 verifyEqual(testCase,model,modelYAML)
81+
0034 <span class="keyword">end</span>
82+
0035
83+
0036 <a name="_sub4" href="#_subfunctions" class="code">function testExcelExport(testCase)</a>
84+
0037 sourceDir=fileparts(fileparts(fileparts(which(mfilename))));
85+
0038 load(fullfile(sourceDir,<span class="string">'testing'</span>,<span class="string">'unit_tests'</span>,<span class="string">'test_data'</span>,<span class="string">'ecoli_textbook.mat'</span>), <span class="string">'model'</span>);
86+
0039 exportToExcelFormat(model,fullfile(sourceDir,<span class="string">'testing'</span>,<span class="string">'unit_tests'</span>,<span class="string">'test_data'</span>,<span class="string">'_test.xlsx'</span>));
87+
0040 <span class="comment">%File will not be exactly equal as it contains the current date and time,</span>
88+
0041 <span class="comment">%so md5 or similar would not work. Just check whether file is reasonably</span>
89+
0042 <span class="comment">%sized.</span>
90+
0043 s = dir(fullfile(sourceDir,<span class="string">'testing'</span>,<span class="string">'unit_tests'</span>,<span class="string">'test_data'</span>,<span class="string">'_test.xlsx'</span>));
91+
0044 filesize = s.bytes;
92+
0045 verifyTrue(testCase,filesize&gt;17000);
93+
0046 delete(fullfile(sourceDir,<span class="string">'testing'</span>,<span class="string">'unit_tests'</span>,<span class="string">'test_data'</span>,<span class="string">'_test.xlsx'</span>));
94+
0047 <span class="keyword">end</span>
95+
0048
96+
0049 <a name="_sub5" href="#_subfunctions" class="code">function testSBMLExport(testCase)</a>
97+
0050 sourceDir=fileparts(fileparts(fileparts(which(mfilename))));
98+
0051 load(fullfile(sourceDir,<span class="string">'testing'</span>,<span class="string">'unit_tests'</span>,<span class="string">'test_data'</span>,<span class="string">'ecoli_textbook.mat'</span>), <span class="string">'model'</span>);
99+
0052 evalc(<span class="string">'exportModel(model,fullfile(sourceDir,''testing'',''unit_tests'',''test_data'',''_test.xml''))'</span>);
100+
0053 <span class="comment">%File will not be exactly equal as it contains the current date and time,</span>
101+
0054 <span class="comment">%so md5 or similar would not work. Just check whether file is reasonably</span>
102+
0055 <span class="comment">%sized.</span>
103+
0056 s = dir(fullfile(sourceDir,<span class="string">'testing'</span>,<span class="string">'unit_tests'</span>,<span class="string">'test_data'</span>,<span class="string">'_test.xml'</span>));
104+
0057 filesize = s.bytes;
105+
0058 verifyTrue(testCase,filesize&gt;18500);
106+
0059 delete(fullfile(sourceDir,<span class="string">'testing'</span>,<span class="string">'unit_tests'</span>,<span class="string">'test_data'</span>,<span class="string">'_test.xml'</span>));
107+
0060 <span class="keyword">end</span>
108+
0061
109+
0062 <a name="_sub6" href="#_subfunctions" class="code">function testYAMLexport(testCase)</a>
110+
0063 sourceDir=fileparts(fileparts(fileparts(which(mfilename))));
111+
0064 load(fullfile(sourceDir,<span class="string">'tutorial'</span>,<span class="string">'empty.mat'</span>), <span class="string">'emptyModel'</span>);
112+
0065 evalc(<span class="string">'writeYAMLmodel(emptyModel,fullfile(sourceDir,''testing'',''unit_tests'',''test_data'',''_test.yml''))'</span>);
113+
0066 <span class="comment">%File will not be exactly equal as it contains the current date and time,</span>
114+
0067 <span class="comment">%so md5 or similar would not work. Just check whether file is reasonably</span>
115+
0068 <span class="comment">%sized.</span>
116+
0069 s = dir(fullfile(sourceDir,<span class="string">'testing'</span>,<span class="string">'unit_tests'</span>,<span class="string">'test_data'</span>,<span class="string">'_test.yml'</span>));
117+
0070 filesize = s.bytes;
118+
0071 verifyTrue(testCase,filesize&gt;1290);
119+
0072 delete(fullfile(sourceDir,<span class="string">'testing'</span>,<span class="string">'unit_tests'</span>,<span class="string">'test_data'</span>,<span class="string">'_test.yml'</span>));
120+
0073 <span class="keyword">end</span></pre></div>
100121
<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>
101122
</body>
102123
</html>

installation/checkInstallation.m

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@
179179
end
180180

181181
fprintf(myStr(' > Export Excel format',40))
182-
if res(3).Passed == 1
182+
if res(4).Passed == 1
183183
fprintf('Pass\n')
184184
else
185185
printOrange('Fail\n')
@@ -193,20 +193,25 @@
193193
end
194194

195195
fprintf(myStr(' > Export SBML format',40))
196-
if res(4).Passed == 1
196+
if res(5).Passed == 1
197197
fprintf('Pass\n')
198198
else
199199
printOrange('Fail\n')
200200
end
201201

202-
%Check if it is possible to import an YAML model
203-
% fprintf(' > Checking import of model in YAML format:\t\t\t');
204-
% try
205-
% readYaml(ymlFile,true);
206-
% fprintf('Pass\n');
207-
% catch
208-
% printOrange('Fail\n');
209-
% end
202+
fprintf(myStr(' > Import YAML format',40))
203+
if res(3).Passed == 1
204+
fprintf('Pass\n')
205+
else
206+
printOrange('Fail\n')
207+
end
208+
209+
fprintf(myStr(' > Export YAML format',40))
210+
if res(6).Passed == 1
211+
fprintf('Pass\n')
212+
else
213+
printOrange('Fail\n')
214+
end
210215

211216
fprintf('\n=== Model solvers ===\n');
212217

io/exportForGit.m

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
function out=exportForGit(model,prefix,path,formats,mainBranchFlag,subDirs,COBRAtext,COBRAstyle)
1+
function out=exportForGit(model,prefix,path,formats,mainBranchFlag,subDirs,COBRAtext,neverPrefixIDs)
22
% exportForGit
33
% Generates a directory structure and populates this with model files, ready
44
% to be commited to a Git(Hub) maintained model repository. Writes the model
@@ -28,16 +28,13 @@
2828
% Toolbox format using metabolite IDs, instead of
2929
% metabolite names and compartments. (optional,
3030
% default false)
31-
% COBRAstyle true if COBRA-style prefixes should be added to all
32-
% identifiers in the SBML file: R_ for reactions, M_
33-
% for metabolites, G_ for genes and C_ for
34-
% compartments. If all identifiers of a particular
35-
% field already have the prefix, then no additional
36-
% prefixes are added. (optional, default false)
31+
% neverPrefixIDs true if prefixes are never added to identifiers,
32+
% even if start with e.g. digits. This might result
33+
% in invalid SBML files (optional, default false)
3734
%
3835
% Usage: exportForGit(model,prefix,path,formats,mainBranchFlag,subDirs,COBRAtext,COBRAstyle)
3936
if nargin<8
40-
COBRAstyle=false;
37+
neverPrefixIDs=false;
4138
end
4239
if nargin<7 || isempty(COBRAtext)
4340
COBRAtext=false;
@@ -73,7 +70,9 @@
7370

7471
%Get versions or commits of toolboxes:
7572
RAVENver = getToolboxVersion('RAVEN','ravenCobraWrapper.m',mainBranchFlag);
76-
COBRAver = getToolboxVersion('COBRA','initCobraToolbox.m',mainBranchFlag);
73+
if exist('initCobraToolbox.m','file')
74+
COBRAver = getToolboxVersion('COBRA','initCobraToolbox.m',mainBranchFlag);
75+
end
7776

7877
%Retrieve libSBML version:
7978
[ravenDir,prevDir]=findRAVENroot();
@@ -142,7 +141,7 @@
142141

143142
% Write XML format
144143
if ismember('xml', formats)
145-
exportModel(model,fullfile(filePath{5},strcat(prefix,'.xml')),COBRAstyle);
144+
exportModel(model,fullfile(filePath{5},strcat(prefix,'.xml')),neverPrefixIDs);
146145
end
147146

148147
%Save file with versions:

io/readYAMLmodel.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -625,7 +625,7 @@
625625
[~,enzIdx] = ismember(enzStoich(:,2),model.ec.enzymes);
626626
coeffs = cell2mat(enzStoich(:,3));
627627
model.ec.rxnEnzMat = zeros(numel(model.ec.rxns), numel(model.ec.genes));
628-
linearIndices = sub2ind([max(rxnIdx), max(enzIdx)], rxnIdx, enzIdx);
628+
linearIndices = sub2ind([numel(model.ec.rxns), numel(model.ec.genes)], rxnIdx, enzIdx);
629629
model.ec.rxnEnzMat(linearIndices) = coeffs;
630630
%Parse ec-codes
631631
if ~isempty(ecGecko)

0 commit comments

Comments
 (0)