libSBML Python API  5.18.0
addModelHistory.py

Adds a model history to a model.

1 #!/usr/bin/env python
2 ##
3 ## \file addModelHistory.py
4 ## \brief adds Model History to a model
5 ## \author Sarah Keating
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 os.path
43 from libsbml import *
44 
45 def printStatus(message, status):
46  statusString = ""
47  if status == LIBSBML_OPERATION_SUCCESS:
48  statusString = "succeeded"
49  elif status == LIBSBML_INVALID_OBJECT:
50  statusString = "invalid object"
51  elif status == LIBSBML_OPERATION_FAILED:
52  statusString = "operation failed"
53  else:
54  statusString = "unknown"
55 
56  print (message + statusString )
57 
58 
59 def main (args):
60  """usage: addModelHistory <input-filename> <output-filename>
61  Adds a model history to the model
62  """
63  if len(args) != 3:
64  print(main.__doc__)
65  sys.exit(2)
66 
67 
68  d = readSBML(args[1])
69  errors = d.getNumErrors()
70 
71  if errors > 0:
72  print("Read Error(s):" )
73  d.printErrors()
74  print("Correct the above and re-run." )
75  else:
76  h = ModelHistory()
77 
78  c = ModelCreator()
79  c.setFamilyName("Keating")
80  c.setGivenName("Sarah")
81  c.setEmail("sbml-team@caltech.edu")
82  c.setOrganization("University of Hertfordshire")
83 
84  status = h.addCreator(c)
85  printStatus("Status for addCreator: ", status)
86 
87  date = Date("1999-11-13T06:54:32")
88  date2 = Date("2007-11-30T06:54:00-02:00")
89 
90  status = h.setCreatedDate(date)
91  printStatus("Set created date: ", status)
92 
93  status = h.setModifiedDate(date2)
94  printStatus("Set modified date: ", status)
95 
96  status = d.getModel().setModelHistory(h)
97  printStatus("Set model history: ", status)
98 
99  writeSBML(d, args[2])
100  return errors
101 
102 
103 if __name__ == '__main__':
104  main(sys.argv)