1 /**
2 * @file printAnnotation.cpp
3 * @brief Prints annotation strings for each element
4 * @author Akiya Jouraku
5 *
6 * <!--------------------------------------------------------------------------
7 * This sample program is distributed under a different license than the rest
8 * of libSBML. This program uses the open-source MIT license, as follows:
9 *
10 * Copyright (c) 2013-2018 by the California Institute of Technology
11 * (California, USA), the European Bioinformatics Institute (EMBL-EBI, UK)
12 * and the University of Heidelberg (Germany), with support from the National
13 * Institutes of Health (USA) under grant R01GM070923. All rights reserved.
14 *
15 * Permission is hereby granted, free of charge, to any person obtaining a
16 * copy of this software and associated documentation files (the "Software"),
17 * to deal in the Software without restriction, including without limitation
18 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
19 * and/or sell copies of the Software, and to permit persons to whom the
20 * Software is furnished to do so, subject to the following conditions:
21 *
22 * The above copyright notice and this permission notice shall be included in
23 * all copies or substantial portions of the Software.
24 *
25 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
26 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
27 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
28 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
29 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
30 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
31 * DEALINGS IN THE SOFTWARE.
32 *
33 * Neither the name of the California Institute of Technology (Caltech), nor
34 * of the European Bioinformatics Institute (EMBL-EBI), nor of the University
35 * of Heidelberg, nor the names of any contributors, may be used to endorse
36 * or promote products derived from this software without specific prior
37 * written permission.
38 * ------------------------------------------------------------------------ -->
39 */
40
41
42 #include <stdio.h>
43
44 #include <sbml/SBMLTypes.h>
45 #include "util.h"
46
47
printAnnotation(SBase_t * sb,const char * id)48 void printAnnotation(SBase_t *sb, const char* id )
49 {
50 if (!SBase_isSetAnnotation(sb)) return;
51
52 printf("----- %s (%s) annotation -----\n%s\n\n"
53 , SBase_getElementName(sb)
54 , id
55 , SBase_getAnnotationString(sb)
56 );
57 }
58
59
60 int
main(int argc,char * argv[])61 main (int argc, char* argv[])
62 {
63 unsigned int i,j,errors;
64 const char* filename;
65 SBMLDocument_t* document;
66 Model_t* m;
67
68 if (argc != 2)
69 {
70 printf("\nUsage: printAnnotation filename\n\n");
71 return 1;
72 }
73
74 filename = argv[1];
75 document = readSBML(filename);
76
77 errors = SBMLDocument_getNumErrors( document);
78
79 printf("\n%s\n\n", filename);
80
81 if(errors > 0)
82 {
83 SBMLDocument_printErrors(document, stderr);
84 SBMLDocument_free(document);
85 return errors;
86 }
87
88
89 /* Model */
90
91 m = SBMLDocument_getModel(document);
92 printAnnotation((SBase_t*)m, Model_getId(m));
93
94 for(i=0; i < Model_getNumReactions(m); i++)
95 {
96 Reaction_t* re = Model_getReaction( m, i);
97 printAnnotation((SBase_t*)re, Reaction_getId(re));
98
99 /* SpeciesReference (Reactant) */
100
101 for(j=0; j < Reaction_getNumReactants( re); j++)
102 {
103 SpeciesReference_t* rt = Reaction_getReactant(re, j);
104 if (SBase_isSetAnnotation((SBase_t*) rt)) printf(" ");
105 printAnnotation((SBase_t*)rt, SpeciesReference_getSpecies( rt ) );
106 }
107
108 /* SpeciesReference (Product) */
109
110 for(j=0; j < Reaction_getNumProducts( re ); j++)
111 {
112 SpeciesReference_t* rt = Reaction_getProduct( re, j);
113 if (SBase_isSetAnnotation((SBase_t*) rt)) printf(" ");
114 printAnnotation((SBase_t*)rt, SpeciesReference_getSpecies( rt ) );
115 }
116
117 /* ModifierSpeciesReference (Modifiers) */
118
119 for(j=0; j < Reaction_getNumModifiers( re ); j++)
120 {
121 SpeciesReference_t* md = Reaction_getModifier(re, j);
122 if (SBase_isSetAnnotation((SBase_t*) md)) printf(" ");
123 printAnnotation((SBase_t*)md, SpeciesReference_getSpecies( md ) );
124 }
125
126 /* KineticLaw */
127
128 if(Reaction_isSetKineticLaw( re ))
129 {
130 KineticLaw_t* kl = Reaction_getKineticLaw( re );
131 if (SBase_isSetAnnotation((SBase_t*) kl)) printf(" ");
132 printAnnotation((SBase_t*)kl, "");
133
134 /* Parameter */
135
136 for(j=0; j < KineticLaw_getNumParameters( kl ); j++)
137 {
138 Parameter_t* pa = KineticLaw_getParameter( kl, j);
139 if (SBase_isSetAnnotation((SBase_t*) pa)) printf(" ");
140 printAnnotation((SBase_t*)pa, Parameter_getId(pa));
141 }
142 }
143
144 }
145
146 /* Species */
147
148 for(i=0; i < Model_getNumSpecies(m); i++)
149 {
150 Species_t* sp = Model_getSpecies(m, i);
151 printAnnotation((SBase_t*)sp, Species_getId(sp));
152 }
153
154 /* Compartments */
155
156 for(i=0; i < Model_getNumCompartments( m ); i++)
157 {
158 Compartment_t* sp = Model_getCompartment(m, i);
159 printAnnotation((SBase_t*)sp, Compartment_getId(sp));
160 }
161
162 /* FunctionDefinition */
163
164 for(i=0; i < Model_getNumFunctionDefinitions(m); i++)
165 {
166 FunctionDefinition_t* sp = Model_getFunctionDefinition(m, i);
167 printAnnotation((SBase_t*)sp, FunctionDefinition_getId(sp));
168 }
169
170 /* UnitDefinition */
171
172 for(i=0; i < Model_getNumUnitDefinitions(m); i++)
173 {
174 UnitDefinition_t* sp = Model_getUnitDefinition( m, i);
175 printAnnotation((SBase_t*)sp, UnitDefinition_getId(sp));
176 }
177
178 /* Parameter */
179
180 for(i=0; i < Model_getNumParameters( m ); i++)
181 {
182 Parameter_t* sp = Model_getParameter( m, i);
183 printAnnotation((SBase_t*)sp, Parameter_getId(sp));
184 }
185
186 /* Rule */
187
188 for(i=0; i < Model_getNumReactions( m ); i++)
189 {
190 Rule_t* sp = Model_getRule(m, i);
191 printAnnotation((SBase_t*)sp, "");
192 }
193
194 /* InitialAssignment */
195
196 for(i=0; i < Model_getNumInitialAssignments(m); i++)
197 {
198 InitialAssignment_t* sp = Model_getInitialAssignment(m, i);
199 printAnnotation((SBase_t*)sp, "");
200 }
201
202 /* Event */
203
204 for(i=0; i < Model_getNumEvents(m); i++)
205 {
206 Event_t* sp = Model_getEvent(m, i);
207 printAnnotation((SBase_t*)sp, Event_getId(sp));
208
209 /* Trigger */
210
211 if(Event_isSetTrigger( sp ))
212 {
213 Trigger_t* tg = Event_getTrigger(sp);
214 if (SBase_isSetAnnotation( (SBase_t*) tg)) printf( " " );
215 printAnnotation((SBase_t*)tg, "");
216 }
217
218 /* Delay */
219
220 if(Event_isSetDelay(sp))
221 {
222 Delay_t* dl = Event_getDelay(sp);
223 if (SBase_isSetAnnotation( (SBase_t*) dl)) printf( " " );
224 printAnnotation((SBase_t*) dl, "");
225 }
226
227 /* EventAssignment */
228
229 for(j=0; j < Event_getNumEventAssignments(sp); j++)
230 {
231 EventAssignment_t* ea = Event_getEventAssignment(sp, j);
232 if (SBase_isSetAnnotation( (SBase_t*) ea)) printf( " " );
233 printAnnotation((SBase_t*)ea, "");
234 }
235 }
236
237 /* SpeciesType */
238
239 for(i=0; i < Model_getNumSpeciesTypes(m); i++)
240 {
241 SpeciesType_t* sp = Model_getSpeciesType(m, i);
242 printAnnotation((SBase_t*)sp, SpeciesType_getId(sp));
243 }
244
245 /* Constraints */
246
247 for(i=0; i < Model_getNumConstraints(m); i++)
248 {
249 Constraint_t* sp = Model_getConstraint(m, i);
250 printAnnotation((SBase_t*)sp, "");
251 }
252
253 SBMLDocument_free( document );
254 return errors;
255 }
256
257
258