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 <stdio.h>
43
44 #include <sbml/SBMLTypes.h>
45 #include "util.h"
46
47 int
main(int argc,char * argv[])48 main (int argc, char* argv[])
49 {
50 unsigned int i,j,errors;
51 const char* filename = argv[1];
52 SBMLDocument_t* document;
53 Model_t* m;
54
55 if (argc != 3)
56 {
57 printf("\nUsage: unsetAnnotation <input-filename> <output-filename>\n");
58 return 1;
59 }
60
61
62 filename = argv[1];
63 document = readSBML(filename);
64
65 errors = SBMLDocument_getNumErrors(document);
66
67 if(errors > 0)
68 {
69 SBMLDocument_printErrors(document, stderr);
70 SBMLDocument_free(document);
71 return errors;
72 }
73
74 m = SBMLDocument_getModel( document );
75 SBase_unsetAnnotation((SBase_t*)m);
76
77 for(i=0; i < Model_getNumReactions(m); i++)
78 {
79 Reaction_t* re = Model_getReaction(m, i);
80 SBase_unsetAnnotation((SBase_t*)re);
81
82 for(j=0; j < Reaction_getNumReactants(re); j++)
83 {
84 SpeciesReference_t* rt = Reaction_getReactant(re,j);
85 SBase_unsetAnnotation((SBase_t*)rt);
86 }
87
88 for(j=0; j < Reaction_getNumProducts(re); j++)
89 {
90 SpeciesReference_t* rt = Reaction_getProduct(re,j);
91 SBase_unsetAnnotation((SBase_t*)rt);
92 }
93
94 for(j=0; j < Reaction_getNumModifiers(re); j++)
95 {
96 SpeciesReference_t* md = Reaction_getModifier(re,j);
97 SBase_unsetAnnotation((SBase_t*)md);
98 }
99
100 if(Reaction_isSetKineticLaw(re))
101 {
102 KineticLaw_t* kl = Reaction_getKineticLaw(re);
103 SBase_unsetAnnotation((SBase_t*)kl);
104
105 for(j=0; j < KineticLaw_getNumParameters(kl); j++)
106 {
107 Parameter_t* pa = KineticLaw_getParameter(kl, j);
108 SBase_unsetAnnotation((SBase_t*)pa);
109 }
110 }
111
112 }
113
114 for(i=0; i < Model_getNumSpecies(m); i++)
115 {
116 Species_t* sp = Model_getSpecies(m, i);
117 SBase_unsetAnnotation((SBase_t*)sp);
118 }
119
120 for(i=0; i < Model_getNumCompartments(m); i++)
121 {
122 Compartment_t* sp = Model_getCompartment(m,i);
123 SBase_unsetAnnotation((SBase_t*)sp);
124 }
125
126 for(i=0; i < Model_getNumFunctionDefinitions(m); i++)
127 {
128 FunctionDefinition_t* sp = Model_getFunctionDefinition(m,i);
129 SBase_unsetAnnotation((SBase_t*)sp);
130 }
131
132 for(i=0; i < Model_getNumUnitDefinitions(m); i++)
133 {
134 UnitDefinition_t* sp = Model_getUnitDefinition(m, i);
135 SBase_unsetAnnotation((SBase_t*)sp);
136 }
137
138 for(i=0; i < Model_getNumParameters(m); i++)
139 {
140 Parameter_t* sp = Model_getParameter(m, i);
141 SBase_unsetAnnotation((SBase_t*)sp);
142 }
143
144 for(i=0; i < Model_getNumRules(m); i++)
145 {
146 Rule_t* sp = Model_getRule(m, i);
147 SBase_unsetAnnotation((SBase_t*)sp);
148 }
149
150 for(i=0; i < Model_getNumInitialAssignments(m); i++)
151 {
152 InitialAssignment_t* sp = Model_getInitialAssignment(m, i);
153 SBase_unsetAnnotation((SBase_t*)sp);
154 }
155
156 for(i=0; i < Model_getNumEvents(m); i++)
157 {
158 Event_t* sp = Model_getEvent(m, i);
159 SBase_unsetAnnotation((SBase_t*)sp);
160
161 for(j=0; j < Event_getNumEventAssignments(sp); j++)
162 {
163 EventAssignment_t* ea = Event_getEventAssignment(sp, j);
164 SBase_unsetAnnotation((SBase_t*)ea);
165 }
166 }
167
168 for(i=0; i < Model_getNumSpeciesTypes(m); i++)
169 {
170 SpeciesType_t* sp = Model_getSpeciesType(m, i);
171 SBase_unsetAnnotation((SBase_t*)sp);
172 }
173
174 for(i=0; i < Model_getNumConstraints(m); i++)
175 {
176 Constraint_t* sp = Model_getConstraint(m, i);
177 SBase_unsetAnnotation((SBase_t*)sp);
178 }
179
180 writeSBML(document, argv[2]);
181
182 SBMLDocument_free(document);
183 return errors;
184 }
185
186
187
188