0001 function exportToExcelFormat(model,fileName,sortIds)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018 if nargin<2 || isempty(fileName)
0019 [fileName, pathName] = uiputfile('*.xlsx', 'Select file for model export',[model.id '.xlsx']);
0020 if fileName == 0
0021 error('You should provide a file location')
0022 else
0023 fileName = fullfile(pathName,fileName);
0024 end
0025 end
0026 fileName=char(fileName);
0027 if nargin<3
0028 sortIds=false;
0029 end
0030 if sortIds==true
0031 model=sortIdentifiers(model);
0032 end
0033
0034 checkModelStruct(model);
0035
0036 addList = matlab.addons.installedAddons;
0037 if any(strcmpi(addList.Name,'Text Analytics Toolbox'))
0038 error(['exportToExcelFormat is incompatible with MATLAB Text Analytics Toolbox. ' ...
0039 'Further instructions => https://github.com/SysBioChalmers/RAVEN/issues/55#issuecomment-1514369299'])
0040 end
0041
0042 [~, A, B]=fileparts(fileName);
0043
0044
0045 if ~any(A) || ~any(B)
0046 exportToTabDelimited(model,fileName);
0047 return;
0048 end
0049
0050 if ~strcmpi(B,'.xlsx')
0051 EM='As of RAVEN version 1.9, only export to xlsx format is supported';
0052 dispEM(EM);
0053 end
0054
0055 import java.io.File;
0056 import java.io.FileOutputStream;
0057 import java.io.IOException;
0058
0059
0060 if isfile(fileName)
0061 delete(fileName);
0062 end
0063
0064
0065 wb=loadWorkbook(fileName,true);
0066
0067
0068 model.equations=constructEquations(model,model.rxns,true);
0069
0070
0071 if isfield(model,'grRules')
0072 rules=model.grRules;
0073 else
0074 rules=[];
0075 end
0076
0077
0078
0079 hasDefaultLB=false;
0080 hasDefaultUB=false;
0081 if isfield(model,'annotation')
0082 if isfield(model.annotation,'defaultLB')
0083 hasDefaultLB=true;
0084 end
0085 if isfield(model.annotation,'defaultUB')
0086 hasDefaultUB=true;
0087 end
0088 end
0089
0090
0091
0092
0093 headers={'#';'ID';'NAME';'EQUATION';'EC-NUMBER';'GENE ASSOCIATION';'LOWER BOUND';'UPPER BOUND';'OBJECTIVE';'COMPARTMENT';'MIRIAM';'SUBSYSTEM';'REPLACEMENT ID';'NOTE';'REFERENCE';'CONFIDENCE SCORE'};
0094
0095
0096 emptyColumn=cell(numel(model.rxns),1);
0097 rxnSheet=emptyColumn;
0098
0099
0100 rxnSheet=[rxnSheet model.rxns];
0101
0102 if isfield(model,'rxnNames')
0103 rxnSheet=[rxnSheet model.rxnNames];
0104 else
0105 rxnSheet=[rxnSheet emptyColumn];
0106 end
0107
0108 rxnSheet=[rxnSheet model.equations];
0109
0110 if isfield(model,'eccodes')
0111 rxnSheet=[rxnSheet model.eccodes];
0112 else
0113 rxnSheet=[rxnSheet emptyColumn];
0114 end
0115
0116 if ~isempty(rules)
0117 rxnSheet=[rxnSheet rules];
0118 else
0119 rxnSheet=[rxnSheet emptyColumn];
0120 end
0121
0122 lb=emptyColumn;
0123 ub=emptyColumn;
0124 objective=emptyColumn;
0125 rxnMiriams=emptyColumn;
0126
0127 for i=1:numel(model.rxns)
0128 if isfield(model,'lb')
0129 if hasDefaultLB==true
0130 if model.rev(i)==1
0131
0132 if model.lb(i) ~= model.annotation.defaultLB
0133 lb{i}=model.lb(i);
0134 end
0135 else
0136
0137 if model.lb(i)~=0
0138 lb{i}=model.lb(i);
0139 end
0140 end
0141 else
0142 lb{i}=model.lb(i);
0143 end
0144 end
0145
0146 if isfield(model,'ub')
0147 if hasDefaultUB==true
0148 if model.ub(i) ~= model.annotation.defaultUB
0149 ub{i}=model.ub(i);
0150 end
0151 else
0152 ub{i}=model.ub(i);
0153 end
0154 end
0155
0156 if isfield(model,'c')
0157 if model.c(i)~=0
0158 objective{i}=model.c(i);
0159 end
0160 end
0161
0162 if isfield(model,'rxnMiriams')
0163 if ~isempty(model.rxnMiriams{i})
0164 toPrint=[];
0165 for j=1:numel(model.rxnMiriams{i}.name)
0166 toPrint=[toPrint strtrim(model.rxnMiriams{i}.name{j}) '/' strtrim(model.rxnMiriams{i}.value{j}) ';'];
0167 end
0168 rxnMiriams{i}=toPrint(1:end-1);
0169 end
0170 end
0171 end
0172
0173 rxnSheet=[rxnSheet lb];
0174 rxnSheet=[rxnSheet ub];
0175 rxnSheet=[rxnSheet objective];
0176
0177 if isfield(model,'rxnComps')
0178 rxnSheet=[rxnSheet model.comps(model.rxnComps)];
0179 else
0180 rxnSheet=[rxnSheet emptyColumn];
0181 end
0182
0183 rxnSheet=[rxnSheet rxnMiriams];
0184
0185 subsystems='';
0186 if isfield(model,'subSystems')
0187 for i=1:numel(model.subSystems)
0188 if ~iscell(model.subSystems{i})
0189 model.subSystems{i} = {model.subSystems{i}};
0190 end
0191 if ~isempty(model.subSystems{i,1})
0192 subsystems{i,1}=strjoin(model.subSystems{i,1},';');
0193 else
0194 subsystems{i,1}='';
0195 end
0196 end
0197 rxnSheet=[rxnSheet subsystems];
0198 else
0199 rxnSheet=[rxnSheet emptyColumn];
0200 end
0201
0202
0203 rxnSheet=[rxnSheet emptyColumn];
0204
0205 if isfield(model,'rxnNotes')
0206 rxnSheet=[rxnSheet model.rxnNotes];
0207 else
0208 rxnSheet=[rxnSheet emptyColumn];
0209 end
0210
0211 if isfield(model,'rxnReferences')
0212 rxnSheet=[rxnSheet model.rxnReferences];
0213 else
0214 rxnSheet=[rxnSheet emptyColumn];
0215 end
0216
0217 if isfield(model,'rxnConfidenceScores')
0218 rxnSheet=[rxnSheet num2cell(model.rxnConfidenceScores)];
0219 else
0220 rxnSheet=[rxnSheet emptyColumn];
0221 end
0222
0223 wb=writeSheet(wb,'RXNS',0,headers,[],rxnSheet);
0224
0225 headers={'#';'ID';'NAME';'UNCONSTRAINED';'MIRIAM';'COMPOSITION';'InChI';'COMPARTMENT';'REPLACEMENT ID';'CHARGE'};
0226
0227 metSheet=cell(numel(model.mets),numel(headers));
0228
0229 for i=1:numel(model.mets)
0230 metSheet{i,2}=[model.metNames{i} '[' model.comps{model.metComps(i)} ']'];
0231
0232 if isfield(model,'metNames')
0233 metSheet(i,3)=model.metNames(i);
0234 end
0235
0236 if isfield(model,'unconstrained')
0237 if model.unconstrained(i)~=0
0238 metSheet{i,4}=true;
0239 end
0240 end
0241
0242 if isfield(model,'metMiriams')
0243 if ~isempty(model.metMiriams{i})
0244 toPrint=[];
0245 for j=1:numel(model.metMiriams{i}.name)
0246 toPrint=[toPrint strtrim(model.metMiriams{i}.name{j}) '/' strtrim(model.metMiriams{i}.value{j}) ';'];
0247 end
0248 metSheet{i,5}=toPrint(1:end-1);
0249 end
0250 end
0251
0252
0253
0254 if isfield(model,'metFormulas')
0255 if isfield(model,'inchis')
0256 if isempty(model.inchis{i})
0257 metSheet(i,6)=model.metFormulas(i);
0258 end
0259 else
0260 metSheet(i,6)=model.metFormulas(i);
0261 end
0262 end
0263
0264 if isfield(model,'inchis')
0265 metSheet(i,7)=model.inchis(i);
0266 end
0267
0268 if isfield(model,'metComps')
0269 metSheet(i,8)=model.comps(model.metComps(i));
0270 end
0271
0272 metSheet(i,9)=model.mets(i);
0273
0274 if isfield(model,'metCharges')
0275 metSheet{i,10}=model.metCharges(i);
0276 end
0277 end
0278
0279 wb=writeSheet(wb,'METS',1,headers,[],metSheet);
0280
0281
0282
0283
0284 headers={'#';'ABBREVIATION';'NAME';'INSIDE';'MIRIAM'};
0285
0286 compSheet=cell(numel(model.comps),numel(headers));
0287
0288 for i=1:numel(model.comps)
0289 compSheet(i,2)=model.comps(i);
0290
0291 if isfield(model,'compNames')
0292 compSheet(i,3)=model.compNames(i);
0293 end
0294
0295 if isfield(model,'compOutside')
0296 compSheet(i,4)=model.compOutside(i);
0297 end
0298
0299 if isfield(model,'compMiriams')
0300 if ~isempty(model.compMiriams{i})
0301 toPrint=[];
0302 for j=1:numel(model.compMiriams{i}.name)
0303 toPrint=[toPrint strtrim(model.compMiriams{i}.name{j}) '/' strtrim(model.compMiriams{i}.value{j}) ';'];
0304 end
0305 compSheet{i,5}=toPrint(1:end-1);
0306 end
0307 end
0308 end
0309
0310 wb=writeSheet(wb,'COMPS',2,headers,[],compSheet);
0311
0312
0313 if isfield(model,'genes')
0314
0315 headers={'#';'NAME';'MIRIAM';'SHORT NAME';'COMPARTMENT'};
0316
0317 geneSheet=cell(numel(model.genes),numel(headers));
0318
0319 for i=1:numel(model.genes)
0320 geneSheet(i,2)=model.genes(i);
0321
0322 if isfield(model,'geneMiriams')
0323 if ~isempty(model.geneMiriams{i})
0324 toPrint=[];
0325 for j=1:numel(model.geneMiriams{i}.name)
0326 toPrint=[toPrint strtrim(model.geneMiriams{i}.name{j}) '/' strtrim(model.geneMiriams{i}.value{j}) ';'];
0327 end
0328 geneSheet{i,3}=toPrint(1:end-1);
0329 end
0330 end
0331 if isfield(model,'geneShortNames')
0332 geneSheet(i,4)=model.geneShortNames(i);
0333 end
0334 if isfield(model,'geneComps')
0335 geneSheet(i,5)=model.comps(model.geneComps(i));
0336 end
0337 end
0338
0339 wb=writeSheet(wb,'GENES',3,headers,[],geneSheet);
0340 end
0341
0342
0343
0344
0345 headers={'#';'ID';'NAME';'TAXONOMY';'DEFAULT LOWER';'DEFAULT UPPER';'CONTACT GIVEN NAME';'CONTACT FAMILY NAME';'CONTACT EMAIL';'ORGANIZATION';'NOTES'};
0346
0347 modelSheet=cell(1,numel(headers));
0348
0349 if ~isfield(model,'annotation')
0350 model.annotation = [];
0351 end
0352
0353 if isfield(model,'id')
0354 modelSheet{1,2}=model.id;
0355 else
0356 modelSheet{1,2}='blankID';
0357 end
0358 if isfield(model,'name')
0359 modelSheet{1,3}=model.name;
0360 else
0361 modelSheet{1,3}='blankName';
0362 end
0363 if isfield(model.annotation,'taxonomy')
0364 modelSheet{1,4}=model.annotation.taxonomy;
0365 end
0366 if isfield(model.annotation,'defaultLB')
0367 modelSheet{1,5}=model.annotation.defaultLB;
0368 end
0369 if isfield(model.annotation,'defaultUB')
0370 modelSheet{1,6}=model.annotation.defaultUB;
0371 end
0372 if isfield(model.annotation,'givenName')
0373 modelSheet{1,7}=model.annotation.givenName;
0374 end
0375 if isfield(model.annotation,'familyName')
0376 modelSheet{1,8}=model.annotation.familyName;
0377 end
0378 if isfield(model.annotation,'email')
0379 modelSheet{1,9}=model.annotation.email;
0380 end
0381 if isfield(model.annotation,'organization')
0382 modelSheet{1,10}=model.annotation.organization;
0383 end
0384 if isfield(model.annotation,'note')
0385 modelSheet{1,11}=model.annotation.note;
0386 end
0387
0388 if isfield(model,'genes')
0389 wb=writeSheet(wb,'MODEL',4,headers,[],modelSheet);
0390 else
0391 wb=writeSheet(wb,'MODEL',3,headers,[],modelSheet);
0392 end
0393
0394
0395 out = FileOutputStream(fileName);
0396 wb.write(out);
0397 out.close();
0398 end