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 <iostream>
43
44 #include <sbml/SBMLTypes.h>
45 #include "util.h"
46
47
48 using namespace std;
49 LIBSBML_CPP_NAMESPACE_USE
50
printAnnotation(SBase * sb,const string & id="")51 void printAnnotation(SBase *sb, const string& id = "")
52 {
53 if (!sb->isSetAnnotation()) return;
54
55 string pid = id;
56
57 if (pid == "" && sb->isSetId())
58 {
59 pid = sb->getId();
60 }
61
62 cout << "----- " << sb->getElementName() << " (" << pid
63 << ") annotation -----" << endl;
64 cout << sb->getAnnotationString() << endl;
65 cout << endl;
66 }
67
68
69 int
main(int argc,char * argv[])70 main (int argc, char* argv[])
71 {
72 if (argc != 2)
73 {
74 cout << endl << "Usage: printAnnotation filename" << endl << endl;
75 return 1;
76 }
77
78 unsigned int i,j;
79 const char* filename = argv[1];
80 SBMLDocument* document;
81 SBMLReader reader;
82
83 document = reader.readSBML(filename);
84
85 unsigned int errors = document->getNumErrors();
86
87 cout << endl;
88 cout << "filename: " << filename << endl;
89 cout << endl;
90
91 if(errors > 0)
92 {
93 document->printErrors(cerr);
94 delete document;
95
96 return errors;
97 }
98
99
100 /* Model */
101
102 Model* m = document->getModel();
103 printAnnotation(m);
104
105 for(i=0; i < m->getNumReactions(); i++)
106 {
107 Reaction* re = m->getReaction(i);
108 printAnnotation(re);
109
110 /* SpeciesReference (Reacatant) */
111
112 for(j=0; j < re->getNumReactants(); j++)
113 {
114 SpeciesReference* rt = re->getReactant(j);
115 if (rt->isSetAnnotation()) cout << " ";
116 printAnnotation(rt, (rt->isSetSpecies() ? rt->getSpecies() : std::string("")) );
117 }
118
119 /* SpeciesReference (Product) */
120
121 for(j=0; j < re->getNumProducts(); j++)
122 {
123 SpeciesReference* rt = re->getProduct(j);
124 if (rt->isSetAnnotation()) cout << " ";
125 printAnnotation(rt, (rt->isSetSpecies() ? rt->getSpecies() : std::string("")) );
126 }
127
128 /* ModifierSpeciesReference (Modifiers) */
129
130 for(j=0; j < re->getNumModifiers(); j++)
131 {
132 ModifierSpeciesReference* md = re->getModifier(j);
133 if (md->isSetAnnotation()) cout << " ";
134 printAnnotation(md, (md->isSetSpecies() ? md->getSpecies() : std::string("")) );
135 }
136
137 /* KineticLaw */
138
139 if(re->isSetKineticLaw())
140 {
141 KineticLaw* kl = re->getKineticLaw();
142 if (kl->isSetAnnotation()) cout << " ";
143 printAnnotation(kl);
144
145 /* Parameter */
146
147 for(j=0; j < kl->getNumParameters(); j++)
148 {
149 Parameter* pa = kl->getParameter(j);
150 if (pa->isSetAnnotation()) cout << " ";
151 printAnnotation(pa);
152 }
153 }
154
155 }
156
157 /* Species */
158
159 for(i=0; i < m->getNumSpecies(); i++)
160 {
161 Species* sp = m->getSpecies(i);
162 printAnnotation(sp);
163 }
164
165 /* Compartments */
166
167 for(i=0; i < m->getNumCompartments(); i++)
168 {
169 Compartment* sp = m->getCompartment(i);
170 printAnnotation(sp);
171 }
172
173 /* FunctionDefinition */
174
175 for(i=0; i < m->getNumFunctionDefinitions(); i++)
176 {
177 FunctionDefinition* sp = m->getFunctionDefinition(i);
178 printAnnotation(sp);
179 }
180
181 /* UnitDefinition */
182
183 for(i=0; i < m->getNumUnitDefinitions(); i++)
184 {
185 UnitDefinition* sp = m->getUnitDefinition(i);
186 printAnnotation(sp);
187 }
188
189 /* Parameter */
190
191 for(i=0; i < m->getNumParameters(); i++)
192 {
193 Parameter* sp = m->getParameter(i);
194 printAnnotation(sp);
195 }
196
197 /* Rule */
198
199 for(i=0; i < m->getNumRules(); i++)
200 {
201 Rule* sp = m->getRule(i);
202 printAnnotation(sp);
203 }
204
205 /* InitialAssignment */
206
207 for(i=0; i < m->getNumInitialAssignments(); i++)
208 {
209 InitialAssignment* sp = m->getInitialAssignment(i);
210 printAnnotation(sp);
211 }
212
213 /* Event */
214
215 for(i=0; i < m->getNumEvents(); i++)
216 {
217 Event* sp = m->getEvent(i);
218 printAnnotation(sp);
219
220 /* Trigger */
221
222 if(sp->isSetTrigger())
223 {
224 const Trigger* tg = sp->getTrigger();
225 if (tg->isSetAnnotation()) cout << " ";
226 printAnnotation(const_cast<Trigger*>(tg));
227 }
228
229 /* Delay */
230
231 if(sp->isSetDelay())
232 {
233 const Delay* dl = sp->getDelay();
234 if (dl->isSetAnnotation()) cout << " ";
235 printAnnotation(const_cast<Delay*>(dl));
236 }
237
238 /* EventAssignment */
239
240 for(j=0; j < sp->getNumEventAssignments(); j++)
241 {
242 EventAssignment* ea = sp->getEventAssignment(j);
243 if (ea->isSetAnnotation()) cout << " ";
244 printAnnotation(ea);
245 }
246 }
247
248 /* SpeciesType */
249
250 for(i=0; i < m->getNumSpeciesTypes(); i++)
251 {
252 SpeciesType* sp = m->getSpeciesType(i);
253 printAnnotation(sp);
254 }
255
256 /* Constraints */
257
258 for(i=0; i < m->getNumConstraints(); i++)
259 {
260 Constraint* sp = m->getConstraint(i);
261 printAnnotation(sp);
262 }
263
264 delete document;
265 return errors;
266 }
267
268
269