libSBML Python API  5.18.0
unsetNotes.py

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

1 #!/usr/bin/env python
2 ##
3 ## @file unsetNotes.py
4 ## @brief unset notes 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 import sys
42 import time
43 import os
44 import os.path
45 from libsbml import *
46 
47 def main (args):
48  """Usage: unsetNotes <input-filename> <output-filename>
49  """
50  if len(args) != 3:
51  print("\n" + "Usage: unsetNotes <input-filename> <output-filename>" + "\n" + "\n")
52  return 1
53 
54  filename = args[1]
55 
56  document = readSBML(filename)
57 
58  errors = document.getNumErrors()
59 
60  if errors > 0:
61  document.printErrors()
62  return errors
63 
64  m = document.getModel()
65  m.unsetNotes()
66 
67  for i in range(0, m.getNumReactions()):
68  re = m.getReaction(i)
69  re.unsetNotes()
70 
71  for j in range(0, re.getNumReactants()):
72  rt = re.getReactant(j)
73  rt.unsetNotes()
74 
75  for j in range(0, re.getNumProducts()):
76  rt = re.getProduct(j)
77  rt.unsetNotes()
78 
79  for j in range(0, re.getNumModifiers()):
80  md = re.getModifier(j)
81  md.unsetNotes()
82 
83  if re.isSetKineticLaw():
84  kl = re.getKineticLaw()
85  kl.unsetNotes()
86 
87  for j in range(0, kl.getNumParameters()):
88  pa = kl.getParameter(j)
89  pa.unsetNotes()
90 
91  for i in range(0, m.getNumSpecies()):
92  sp = m.getSpecies(i)
93  sp.unsetNotes()
94 
95  for i in range(0, m.getNumCompartments()):
96  sp = m.getCompartment(i)
97  sp.unsetNotes()
98 
99  for i in range(0, m.getNumFunctionDefinitions()):
100  sp = m.getFunctionDefinition(i)
101  sp.unsetNotes()
102 
103  for i in range(0, m.getNumUnitDefinitions()):
104  sp = m.getUnitDefinition(i)
105  sp.unsetNotes()
106 
107  for i in range(0, m.getNumParameters()):
108  sp = m.getParameter(i)
109  sp.unsetNotes()
110 
111  for i in range(0, m.getNumRules()):
112  sp = m.getRule(i)
113  sp.unsetNotes()
114 
115  for i in range(0, m.getNumInitialAssignments()):
116  sp = m.getInitialAssignment(i)
117  sp.unsetNotes()
118 
119  for i in range(0, m.getNumEvents()):
120  sp = m.getEvent(i)
121  sp.unsetNotes()
122 
123  for j in range(0, sp.getNumEventAssignments()):
124  ea = sp.getEventAssignment(j)
125  ea.unsetNotes()
126 
127  for i in range(0, m.getNumSpeciesTypes()):
128  sp = m.getSpeciesType(i)
129  sp.unsetNotes()
130 
131  for i in range(0, m.getNumConstraints()):
132  sp = m.getConstraint(i)
133  sp.unsetNotes()
134 
135  writeSBML(document, args[2])
136 
137  return errors
138 
139 
140 if __name__ == '__main__':
141  main(sys.argv)