libSBML Python API  5.18.0
printSBML.py

Prints information about the top-level model in the given SBML file.

1 #!/usr/bin/env python
2 ##
3 ## @file printModel.py
4 ## @brief Prints some information about the top-level model
5 ## @author Sarah Keating
6 ## @author Ben Bornstein
7 ## @author Michael Hucka
8 ##
9 ## <!--------------------------------------------------------------------------
10 ## This sample program is distributed under a different license than the rest
11 ## of libSBML. This program uses the open-source MIT license, as follows:
12 ##
13 ## Copyright (c) 2013-2018 by the California Institute of Technology
14 ## (California, USA), the European Bioinformatics Institute (EMBL-EBI, UK)
15 ## and the University of Heidelberg (Germany), with support from the National
16 ## Institutes of Health (USA) under grant R01GM070923. All rights reserved.
17 ##
18 ## Permission is hereby granted, free of charge, to any person obtaining a
19 ## copy of this software and associated documentation files (the "Software"),
20 ## to deal in the Software without restriction, including without limitation
21 ## the rights to use, copy, modify, merge, publish, distribute, sublicense,
22 ## and/or sell copies of the Software, and to permit persons to whom the
23 ## Software is furnished to do so, subject to the following conditions:
24 ##
25 ## The above copyright notice and this permission notice shall be included in
26 ## all copies or substantial portions of the Software.
27 ##
28 ## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
29 ## IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
30 ## FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
31 ## THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
32 ## LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
33 ## FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
34 ## DEALINGS IN THE SOFTWARE.
35 ##
36 ## Neither the name of the California Institute of Technology (Caltech), nor
37 ## of the European Bioinformatics Institute (EMBL-EBI), nor of the University
38 ## of Heidelberg, nor the names of any contributors, may be used to endorse
39 ## or promote products derived from this software without specific prior
40 ## written permission.
41 ## ------------------------------------------------------------------------ -->
42 ##
43 
44 import sys
45 import os.path
46 from libsbml import *
47 
48 def main (args):
49  """Usage: printNotes filename
50  """
51 
52 
53  if len(args) != 2:
54  print("\n" + "Usage: printSBML filename" )
55  return 1
56 
57  filename = args[1]
58  document = readSBML(filename)
59 
60  if document.getNumErrors() > 0:
61  printLine("Encountered the following SBML errors:" )
62  document.printErrors()
63  return 1
64 
65  level = document.getLevel()
66  version = document.getVersion()
67 
68  print("\n"
69  + "File: " + filename
70  + " (Level " + str(level) + ", version " + str(version) + ")" )
71 
72  model = document.getModel()
73 
74  if model is None:
75  print("No model present." )
76  return 1
77 
78  idString = " id: "
79  if level == 1:
80  idString = "name: "
81  id = "(empty)"
82  if model.isSetId():
83  id = model.getId()
84  print(" "
85  + idString
86  + id )
87 
88  if model.isSetSBOTerm():
89  print(" model sboTerm: " + model.getSBOTerm() )
90 
91  print("functionDefinitions: " + str(model.getNumFunctionDefinitions()) )
92  print(" unitDefinitions: " + str(model.getNumUnitDefinitions()) )
93  print(" compartmentTypes: " + str(model.getNumCompartmentTypes()) )
94  print(" specieTypes: " + str(model.getNumSpeciesTypes()) )
95  print(" compartments: " + str(model.getNumCompartments()) )
96  print(" species: " + str(model.getNumSpecies()) )
97  print(" parameters: " + str(model.getNumParameters()) )
98  print(" initialAssignments: " + str(model.getNumInitialAssignments()) )
99  print(" rules: " + str(model.getNumRules()) )
100  print(" constraints: " + str(model.getNumConstraints()) )
101  print(" reactions: " + str(model.getNumReactions()) )
102  print(" events: " + str(model.getNumEvents()) )
103  print("\n")
104 
105  return 0
106 
107 
108 if __name__ == '__main__':
109  main(sys.argv)