libSBML Python API  5.11.0
unsetAnnotation.py

Unsets the annotation for each element in the given SBML file.

1 #!/usr/bin/env python
2 ##
3 ## @file unsetAnnotation.py
4 ## @brief unset annotation for each element
5 ## @author Akiya Jouraku
6 ##
7 ## <!--------------------------------------------------------------------------
8 ## This sample program is distributed under a different license than the rest
9 ## of libSBML. This program uses the open-source MIT license, as follows:
10 ##
11 ## Copyright (c) 2013-2014 by the California Institute of Technology
12 ## (California, USA), the European Bioinformatics Institute (EMBL-EBI, UK)
13 ## and the University of Heidelberg (Germany), with support from the National
14 ## Institutes of Health (USA) under grant R01GM070923. All rights reserved.
15 ##
16 ## Permission is hereby granted, free of charge, to any person obtaining a
17 ## copy of this software and associated documentation files (the "Software"),
18 ## to deal in the Software without restriction, including without limitation
19 ## the rights to use, copy, modify, merge, publish, distribute, sublicense,
20 ## and/or sell copies of the Software, and to permit persons to whom the
21 ## Software is furnished to do so, subject to the following conditions:
22 ##
23 ## The above copyright notice and this permission notice shall be included in
24 ## all copies or substantial portions of the Software.
25 ##
26 ## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
27 ## IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
28 ## FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
29 ## THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
30 ## LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
31 ## FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
32 ## DEALINGS IN THE SOFTWARE.
33 ##
34 ## Neither the name of the California Institute of Technology (Caltech), nor
35 ## of the European Bioinformatics Institute (EMBL-EBI), nor of the University
36 ## of Heidelberg, nor the names of any contributors, may be used to endorse
37 ## or promote products derived from this software without specific prior
38 ## written permission.
39 ## ------------------------------------------------------------------------ -->
40 ##
41 
42 import sys
43 import time
44 import os
45 import os.path
46 from libsbml import *
47 
48 def main (args):
49  """Usage: unsetAnnotation <input-filename> <output-filename>
50  """
51  if (len(args) != 3):
52  print("\n" + "Usage: unsetAnnotation <input-filename> <output-filename>" + "\n" + "\n");
53  return 1;
54 
55  filename = args[1];
56 
57  document = readSBML(filename);
58 
59 
60  errors = document.getNumErrors();
61 
62  if (errors > 0):
63  document.printErrors();
64  return errors;
65 
66  m = document.getModel();
67  m.unsetAnnotation();
68 
69  for i in range(0, m.getNumReactions()):
70  re = m.getReaction(i);
71  re.unsetAnnotation();
72 
73  for j in range(0, re.getNumReactants()):
74  rt = re.getReactant(j);
75  rt.unsetAnnotation();
76 
77  for j in range(0, re.getNumProducts()):
78  rt = re.getProduct(j);
79  rt.unsetAnnotation();
80 
81  for j in range(0, re.getNumModifiers()):
82  md = re.getModifier(j);
83  md.unsetAnnotation();
84 
85  if (re.isSetKineticLaw()):
86  kl = re.getKineticLaw();
87  kl.unsetAnnotation();
88 
89  for j in range(0, kl.getNumParameters()):
90  pa = kl.getParameter(j);
91  pa.unsetAnnotation();
92 
93  for i in range(0, m.getNumSpecies()):
94  sp = m.getSpecies(i);
95  sp.unsetAnnotation();
96 
97  for i in range(0, m.getNumCompartments()):
98  sp = m.getCompartment(i);
99  sp.unsetAnnotation();
100 
101  for i in range(0, m.getNumFunctionDefinitions()):
102  sp = m.getFunctionDefinition(i);
103  sp.unsetAnnotation();
104 
105  for i in range(0, m.getNumUnitDefinitions()):
106  sp = m.getUnitDefinition(i);
107  sp.unsetAnnotation();
108 
109  for i in range(0, m.getNumParameters()):
110  sp = m.getParameter(i);
111  sp.unsetAnnotation();
112 
113  for i in range(0, m.getNumRules()):
114  sp = m.getRule(i);
115  sp.unsetAnnotation();
116 
117  for i in range(0, m.getNumInitialAssignments()):
118  sp = m.getInitialAssignment(i);
119  sp.unsetAnnotation();
120 
121  for i in range(0, m.getNumEvents()):
122  sp = m.getEvent(i);
123  sp.unsetAnnotation();
124 
125  for j in range(0, sp.getNumEventAssignments()):
126  ea = sp.getEventAssignment(j);
127  ea.unsetAnnotation();
128 
129  for i in range(0, m.getNumSpeciesTypes()):
130  sp = m.getSpeciesType(i);
131  sp.unsetAnnotation();
132 
133  for i in range(0, m.getNumConstraints()):
134  sp = m.getConstraint(i);
135  sp.unsetAnnotation();
136 
137  writeSBML(document, args[2]);
138 
139  return errors;
140 
141 if __name__ == '__main__':
142  main(sys.argv)