libSBML Python API  5.18.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-2018 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  errors = document.getNumErrors()
60 
61  if errors > 0:
62  document.printErrors()
63  return errors
64 
65  m = document.getModel()
66  m.unsetAnnotation()
67 
68  for i in range(0, m.getNumReactions()):
69  re = m.getReaction(i)
70  re.unsetAnnotation()
71 
72  for j in range(0, re.getNumReactants()):
73  rt = re.getReactant(j)
74  rt.unsetAnnotation()
75 
76  for j in range(0, re.getNumProducts()):
77  rt = re.getProduct(j)
78  rt.unsetAnnotation()
79 
80  for j in range(0, re.getNumModifiers()):
81  md = re.getModifier(j)
82  md.unsetAnnotation()
83 
84  if re.isSetKineticLaw():
85  kl = re.getKineticLaw()
86  kl.unsetAnnotation()
87 
88  for j in range(0, kl.getNumParameters()):
89  pa = kl.getParameter(j)
90  pa.unsetAnnotation()
91 
92  for i in range(0, m.getNumSpecies()):
93  sp = m.getSpecies(i)
94  sp.unsetAnnotation()
95 
96  for i in range(0, m.getNumCompartments()):
97  sp = m.getCompartment(i)
98  sp.unsetAnnotation()
99 
100  for i in range(0, m.getNumFunctionDefinitions()):
101  sp = m.getFunctionDefinition(i)
102  sp.unsetAnnotation()
103 
104  for i in range(0, m.getNumUnitDefinitions()):
105  sp = m.getUnitDefinition(i)
106  sp.unsetAnnotation()
107 
108  for i in range(0, m.getNumParameters()):
109  sp = m.getParameter(i)
110  sp.unsetAnnotation()
111 
112  for i in range(0, m.getNumRules()):
113  sp = m.getRule(i)
114  sp.unsetAnnotation()
115 
116  for i in range(0, m.getNumInitialAssignments()):
117  sp = m.getInitialAssignment(i)
118  sp.unsetAnnotation()
119 
120  for i in range(0, m.getNumEvents()):
121  sp = m.getEvent(i)
122  sp.unsetAnnotation()
123 
124  for j in range(0, sp.getNumEventAssignments()):
125  ea = sp.getEventAssignment(j)
126  ea.unsetAnnotation()
127 
128  for i in range(0, m.getNumSpeciesTypes()):
129  sp = m.getSpeciesType(i)
130  sp.unsetAnnotation()
131 
132  for i in range(0, m.getNumConstraints()):
133  sp = m.getConstraint(i)
134  sp.unsetAnnotation()
135 
136  writeSBML(document, args[2])
137 
138  return errors
139 
140 
141 if __name__ == '__main__':
142  main(sys.argv)