1 /**
2 * @file unsetAnnotation.cpp
3 * @brief unset annotation 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
51 int
main(int argc,char * argv[])52 main (int argc, char* argv[])
53 {
54 if (argc != 3)
55 {
56 cout << endl << "Usage: unsetAnnotation <input-filename> <output-filename>" << endl << endl;
57 return 1;
58 }
59
60 unsigned int i,j;
61 const char* filename = argv[1];
62 SBMLDocument* document;
63 SBMLReader reader;
64
65 document = reader.readSBML(filename);
66
67 unsigned int errors = document->getNumErrors();
68
69 if(errors > 0)
70 {
71 document->printErrors(cerr);
72 delete document;
73
74 return errors;
75 }
76
77 Model* m = document->getModel();
78 m->unsetAnnotation();
79
80 for(i=0; i < m->getNumReactions(); i++)
81 {
82 Reaction* re = m->getReaction(i);
83 re->unsetAnnotation();
84
85 for(j=0; j < re->getNumReactants(); j++)
86 {
87 SpeciesReference* rt = re->getReactant(j);
88 rt->unsetAnnotation();
89 }
90
91 for(j=0; j < re->getNumProducts(); j++)
92 {
93 SpeciesReference* rt = re->getProduct(j);
94 rt->unsetAnnotation();
95 }
96
97 for(j=0; j < re->getNumModifiers(); j++)
98 {
99 ModifierSpeciesReference* md = re->getModifier(j);
100 md->unsetAnnotation();
101 }
102
103 if(re->isSetKineticLaw())
104 {
105 KineticLaw* kl = re->getKineticLaw();
106 kl->unsetAnnotation();
107
108 for(j=0; j < kl->getNumParameters(); j++)
109 {
110 Parameter* pa = kl->getParameter(j);
111 pa->unsetAnnotation();
112 }
113 }
114
115 }
116
117 for(i=0; i < m->getNumSpecies(); i++)
118 {
119 Species* sp = m->getSpecies(i);
120 sp->unsetAnnotation();
121 }
122
123 for(i=0; i < m->getNumCompartments(); i++)
124 {
125 Compartment* sp = m->getCompartment(i);
126 sp->unsetAnnotation();
127 }
128
129 for(i=0; i < m->getNumFunctionDefinitions(); i++)
130 {
131 FunctionDefinition* sp = m->getFunctionDefinition(i);
132 sp->unsetAnnotation();
133 }
134
135 for(i=0; i < m->getNumUnitDefinitions(); i++)
136 {
137 UnitDefinition* sp = m->getUnitDefinition(i);
138 sp->unsetAnnotation();
139 }
140
141 for(i=0; i < m->getNumParameters(); i++)
142 {
143 Parameter* sp = m->getParameter(i);
144 sp->unsetAnnotation();
145 }
146
147 for(i=0; i < m->getNumRules(); i++)
148 {
149 Rule* sp = m->getRule(i);
150 sp->unsetAnnotation();
151 }
152
153 for(i=0; i < m->getNumInitialAssignments(); i++)
154 {
155 InitialAssignment* sp = m->getInitialAssignment(i);
156 sp->unsetAnnotation();
157 }
158
159 for(i=0; i < m->getNumEvents(); i++)
160 {
161 Event* sp = m->getEvent(i);
162 sp->unsetAnnotation();
163
164 for(j=0; j < sp->getNumEventAssignments(); j++)
165 {
166 EventAssignment* ea = sp->getEventAssignment(j);
167 ea->unsetAnnotation();
168 }
169 }
170
171 for(i=0; i < m->getNumSpeciesTypes(); i++)
172 {
173 SpeciesType* sp = m->getSpeciesType(i);
174 sp->unsetAnnotation();
175 }
176
177 for(i=0; i < m->getNumConstraints(); i++)
178 {
179 Constraint* sp = m->getConstraint(i);
180 sp->unsetAnnotation();
181 }
182
183 writeSBML(document, argv[2]);
184
185 delete document;
186 return errors;
187 }
188
189
190
191