-
Notifications
You must be signed in to change notification settings - Fork 54
/
exportModel.html
856 lines (846 loc) · 65.4 KB
/
exportModel.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/REC-html40/loose.dtd">
<html>
<head>
<title>Description of exportModel</title>
<meta name="keywords" content="exportModel">
<meta name="description" content="exportModel">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="generator" content="m2html v1.5 © 2003-2005 Guillaume Flandin">
<meta name="robots" content="index, follow">
<link type="text/css" rel="stylesheet" href="../m2html.css">
</head>
<body>
<a name="_top"></a>
<div><a href="../index.html">Home</a> > <a href="index.html">io</a> > exportModel.m</div>
<!--<table width="100%"><tr><td align="left"><a href="../index.html"><img alt="<" border="0" src="../left.png"> Master index</a></td>
<td align="right"><a href="index.html">Index for io <img alt=">" border="0" src="../right.png"></a></td></tr></table>-->
<h1>exportModel
</h1>
<h2><a name="_name"></a>PURPOSE <a href="#_top"><img alt="^" border="0" src="../up.png"></a></h2>
<div class="box"><strong>exportModel</strong></div>
<h2><a name="_synopsis"></a>SYNOPSIS <a href="#_top"><img alt="^" border="0" src="../up.png"></a></h2>
<div class="box"><strong>function exportModel(model,fileName,neverPrefix,supressWarnings,sortIds) </strong></div>
<h2><a name="_description"></a>DESCRIPTION <a href="#_top"><img alt="^" border="0" src="../up.png"></a></h2>
<div class="fragment"><pre class="comment"> exportModel
Exports a constraint-based model to an SBML file (L3V1 FBCv2)
Input:
model a model structure
fileName filename to export the model to. A dialog window
will open if no file name is specified.
neverPrefix true if prefixes are never added to identifiers,
even if start with e.g. digits. This might result
in invalid SBML files (optional, default false)
supressWarnings true if warnings should be supressed. This might
results in invalid SBML files, as no checks are
performed (optional, default false)
sortIds logical whether metabolites, reactions and genes
should be sorted alphabetically by their
identifiers (optional, default false)
Usage: exportModel(model,fileName,neverPrefix,supressWarnings,sortIds)</pre></div>
<!-- crossreference -->
<h2><a name="_cross"></a>CROSS-REFERENCE INFORMATION <a href="#_top"><img alt="^" border="0" src="../up.png"></a></h2>
This function calls:
<ul style="list-style-image:url(../matlabicon.gif)">
<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>
This function is called by:
<ul style="list-style-image:url(../matlabicon.gif)">
<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>
<!-- crossreference -->
<h2><a name="_subfunctions"></a>SUBFUNCTIONS <a href="#_top"><img alt="^" border="0" src="../up.png"></a></h2>
<ul style="list-style-image:url(../matlabicon.gif)">
<li><a href="#_sub1" class="code">function modelSBML=getSBMLStructure(sbmlLevel,sbmlVersion,sbmlPackages,sbmlPackageVersions)</a></li><li><a href="#_sub2" class="code">function miriamString=getMiriam(miriamStruct)</a></li><li><a href="#_sub3" class="code">function [tmp_Rxn]=addReactantsProducts(model,sbmlModel,i)</a></li><li><a href="#_sub4" class="code">function vecT = columnVector(vec)</a></li></ul>
<h2><a name="_source"></a>SOURCE CODE <a href="#_top"><img alt="^" border="0" src="../up.png"></a></h2>
<div class="fragment"><pre>0001 <a name="_sub0" href="#_subfunctions" class="code">function exportModel(model,fileName,neverPrefix,supressWarnings,sortIds)</a>
0002 <span class="comment">% exportModel</span>
0003 <span class="comment">% Exports a constraint-based model to an SBML file (L3V1 FBCv2)</span>
0004 <span class="comment">%</span>
0005 <span class="comment">% Input:</span>
0006 <span class="comment">% model a model structure</span>
0007 <span class="comment">% fileName filename to export the model to. A dialog window</span>
0008 <span class="comment">% will open if no file name is specified.</span>
0009 <span class="comment">% neverPrefix true if prefixes are never added to identifiers,</span>
0010 <span class="comment">% even if start with e.g. digits. This might result</span>
0011 <span class="comment">% in invalid SBML files (optional, default false)</span>
0012 <span class="comment">% supressWarnings true if warnings should be supressed. This might</span>
0013 <span class="comment">% results in invalid SBML files, as no checks are</span>
0014 <span class="comment">% performed (optional, default false)</span>
0015 <span class="comment">% sortIds logical whether metabolites, reactions and genes</span>
0016 <span class="comment">% should be sorted alphabetically by their</span>
0017 <span class="comment">% identifiers (optional, default false)</span>
0018 <span class="comment">%</span>
0019 <span class="comment">% Usage: exportModel(model,fileName,neverPrefix,supressWarnings,sortIds)</span>
0020
0021 <span class="keyword">if</span> nargin<2 || isempty(fileName)
0022 [fileName, pathName] = uiputfile({<span class="string">'*.xml;*.sbml'</span>}, <span class="string">'Select file for model export'</span>,[model.id <span class="string">'.xml'</span>]);
0023 <span class="keyword">if</span> fileName == 0
0024 error(<span class="string">'You should provide a file location'</span>)
0025 <span class="keyword">else</span>
0026 fileName = fullfile(pathName,fileName);
0027 <span class="keyword">end</span>
0028 <span class="keyword">end</span>
0029 fileName=char(fileName);
0030 <span class="keyword">if</span> nargin<3 || isempty(neverPrefix)
0031 neverPrefix=false;
0032 <span class="keyword">end</span>
0033 <span class="keyword">if</span> nargin<4 || isempty(supressWarnings)
0034 supressWarnings=false;
0035 <span class="keyword">end</span>
0036 <span class="keyword">if</span> nargin<5 || isempty(sortIds)
0037 sortIds=false;
0038 <span class="keyword">end</span>
0039 <span class="keyword">if</span> sortIds==true
0040 model=<a href="sortIdentifiers.html" class="code" title="function newModel = sortIdentifiers(model)">sortIdentifiers</a>(model);
0041 <span class="keyword">end</span>
0042
0043 <span class="keyword">if</span> isfield(model,<span class="string">'ec'</span>)
0044 warning("<a href="exportModel.html" class="code" title="function exportModel(model,fileName,neverPrefix,supressWarnings,sortIds)">exportModel</a> does not store information from the <span class="string">'model.ec'</span> structure. Use <span class="string">'writeYAMLmodel(model)'</span> to export all content from a GECKO model.")
0045 <span class="keyword">end</span>
0046
0047 <span class="comment">%If no subSystems are defined, then no need to use groups package</span>
0048 <span class="keyword">if</span> isfield(model,<span class="string">'subSystems'</span>)
0049 modelHasSubsystems=true;
0050 <span class="keyword">else</span>
0051 modelHasSubsystems=false;
0052 <span class="keyword">end</span>
0053
0054 <span class="comment">%The default SBML format settings, which are used as input for appropriate</span>
0055 <span class="comment">%libSBML functions to generate the blank SBML model structure before using</span>
0056 <span class="comment">%exporting in with OutputSBML to xml file</span>
0057 sbmlLevel=3;
0058 sbmlVersion=1;
0059 sbmlPackages={<span class="string">'fbc'</span>};
0060 sbmlPackageVersions=2;
0061 <span class="keyword">if</span> modelHasSubsystems
0062 sbmlPackages={sbmlPackages,<span class="string">'groups'</span>};
0063 sbmlPackageVersions=[sbmlPackageVersions,1];
0064 <span class="keyword">end</span>
0065
0066 <span class="comment">%Check if the "unconstrained" field is still present. This shows if</span>
0067 <span class="comment">%exchange metabolites have been removed</span>
0068 <span class="keyword">if</span> ~isfield(model,<span class="string">'unconstrained'</span>)
0069 model.unconstrained=zeros(numel(model.mets),1);
0070 <span class="keyword">end</span>
0071
0072 <span class="comment">%If model id and name do not exist, make sure that default</span>
0073 <span class="comment">%strings are included</span>
0074 <span class="keyword">if</span> ~isfield(model,<span class="string">'id'</span>)
0075 fprintf(<span class="string">'WARNING: The model is missing the "id" field. Uses "blankID". \n'</span>);
0076 model.id=<span class="string">'blankID'</span>;
0077 <span class="keyword">end</span>
0078 <span class="keyword">if</span> ~isfield(model,<span class="string">'name'</span>)
0079 fprintf(<span class="string">'WARNING: The model is missing the "name" field. Uses "blankName". \n'</span>);
0080 model.name=<span class="string">'blankName'</span>;
0081 <span class="keyword">end</span>
0082
0083 <span class="comment">% Add prefixes if required</span>
0084 <span class="keyword">if</span> ~neverPrefix
0085 [model,hasChanged] = addIdentifierPrefix(model);
0086 dispEM([<span class="string">'The following fields have one or more entries that do not start '</span><span class="keyword">...</span>
0087 <span class="string">'with a letter or _ (conflicting with SBML specifications). Prefixes '</span><span class="keyword">...</span>
0088 <span class="string">'are added to all entries in those fields:'</span>],false,hasChanged)
0089 <span class="keyword">end</span>
0090
0091 <span class="comment">%Check the model structure</span>
0092 <span class="keyword">if</span> supressWarnings==false
0093 checkModelStruct(model);
0094 <span class="keyword">end</span>
0095
0096 <span class="comment">%Add several blank fields, if they do not exist already. This is to reduce</span>
0097 <span class="comment">%the number of conditions below</span>
0098 <span class="keyword">if</span> ~isfield(model,<span class="string">'compMiriams'</span>)
0099 model.compMiriams=cell(numel(model.comps),1);
0100 <span class="keyword">end</span>
0101 <span class="keyword">if</span> ~isfield(model,<span class="string">'inchis'</span>)
0102 model.inchis=cell(numel(model.mets),1);
0103 <span class="keyword">end</span>
0104 <span class="keyword">if</span> ~isfield(model,<span class="string">'metFormulas'</span>)
0105 model.metFormulas=cell(numel(model.mets),1);
0106 <span class="keyword">end</span>
0107 <span class="keyword">if</span> ~isfield(model,<span class="string">'metMiriams'</span>)
0108 model.metMiriams=cell(numel(model.mets),1);
0109 <span class="keyword">end</span>
0110 <span class="keyword">if</span> ~isfield(model,<span class="string">'geneMiriams'</span>) && isfield(model,<span class="string">'genes'</span>)
0111 model.geneMiriams=cell(numel(model.genes),1);
0112 <span class="keyword">end</span>
0113 <span class="keyword">if</span> ~isfield(model,<span class="string">'geneShortNames'</span>) && isfield(model,<span class="string">'genes'</span>)
0114 model.geneShortNames=cell(numel(model.genes),1);
0115 <span class="keyword">end</span>
0116 <span class="keyword">if</span> ~isfield(model,<span class="string">'proteins'</span>) && isfield(model,<span class="string">'genes'</span>)
0117 model.proteins=cell(numel(model.genes),1);
0118 <span class="keyword">end</span>
0119 <span class="keyword">if</span> ~isfield(model,<span class="string">'subSystems'</span>)
0120 model.subSystems=cell(numel(model.rxns),1);
0121 <span class="keyword">end</span>
0122 <span class="keyword">if</span> ~isfield(model,<span class="string">'eccodes'</span>)
0123 model.eccodes=cell(numel(model.rxns),1);
0124 <span class="keyword">end</span>
0125 <span class="keyword">if</span> ~isfield(model,<span class="string">'rxnReferences'</span>)
0126 model.rxnReferences=cell(numel(model.rxns),1);
0127 <span class="keyword">end</span>
0128 <span class="keyword">if</span> ~isfield(model,<span class="string">'rxnConfidenceScores'</span>)
0129 model.rxnConfidenceScores=NaN(numel(model.rxns),1);
0130 <span class="keyword">end</span>
0131 <span class="keyword">if</span> ~isfield(model,<span class="string">'rxnNotes'</span>)
0132 model.rxnNotes=cell(numel(model.rxns),1);
0133 <span class="keyword">end</span>
0134 <span class="keyword">if</span> ~isfield(model,<span class="string">'rxnMiriams'</span>)
0135 model.rxnMiriams=cell(numel(model.rxns),1);
0136 <span class="keyword">end</span>
0137
0138 <span class="keyword">if</span> sbmlLevel<3
0139 <span class="comment">%Check if genes have associated compartments</span>
0140 <span class="keyword">if</span> ~isfield(model,<span class="string">'geneComps'</span>) && isfield(model,<span class="string">'genes'</span>)
0141 <span class="keyword">if</span> supressWarnings==false
0142 EM=<span class="string">'There are no compartments specified for genes. All genes will be assigned to the first compartment. This is because the SBML structure requires all elements to be assigned to a compartment'</span>;
0143 dispEM(EM,false);
0144 <span class="keyword">end</span>
0145 model.geneComps=ones(numel(model.genes),1);
0146 <span class="keyword">end</span>
0147 <span class="keyword">end</span>
0148
0149 <span class="comment">%Convert ids to SBML-convenient format. This is to avoid the data loss when</span>
0150 <span class="comment">%unsupported characters are included in ids. Here we are using part from</span>
0151 <span class="comment">%convertSBMLID, originating from the COBRA Toolbox</span>
0152 model.rxns=regexprep(model.rxns,<span class="string">'([^0-9_a-zA-Z])'</span>,<span class="string">'__${num2str($1+0)}__'</span>);
0153 model.mets=regexprep(model.mets,<span class="string">'([^0-9_a-zA-Z])'</span>,<span class="string">'__${num2str($1+0)}__'</span>);
0154 model.comps=regexprep(model.comps,<span class="string">'([^0-9_a-zA-Z])'</span>,<span class="string">'__${num2str($1+0)}__'</span>);
0155 <span class="keyword">if</span> isfield(model,<span class="string">'genes'</span>)
0156 problemGenes=find(~cellfun(<span class="string">'isempty'</span>,regexp(model.genes,<span class="string">'([^0-9_a-zA-Z])'</span>)));
0157 originalGenes=model.genes(problemGenes);
0158 replacedGenes=regexprep(model.genes(problemGenes),<span class="string">'([^0-9_a-zA-Z])'</span>,<span class="string">'__${num2str($1+0)}__'</span>);
0159 model.genes(problemGenes)=replacedGenes;
0160 <span class="keyword">for</span> i=1:numel(problemGenes)
0161 model.grRules = regexprep(model.grRules, [<span class="string">'(^|\s|\()'</span> originalGenes{i} <span class="string">'($|\s|\))'</span>], [<span class="string">'$1'</span> replacedGenes{i} <span class="string">'$2'</span>]);
0162 <span class="keyword">end</span>
0163 <span class="keyword">end</span>
0164
0165 <span class="comment">%Generate an empty SBML structure</span>
0166 modelSBML=<a href="#_sub1" class="code" title="subfunction modelSBML=getSBMLStructure(sbmlLevel,sbmlVersion,sbmlPackages,sbmlPackageVersions)">getSBMLStructure</a>(sbmlLevel,sbmlVersion,sbmlPackages,sbmlPackageVersions);
0167 modelSBML.metaid=model.id;
0168 modelSBML.id=regexprep(model.id,<span class="string">'([^0-9_a-zA-Z])'</span>,<span class="string">'__${num2str($1+0)}__'</span>);
0169 modelSBML.name=model.name;
0170
0171 <span class="keyword">if</span> isfield(model,<span class="string">'annotation'</span>)
0172 <span class="keyword">if</span> isfield(model.annotation,<span class="string">'note'</span>)
0173 modelSBML.notes=[<span class="string">'<notes><body xmlns="http://www.w3.org/1999/xhtml"><p>'</span>,regexprep(model.annotation.note,<span class="string">'<p>|</p>'</span>,<span class="string">''</span>),<span class="string">'</p></body></notes>'</span>];
0174 <span class="keyword">end</span>
0175 <span class="keyword">else</span>
0176 modelSBML.notes=<span class="string">'<notes><body xmlns="http://www.w3.org/1999/xhtml"><p>This file was generated using the exportModel function in RAVEN Toolbox 2 and OutputSBML in libSBML </p></body></notes>'</span>;
0177 <span class="keyword">end</span>
0178
0179 <span class="keyword">if</span> isfield(model,<span class="string">'annotation'</span>)
0180 nameString=<span class="string">''</span>;
0181 <span class="keyword">if</span> isfield(model.annotation,<span class="string">'familyName'</span>)
0182 <span class="keyword">if</span> ~isempty(model.annotation.familyName)
0183 nameString=[<span class="string">'<vCard:Family>'</span> model.annotation.familyName <span class="string">'</vCard:Family>'</span>];
0184 <span class="keyword">end</span>
0185 <span class="keyword">end</span>
0186 <span class="keyword">if</span> isfield(model.annotation,<span class="string">'givenName'</span>)
0187 <span class="keyword">if</span> ~isempty(model.annotation.givenName)
0188 nameString=[nameString <span class="string">'<vCard:Given>'</span> model.annotation.givenName <span class="string">'</vCard:Given>'</span>];
0189 <span class="keyword">end</span>
0190 <span class="keyword">end</span>
0191 email=<span class="string">''</span>;
0192 <span class="keyword">if</span> isfield(model.annotation,<span class="string">'email'</span>)
0193 <span class="keyword">if</span> ~isempty(model.annotation.email)
0194 email=[<span class="string">'<vCard:EMAIL>'</span> model.annotation.email <span class="string">'</vCard:EMAIL>'</span>];
0195 <span class="keyword">end</span>
0196 <span class="keyword">end</span>
0197 org=<span class="string">''</span>;
0198 <span class="keyword">if</span> isfield(model.annotation,<span class="string">'organization'</span>)
0199 <span class="keyword">if</span> ~isempty(model.annotation.organization)
0200 org=[<span class="string">'<vCard:ORG rdf:parseType="Resource"><vCard:Orgname>'</span> model.annotation.organization <span class="string">'</vCard:Orgname></vCard:ORG>'</span>];
0201 <span class="keyword">end</span>
0202 <span class="keyword">end</span>
0203 <span class="keyword">if</span> ~isempty(nameString) || ~isempty(email) || ~isempty(org) <span class="comment">% Only fill .annotation if ownership data is provided</span>
0204 modelSBML.annotation=[<span class="string">'<annotation><rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:dcterms="http://purl.org/dc/terms/" xmlns:vCard="http://www.w3.org/2001/vcard-rdf/3.0#" xmlns:bqbiol="http://biomodels.net/biology-qualifiers/" xmlns:bqmodel="http://biomodels.net/model-qualifiers/"><rdf:Description rdf:about="#meta_'</span> model.id <span class="string">'">'</span>];
0205 modelSBML.annotation=[modelSBML.annotation <span class="string">'<dc:creator><rdf:Bag><rdf:li rdf:parseType="Resource">'</span>];
0206 <span class="keyword">if</span> ~isempty(nameString)
0207 modelSBML.annotation=[modelSBML.annotation <span class="string">'<vCard:N rdf:parseType="Resource">'</span> nameString <span class="string">'</vCard:N>'</span>];
0208 <span class="keyword">end</span>
0209 modelSBML.annotation=[modelSBML.annotation email org <span class="string">'</rdf:li></rdf:Bag></dc:creator>'</span>];
0210 modelSBML.annotation=[modelSBML.annotation <span class="string">'<dcterms:created rdf:parseType="Resource">'</span><span class="keyword">...</span>
0211 <span class="string">'<dcterms:W3CDTF>'</span> datestr(now,<span class="string">'yyyy-mm-ddTHH:MM:SSZ'</span>) <span class="string">'</dcterms:W3CDTF></dcterms:created><dcterms:modified rdf:parseType="Resource">'</span><span class="keyword">...</span>
0212 <span class="string">'<dcterms:W3CDTF>'</span> datestr(now,<span class="string">'yyyy-mm-ddTHH:MM:SSZ'</span>) <span class="string">'</dcterms:W3CDTF></dcterms:modified>'</span>];
0213 <span class="keyword">if</span> isfield(model.annotation,<span class="string">'taxonomy'</span>)
0214 modelSBML.annotation=[modelSBML.annotation <span class="string">'<bqbiol:is><rdf:Bag><rdf:li rdf:resource="https://identifiers.org/taxonomy/'</span> regexprep(model.annotation.taxonomy,<span class="string">'taxonomy/'</span>,<span class="string">''</span>) <span class="string">'"/></rdf:Bag></bqbiol:is>'</span>];
0215 <span class="keyword">end</span>
0216 modelSBML.annotation=[modelSBML.annotation <span class="string">'</rdf:Description></rdf:RDF></annotation>'</span>];
0217 <span class="keyword">end</span>
0218 <span class="keyword">end</span>
0219
0220 <span class="comment">%Prepare compartments</span>
0221 <span class="keyword">for</span> i=1:numel(model.comps)
0222 <span class="comment">%Add the default values, as these will be the same in all entries</span>
0223 <span class="keyword">if</span> i==1
0224 <span class="keyword">if</span> isfield(modelSBML.compartment, <span class="string">'sboTerm'</span>)
0225 modelSBML.compartment(i).sboTerm=290;
0226 <span class="keyword">end</span>
0227 <span class="keyword">if</span> isfield(modelSBML.compartment, <span class="string">'spatialDimensions'</span>)
0228 modelSBML.compartment(i).spatialDimensions=3;
0229 <span class="keyword">end</span>
0230 <span class="keyword">if</span> isfield(modelSBML.compartment, <span class="string">'size'</span>)
0231 modelSBML.compartment(i).size=1;
0232 <span class="keyword">end</span>
0233 <span class="keyword">if</span> isfield(modelSBML.compartment, <span class="string">'constant'</span>)
0234 modelSBML.compartment(i).constant=1;
0235 <span class="keyword">end</span>
0236 <span class="keyword">if</span> isfield(modelSBML.compartment, <span class="string">'isSetSize'</span>)
0237 modelSBML.compartment(i).isSetSize=1;
0238 <span class="keyword">end</span>
0239 <span class="keyword">if</span> isfield(modelSBML.compartment, <span class="string">'isSetSpatialDimensions'</span>)
0240 modelSBML.compartment(i).isSetSpatialDimensions=1;
0241 <span class="keyword">end</span>
0242 <span class="keyword">end</span>
0243 <span class="comment">%Copy the default values to the next entry as long as it is not the</span>
0244 <span class="comment">%last one</span>
0245 <span class="keyword">if</span> i<numel(model.comps)
0246 modelSBML.compartment(i+1)=modelSBML.compartment(i);
0247 <span class="keyword">end</span>
0248
0249 <span class="keyword">if</span> isfield(modelSBML.compartment,<span class="string">'metaid'</span>)
0250 modelSBML.compartment(i).metaid=model.comps{i};
0251 <span class="keyword">end</span>
0252 <span class="comment">%Prepare Miriam strings</span>
0253 <span class="keyword">if</span> ~isempty(model.compMiriams{i})
0254 [~,sbo_ind] = ismember(<span class="string">'sbo'</span>,model.compMiriams{i}.name);
0255 <span class="keyword">if</span> sbo_ind > 0
0256 modelSBML.compartment(i).sboTerm=str2double(regexprep(model.compMiriams{i}.value{sbo_ind},<span class="string">'SBO:'</span>,<span class="string">''</span>,<span class="string">'ignorecase'</span>));
0257 <span class="comment">% remove the SBO term from compMiriams so the information is</span>
0258 <span class="comment">% not duplicated in the "annotation" field later on</span>
0259 model.compMiriams{i}.name(sbo_ind) = [];
0260 model.compMiriams{i}.value(sbo_ind) = [];
0261 <span class="keyword">end</span>
0262 <span class="keyword">end</span>
0263 <span class="keyword">if</span> ~isempty(model.compMiriams{i}) && isfield(modelSBML.compartment(i),<span class="string">'annotation'</span>)
0264 modelSBML.compartment(i).annotation=[<span class="string">'<annotation><rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:dcterms="http://purl.org/dc/terms/" xmlns:vCard="http://www.w3.org/2001/vcard-rdf/3.0#" xmlns:bqbiol="http://biomodels.net/biology-qualifiers/" xmlns:bqmodel="http://biomodels.net/model-qualifiers/"><rdf:Description rdf:about="#meta_'</span> model.comps{i} <span class="string">'">'</span>];
0265 modelSBML.compartment(i).annotation=[modelSBML.compartment(i).annotation <span class="string">'<bqbiol:is><rdf:Bag>'</span>];
0266 modelSBML.compartment(i).annotation=[modelSBML.compartment(i).annotation <a href="#_sub2" class="code" title="subfunction miriamString=getMiriam(miriamStruct)">getMiriam</a>(model.compMiriams{i}) <span class="string">'</rdf:Bag></bqbiol:is></rdf:Description></rdf:RDF></annotation>'</span>];
0267 <span class="keyword">end</span>
0268 <span class="keyword">if</span> isfield(modelSBML.compartment, <span class="string">'name'</span>)
0269 modelSBML.compartment(i).name=model.compNames{i};
0270 <span class="keyword">end</span>
0271 <span class="keyword">if</span> isfield(modelSBML.compartment, <span class="string">'id'</span>)
0272 modelSBML.compartment(i).id=model.comps{i};
0273 <span class="keyword">end</span>
0274
0275 <span class="keyword">end</span>
0276
0277 <span class="comment">%Begin writing species</span>
0278 <span class="keyword">for</span> i=1:numel(model.mets)
0279 <span class="comment">%Add the default values, as these will be the same in all entries</span>
0280 <span class="keyword">if</span> i==1
0281 <span class="keyword">if</span> isfield(modelSBML.species, <span class="string">'sboTerm'</span>)
0282 modelSBML.species(i).sboTerm=247;
0283 <span class="keyword">end</span>
0284 <span class="keyword">if</span> isfield(modelSBML.species, <span class="string">'initialAmount'</span>)
0285 modelSBML.species(i).initialAmount=1;
0286 <span class="keyword">end</span>
0287 <span class="keyword">if</span> isfield(modelSBML.species, <span class="string">'initialConcentration'</span>)
0288 modelSBML.species(i).initialConcentration=0;
0289 <span class="keyword">end</span>
0290 <span class="keyword">if</span> isfield(modelSBML.species, <span class="string">'isSetInitialAmount'</span>)
0291 modelSBML.species(i).isSetInitialAmount=1;
0292 <span class="keyword">end</span>
0293 <span class="keyword">if</span> isfield(modelSBML.species, <span class="string">'isSetInitialConcentration'</span>)
0294 modelSBML.species(i).isSetInitialConcentration=1;
0295 <span class="keyword">end</span>
0296 <span class="keyword">end</span>
0297 <span class="comment">%Copy the default values to the next entry as long as it is not the</span>
0298 <span class="comment">%last one</span>
0299 <span class="keyword">if</span> i<numel(model.mets)
0300 modelSBML.species(i+1)=modelSBML.species(i);
0301 <span class="keyword">end</span>
0302
0303 <span class="keyword">if</span> isfield(modelSBML.species,<span class="string">'metaid'</span>)
0304 modelSBML.species(i).metaid=model.mets{i};
0305 <span class="keyword">end</span>
0306 <span class="keyword">if</span> isfield(modelSBML.species, <span class="string">'name'</span>)
0307 modelSBML.species(i).name=model.metNames{i};
0308 <span class="keyword">end</span>
0309 <span class="keyword">if</span> isfield(modelSBML.species, <span class="string">'id'</span>)
0310 modelSBML.species(i).id=model.mets{i};
0311 <span class="keyword">end</span>
0312 <span class="keyword">if</span> isfield(modelSBML.species, <span class="string">'compartment'</span>)
0313 modelSBML.species(i).compartment=model.comps{model.metComps(i)};
0314 <span class="keyword">end</span>
0315 <span class="keyword">if</span> isfield(model,<span class="string">'unconstrained'</span>)
0316 <span class="keyword">if</span> model.unconstrained(i)
0317 modelSBML.species(i).boundaryCondition=1;
0318 <span class="keyword">end</span>
0319 <span class="keyword">end</span>
0320 <span class="keyword">if</span> isfield(modelSBML.species, <span class="string">'fbc_charge'</span>) && isfield(model,<span class="string">'metCharges'</span>)
0321 <span class="keyword">if</span> ~isnan(model.metCharges(i))
0322 modelSBML.species(i).fbc_charge=model.metCharges(i);
0323 modelSBML.species(i).isSetfbc_charge=1;
0324 <span class="keyword">else</span>
0325 modelSBML.species(i).isSetfbc_charge=0;
0326 <span class="keyword">end</span>
0327 <span class="keyword">end</span>
0328 <span class="keyword">if</span> ~isempty(model.metMiriams{i})
0329 [~,sbo_ind] = ismember(<span class="string">'sbo'</span>,model.metMiriams{i}.name);
0330 <span class="keyword">if</span> sbo_ind > 0
0331 modelSBML.species(i).sboTerm=str2double(regexprep(model.metMiriams{i}.value{sbo_ind},<span class="string">'SBO:'</span>,<span class="string">''</span>,<span class="string">'ignorecase'</span>));
0332 <span class="comment">% remove the SBO term from metMiriams so the information is</span>
0333 <span class="comment">% not duplicated in the "annotation" field later on</span>
0334 model.metMiriams{i}.name(sbo_ind) = [];
0335 model.metMiriams{i}.value(sbo_ind) = [];
0336 <span class="keyword">end</span>
0337 <span class="keyword">end</span>
0338 <span class="keyword">if</span> isfield(modelSBML.species,<span class="string">'annotation'</span>)
0339 <span class="keyword">if</span> ~isempty(model.metMiriams{i}) || ~isempty(model.metFormulas{i})
0340 hasInchi=false;
0341 <span class="keyword">if</span> ~isempty(model.metFormulas{i})
0342 <span class="comment">%Only export formula if there is no InChI. This is because</span>
0343 <span class="comment">%the metFormulas field is populated by InChIs if available</span>
0344 <span class="keyword">if</span> ~isempty(model.inchis{i})
0345 hasInchi=true;
0346 <span class="keyword">end</span>
0347 <span class="keyword">if</span> hasInchi==false
0348 modelSBML.species(i).fbc_chemicalFormula=model.metFormulas{i};
0349 <span class="keyword">end</span>
0350 <span class="keyword">end</span>
0351 <span class="keyword">if</span> ~isempty(model.metMiriams{i}) || hasInchi==true
0352 modelSBML.species(i).annotation=[<span class="string">'<annotation><rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:dcterms="http://purl.org/dc/terms/" xmlns:vCard="http://www.w3.org/2001/vcard-rdf/3.0#" xmlns:bqbiol="http://biomodels.net/biology-qualifiers/" xmlns:bqmodel="http://biomodels.net/model-qualifiers/"><rdf:Description rdf:about="#meta_'</span> model.mets{i} <span class="string">'">'</span>];
0353 modelSBML.species(i).annotation=[modelSBML.species(i).annotation <span class="string">'<bqbiol:is><rdf:Bag>'</span>];
0354 <span class="keyword">if</span> ~isempty(model.metMiriams{i})
0355 modelSBML.species(i).annotation=[modelSBML.species(i).annotation <a href="#_sub2" class="code" title="subfunction miriamString=getMiriam(miriamStruct)">getMiriam</a>(model.metMiriams{i})];
0356 <span class="keyword">end</span>
0357 <span class="keyword">if</span> hasInchi==true
0358 modelSBML.species(i).annotation=[modelSBML.species(i).annotation <span class="string">'<rdf:li rdf:resource="https://identifiers.org/inchi/InChI='</span> regexprep(model.inchis{i},<span class="string">'^InChI='</span>,<span class="string">''</span>) <span class="string">'"/>'</span>];
0359 modelSBML.species(i).fbc_chemicalFormula=char(regexp(model.inchis{i}, <span class="string">'/(\w+)/'</span>, <span class="string">'tokens'</span>, <span class="string">'once'</span>));
0360 <span class="keyword">end</span>
0361 modelSBML.species(i).annotation=[modelSBML.species(i).annotation <span class="string">'</rdf:Bag></bqbiol:is></rdf:Description></rdf:RDF></annotation>'</span>];
0362 <span class="keyword">end</span>
0363 <span class="keyword">end</span>
0364 <span class="keyword">end</span>
0365 <span class="keyword">end</span>
0366
0367 <span class="keyword">if</span> isfield(model,<span class="string">'genes'</span>)
0368 <span class="keyword">for</span> i=1:numel(model.genes)
0369 <span class="comment">%Add the default values, as these will be the same in all entries</span>
0370 <span class="keyword">if</span> i==1
0371 <span class="keyword">if</span> isfield(modelSBML.fbc_geneProduct, <span class="string">'sboTerm'</span>)
0372 modelSBML.fbc_geneProduct(i).sboTerm=243;
0373 <span class="keyword">end</span>
0374 <span class="keyword">end</span>
0375 <span class="comment">%Copy the default values to the next index as long as it is not the</span>
0376 <span class="comment">%last one</span>
0377 <span class="keyword">if</span> i<numel(model.genes)
0378 modelSBML.fbc_geneProduct(i+1)=modelSBML.fbc_geneProduct(i);
0379 <span class="keyword">end</span>
0380
0381 <span class="keyword">if</span> isfield(modelSBML.fbc_geneProduct,<span class="string">'metaid'</span>)
0382 modelSBML.fbc_geneProduct(i).metaid=model.genes{i};
0383 <span class="keyword">end</span>
0384 <span class="keyword">if</span> ~isempty(model.geneMiriams{i})
0385 [~,sbo_ind] = ismember(<span class="string">'sbo'</span>,model.geneMiriams{i}.name);
0386 <span class="keyword">if</span> sbo_ind > 0
0387 modelSBML.fbc_geneProduct(i).sboTerm=str2double(regexprep(model.geneMiriams{i}.value{sbo_ind},<span class="string">'SBO:'</span>,<span class="string">''</span>,<span class="string">'ignorecase'</span>));
0388 <span class="comment">% remove the SBO term from compMiriams so the information is</span>
0389 <span class="comment">% not duplicated in the "annotation" field later on</span>
0390 model.geneMiriams{i}.name(sbo_ind) = [];
0391 model.geneMiriams{i}.value(sbo_ind) = [];
0392 <span class="keyword">end</span>
0393 <span class="keyword">end</span>
0394 <span class="keyword">if</span> ~isempty(model.geneMiriams{i}) && isfield(modelSBML.fbc_geneProduct(i),<span class="string">'annotation'</span>)
0395 modelSBML.fbc_geneProduct(i).annotation=[<span class="string">'<annotation><rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:dcterms="http://purl.org/dc/terms/" xmlns:vCard="http://www.w3.org/2001/vcard-rdf/3.0#" xmlns:bqbiol="http://biomodels.net/biology-qualifiers/" xmlns:bqmodel="http://biomodels.net/model-qualifiers/"><rdf:Description rdf:about="#meta_'</span> model.genes{i} <span class="string">'">'</span>];
0396 modelSBML.fbc_geneProduct(i).annotation=[modelSBML.fbc_geneProduct(i).annotation <span class="string">'<bqbiol:is><rdf:Bag>'</span>];
0397 modelSBML.fbc_geneProduct(i).annotation=[modelSBML.fbc_geneProduct(i).annotation <a href="#_sub2" class="code" title="subfunction miriamString=getMiriam(miriamStruct)">getMiriam</a>(model.geneMiriams{i}) <span class="string">'</rdf:Bag></bqbiol:is></rdf:Description></rdf:RDF></annotation>'</span>];
0398 <span class="keyword">end</span>
0399 <span class="keyword">if</span> isfield(modelSBML.fbc_geneProduct, <span class="string">'fbc_id'</span>)
0400 modelSBML.fbc_geneProduct(i).fbc_id=model.genes{i};
0401 <span class="keyword">end</span>
0402 <span class="keyword">if</span> isfield(modelSBML.fbc_geneProduct, <span class="string">'fbc_label'</span>) && isfield(model,<span class="string">'geneShortNames'</span>)
0403 <span class="keyword">if</span> isempty(model.geneShortNames{i})
0404 modelSBML.fbc_geneProduct(i).fbc_label=model.genes{i};
0405 <span class="keyword">else</span>
0406 modelSBML.fbc_geneProduct(i).fbc_label=model.geneShortNames{i};
0407 <span class="keyword">end</span>
0408 <span class="keyword">end</span>
0409 <span class="keyword">if</span> isfield(modelSBML.fbc_geneProduct, <span class="string">'fbc_name'</span>) && isfield(model,<span class="string">'proteins'</span>)
0410 <span class="keyword">if</span> ~isempty(model.proteins{i})
0411 modelSBML.fbc_geneProduct(i).fbc_name=model.proteins{i};
0412 <span class="keyword">end</span>
0413 <span class="keyword">end</span>
0414 <span class="keyword">end</span>
0415 <span class="keyword">end</span>
0416
0417 <span class="comment">%Generate a list of unique fbc_bound names</span>
0418 totalValues=[model.lb; model.ub];
0419 totalNames=cell(size(totalValues,1),1);
0420
0421 listUniqueValues=unique(totalValues);
0422
0423 <span class="keyword">for</span> i=1:length(listUniqueValues)
0424 listUniqueNames{i,1}=[<span class="string">'FB'</span>,num2str(i),<span class="string">'N'</span>,num2str(abs(round(listUniqueValues(i))))]; <span class="comment">% create unique flux bound IDs.</span>
0425 ind=find(ismember(totalValues,listUniqueValues(i)));
0426 totalNames(ind)=listUniqueNames(i,1);
0427 <span class="keyword">end</span>
0428
0429 <span class="keyword">for</span> i=1:length(listUniqueNames)
0430 <span class="comment">%Add the default values, as these will be the same in all entries</span>
0431 <span class="keyword">if</span> i==1
0432 <span class="keyword">if</span> isfield(modelSBML.parameter, <span class="string">'constant'</span>)
0433 modelSBML.parameter(i).constant=1;
0434 <span class="keyword">end</span>
0435 <span class="keyword">if</span> isfield(modelSBML.parameter, <span class="string">'isSetValue'</span>)
0436 modelSBML.parameter(i).isSetValue=1;
0437 <span class="keyword">end</span>
0438 <span class="keyword">end</span>
0439 <span class="comment">%Copy the default values to the next index as long as it is not the</span>
0440 <span class="comment">%last one</span>
0441 <span class="keyword">if</span> i<numel(listUniqueNames)
0442 modelSBML.parameter(i+1)=modelSBML.parameter(i);
0443 <span class="keyword">end</span>
0444 modelSBML.parameter(i).id=listUniqueNames{i};
0445 modelSBML.parameter(i).value=listUniqueValues(i);
0446 <span class="keyword">end</span>
0447
0448 <span class="keyword">for</span> i=1:numel(model.rxns)
0449 <span class="comment">%Add the default values, as these will be the same in all entries</span>
0450 <span class="keyword">if</span> i==1
0451 <span class="keyword">if</span> isfield(modelSBML.reaction, <span class="string">'sboTerm'</span>)
0452 modelSBML.reaction(i).sboTerm=176;
0453 <span class="keyword">end</span>
0454 <span class="keyword">if</span> isfield(modelSBML.reaction, <span class="string">'isSetFast'</span>)
0455 modelSBML.reaction(i).isSetFast=1;
0456 <span class="keyword">end</span>
0457 <span class="keyword">end</span>
0458 <span class="comment">%Copy the default values to the next index as long as it is not the</span>
0459 <span class="comment">%last one</span>
0460 <span class="keyword">if</span> i<numel(model.rxns)
0461 modelSBML.reaction(i+1)=modelSBML.reaction(i);
0462 <span class="keyword">end</span>
0463
0464 <span class="keyword">if</span> isfield(modelSBML.reaction,<span class="string">'metaid'</span>)
0465 modelSBML.reaction(i).metaid=model.rxns{i};
0466 <span class="keyword">end</span>
0467
0468 <span class="comment">%Export notes information</span>
0469 <span class="keyword">if</span> (~isnan(model.rxnConfidenceScores(i)) || ~isempty(model.rxnReferences{i}) || ~isempty(model.rxnNotes{i}))
0470 modelSBML.reaction(i).notes=<span class="string">'<notes><body xmlns="http://www.w3.org/1999/xhtml">'</span>;
0471 <span class="keyword">if</span> ~isnan(model.rxnConfidenceScores(i))
0472 modelSBML.reaction(i).notes=[modelSBML.reaction(i).notes <span class="string">'<p>Confidence Level: '</span> num2str(model.rxnConfidenceScores(i)) <span class="string">'</p>'</span>];
0473 <span class="keyword">end</span>
0474 <span class="keyword">if</span> ~isempty(model.rxnReferences{i})
0475 modelSBML.reaction(i).notes=[modelSBML.reaction(i).notes <span class="string">'<p>AUTHORS: '</span> model.rxnReferences{i} <span class="string">'</p>'</span>];
0476 <span class="keyword">end</span>
0477 <span class="keyword">if</span> ~isempty(model.rxnNotes{i})
0478 modelSBML.reaction(i).notes=[modelSBML.reaction(i).notes <span class="string">'<p>NOTES: '</span> model.rxnNotes{i} <span class="string">'</p>'</span>];
0479 <span class="keyword">end</span>
0480 modelSBML.reaction(i).notes=[modelSBML.reaction(i).notes <span class="string">'</body></notes>'</span>];
0481 <span class="keyword">end</span>
0482
0483 <span class="comment">% Export SBO terms from rxnMiriams</span>
0484 <span class="keyword">if</span> ~isempty(model.rxnMiriams{i})
0485 [~,sbo_ind] = ismember(<span class="string">'sbo'</span>,model.rxnMiriams{i}.name);
0486 <span class="keyword">if</span> sbo_ind > 0
0487 modelSBML.reaction(i).sboTerm=str2double(regexprep(model.rxnMiriams{i}.value{sbo_ind},<span class="string">'SBO:'</span>,<span class="string">''</span>,<span class="string">'ignorecase'</span>));
0488 <span class="comment">% remove the SBO term from rxnMiriams so the information is not</span>
0489 <span class="comment">% duplicated in the "annotation" field later on</span>
0490 model.rxnMiriams{i}.name(sbo_ind) = [];
0491 model.rxnMiriams{i}.value(sbo_ind) = [];
0492 <span class="keyword">end</span>
0493 <span class="keyword">end</span>
0494
0495 <span class="comment">%Export annotation information from rxnMiriams</span>
0496 <span class="keyword">if</span> (~isempty(model.rxnMiriams{i}) && isfield(modelSBML.reaction(i),<span class="string">'annotation'</span>)) || ~isempty(model.eccodes{i})
0497 modelSBML.reaction(i).annotation=[<span class="string">'<annotation><rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:dcterms="http://purl.org/dc/terms/" xmlns:vCard="http://www.w3.org/2001/vcard-rdf/3.0#" xmlns:bqbiol="http://biomodels.net/biology-qualifiers/" xmlns:bqmodel="http://biomodels.net/model-qualifiers/"><rdf:Description rdf:about="#meta_'</span> model.rxns{i} <span class="string">'">'</span>];
0498 modelSBML.reaction(i).annotation=[modelSBML.reaction(i).annotation <span class="string">'<bqbiol:is><rdf:Bag>'</span>];
0499 <span class="keyword">if</span> ~isempty(model.eccodes{i})
0500 eccodes=regexp(model.eccodes{i},<span class="string">';'</span>,<span class="string">'split'</span>);
0501 <span class="keyword">for</span> j=1:numel(eccodes)
0502 modelSBML.reaction(i).annotation=[modelSBML.reaction(i).annotation <span class="string">'<rdf:li rdf:resource="https://identifiers.org/ec-code/'</span> regexprep(eccodes{j},<span class="string">'ec-code/|EC'</span>,<span class="string">''</span>) <span class="string">'"/>'</span>];
0503 <span class="keyword">end</span>
0504 <span class="keyword">end</span>
0505 modelSBML.reaction(i).annotation=[modelSBML.reaction(i).annotation <a href="#_sub2" class="code" title="subfunction miriamString=getMiriam(miriamStruct)">getMiriam</a>(model.rxnMiriams{i}) <span class="string">'</rdf:Bag></bqbiol:is></rdf:Description></rdf:RDF></annotation>'</span>];
0506 <span class="keyword">end</span>
0507
0508 <span class="keyword">if</span> isfield(modelSBML.reaction, <span class="string">'name'</span>)
0509 modelSBML.reaction(i).name=model.rxnNames{i};
0510 <span class="keyword">end</span>
0511 <span class="keyword">if</span> isfield(modelSBML.reaction, <span class="string">'id'</span>)
0512 modelSBML.reaction(i).id=model.rxns{i};
0513 <span class="keyword">end</span>
0514
0515 <span class="comment">%Add the information about reactants and products</span>
0516 involvedMets=<a href="#_sub3" class="code" title="subfunction [tmp_Rxn]=addReactantsProducts(model,sbmlModel,i)">addReactantsProducts</a>(model,modelSBML,i);
0517 <span class="keyword">for</span> j=1:numel(involvedMets.reactant)
0518 <span class="keyword">if</span> j<numel(involvedMets.reactant)
0519 modelSBML.reaction(i).reactant(j+1)=modelSBML.reaction(i).reactant(j);
0520 <span class="keyword">end</span>
0521 modelSBML.reaction(i).reactant(j).species=involvedMets.reactant(j).species;
0522 modelSBML.reaction(i).reactant(j).stoichiometry=involvedMets.reactant(j).stoichiometry;
0523 modelSBML.reaction(i).reactant(j).isSetStoichiometry=involvedMets.reactant(j).isSetStoichiometry;
0524 modelSBML.reaction(i).reactant(j).constant=involvedMets.reactant(j).constant;
0525 <span class="keyword">end</span>
0526 <span class="keyword">if</span> numel(involvedMets.reactant)==0
0527 modelSBML.reaction(i).reactant=<span class="string">''</span>;
0528 <span class="keyword">end</span>
0529 <span class="keyword">for</span> j=1:numel(involvedMets.product)
0530 <span class="keyword">if</span> j<numel(involvedMets.product)
0531 modelSBML.reaction(i).product(j+1)=modelSBML.reaction(i).product(j);
0532 <span class="keyword">end</span>
0533 modelSBML.reaction(i).product(j).species=involvedMets.product(j).species;
0534 modelSBML.reaction(i).product(j).stoichiometry=involvedMets.product(j).stoichiometry;
0535 modelSBML.reaction(i).product(j).isSetStoichiometry=involvedMets.product(j).isSetStoichiometry;
0536 modelSBML.reaction(i).product(j).constant=involvedMets.product(j).constant;
0537 <span class="keyword">end</span>
0538 <span class="keyword">if</span> numel(involvedMets.product)==0
0539 modelSBML.reaction(i).product=<span class="string">''</span>;
0540 <span class="keyword">end</span>
0541 <span class="comment">%Export reversibility information. Reactions are irreversible by</span>
0542 <span class="comment">%default</span>
0543 <span class="keyword">if</span> model.rev(i)==1
0544 modelSBML.reaction(i).reversible=1;
0545 <span class="keyword">end</span>
0546 <span class="keyword">if</span> isfield(model, <span class="string">'rxnComps'</span>)
0547 modelSBML.reaction(i).compartment=model.comps{model.rxnComps(i)};
0548 <span class="keyword">end</span>
0549 <span class="keyword">if</span> isfield(model, <span class="string">'grRules'</span>)
0550 modelSBML.reaction(i).fbc_geneProductAssociation.fbc_association.fbc_association=model.grRules{i};
0551 <span class="keyword">end</span>
0552 modelSBML.reaction(i).fbc_lowerFluxBound=totalNames{i};
0553 modelSBML.reaction(i).fbc_upperFluxBound=totalNames{length(model.lb)+i};
0554 <span class="keyword">end</span>
0555
0556 <span class="comment">%Prepare subSystems Code taken from COBRA functions getModelSubSystems,</span>
0557 <span class="comment">%writeSBML, findRxnsFromSubSystem under GNU General Public License v3.0,</span>
0558 <span class="comment">%license file in readme/GPL.MD. Code modified for RAVEN</span>
0559 <span class="keyword">if</span> modelHasSubsystems
0560 modelSBML.groups_group.groups_kind = <span class="string">'partonomy'</span>;
0561 modelSBML.groups_group.sboTerm = 633;
0562 tmpStruct=modelSBML.groups_group;
0563
0564 rxns=model.rxns;
0565 <span class="keyword">if</span> ~any(cellfun(@iscell,model.subSystems))
0566 <span class="keyword">if</span> ~any(~cellfun(@isempty,model.subSystems))
0567 subSystems = {};
0568 <span class="keyword">else</span>
0569 subSystems = setdiff(model.subSystems,<span class="string">''</span>);
0570 <span class="keyword">end</span>
0571 <span class="keyword">else</span>
0572 orderedSubs = cellfun(@(x) <a href="#_sub4" class="code" title="subfunction vecT = columnVector(vec)">columnVector</a>(x),model.subSystems,<span class="string">'UniformOUtput'</span>,false);
0573 subSystems = setdiff(vertcat(orderedSubs{:}),<span class="string">''</span>);
0574 <span class="keyword">end</span>
0575 <span class="keyword">if</span> isempty(subSystems)
0576 subSystems = {};
0577 <span class="keyword">end</span>
0578 <span class="keyword">if</span> ~isempty(subSystems)
0579 <span class="comment">%Build the groups for the group package</span>
0580 groupIDs = strcat(<span class="string">'group'</span>,cellfun(@num2str, num2cell(1:length(subSystems)),<span class="string">'UniformOutput'</span>,false));
0581 <span class="keyword">for</span> i = 1:length(subSystems)
0582 cgroup = tmpStruct;
0583 <span class="keyword">if</span> ~any(cellfun(@iscell,model.subSystems))
0584 present = ismember(model.subSystems,subSystems{i});
0585 <span class="keyword">else</span>
0586 present = cellfun(@(x) any(ismember(x,subSystems{i})),model.subSystems);
0587 <span class="keyword">end</span>
0588 groupMembers = rxns(present);
0589 <span class="keyword">for</span> j = 1:numel(groupMembers)
0590 cMember = tmpStruct.groups_member;
0591 cMember.groups_idRef = groupMembers{j};
0592 <span class="keyword">if</span> j == 1
0593 cgroup.groups_member = cMember;
0594 <span class="keyword">else</span>
0595 cgroup.groups_member(j) = cMember;
0596 <span class="keyword">end</span>
0597 <span class="keyword">end</span>
0598 cgroup.groups_id = groupIDs{i};
0599 cgroup.groups_name = subSystems{i};
0600 <span class="keyword">if</span> i == 1
0601 modelSBML.groups_group = cgroup;
0602 <span class="keyword">else</span>
0603 modelSBML.groups_group(i) = cgroup;
0604 <span class="keyword">end</span>
0605 <span class="keyword">end</span>
0606 <span class="keyword">end</span>
0607 <span class="keyword">end</span>
0608
0609 <span class="comment">%Prepare fbc_objective subfield</span>
0610
0611 modelSBML.fbc_objective.fbc_type=<span class="string">'maximize'</span>;
0612 modelSBML.fbc_objective.fbc_id=<span class="string">'obj'</span>;
0613
0614 ind=find(model.c);
0615
0616 <span class="keyword">if</span> isempty(ind)
0617 modelSBML.fbc_objective.fbc_fluxObjective.fbc_coefficient=0;
0618 <span class="keyword">else</span>
0619 <span class="keyword">for</span> i=1:length(ind)
0620 <span class="comment">%Copy the default values to the next index as long as it is not the</span>
0621 <span class="comment">%last one</span>
0622 <span class="keyword">if</span> i<numel(ind)
0623 modelSBML.reaction(i+1)=modelSBML.reaction(i);
0624 <span class="keyword">end</span>
0625 values=model.c(model.c~=0);
0626 modelSBML.fbc_objective(i).fbc_fluxObjective.fbc_reaction=modelSBML.reaction(ind(i)).id;
0627 modelSBML.fbc_objective(i).fbc_fluxObjective.fbc_coefficient=values(i);
0628 modelSBML.fbc_objective(i).fbc_fluxObjective.isSetfbc_coefficient=1;
0629 <span class="keyword">end</span>
0630 <span class="keyword">end</span>
0631
0632 modelSBML.fbc_activeObjective=modelSBML.fbc_objective.fbc_id;
0633
0634 fbcStr=[<span class="string">'http://www.sbml.org/sbml/level'</span>, num2str(sbmlLevel), <span class="string">'/version'</span>, num2str(sbmlVersion), <span class="string">'/fbc/version'</span>,num2str(sbmlPackageVersions(1))];
0635 <span class="keyword">if</span> modelHasSubsystems
0636 groupStr=[<span class="string">'http://www.sbml.org/sbml/level'</span>, num2str(sbmlLevel), <span class="string">'/version'</span>, num2str(sbmlVersion), <span class="string">'/groups/version'</span>,num2str(sbmlPackageVersions(2))];
0637 modelSBML.namespaces=struct(<span class="string">'prefix'</span>,{<span class="string">''</span>,<span class="string">'fbc'</span>,<span class="string">'groups'</span>},<span class="keyword">...</span>
0638 <span class="string">'uri'</span>,{[<span class="string">'http://www.sbml.org/sbml/level'</span>, num2str(sbmlLevel), <span class="string">'/version'</span>, num2str(sbmlVersion), <span class="string">'/core'</span>],<span class="keyword">...</span>
0639 fbcStr,groupStr});
0640 <span class="keyword">else</span>
0641 modelSBML.namespaces=struct(<span class="string">'prefix'</span>,{<span class="string">''</span>,<span class="string">'fbc'</span>},<span class="keyword">...</span>
0642 <span class="string">'uri'</span>,{[<span class="string">'http://www.sbml.org/sbml/level'</span>, num2str(sbmlLevel), <span class="string">'/version'</span>, num2str(sbmlVersion), <span class="string">'/core'</span>],<span class="keyword">...</span>
0643 fbcStr});
0644 <span class="keyword">end</span>
0645
0646 <span class="keyword">if</span> sbmlPackageVersions(1) == 2
0647 modelSBML.fbc_strict=1;
0648 modelSBML.isSetfbc_strict = 1;
0649 <span class="keyword">end</span>
0650
0651 modelSBML.rule=[];
0652 modelSBML.constraint=[];
0653
0654 [ravenDir,prevDir]=findRAVENroot();
0655 fileName=<a href="checkFileExistence.html" class="code" title="function files=checkFileExistence(files,fullOrTemp,allowSpace,checkExist)">checkFileExistence</a>(fileName,1,true,false);
0656
0657 OutputSBML_RAVEN(modelSBML,fileName,1,0,[1,0]);
0658 <span class="keyword">end</span>
0659
0660
0661 <a name="_sub1" href="#_subfunctions" class="code">function modelSBML=getSBMLStructure(sbmlLevel,sbmlVersion,sbmlPackages,sbmlPackageVersions)</a>
0662 <span class="comment">%Returns the blank SBML model structure by using appropriate libSBML</span>
0663 <span class="comment">%functions. This creates structure by considering three levels</span>
0664
0665 sbmlFieldNames=getStructureFieldnames(<span class="string">'model'</span>,sbmlLevel,sbmlVersion,sbmlPackages,sbmlPackageVersions);
0666 sbmlDefaultValues=getDefaultValues(<span class="string">'model'</span>,sbmlLevel,sbmlVersion,sbmlPackages,sbmlPackageVersions);
0667
0668 <span class="keyword">for</span> i=1:numel(sbmlFieldNames)
0669 modelSBML.(sbmlFieldNames{1,i})=sbmlDefaultValues{1,i};
0670 sbmlSubfieldNames=getStructureFieldnames(sbmlFieldNames{1,i},sbmlLevel,sbmlVersion,sbmlPackages,sbmlPackageVersions);
0671 sbmlSubfieldValues=getDefaultValues(sbmlFieldNames{1,i},sbmlLevel,sbmlVersion,sbmlPackages,sbmlPackageVersions);
0672 <span class="keyword">if</span> ~strcmp(sbmlFieldNames{1,i},<span class="string">'event'</span>) && ~strcmp(sbmlFieldNames{1,i},<span class="string">'functionDefinition'</span>) && ~strcmp(sbmlFieldNames{1,i},<span class="string">'initialAssignment'</span>)
0673 <span class="keyword">for</span> j=1:numel(sbmlSubfieldNames)
0674 modelSBML.(sbmlFieldNames{1,i}).(sbmlSubfieldNames{1,j})=sbmlSubfieldValues{1,j};
0675 sbmlSubsubfieldNames=getStructureFieldnames(sbmlSubfieldNames{1,j},sbmlLevel,sbmlVersion,sbmlPackages,sbmlPackageVersions);
0676 sbmlSubsubfieldValues=getDefaultValues(sbmlSubfieldNames{1,j},sbmlLevel,sbmlVersion,sbmlPackages,sbmlPackageVersions);
0677 <span class="keyword">if</span> ~strcmp(sbmlSubfieldNames{1,j},<span class="string">'modifier'</span>) && ~strcmp(sbmlSubfieldNames{1,j},<span class="string">'kineticLaw'</span>)
0678 <span class="keyword">for</span> k=1:numel(sbmlSubsubfieldNames)
0679 <span class="comment">%'compartment' and 'species' fields are not supposed to</span>
0680 <span class="comment">%have their standalone structures if they are subfields</span>
0681 <span class="comment">%or subsubfields</span>
0682 <span class="keyword">if</span> ~strcmp(sbmlSubfieldNames{1,j},<span class="string">'compartment'</span>) && ~strcmp(sbmlSubfieldNames{1,j},<span class="string">'species'</span>)
0683 modelSBML.(sbmlFieldNames{1,i}).(sbmlSubfieldNames{1,j}).(sbmlSubsubfieldNames{1,k})=sbmlSubsubfieldValues{1,k};
0684 <span class="keyword">end</span>
0685 <span class="comment">%If it is fbc_association in the third level, we need</span>
0686 <span class="comment">%to establish the fourth level, since libSBML requires</span>
0687 <span class="comment">%it</span>
0688 <span class="keyword">if</span> strcmp(sbmlSubsubfieldNames{1,k},<span class="string">'fbc_association'</span>)
0689 fbc_associationFieldNames=getStructureFieldnames(<span class="string">'fbc_association'</span>,sbmlLevel,sbmlVersion,sbmlPackages,sbmlPackageVersions);
0690 fbc_associationFieldValues=getDefaultValues(<span class="string">'fbc_association'</span>,sbmlLevel,sbmlVersion,sbmlPackages,sbmlPackageVersions);
0691 <span class="keyword">for</span> l=1:numel(fbc_associationFieldNames)
0692 modelSBML.(sbmlFieldNames{1,i}).(sbmlSubfieldNames{1,j}).(sbmlSubsubfieldNames{1,k}).(fbc_associationFieldNames{1,l})=fbc_associationFieldValues{1,l};
0693 <span class="keyword">end</span>
0694 <span class="keyword">end</span>
0695 <span class="keyword">end</span>
0696 <span class="keyword">end</span>
0697 <span class="keyword">end</span>
0698 <span class="keyword">end</span>
0699 <span class="keyword">if</span> ~isstruct(modelSBML.(sbmlFieldNames{1,i}))
0700 modelSBML.(sbmlFieldNames{1,i})=sbmlDefaultValues{1,i};
0701 <span class="keyword">end</span>
0702 <span class="keyword">end</span>
0703
0704 modelSBML.unitDefinition.id=<span class="string">'mmol_per_gDW_per_hr'</span>;
0705
0706 unitFieldNames=getStructureFieldnames(<span class="string">'unit'</span>,sbmlLevel,sbmlVersion,sbmlPackages,sbmlPackageVersions);
0707 unitDefaultValues=getDefaultValues(<span class="string">'unit'</span>,sbmlLevel,sbmlVersion,sbmlPackages,sbmlPackageVersions);
0708
0709 kinds={<span class="string">'mole'</span>,<span class="string">'gram'</span>,<span class="string">'second'</span>};
0710 exponents=[1 -1 -1];
0711 scales=[-3 0 0];
0712 multipliers=[1 1 1*60*60];
0713
0714 <span class="keyword">for</span> i=1:numel(unitFieldNames)
0715 modelSBML.unitDefinition.unit(1).(unitFieldNames{1,i})=unitDefaultValues{1,i};
0716 <span class="keyword">for</span> j=1:3
0717 modelSBML.unitDefinition.unit(j).(unitFieldNames{1,i})=unitDefaultValues{1,i};
0718 <span class="keyword">if</span> strcmp(unitFieldNames{1,i},<span class="string">'kind'</span>)
0719 modelSBML.unitDefinition.unit(j).(unitFieldNames{1,i})=kinds{j};
0720 <span class="keyword">elseif</span> strcmp(unitFieldNames{1,i},<span class="string">'exponent'</span>)
0721 modelSBML.unitDefinition.unit(j).(unitFieldNames{1,i})=exponents(j);
0722 <span class="keyword">elseif</span> strcmp(unitFieldNames{1,i},<span class="string">'scale'</span>)
0723 modelSBML.unitDefinition.unit(j).(unitFieldNames{1,i})=scales(j);
0724 <span class="keyword">elseif</span> strcmp(unitFieldNames{1,i},<span class="string">'multiplier'</span>)
0725 modelSBML.unitDefinition.unit(j).(unitFieldNames{1,i})=multipliers(j);
0726 <span class="keyword">end</span>
0727 <span class="keyword">end</span>
0728 <span class="keyword">end</span>
0729 <span class="keyword">end</span>
0730
0731 <a name="_sub2" href="#_subfunctions" class="code">function miriamString=getMiriam(miriamStruct)</a>
0732 <span class="comment">%Returns a string with list elements for a miriam structure ('<rdf:li</span>
0733 <span class="comment">%rdf:resource="https://identifiers.org/go/GO:0005739"/>' for example). This</span>
0734 <span class="comment">%is just to speed up things since this is done many times during the</span>
0735 <span class="comment">%exporting</span>
0736
0737 miriamString=<span class="string">''</span>;
0738 <span class="keyword">if</span> isfield(miriamStruct,<span class="string">'name'</span>)
0739 <span class="keyword">for</span> i=1:numel(miriamStruct.name)
0740 miriamString=[miriamString <span class="string">'<rdf:li rdf:resource="https://identifiers.org/'</span> miriamStruct.name{i} <span class="string">'/'</span> miriamStruct.value{i} <span class="string">'"/>'</span>];
0741 <span class="keyword">end</span>
0742 <span class="keyword">end</span>
0743 <span class="keyword">end</span>
0744
0745 <a name="_sub3" href="#_subfunctions" class="code">function [tmp_Rxn]=addReactantsProducts(model,sbmlModel,i)</a>
0746 <span class="comment">%This function provides reactants and products for particular reaction. The</span>
0747 <span class="comment">%function was 'borrowed' from writeSBML in COBRA toolbox, lines 663-679</span>
0748
0749 met_idx = find(model.S(:, i));
0750 tmp_Rxn.product=[];
0751 tmp_Rxn.reactant=[];
0752 <span class="keyword">for</span> j_met=1:size(met_idx,1)
0753 tmp_idx = met_idx(j_met,1);
0754 sbml_tmp_species_ref.species = sbmlModel.species(tmp_idx).id;
0755 met_stoich = model.S(tmp_idx, i);
0756 sbml_tmp_species_ref.stoichiometry = abs(met_stoich);
0757 sbml_tmp_species_ref.isSetStoichiometry=1;
0758 sbml_tmp_species_ref.constant=1;
0759 <span class="keyword">if</span> (met_stoich > 0)
0760 tmp_Rxn.product = [ tmp_Rxn.product, sbml_tmp_species_ref ];
0761 <span class="keyword">else</span>
0762 tmp_Rxn.reactant = [ tmp_Rxn.reactant, sbml_tmp_species_ref];
0763 <span class="keyword">end</span>
0764 <span class="keyword">end</span>
0765 <span class="keyword">end</span>
0766
0767 <a name="_sub4" href="#_subfunctions" class="code">function vecT = columnVector(vec)</a>
0768 <span class="comment">% Code below taken from COBRA Toolbox under GNU General Public License v3.0</span>
0769 <span class="comment">% license file in readme/GPL.MD.</span>
0770 <span class="comment">%</span>
0771 <span class="comment">% Converts a vector to a column vector</span>
0772 <span class="comment">%</span>
0773 <span class="comment">% USAGE:</span>
0774 <span class="comment">%</span>
0775 <span class="comment">% vecT = columnVector(vec)</span>
0776 <span class="comment">%</span>
0777 <span class="comment">% INPUT:</span>
0778 <span class="comment">% vec: a vector</span>
0779 <span class="comment">%</span>
0780 <span class="comment">% OUTPUT:</span>
0781 <span class="comment">% vecT: a column vector</span>
0782
0783 [n, m] = size(vec);
0784
0785 <span class="keyword">if</span> n < m
0786 vecT = vec';
0787 <span class="keyword">else</span>
0788 vecT = vec;
0789 <span class="keyword">end</span>
0790 <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> © 2005</address>
</body>
</html>