File: printMulti.py

package info (click to toggle)
libsbml 5.19.0%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 157,308 kB
  • sloc: cpp: 972,686; xml: 332,385; python: 128,188; cs: 57,289; ansic: 54,332; java: 27,244; makefile: 9,740; perl: 9,114; sh: 8,777; ruby: 4,760; javascript: 1,605; php: 202; csh: 3
file content (180 lines) | stat: -rw-r--r-- 6,922 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
# 
# @file    printMulti.cs
# @brief   multi print example
# @author  Frank Bergmann
# 
# <!--------------------------------------------------------------------------
# This file is part of libSBML.  Please visit http://sbml.org for more
# information about SBML, and the latest version of libSBML.
# 
# Copyright (C) 2009-2013 jointly by the following organizations:
#     1. California Institute of Technology, Pasadena, CA, USA
#     2. EMBL European Bioinformatics Institute (EMBL-EBI), Hinxton, UK
# 
# Copyright (C) 2006-2008 by the California Institute of Technology,
#     Pasadena, CA, USA 
# 
# Copyright (C) 2002-2005 jointly by the following organizations:
#     1. California Institute of Technology, Pasadena, CA, USA
#     2. Japan Science and Technology Agency, Japan
# 
# This library is free software; you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation.  A copy of the license agreement is provided
# in the file named "LICENSE.txt" included with this software distribution
# and also available online as http://sbml.org/software/libsbml/license.html
# ------------------------------------------------------------------------ -->
# 

import sys
from libsbml import * 

def printCompartmentInfo(compartment):
  plugin = compartment.getPlugin("multi")
  name = compartment.getName() if compartment.isSetName()else compartment.getId()

  print("Compartment {0}: isType = {1}".format(name, plugin.getIsType()))
  for i in range(plugin.getNumCompartmentReferences()):
    current = plugin.getCompartmentReference(i)
    print("  compartmentReference: {0}".format(current.getCompartment()))

  print('')


def printSpeciesInfo(species):
  plugin = species.getPlugin("multi")
  name = species.getName() if species.isSetName() else species.getId()

  print("Species {0}: speciesType = {1}".format(name, plugin.getSpeciesType()))
  for i in range(plugin.getNumOutwardBindingSites()):
    current = plugin.getOutwardBindingSite(i)
    print("  outwardBindingSite bindingStatus={0} component={1}".format(
      BindingStatus_toString(current.getBindingStatus()), current.getComponent()))

  for i in range(plugin.getNumSpeciesFeatures()):
    current = plugin.getSpeciesFeature(i)
    print("  speciesFeature speciesFeatureType={0} occur={1}".format(current.getSpeciesFeatureType(), current.getOccur()))
    for j in range(current.getNumSpeciesFeatureValues()):
      element = current.getSpeciesFeatureValue(j)
      print("    speciesFeatureValue value={0}".format(element.getValue()))

  print('')


def printMultiMathReferences(node):
  if node is None:
    return

  for i in range(node.getNumChildren()):
    current = node.getChild(i)
    printMultiMathReferences(current)

  plugin = node.getPlugin("multi")
  if plugin is None:
    return

  if plugin.isSetRepresentationType():
    print("   math representationType={0}".format(plugin.getRepresentationType()))

  if plugin.isSetSpeciesReference():
    print("   math speciesReference={0}".format(plugin.getSpeciesReference()))


def printReactionInfo(reaction):
  name = reaction.getName() if reaction.isSetName() else reaction.getId()
  isIntraSpeciesReaction = isinstance(reaction, IntraSpeciesReaction)
  print("Reaction {0}: isIntraSpeciesReaction={1}".format(name, isIntraSpeciesReaction))

  for i in range(reaction.getNumReactants()):
    current = reaction.getReactant(i)
    plugin = current.getPlugin("multi")
    if plugin is None:
      continue

    print("  reactant {0}: compartmentReference={1}".format(current.getSpecies(), plugin.getCompartmentReference()))
    for j in range(plugin.getNumSpeciesTypeComponentMapInProducts()):
      element = plugin.getSpeciesTypeComponentMapInProduct(j)
      print("    speciesTypeComponentMapInProduct: reactant={0} reactantComponent={1} productComponent={2}".format(
        element.getReactant(), element.getReactantComponent(), element.getProductComponent()))

    print('')

  for i in range(reaction.getNumProducts()):
    current = reaction.getProduct(i)
    plugin = current.getPlugin("multi")
    if plugin is None:
      continue

    print("  product {0}: compartmentReference={1}".format(current.getSpecies(), plugin.getCompartmentReference()))
    for j in range(plugin.getNumSpeciesTypeComponentMapInProducts()):
      element = plugin.getSpeciesTypeComponentMapInProduct(j)
      print("    speciesTypeComponentMapInProduct: reactant={0} reactantComponent={1} productComponent={2}".format(
        element.getReactant(), element.getReactantComponent(), element.getProductComponent()))

    print('')

  if not reaction.isSetKineticLaw() or not reaction.getKineticLaw().isSetMath():
    print('')
    return

  printMultiMathReferences(reaction.getKineticLaw().getMath())

  print('')


def printModelInfo(model):
  plugin = model.getPlugin("multi")

  for i in range (plugin.getNumMultiSpeciesTypes()):
    current = plugin.getMultiSpeciesType(i)
    isBindingSiteSpeciesType = isinstance(current, BindingSiteSpeciesType)
    print("speciesType id={0} name={1} compartment={2} isBindingSiteSpeciesType={3}".format(current.getId(), current.getName(), current.getCompartment(), isBindingSiteSpeciesType))

    for j in range(current.getNumSpeciesTypeInstances()):
      element = current.getSpeciesTypeInstance(j)
      print("  speciesTypeInstance id={0} name={1} speciesType={2}".format(element.getId(), element.getName(), element.getSpeciesType()))

    for j in range(current.getNumSpeciesTypeComponentIndexes()):
      element = current.getSpeciesTypeComponentIndex(j)
      print("  speciesTypeComponentIndex id={0} component={1}".format(element.getId(), element.getComponent()))

    for j in range(current.getNumInSpeciesTypeBonds()):
      element = current.getInSpeciesTypeBond(j)
      print("  inSpeciesTypeBond bindingSite1={0} bindingSite2={1}".format(element.getBindingSite1(), element.getBindingSite2()))

    print('')

  print('')


def printMulti(fileName):
  document = readSBMLFromFile(fileName)

  if document.getNumErrors(LIBSBML_SEV_ERROR) > 0:
    document.printErrors()
    return

  model = document.getModel()

  # print multi model information
  printModelInfo(model)

  # print multi compartment information
  for i in range(model.getNumCompartments()):
    printCompartmentInfo(model.getCompartment(i))

  # print multi species information
  for i in range(model.getNumSpecies()):
    printSpeciesInfo(model.getSpecies(i))

  # print multi reaction information
  for i in range(model.getNumReactions()):
    printReactionInfo(model.getReaction(i))


if __name__ == "__main__":
  if len(sys.argv) < 2:
    print("usage: printMulti sbml-file")
  else:
    printMulti(sys.argv[1])