libsbgnpy 0.3.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- libsbgnpy/__init__.py +16 -0
- libsbgnpy/examples/__init__.py +0 -0
- libsbgnpy/examples/extension_example.py +103 -0
- libsbgnpy/examples/info_example.py +70 -0
- libsbgnpy/examples/notes_example.py +66 -0
- libsbgnpy/examples/read_example.py +35 -0
- libsbgnpy/examples/sbgn/adh.sbgn +61 -0
- libsbgnpy/examples/sbgn/glycolysis.sbgn +375 -0
- libsbgnpy/examples/sbgn/neuronal_muscle_signalling_color.sbgn +439 -0
- libsbgnpy/examples/sbgn/notes.sbgn +13 -0
- libsbgnpy/examples/sbgn/test-output-01.sbgn +8 -0
- libsbgnpy/examples/sbgn/test-output-02.sbgn +59 -0
- libsbgnpy/examples/sbgn/test-output-03.sbgn +16 -0
- libsbgnpy/examples/write_example.py +223 -0
- libsbgnpy/libsbgn.py +4490 -0
- libsbgnpy/libsbgnSubs.py +127 -0
- libsbgnpy/libsbgnTypes.py +112 -0
- libsbgnpy/render.py +59 -0
- libsbgnpy/sbo/__init__.py +0 -0
- libsbgnpy/sbo/sbgn_sbo_mapping.txt +1304 -0
- libsbgnpy/sbo/sbo2sbgn.py +58 -0
- libsbgnpy/sbo/sbo_sbgn_map.txt +38 -0
- libsbgnpy/schema/README.md +156 -0
- libsbgnpy/schema/SBGN.xsd +1018 -0
- libsbgnpy/schema/__init__.py +0 -0
- libsbgnpy/utils.py +93 -0
- libsbgnpy/validation/__init__.py +0 -0
- libsbgnpy/validation/error-test-files/AF/af10101-fail.sbgn +34 -0
- libsbgnpy/validation/error-test-files/AF/af10101-pass.sbgn +35 -0
- libsbgnpy/validation/error-test-files/AF/af10102-fail-1.sbgn +17 -0
- libsbgnpy/validation/error-test-files/AF/af10102-fail-2.sbgn +17 -0
- libsbgnpy/validation/error-test-files/AF/af10102-fail-3.sbgn +17 -0
- libsbgnpy/validation/error-test-files/AF/af10102-fail-4.sbgn +17 -0
- libsbgnpy/validation/error-test-files/AF/af10102-pass.sbgn +17 -0
- libsbgnpy/validation/error-test-files/AF/af10103-fail.sbgn +35 -0
- libsbgnpy/validation/error-test-files/AF/af10103-pass.sbgn +35 -0
- libsbgnpy/validation/error-test-files/AF/af10104-fail.sbgn +34 -0
- libsbgnpy/validation/error-test-files/AF/af10104-pass.sbgn +35 -0
- libsbgnpy/validation/error-test-files/AF/af10109-fail.sbgn +35 -0
- libsbgnpy/validation/error-test-files/AF/af10109-pass.sbgn +35 -0
- libsbgnpy/validation/error-test-files/AF/af10110-fail.sbgn +34 -0
- libsbgnpy/validation/error-test-files/AF/af10111-fail.sbgn +42 -0
- libsbgnpy/validation/error-test-files/AF/af10111-pass.sbgn +26 -0
- libsbgnpy/validation/error-test-files/AF/af10112-fail.sbgn +25 -0
- libsbgnpy/validation/error-test-files/AF/af10113-fail.sbgn +17 -0
- libsbgnpy/validation/error-test-files/ER/er10103-fail.sbgn +29 -0
- libsbgnpy/validation/error-test-files/ER/er10103-pass.sbgn +25 -0
- libsbgnpy/validation/error-test-files/ER/er10104-fail.sbgn +31 -0
- libsbgnpy/validation/error-test-files/ER/er10104-pass.sbgn +27 -0
- libsbgnpy/validation/error-test-files/ER/er10106-fail-1.sbgn +26 -0
- libsbgnpy/validation/error-test-files/ER/er10106-fail-2.sbgn +26 -0
- libsbgnpy/validation/error-test-files/ER/er10106-fail-3.sbgn +26 -0
- libsbgnpy/validation/error-test-files/ER/er10106-fail-4.sbgn +26 -0
- libsbgnpy/validation/error-test-files/ER/er10106-fail-5.sbgn +26 -0
- libsbgnpy/validation/error-test-files/ER/er10106-fail-6.sbgn +26 -0
- libsbgnpy/validation/error-test-files/ER/er10106-pass.sbgn +26 -0
- libsbgnpy/validation/error-test-files/ER/er10107-fail-1.sbgn +25 -0
- libsbgnpy/validation/error-test-files/ER/er10107-fail-2.sbgn +25 -0
- libsbgnpy/validation/error-test-files/ER/er10107-fail-3.sbgn +25 -0
- libsbgnpy/validation/error-test-files/ER/er10107-fail-4.sbgn +25 -0
- libsbgnpy/validation/error-test-files/ER/er10107-fail-5.sbgn +25 -0
- libsbgnpy/validation/error-test-files/ER/er10107-fail-6.sbgn +25 -0
- libsbgnpy/validation/error-test-files/ER/er10107-pass.sbgn +26 -0
- libsbgnpy/validation/error-test-files/ER/er10108-fail-1.sbgn +43 -0
- libsbgnpy/validation/error-test-files/ER/er10108-fail-2.sbgn +43 -0
- libsbgnpy/validation/error-test-files/ER/er10108-pass.sbgn +35 -0
- libsbgnpy/validation/error-test-files/ER/er10109-fail.sbgn +40 -0
- libsbgnpy/validation/error-test-files/ER/er10109-pass.sbgn +40 -0
- libsbgnpy/validation/error-test-files/ER/er10111-fail.sbgn +53 -0
- libsbgnpy/validation/error-test-files/ER/er10111-pass.sbgn +27 -0
- libsbgnpy/validation/error-test-files/ER/er20001-fail.sbgn +55 -0
- libsbgnpy/validation/error-test-files/ER/er20001-pass.sbgn +57 -0
- libsbgnpy/validation/error-test-files/PD/pd10101-fail.sbgn +27 -0
- libsbgnpy/validation/error-test-files/PD/pd10101-pass.sbgn +27 -0
- libsbgnpy/validation/error-test-files/PD/pd10102-fail.sbgn +55 -0
- libsbgnpy/validation/error-test-files/PD/pd10102-pass.sbgn +55 -0
- libsbgnpy/validation/error-test-files/PD/pd10103-fail.sbgn +37 -0
- libsbgnpy/validation/error-test-files/PD/pd10103-pass.sbgn +45 -0
- libsbgnpy/validation/error-test-files/PD/pd10104-fail.sbgn +55 -0
- libsbgnpy/validation/error-test-files/PD/pd10104-pass.sbgn +47 -0
- libsbgnpy/validation/error-test-files/PD/pd10105-fail.sbgn +27 -0
- libsbgnpy/validation/error-test-files/PD/pd10105-pass.sbgn +27 -0
- libsbgnpy/validation/error-test-files/PD/pd10106-fail.sbgn +27 -0
- libsbgnpy/validation/error-test-files/PD/pd10106-pass.sbgn +27 -0
- libsbgnpy/validation/error-test-files/PD/pd10107-fail.sbgn +37 -0
- libsbgnpy/validation/error-test-files/PD/pd10107-pass.sbgn +45 -0
- libsbgnpy/validation/error-test-files/PD/pd10108-fail.sbgn +42 -0
- libsbgnpy/validation/error-test-files/PD/pd10108-pass.sbgn +35 -0
- libsbgnpy/validation/error-test-files/PD/pd10109-fail-1.sbgn +51 -0
- libsbgnpy/validation/error-test-files/PD/pd10109-fail-2.sbgn +51 -0
- libsbgnpy/validation/error-test-files/PD/pd10109-fail-3.sbgn +51 -0
- libsbgnpy/validation/error-test-files/PD/pd10109-fail-4.sbgn +51 -0
- libsbgnpy/validation/error-test-files/PD/pd10109-fail-5.sbgn +51 -0
- libsbgnpy/validation/error-test-files/PD/pd10109-pass.sbgn +35 -0
- libsbgnpy/validation/error-test-files/PD/pd10110-fail-1.sbgn +35 -0
- libsbgnpy/validation/error-test-files/PD/pd10110-fail-2.sbgn +35 -0
- libsbgnpy/validation/error-test-files/PD/pd10110-fail-3.sbgn +35 -0
- libsbgnpy/validation/error-test-files/PD/pd10110-fail-4.sbgn +35 -0
- libsbgnpy/validation/error-test-files/PD/pd10110-fail-5.sbgn +35 -0
- libsbgnpy/validation/error-test-files/PD/pd10110-pass.sbgn +35 -0
- libsbgnpy/validation/error-test-files/PD/pd10111-fail-2.sbgn +72 -0
- libsbgnpy/validation/error-test-files/PD/pd10111-fail.sbgn +72 -0
- libsbgnpy/validation/error-test-files/PD/pd10111-pass.sbgn +68 -0
- libsbgnpy/validation/error-test-files/PD/pd10112-fail-1.sbgn +28 -0
- libsbgnpy/validation/error-test-files/PD/pd10112-fail-2.sbgn +28 -0
- libsbgnpy/validation/error-test-files/PD/pd10112-pass.sbgn +28 -0
- libsbgnpy/validation/error-test-files/PD/pd10124-fail.sbgn +67 -0
- libsbgnpy/validation/error-test-files/PD/pd10124-pass.sbgn +67 -0
- libsbgnpy/validation/error-test-files/PD/pd10125-fail.sbgn +35 -0
- libsbgnpy/validation/error-test-files/PD/pd10126-fail.sbgn +53 -0
- libsbgnpy/validation/error-test-files/PD/pd10126-pass.sbgn +45 -0
- libsbgnpy/validation/error-test-files/PD/pd10127-fail.sbgn +21 -0
- libsbgnpy/validation/error-test-files/PD/pd10127-pass.sbgn +17 -0
- libsbgnpy/validation/error-test-files/PD/pd10128-fail.sbgn +21 -0
- libsbgnpy/validation/error-test-files/PD/pd10128-pass.sbgn +17 -0
- libsbgnpy/validation/error-test-files/PD/pd10131-fail.sbgn +9 -0
- libsbgnpy/validation/error-test-files/PD/pd10131-pass.sbgn +27 -0
- libsbgnpy/validation/error-test-files/PD/pd10132-fail.sbgn +10 -0
- libsbgnpy/validation/error-test-files/PD/pd10132-pass.sbgn +27 -0
- libsbgnpy/validation/error-test-files/PD/pd10140-fail.sbgn +31 -0
- libsbgnpy/validation/error-test-files/PD/pd10140-pass.sbgn +27 -0
- libsbgnpy/validation/error-test-files/PD/pd10141-fail.sbgn +11 -0
- libsbgnpy/validation/error-test-files/PD/pd10141-pass.sbgn +27 -0
- libsbgnpy/validation/error-test-files/PD/pd10142-fail.sbgn +35 -0
- libsbgnpy/validation/error-test-files/PD/pd10142-pass.sbgn +53 -0
- libsbgnpy/validation/error-test-files/error_notes.txt +7 -0
- libsbgnpy/validation/rules/sbgn_af.sch +275 -0
- libsbgnpy/validation/rules/sbgn_er.sch +288 -0
- libsbgnpy/validation/rules/sbgn_pd.sch +634 -0
- libsbgnpy/validation/schematron/ExtractSchFromRNG.xsl +75 -0
- libsbgnpy/validation/schematron/ExtractSchFromXSD.xsl +77 -0
- libsbgnpy/validation/schematron/iso-schematron-xslt1.zip +0 -0
- libsbgnpy/validation/schematron/iso-schematron-xslt2.zip +0 -0
- libsbgnpy/validation/schematron/iso_abstract_expand.xsl +297 -0
- libsbgnpy/validation/schematron/iso_dsdl_include.xsl +1509 -0
- libsbgnpy/validation/schematron/iso_schematron_message.xsl +55 -0
- libsbgnpy/validation/schematron/iso_schematron_skeleton_for_xslt1.xsl +1841 -0
- libsbgnpy/validation/schematron/iso_svrl_for_xslt1.xsl +604 -0
- libsbgnpy/validation/schematron/readme.txt +101 -0
- libsbgnpy/validation/schematron/schematron-skeleton-api.htm +723 -0
- libsbgnpy/validation/validator.py +141 -0
- libsbgnpy-0.3.0.dist-info/METADATA +91 -0
- libsbgnpy-0.3.0.dist-info/RECORD +145 -0
- libsbgnpy-0.3.0.dist-info/WHEEL +4 -0
- libsbgnpy-0.3.0.dist-info/licenses/LICENSE +7 -0
libsbgnpy/libsbgn.py
ADDED
|
@@ -0,0 +1,4490 @@
|
|
|
1
|
+
#!/usr/bin/env python
|
|
2
|
+
# -*- coding: utf-8 -*-
|
|
3
|
+
|
|
4
|
+
# Generated Mon Nov 28 14:10:23 2016 by generateDS.py version 2.24a.
|
|
5
|
+
#
|
|
6
|
+
# Command line options:
|
|
7
|
+
# ('-o', 'libsbgn.py')
|
|
8
|
+
# ('-s', 'libsbgnSubs.py')
|
|
9
|
+
#
|
|
10
|
+
# Command line arguments:
|
|
11
|
+
# SBGN.xsd
|
|
12
|
+
#
|
|
13
|
+
# Command line:
|
|
14
|
+
# /usr/local/bin/generateDS.py -o "libsbgn.py" -s "libsbgnSubs.py" SBGN.xsd
|
|
15
|
+
#
|
|
16
|
+
# Current working directory (os.getcwd()):
|
|
17
|
+
# schema
|
|
18
|
+
|
|
19
|
+
from pathlib import Path
|
|
20
|
+
import base64
|
|
21
|
+
import datetime as datetime_
|
|
22
|
+
import re as re_
|
|
23
|
+
import sys
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
try:
|
|
27
|
+
from lxml import etree as etree_
|
|
28
|
+
except ImportError:
|
|
29
|
+
from xml.etree import ElementTree as etree_
|
|
30
|
+
|
|
31
|
+
from .libsbgnTypes import ArcClass, GlyphClass, Language, Orientation
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
Validate_simpletypes_ = True
|
|
35
|
+
BaseStrType_ = str
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def parsexml_(infile, parser=None, **kwargs):
|
|
39
|
+
if parser is None:
|
|
40
|
+
# Use the lxml ElementTree compatible parser so that, e.g.,
|
|
41
|
+
# we ignore comments.
|
|
42
|
+
try:
|
|
43
|
+
parser = etree_.ETCompatXMLParser()
|
|
44
|
+
except AttributeError:
|
|
45
|
+
# fallback to xml.etree
|
|
46
|
+
parser = etree_.XMLParser()
|
|
47
|
+
doc = etree_.parse(infile, parser=parser, **kwargs)
|
|
48
|
+
return doc
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
#
|
|
52
|
+
# User methods
|
|
53
|
+
#
|
|
54
|
+
# Calls to the methods in these classes are generated by generateDS.py.
|
|
55
|
+
# You can replace these methods by re-implementing the following class
|
|
56
|
+
# in a module named generatedssuper.py.
|
|
57
|
+
|
|
58
|
+
try:
|
|
59
|
+
from generatedssuper import GeneratedsSuper
|
|
60
|
+
except ImportError:
|
|
61
|
+
|
|
62
|
+
class GeneratedsSuper(object):
|
|
63
|
+
tzoff_pattern = re_.compile(r"(\+|-)((0\d|1[0-3]):[0-5]\d|14:00)$")
|
|
64
|
+
|
|
65
|
+
class _FixedOffsetTZ(datetime_.tzinfo):
|
|
66
|
+
def __init__(self, offset, name):
|
|
67
|
+
self.__offset = datetime_.timedelta(minutes=offset)
|
|
68
|
+
self.__name = name
|
|
69
|
+
|
|
70
|
+
def utcoffset(self, dt):
|
|
71
|
+
return self.__offset
|
|
72
|
+
|
|
73
|
+
def tzname(self, dt):
|
|
74
|
+
return self.__name
|
|
75
|
+
|
|
76
|
+
def dst(self, dt):
|
|
77
|
+
return None
|
|
78
|
+
|
|
79
|
+
def gds_format_string(self, input_data, input_name=""):
|
|
80
|
+
return input_data
|
|
81
|
+
|
|
82
|
+
def gds_validate_string(self, input_data, node=None, input_name=""):
|
|
83
|
+
if not input_data:
|
|
84
|
+
return ""
|
|
85
|
+
else:
|
|
86
|
+
return input_data
|
|
87
|
+
|
|
88
|
+
def gds_format_base64(self, input_data, input_name=""):
|
|
89
|
+
return base64.b64encode(input_data)
|
|
90
|
+
|
|
91
|
+
def gds_validate_base64(self, input_data, node=None, input_name=""):
|
|
92
|
+
return input_data
|
|
93
|
+
|
|
94
|
+
def gds_format_integer(self, input_data, input_name=""):
|
|
95
|
+
return "%d" % input_data
|
|
96
|
+
|
|
97
|
+
def gds_validate_integer(self, input_data, node=None, input_name=""):
|
|
98
|
+
return input_data
|
|
99
|
+
|
|
100
|
+
def gds_format_integer_list(self, input_data, input_name=""):
|
|
101
|
+
return "%s" % " ".join(input_data)
|
|
102
|
+
|
|
103
|
+
def gds_validate_integer_list(self, input_data, node=None, input_name=""):
|
|
104
|
+
values = input_data.split()
|
|
105
|
+
for value in values:
|
|
106
|
+
try:
|
|
107
|
+
int(value)
|
|
108
|
+
except (TypeError, ValueError):
|
|
109
|
+
raise_parse_error(node, "Requires sequence of integers")
|
|
110
|
+
return values
|
|
111
|
+
|
|
112
|
+
def gds_format_float(self, input_data, input_name=""):
|
|
113
|
+
return ("%.15f" % input_data).rstrip("0")
|
|
114
|
+
|
|
115
|
+
def gds_validate_float(self, input_data, node=None, input_name=""):
|
|
116
|
+
return input_data
|
|
117
|
+
|
|
118
|
+
def gds_format_float_list(self, input_data, input_name=""):
|
|
119
|
+
return "%s" % " ".join(input_data)
|
|
120
|
+
|
|
121
|
+
def gds_validate_float_list(self, input_data, node=None, input_name=""):
|
|
122
|
+
values = input_data.split()
|
|
123
|
+
for value in values:
|
|
124
|
+
try:
|
|
125
|
+
float(value)
|
|
126
|
+
except (TypeError, ValueError):
|
|
127
|
+
raise_parse_error(node, "Requires sequence of floats")
|
|
128
|
+
return values
|
|
129
|
+
|
|
130
|
+
def gds_format_double(self, input_data, input_name=""):
|
|
131
|
+
return "%e" % input_data
|
|
132
|
+
|
|
133
|
+
def gds_validate_double(self, input_data, node=None, input_name=""):
|
|
134
|
+
return input_data
|
|
135
|
+
|
|
136
|
+
def gds_format_double_list(self, input_data, input_name=""):
|
|
137
|
+
return "%s" % " ".join(input_data)
|
|
138
|
+
|
|
139
|
+
def gds_validate_double_list(self, input_data, node=None, input_name=""):
|
|
140
|
+
values = input_data.split()
|
|
141
|
+
for value in values:
|
|
142
|
+
try:
|
|
143
|
+
float(value)
|
|
144
|
+
except (TypeError, ValueError):
|
|
145
|
+
raise_parse_error(node, "Requires sequence of doubles")
|
|
146
|
+
return values
|
|
147
|
+
|
|
148
|
+
def gds_format_boolean(self, input_data, input_name=""):
|
|
149
|
+
return ("%s" % input_data).lower()
|
|
150
|
+
|
|
151
|
+
def gds_validate_boolean(self, input_data, node=None, input_name=""):
|
|
152
|
+
return input_data
|
|
153
|
+
|
|
154
|
+
def gds_format_boolean_list(self, input_data, input_name=""):
|
|
155
|
+
return "%s" % " ".join(input_data)
|
|
156
|
+
|
|
157
|
+
def gds_validate_boolean_list(self, input_data, node=None, input_name=""):
|
|
158
|
+
values = input_data.split()
|
|
159
|
+
for value in values:
|
|
160
|
+
if value not in (
|
|
161
|
+
"true",
|
|
162
|
+
"1",
|
|
163
|
+
"false",
|
|
164
|
+
"0",
|
|
165
|
+
):
|
|
166
|
+
raise_parse_error(
|
|
167
|
+
node,
|
|
168
|
+
"Requires sequence of booleans " '("true", "1", "false", "0")',
|
|
169
|
+
)
|
|
170
|
+
return values
|
|
171
|
+
|
|
172
|
+
def gds_validate_datetime(self, input_data, node=None, input_name=""):
|
|
173
|
+
return input_data
|
|
174
|
+
|
|
175
|
+
def gds_format_datetime(self, input_data, input_name=""):
|
|
176
|
+
if input_data.microsecond == 0:
|
|
177
|
+
_svalue = "%04d-%02d-%02dT%02d:%02d:%02d" % (
|
|
178
|
+
input_data.year,
|
|
179
|
+
input_data.month,
|
|
180
|
+
input_data.day,
|
|
181
|
+
input_data.hour,
|
|
182
|
+
input_data.minute,
|
|
183
|
+
input_data.second,
|
|
184
|
+
)
|
|
185
|
+
else:
|
|
186
|
+
_svalue = "%04d-%02d-%02dT%02d:%02d:%02d.%s" % (
|
|
187
|
+
input_data.year,
|
|
188
|
+
input_data.month,
|
|
189
|
+
input_data.day,
|
|
190
|
+
input_data.hour,
|
|
191
|
+
input_data.minute,
|
|
192
|
+
input_data.second,
|
|
193
|
+
("%f" % (float(input_data.microsecond) / 1000000))[2:],
|
|
194
|
+
)
|
|
195
|
+
if input_data.tzinfo is not None:
|
|
196
|
+
tzoff = input_data.tzinfo.utcoffset(input_data)
|
|
197
|
+
if tzoff is not None:
|
|
198
|
+
total_seconds = tzoff.seconds + (86400 * tzoff.days)
|
|
199
|
+
if total_seconds == 0:
|
|
200
|
+
_svalue += "Z"
|
|
201
|
+
else:
|
|
202
|
+
if total_seconds < 0:
|
|
203
|
+
_svalue += "-"
|
|
204
|
+
total_seconds *= -1
|
|
205
|
+
else:
|
|
206
|
+
_svalue += "+"
|
|
207
|
+
hours = total_seconds // 3600
|
|
208
|
+
minutes = (total_seconds - (hours * 3600)) // 60
|
|
209
|
+
_svalue += "{0:02d}:{1:02d}".format(hours, minutes)
|
|
210
|
+
return _svalue
|
|
211
|
+
|
|
212
|
+
@classmethod
|
|
213
|
+
def gds_parse_datetime(cls, input_data):
|
|
214
|
+
tz = None
|
|
215
|
+
if input_data[-1] == "Z":
|
|
216
|
+
tz = GeneratedsSuper._FixedOffsetTZ(0, "UTC")
|
|
217
|
+
input_data = input_data[:-1]
|
|
218
|
+
else:
|
|
219
|
+
results = GeneratedsSuper.tzoff_pattern.search(input_data)
|
|
220
|
+
if results is not None:
|
|
221
|
+
tzoff_parts = results.group(2).split(":")
|
|
222
|
+
tzoff = int(tzoff_parts[0]) * 60 + int(tzoff_parts[1])
|
|
223
|
+
if results.group(1) == "-":
|
|
224
|
+
tzoff *= -1
|
|
225
|
+
tz = GeneratedsSuper._FixedOffsetTZ(tzoff, results.group(0))
|
|
226
|
+
input_data = input_data[:-6]
|
|
227
|
+
time_parts = input_data.split(".")
|
|
228
|
+
if len(time_parts) > 1:
|
|
229
|
+
micro_seconds = int(float("0." + time_parts[1]) * 1000000)
|
|
230
|
+
input_data = "%s.%s" % (
|
|
231
|
+
time_parts[0],
|
|
232
|
+
micro_seconds,
|
|
233
|
+
)
|
|
234
|
+
dt = datetime_.datetime.strptime(input_data, "%Y-%m-%dT%H:%M:%S.%f")
|
|
235
|
+
else:
|
|
236
|
+
dt = datetime_.datetime.strptime(input_data, "%Y-%m-%dT%H:%M:%S")
|
|
237
|
+
dt = dt.replace(tzinfo=tz)
|
|
238
|
+
return dt
|
|
239
|
+
|
|
240
|
+
def gds_validate_date(self, input_data, node=None, input_name=""):
|
|
241
|
+
return input_data
|
|
242
|
+
|
|
243
|
+
def gds_format_date(self, input_data, input_name=""):
|
|
244
|
+
_svalue = "%04d-%02d-%02d" % (
|
|
245
|
+
input_data.year,
|
|
246
|
+
input_data.month,
|
|
247
|
+
input_data.day,
|
|
248
|
+
)
|
|
249
|
+
try:
|
|
250
|
+
if input_data.tzinfo is not None:
|
|
251
|
+
tzoff = input_data.tzinfo.utcoffset(input_data)
|
|
252
|
+
if tzoff is not None:
|
|
253
|
+
total_seconds = tzoff.seconds + (86400 * tzoff.days)
|
|
254
|
+
if total_seconds == 0:
|
|
255
|
+
_svalue += "Z"
|
|
256
|
+
else:
|
|
257
|
+
if total_seconds < 0:
|
|
258
|
+
_svalue += "-"
|
|
259
|
+
total_seconds *= -1
|
|
260
|
+
else:
|
|
261
|
+
_svalue += "+"
|
|
262
|
+
hours = total_seconds // 3600
|
|
263
|
+
minutes = (total_seconds - (hours * 3600)) // 60
|
|
264
|
+
_svalue += "{0:02d}:{1:02d}".format(hours, minutes)
|
|
265
|
+
except AttributeError:
|
|
266
|
+
pass
|
|
267
|
+
return _svalue
|
|
268
|
+
|
|
269
|
+
@classmethod
|
|
270
|
+
def gds_parse_date(cls, input_data):
|
|
271
|
+
tz = None
|
|
272
|
+
if input_data[-1] == "Z":
|
|
273
|
+
tz = GeneratedsSuper._FixedOffsetTZ(0, "UTC")
|
|
274
|
+
input_data = input_data[:-1]
|
|
275
|
+
else:
|
|
276
|
+
results = GeneratedsSuper.tzoff_pattern.search(input_data)
|
|
277
|
+
if results is not None:
|
|
278
|
+
tzoff_parts = results.group(2).split(":")
|
|
279
|
+
tzoff = int(tzoff_parts[0]) * 60 + int(tzoff_parts[1])
|
|
280
|
+
if results.group(1) == "-":
|
|
281
|
+
tzoff *= -1
|
|
282
|
+
tz = GeneratedsSuper._FixedOffsetTZ(tzoff, results.group(0))
|
|
283
|
+
input_data = input_data[:-6]
|
|
284
|
+
dt = datetime_.datetime.strptime(input_data, "%Y-%m-%d")
|
|
285
|
+
dt = dt.replace(tzinfo=tz)
|
|
286
|
+
return dt.date()
|
|
287
|
+
|
|
288
|
+
def gds_validate_time(self, input_data, node=None, input_name=""):
|
|
289
|
+
return input_data
|
|
290
|
+
|
|
291
|
+
def gds_format_time(self, input_data, input_name=""):
|
|
292
|
+
if input_data.microsecond == 0:
|
|
293
|
+
_svalue = "%02d:%02d:%02d" % (
|
|
294
|
+
input_data.hour,
|
|
295
|
+
input_data.minute,
|
|
296
|
+
input_data.second,
|
|
297
|
+
)
|
|
298
|
+
else:
|
|
299
|
+
_svalue = "%02d:%02d:%02d.%s" % (
|
|
300
|
+
input_data.hour,
|
|
301
|
+
input_data.minute,
|
|
302
|
+
input_data.second,
|
|
303
|
+
("%f" % (float(input_data.microsecond) / 1000000))[2:],
|
|
304
|
+
)
|
|
305
|
+
if input_data.tzinfo is not None:
|
|
306
|
+
tzoff = input_data.tzinfo.utcoffset(input_data)
|
|
307
|
+
if tzoff is not None:
|
|
308
|
+
total_seconds = tzoff.seconds + (86400 * tzoff.days)
|
|
309
|
+
if total_seconds == 0:
|
|
310
|
+
_svalue += "Z"
|
|
311
|
+
else:
|
|
312
|
+
if total_seconds < 0:
|
|
313
|
+
_svalue += "-"
|
|
314
|
+
total_seconds *= -1
|
|
315
|
+
else:
|
|
316
|
+
_svalue += "+"
|
|
317
|
+
hours = total_seconds // 3600
|
|
318
|
+
minutes = (total_seconds - (hours * 3600)) // 60
|
|
319
|
+
_svalue += "{0:02d}:{1:02d}".format(hours, minutes)
|
|
320
|
+
return _svalue
|
|
321
|
+
|
|
322
|
+
def gds_validate_simple_patterns(self, patterns, target):
|
|
323
|
+
# pat is a list of lists of strings/patterns. We should:
|
|
324
|
+
# - AND the outer elements
|
|
325
|
+
# - OR the inner elements
|
|
326
|
+
found1 = True
|
|
327
|
+
for patterns1 in patterns:
|
|
328
|
+
found2 = False
|
|
329
|
+
for patterns2 in patterns1:
|
|
330
|
+
if re_.search(patterns2, target) is not None:
|
|
331
|
+
found2 = True
|
|
332
|
+
break
|
|
333
|
+
if not found2:
|
|
334
|
+
found1 = False
|
|
335
|
+
break
|
|
336
|
+
return found1
|
|
337
|
+
|
|
338
|
+
@classmethod
|
|
339
|
+
def gds_parse_time(cls, input_data):
|
|
340
|
+
tz = None
|
|
341
|
+
if input_data[-1] == "Z":
|
|
342
|
+
tz = GeneratedsSuper._FixedOffsetTZ(0, "UTC")
|
|
343
|
+
input_data = input_data[:-1]
|
|
344
|
+
else:
|
|
345
|
+
results = GeneratedsSuper.tzoff_pattern.search(input_data)
|
|
346
|
+
if results is not None:
|
|
347
|
+
tzoff_parts = results.group(2).split(":")
|
|
348
|
+
tzoff = int(tzoff_parts[0]) * 60 + int(tzoff_parts[1])
|
|
349
|
+
if results.group(1) == "-":
|
|
350
|
+
tzoff *= -1
|
|
351
|
+
tz = GeneratedsSuper._FixedOffsetTZ(tzoff, results.group(0))
|
|
352
|
+
input_data = input_data[:-6]
|
|
353
|
+
if len(input_data.split(".")) > 1:
|
|
354
|
+
dt = datetime_.datetime.strptime(input_data, "%H:%M:%S.%f")
|
|
355
|
+
else:
|
|
356
|
+
dt = datetime_.datetime.strptime(input_data, "%H:%M:%S")
|
|
357
|
+
dt = dt.replace(tzinfo=tz)
|
|
358
|
+
return dt.time()
|
|
359
|
+
|
|
360
|
+
def gds_str_lower(self, instring):
|
|
361
|
+
return instring.lower()
|
|
362
|
+
|
|
363
|
+
def get_path_(self, node):
|
|
364
|
+
path_list = []
|
|
365
|
+
self.get_path_list_(node, path_list)
|
|
366
|
+
path_list.reverse()
|
|
367
|
+
path = "/".join(path_list)
|
|
368
|
+
return path
|
|
369
|
+
|
|
370
|
+
Tag_strip_pattern_ = re_.compile(r"\{.*\}")
|
|
371
|
+
|
|
372
|
+
def get_path_list_(self, node, path_list):
|
|
373
|
+
if node is None:
|
|
374
|
+
return
|
|
375
|
+
tag = GeneratedsSuper.Tag_strip_pattern_.sub("", node.tag)
|
|
376
|
+
if tag:
|
|
377
|
+
path_list.append(tag)
|
|
378
|
+
self.get_path_list_(node.getparent(), path_list)
|
|
379
|
+
|
|
380
|
+
def get_class_obj_(self, node, default_class=None):
|
|
381
|
+
class_obj1 = default_class
|
|
382
|
+
if "xsi" in node.nsmap:
|
|
383
|
+
classname = node.get("{%s}type" % node.nsmap["xsi"])
|
|
384
|
+
if classname is not None:
|
|
385
|
+
names = classname.split(":")
|
|
386
|
+
if len(names) == 2:
|
|
387
|
+
classname = names[1]
|
|
388
|
+
class_obj2 = globals().get(classname)
|
|
389
|
+
if class_obj2 is not None:
|
|
390
|
+
class_obj1 = class_obj2
|
|
391
|
+
return class_obj1
|
|
392
|
+
|
|
393
|
+
def gds_build_any(self, node, type_name=None):
|
|
394
|
+
return None
|
|
395
|
+
|
|
396
|
+
@classmethod
|
|
397
|
+
def gds_reverse_node_mapping(cls, mapping):
|
|
398
|
+
return dict(((v, k) for k, v in mapping.iteritems()))
|
|
399
|
+
|
|
400
|
+
@staticmethod
|
|
401
|
+
def gds_encode(instring):
|
|
402
|
+
if sys.version_info.major == 2:
|
|
403
|
+
return instring.encode(ExternalEncoding)
|
|
404
|
+
else:
|
|
405
|
+
return instring
|
|
406
|
+
|
|
407
|
+
def getSubclassFromModule_(module, class_):
|
|
408
|
+
"""Get the subclass of a class from a specific module."""
|
|
409
|
+
name = class_.__name__ + "Sub"
|
|
410
|
+
if hasattr(module, name):
|
|
411
|
+
return getattr(module, name)
|
|
412
|
+
else:
|
|
413
|
+
return None
|
|
414
|
+
|
|
415
|
+
|
|
416
|
+
#
|
|
417
|
+
# If you have installed IPython you can uncomment and use the following.
|
|
418
|
+
# IPython is available from http://ipython.scipy.org/.
|
|
419
|
+
#
|
|
420
|
+
|
|
421
|
+
# from IPython.Shell import IPShellEmbed
|
|
422
|
+
# args = ''
|
|
423
|
+
# ipshell = IPShellEmbed(args,
|
|
424
|
+
# banner = 'Dropping into IPython',
|
|
425
|
+
# exit_msg = 'Leaving Interpreter, back to program.')
|
|
426
|
+
|
|
427
|
+
# Then use the following line where and when you want to drop into the
|
|
428
|
+
# IPython shell:
|
|
429
|
+
# ipshell('<some message> -- Entering ipshell.\nHit Ctrl-D to exit')
|
|
430
|
+
|
|
431
|
+
#
|
|
432
|
+
# Globals
|
|
433
|
+
#
|
|
434
|
+
|
|
435
|
+
ExternalEncoding = "utf8"
|
|
436
|
+
Tag_pattern_ = re_.compile(r"({.*})?(.*)")
|
|
437
|
+
String_cleanup_pat_ = re_.compile(r"[\n\r\s]+")
|
|
438
|
+
Namespace_extract_pat_ = re_.compile(r"{(.*)}(.*)")
|
|
439
|
+
CDATA_pattern_ = re_.compile(r"<!\[CDATA\[.*?\]\]>", re_.DOTALL)
|
|
440
|
+
|
|
441
|
+
# Change this to redirect the generated superclass module to use a
|
|
442
|
+
# specific subclass module.
|
|
443
|
+
CurrentSubclassModule_ = None
|
|
444
|
+
|
|
445
|
+
#
|
|
446
|
+
# Support/utility functions.
|
|
447
|
+
#
|
|
448
|
+
|
|
449
|
+
|
|
450
|
+
def showIndent(outfile, level, pretty_print=True):
|
|
451
|
+
if pretty_print:
|
|
452
|
+
for idx in range(level):
|
|
453
|
+
outfile.write(" ")
|
|
454
|
+
|
|
455
|
+
|
|
456
|
+
def quote_xml(inStr):
|
|
457
|
+
"Escape markup chars, but do not modify CDATA sections."
|
|
458
|
+
if not inStr:
|
|
459
|
+
return ""
|
|
460
|
+
s1 = isinstance(inStr, BaseStrType_) and inStr or "%s" % inStr
|
|
461
|
+
s2 = ""
|
|
462
|
+
pos = 0
|
|
463
|
+
matchobjects = CDATA_pattern_.finditer(s1)
|
|
464
|
+
for mo in matchobjects:
|
|
465
|
+
s3 = s1[pos : mo.start()]
|
|
466
|
+
s2 += quote_xml_aux(s3)
|
|
467
|
+
s2 += s1[mo.start() : mo.end()]
|
|
468
|
+
pos = mo.end()
|
|
469
|
+
s3 = s1[pos:]
|
|
470
|
+
s2 += quote_xml_aux(s3)
|
|
471
|
+
return s2
|
|
472
|
+
|
|
473
|
+
|
|
474
|
+
def quote_xml_aux(inStr):
|
|
475
|
+
s1 = inStr.replace("&", "&")
|
|
476
|
+
s1 = s1.replace("<", "<")
|
|
477
|
+
s1 = s1.replace(">", ">")
|
|
478
|
+
return s1
|
|
479
|
+
|
|
480
|
+
|
|
481
|
+
def quote_attrib(inStr):
|
|
482
|
+
s1 = isinstance(inStr, BaseStrType_) and inStr or "%s" % inStr
|
|
483
|
+
s1 = s1.replace("&", "&")
|
|
484
|
+
s1 = s1.replace("<", "<")
|
|
485
|
+
s1 = s1.replace(">", ">")
|
|
486
|
+
if '"' in s1:
|
|
487
|
+
if "'" in s1:
|
|
488
|
+
s1 = '"%s"' % s1.replace('"', """)
|
|
489
|
+
else:
|
|
490
|
+
s1 = "'%s'" % s1
|
|
491
|
+
else:
|
|
492
|
+
s1 = '"%s"' % s1
|
|
493
|
+
return s1
|
|
494
|
+
|
|
495
|
+
|
|
496
|
+
def quote_python(inStr):
|
|
497
|
+
s1 = inStr
|
|
498
|
+
if s1.find("'") == -1:
|
|
499
|
+
if s1.find("\n") == -1:
|
|
500
|
+
return "'%s'" % s1
|
|
501
|
+
else:
|
|
502
|
+
return "'''%s'''" % s1
|
|
503
|
+
else:
|
|
504
|
+
if s1.find('"') != -1:
|
|
505
|
+
s1 = s1.replace('"', '\\"')
|
|
506
|
+
if s1.find("\n") == -1:
|
|
507
|
+
return '"%s"' % s1
|
|
508
|
+
else:
|
|
509
|
+
return '"""%s"""' % s1
|
|
510
|
+
|
|
511
|
+
|
|
512
|
+
def get_all_text_(node):
|
|
513
|
+
if node.text is not None:
|
|
514
|
+
text = node.text
|
|
515
|
+
else:
|
|
516
|
+
text = ""
|
|
517
|
+
for child in node:
|
|
518
|
+
if child.tail is not None:
|
|
519
|
+
text += child.tail
|
|
520
|
+
return text
|
|
521
|
+
|
|
522
|
+
|
|
523
|
+
def find_attr_value_(attr_name, node):
|
|
524
|
+
attrs = node.attrib
|
|
525
|
+
attr_parts = attr_name.split(":")
|
|
526
|
+
value = None
|
|
527
|
+
if len(attr_parts) == 1:
|
|
528
|
+
value = attrs.get(attr_name)
|
|
529
|
+
elif len(attr_parts) == 2:
|
|
530
|
+
prefix, name = attr_parts
|
|
531
|
+
namespace = node.nsmap.get(prefix)
|
|
532
|
+
if namespace is not None:
|
|
533
|
+
value = attrs.get(
|
|
534
|
+
"{%s}%s"
|
|
535
|
+
% (
|
|
536
|
+
namespace,
|
|
537
|
+
name,
|
|
538
|
+
)
|
|
539
|
+
)
|
|
540
|
+
return value
|
|
541
|
+
|
|
542
|
+
|
|
543
|
+
class GDSParseError(Exception):
|
|
544
|
+
pass
|
|
545
|
+
|
|
546
|
+
|
|
547
|
+
def raise_parse_error(node, msg):
|
|
548
|
+
msg = "%s (element %s/line %d)" % (
|
|
549
|
+
msg,
|
|
550
|
+
node.tag,
|
|
551
|
+
node.sourceline,
|
|
552
|
+
)
|
|
553
|
+
raise GDSParseError(msg)
|
|
554
|
+
|
|
555
|
+
|
|
556
|
+
class MixedContainer:
|
|
557
|
+
# Constants for category:
|
|
558
|
+
CategoryNone = 0
|
|
559
|
+
CategoryText = 1
|
|
560
|
+
CategorySimple = 2
|
|
561
|
+
CategoryComplex = 3
|
|
562
|
+
# Constants for content_type:
|
|
563
|
+
TypeNone = 0
|
|
564
|
+
TypeText = 1
|
|
565
|
+
TypeString = 2
|
|
566
|
+
TypeInteger = 3
|
|
567
|
+
TypeFloat = 4
|
|
568
|
+
TypeDecimal = 5
|
|
569
|
+
TypeDouble = 6
|
|
570
|
+
TypeBoolean = 7
|
|
571
|
+
TypeBase64 = 8
|
|
572
|
+
|
|
573
|
+
def __init__(self, category, content_type, name, value):
|
|
574
|
+
self.category = category
|
|
575
|
+
self.content_type = content_type
|
|
576
|
+
self.name = name
|
|
577
|
+
self.value = value
|
|
578
|
+
|
|
579
|
+
def getCategory(self):
|
|
580
|
+
return self.category
|
|
581
|
+
|
|
582
|
+
def getContenttype(self, content_type):
|
|
583
|
+
return self.content_type
|
|
584
|
+
|
|
585
|
+
def getValue(self):
|
|
586
|
+
return self.value
|
|
587
|
+
|
|
588
|
+
def getName(self):
|
|
589
|
+
return self.name
|
|
590
|
+
|
|
591
|
+
def export(self, outfile, level, name, namespace, pretty_print=True):
|
|
592
|
+
if self.category == MixedContainer.CategoryText:
|
|
593
|
+
# Prevent exporting empty content as empty lines.
|
|
594
|
+
if self.value.strip():
|
|
595
|
+
outfile.write(self.value)
|
|
596
|
+
elif self.category == MixedContainer.CategorySimple:
|
|
597
|
+
self.exportSimple(outfile, level, name)
|
|
598
|
+
else: # category == MixedContainer.CategoryComplex
|
|
599
|
+
self.value.export(
|
|
600
|
+
outfile, level, namespace, name, pretty_print=pretty_print
|
|
601
|
+
)
|
|
602
|
+
|
|
603
|
+
def exportSimple(self, outfile, level, name):
|
|
604
|
+
if self.content_type == MixedContainer.TypeString:
|
|
605
|
+
outfile.write("<%s>%s</%s>" % (self.name, self.value, self.name))
|
|
606
|
+
elif (
|
|
607
|
+
self.content_type == MixedContainer.TypeInteger
|
|
608
|
+
or self.content_type == MixedContainer.TypeBoolean
|
|
609
|
+
):
|
|
610
|
+
outfile.write("<%s>%d</%s>" % (self.name, self.value, self.name))
|
|
611
|
+
elif (
|
|
612
|
+
self.content_type == MixedContainer.TypeFloat
|
|
613
|
+
or self.content_type == MixedContainer.TypeDecimal
|
|
614
|
+
):
|
|
615
|
+
outfile.write("<%s>%f</%s>" % (self.name, self.value, self.name))
|
|
616
|
+
elif self.content_type == MixedContainer.TypeDouble:
|
|
617
|
+
outfile.write("<%s>%g</%s>" % (self.name, self.value, self.name))
|
|
618
|
+
elif self.content_type == MixedContainer.TypeBase64:
|
|
619
|
+
outfile.write(
|
|
620
|
+
"<%s>%s</%s>" % (self.name, base64.b64encode(self.value), self.name)
|
|
621
|
+
)
|
|
622
|
+
|
|
623
|
+
def to_etree(self, element):
|
|
624
|
+
if self.category == MixedContainer.CategoryText:
|
|
625
|
+
# Prevent exporting empty content as empty lines.
|
|
626
|
+
if self.value.strip():
|
|
627
|
+
if len(element) > 0:
|
|
628
|
+
if element[-1].tail is None:
|
|
629
|
+
element[-1].tail = self.value
|
|
630
|
+
else:
|
|
631
|
+
element[-1].tail += self.value
|
|
632
|
+
else:
|
|
633
|
+
if element.text is None:
|
|
634
|
+
element.text = self.value
|
|
635
|
+
else:
|
|
636
|
+
element.text += self.value
|
|
637
|
+
elif self.category == MixedContainer.CategorySimple:
|
|
638
|
+
subelement = etree_.SubElement(element, "%s" % self.name)
|
|
639
|
+
subelement.text = self.to_etree_simple()
|
|
640
|
+
else: # category == MixedContainer.CategoryComplex
|
|
641
|
+
self.value.to_etree(element)
|
|
642
|
+
|
|
643
|
+
def to_etree_simple(self):
|
|
644
|
+
if self.content_type == MixedContainer.TypeString:
|
|
645
|
+
text = self.value
|
|
646
|
+
elif (
|
|
647
|
+
self.content_type == MixedContainer.TypeInteger
|
|
648
|
+
or self.content_type == MixedContainer.TypeBoolean
|
|
649
|
+
):
|
|
650
|
+
text = "%d" % self.value
|
|
651
|
+
elif (
|
|
652
|
+
self.content_type == MixedContainer.TypeFloat
|
|
653
|
+
or self.content_type == MixedContainer.TypeDecimal
|
|
654
|
+
):
|
|
655
|
+
text = "%f" % self.value
|
|
656
|
+
elif self.content_type == MixedContainer.TypeDouble:
|
|
657
|
+
text = "%g" % self.value
|
|
658
|
+
elif self.content_type == MixedContainer.TypeBase64:
|
|
659
|
+
text = "%s" % base64.b64encode(self.value)
|
|
660
|
+
return text
|
|
661
|
+
|
|
662
|
+
def exportLiteral(self, outfile, level, name):
|
|
663
|
+
if self.category == MixedContainer.CategoryText:
|
|
664
|
+
showIndent(outfile, level)
|
|
665
|
+
outfile.write(
|
|
666
|
+
'model_.MixedContainer(%d, %d, "%s", "%s"),\n'
|
|
667
|
+
% (self.category, self.content_type, self.name, self.value)
|
|
668
|
+
)
|
|
669
|
+
elif self.category == MixedContainer.CategorySimple:
|
|
670
|
+
showIndent(outfile, level)
|
|
671
|
+
outfile.write(
|
|
672
|
+
'model_.MixedContainer(%d, %d, "%s", "%s"),\n'
|
|
673
|
+
% (self.category, self.content_type, self.name, self.value)
|
|
674
|
+
)
|
|
675
|
+
else: # category == MixedContainer.CategoryComplex
|
|
676
|
+
showIndent(outfile, level)
|
|
677
|
+
outfile.write(
|
|
678
|
+
'model_.MixedContainer(%d, %d, "%s",\n'
|
|
679
|
+
% (
|
|
680
|
+
self.category,
|
|
681
|
+
self.content_type,
|
|
682
|
+
self.name,
|
|
683
|
+
)
|
|
684
|
+
)
|
|
685
|
+
self.value.exportLiteral(outfile, level + 1)
|
|
686
|
+
showIndent(outfile, level)
|
|
687
|
+
outfile.write(")\n")
|
|
688
|
+
|
|
689
|
+
|
|
690
|
+
class MemberSpec_(object):
|
|
691
|
+
def __init__(self, name="", data_type="", container=0):
|
|
692
|
+
self.name = name
|
|
693
|
+
self.data_type = data_type
|
|
694
|
+
self.container = container
|
|
695
|
+
|
|
696
|
+
def set_name(self, name):
|
|
697
|
+
self.name = name
|
|
698
|
+
|
|
699
|
+
def get_name(self):
|
|
700
|
+
return self.name
|
|
701
|
+
|
|
702
|
+
def set_data_type(self, data_type):
|
|
703
|
+
self.data_type = data_type
|
|
704
|
+
|
|
705
|
+
def get_data_type_chain(self):
|
|
706
|
+
return self.data_type
|
|
707
|
+
|
|
708
|
+
def get_data_type(self):
|
|
709
|
+
if isinstance(self.data_type, list):
|
|
710
|
+
if len(self.data_type) > 0:
|
|
711
|
+
return self.data_type[-1]
|
|
712
|
+
else:
|
|
713
|
+
return "xs:string"
|
|
714
|
+
else:
|
|
715
|
+
return self.data_type
|
|
716
|
+
|
|
717
|
+
def set_container(self, container):
|
|
718
|
+
self.container = container
|
|
719
|
+
|
|
720
|
+
def get_container(self):
|
|
721
|
+
return self.container
|
|
722
|
+
|
|
723
|
+
|
|
724
|
+
def _cast(typ, value):
|
|
725
|
+
if typ is None or value is None:
|
|
726
|
+
return value
|
|
727
|
+
return typ(value)
|
|
728
|
+
|
|
729
|
+
|
|
730
|
+
#
|
|
731
|
+
# Data representation classes.
|
|
732
|
+
#
|
|
733
|
+
|
|
734
|
+
|
|
735
|
+
class SBGNBase(GeneratedsSuper):
|
|
736
|
+
"""The SBGNBase type is the base type of all main components in SBGN.
|
|
737
|
+
It supports attaching metadata, notes and annotations to
|
|
738
|
+
components."""
|
|
739
|
+
|
|
740
|
+
subclass = None
|
|
741
|
+
superclass = None
|
|
742
|
+
|
|
743
|
+
def __init__(self, notes=None, extension=None, extensiontype_=None):
|
|
744
|
+
self.original_tagname_ = None
|
|
745
|
+
self.notes = notes
|
|
746
|
+
self.extension = extension
|
|
747
|
+
self.extensiontype_ = extensiontype_
|
|
748
|
+
|
|
749
|
+
def factory(*args_, **kwargs_):
|
|
750
|
+
if CurrentSubclassModule_ is not None:
|
|
751
|
+
subclass = getSubclassFromModule_(CurrentSubclassModule_, SBGNBase)
|
|
752
|
+
if subclass is not None:
|
|
753
|
+
return subclass(*args_, **kwargs_)
|
|
754
|
+
if SBGNBase.subclass:
|
|
755
|
+
return SBGNBase.subclass(*args_, **kwargs_)
|
|
756
|
+
else:
|
|
757
|
+
return SBGNBase(*args_, **kwargs_)
|
|
758
|
+
|
|
759
|
+
factory = staticmethod(factory)
|
|
760
|
+
|
|
761
|
+
def get_notes(self):
|
|
762
|
+
return self.notes
|
|
763
|
+
|
|
764
|
+
def set_notes(self, notes):
|
|
765
|
+
self.notes = notes
|
|
766
|
+
|
|
767
|
+
def get_extension(self):
|
|
768
|
+
return self.extension
|
|
769
|
+
|
|
770
|
+
def set_extension(self, extension):
|
|
771
|
+
self.extension = extension
|
|
772
|
+
|
|
773
|
+
def get_extensiontype_(self):
|
|
774
|
+
return self.extensiontype_
|
|
775
|
+
|
|
776
|
+
def set_extensiontype_(self, extensiontype_):
|
|
777
|
+
self.extensiontype_ = extensiontype_
|
|
778
|
+
|
|
779
|
+
def hasContent_(self):
|
|
780
|
+
if self.notes is not None or self.extension is not None:
|
|
781
|
+
return True
|
|
782
|
+
else:
|
|
783
|
+
return False
|
|
784
|
+
|
|
785
|
+
def write_file(self, outfile: Path, namespace="sbgn"):
|
|
786
|
+
"""Write SBGN to file.
|
|
787
|
+
|
|
788
|
+
This also fixes the issues of the sbgn namespace prefix.
|
|
789
|
+
|
|
790
|
+
:param outfile: SBGN file to write
|
|
791
|
+
:param namespace:
|
|
792
|
+
:return:
|
|
793
|
+
"""
|
|
794
|
+
f = open(outfile, "w", encoding="utf-8")
|
|
795
|
+
f.write('<?xml version="1.0" encoding="UTF-8"?>\n')
|
|
796
|
+
self.export(f, level=0, namespace_="sbgn", name_="")
|
|
797
|
+
f.close()
|
|
798
|
+
|
|
799
|
+
# this is a bad hack to remove the namespaces, because
|
|
800
|
+
# most of the SBGN tools do not support them.
|
|
801
|
+
import fileinput
|
|
802
|
+
|
|
803
|
+
f = fileinput.input(outfile, inplace=True)
|
|
804
|
+
|
|
805
|
+
for line in f:
|
|
806
|
+
# remove prefix from closing tags, and unnecessary namespace
|
|
807
|
+
line = line.replace(' xmlns:sbgn="http://sbgn.org/libsbgn/0.2"', "")
|
|
808
|
+
line = line.replace("sbgn:", "")
|
|
809
|
+
line = line.replace("<sbgn>", '<sbgn xmlns="http://sbgn.org/libsbgn/0.2">')
|
|
810
|
+
print(line, end="")
|
|
811
|
+
|
|
812
|
+
f.close()
|
|
813
|
+
|
|
814
|
+
def export(
|
|
815
|
+
self,
|
|
816
|
+
outfile,
|
|
817
|
+
level,
|
|
818
|
+
namespace_="sbgn:",
|
|
819
|
+
name_="sbgn",
|
|
820
|
+
namespacedef_='xmlns:sbgn="http://sbgn.org/libsbgn/0.2"',
|
|
821
|
+
pretty_print=True,
|
|
822
|
+
):
|
|
823
|
+
if pretty_print:
|
|
824
|
+
eol_ = "\n"
|
|
825
|
+
else:
|
|
826
|
+
eol_ = ""
|
|
827
|
+
if self.original_tagname_ is not None:
|
|
828
|
+
name_ = self.original_tagname_
|
|
829
|
+
showIndent(outfile, level, pretty_print)
|
|
830
|
+
outfile.write(
|
|
831
|
+
"<%s%s%s"
|
|
832
|
+
% (
|
|
833
|
+
namespace_,
|
|
834
|
+
name_,
|
|
835
|
+
namespacedef_ and " " + namespacedef_ or "",
|
|
836
|
+
)
|
|
837
|
+
)
|
|
838
|
+
already_processed = set()
|
|
839
|
+
self.exportAttributes(
|
|
840
|
+
outfile, level, already_processed, namespace_, name_="sbgn"
|
|
841
|
+
)
|
|
842
|
+
if self.hasContent_():
|
|
843
|
+
outfile.write(">%s" % (eol_,))
|
|
844
|
+
self.exportChildren(
|
|
845
|
+
outfile,
|
|
846
|
+
level + 1,
|
|
847
|
+
namespace_="sbgn:",
|
|
848
|
+
name_="sbgn",
|
|
849
|
+
pretty_print=pretty_print,
|
|
850
|
+
)
|
|
851
|
+
showIndent(outfile, level, pretty_print)
|
|
852
|
+
outfile.write("</%s%s>%s" % (namespace_, name_, eol_))
|
|
853
|
+
else:
|
|
854
|
+
outfile.write("/>%s" % (eol_,))
|
|
855
|
+
|
|
856
|
+
def exportAttributes(
|
|
857
|
+
self, outfile, level, already_processed, namespace_="sbgn:", name_="SBGNBase"
|
|
858
|
+
):
|
|
859
|
+
if self.extensiontype_ is not None and "xsi:type" not in already_processed:
|
|
860
|
+
already_processed.add("xsi:type")
|
|
861
|
+
outfile.write(' xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"')
|
|
862
|
+
outfile.write(' xsi:type="%s"' % self.extensiontype_)
|
|
863
|
+
pass
|
|
864
|
+
|
|
865
|
+
def exportChildren(
|
|
866
|
+
self,
|
|
867
|
+
outfile,
|
|
868
|
+
level,
|
|
869
|
+
namespace_="sbgn:",
|
|
870
|
+
name_="SBGNBase",
|
|
871
|
+
fromsubclass_=False,
|
|
872
|
+
pretty_print=True,
|
|
873
|
+
):
|
|
874
|
+
if self.notes is not None:
|
|
875
|
+
self.notes.export(
|
|
876
|
+
outfile, level, namespace_, name_="notes", pretty_print=pretty_print
|
|
877
|
+
)
|
|
878
|
+
if self.extension is not None:
|
|
879
|
+
self.extension.export(
|
|
880
|
+
outfile, level, namespace_, name_="extension", pretty_print=pretty_print
|
|
881
|
+
)
|
|
882
|
+
|
|
883
|
+
def build(self, node):
|
|
884
|
+
already_processed = set()
|
|
885
|
+
self.buildAttributes(node, node.attrib, already_processed)
|
|
886
|
+
for child in node:
|
|
887
|
+
nodeName_ = Tag_pattern_.match(child.tag).groups()[-1]
|
|
888
|
+
self.buildChildren(child, node, nodeName_)
|
|
889
|
+
return self
|
|
890
|
+
|
|
891
|
+
def buildAttributes(self, node, attrs, already_processed):
|
|
892
|
+
value = find_attr_value_("xsi:type", node)
|
|
893
|
+
if value is not None and "xsi:type" not in already_processed:
|
|
894
|
+
already_processed.add("xsi:type")
|
|
895
|
+
self.extensiontype_ = value
|
|
896
|
+
|
|
897
|
+
def buildChildren(self, child_, node, nodeName_, fromsubclass_=False):
|
|
898
|
+
if nodeName_ == "notes":
|
|
899
|
+
obj_ = notesType.factory()
|
|
900
|
+
obj_.build(child_)
|
|
901
|
+
self.notes = obj_
|
|
902
|
+
obj_.original_tagname_ = "notes"
|
|
903
|
+
elif nodeName_ == "extension":
|
|
904
|
+
obj_ = extensionType.factory()
|
|
905
|
+
obj_.build(child_)
|
|
906
|
+
self.extension = obj_
|
|
907
|
+
obj_.original_tagname_ = "extension"
|
|
908
|
+
|
|
909
|
+
|
|
910
|
+
# end class SBGNBase
|
|
911
|
+
|
|
912
|
+
|
|
913
|
+
class point(SBGNBase):
|
|
914
|
+
"""The point element is characterized by PointAttributes, which
|
|
915
|
+
describe absolute 2D cartesian coordinates. Namely: x
|
|
916
|
+
(horizontal, from left to right), y (vertical, from top to
|
|
917
|
+
bottom). The origin is located in the top-left corner of the
|
|
918
|
+
map. There is no unit: proportions must be preserved, but the
|
|
919
|
+
maps can be drawn at any scale. In the test files examples, to
|
|
920
|
+
obtain a drawing similar to the reference *.png file, values in
|
|
921
|
+
the corresponding *.sbgn file should be read as pixels."""
|
|
922
|
+
|
|
923
|
+
subclass = None
|
|
924
|
+
superclass = SBGNBase
|
|
925
|
+
|
|
926
|
+
def __init__(self, notes=None, extension=None, x=None, y=None):
|
|
927
|
+
self.original_tagname_ = None
|
|
928
|
+
super(point, self).__init__(
|
|
929
|
+
notes,
|
|
930
|
+
extension,
|
|
931
|
+
)
|
|
932
|
+
self.x = _cast(float, x)
|
|
933
|
+
self.y = _cast(float, y)
|
|
934
|
+
|
|
935
|
+
def factory(*args_, **kwargs_):
|
|
936
|
+
if CurrentSubclassModule_ is not None:
|
|
937
|
+
subclass = getSubclassFromModule_(CurrentSubclassModule_, point)
|
|
938
|
+
if subclass is not None:
|
|
939
|
+
return subclass(*args_, **kwargs_)
|
|
940
|
+
if point.subclass:
|
|
941
|
+
return point.subclass(*args_, **kwargs_)
|
|
942
|
+
else:
|
|
943
|
+
return point(*args_, **kwargs_)
|
|
944
|
+
|
|
945
|
+
factory = staticmethod(factory)
|
|
946
|
+
|
|
947
|
+
def get_x(self):
|
|
948
|
+
return self.x
|
|
949
|
+
|
|
950
|
+
def set_x(self, x):
|
|
951
|
+
self.x = x
|
|
952
|
+
|
|
953
|
+
def get_y(self):
|
|
954
|
+
return self.y
|
|
955
|
+
|
|
956
|
+
def set_y(self, y):
|
|
957
|
+
self.y = y
|
|
958
|
+
|
|
959
|
+
def hasContent_(self):
|
|
960
|
+
if super(point, self).hasContent_():
|
|
961
|
+
return True
|
|
962
|
+
else:
|
|
963
|
+
return False
|
|
964
|
+
|
|
965
|
+
def export(
|
|
966
|
+
self,
|
|
967
|
+
outfile,
|
|
968
|
+
level,
|
|
969
|
+
namespace_="sbgn:",
|
|
970
|
+
name_="point",
|
|
971
|
+
namespacedef_='xmlns:sbgn="http://sbgn.org/libsbgn/0.2"',
|
|
972
|
+
pretty_print=True,
|
|
973
|
+
):
|
|
974
|
+
if pretty_print:
|
|
975
|
+
eol_ = "\n"
|
|
976
|
+
else:
|
|
977
|
+
eol_ = ""
|
|
978
|
+
if self.original_tagname_ is not None:
|
|
979
|
+
name_ = self.original_tagname_
|
|
980
|
+
showIndent(outfile, level, pretty_print)
|
|
981
|
+
outfile.write(
|
|
982
|
+
"<%s%s%s"
|
|
983
|
+
% (
|
|
984
|
+
namespace_,
|
|
985
|
+
name_,
|
|
986
|
+
namespacedef_ and " " + namespacedef_ or "",
|
|
987
|
+
)
|
|
988
|
+
)
|
|
989
|
+
already_processed = set()
|
|
990
|
+
self.exportAttributes(
|
|
991
|
+
outfile, level, already_processed, namespace_, name_="point"
|
|
992
|
+
)
|
|
993
|
+
if self.hasContent_():
|
|
994
|
+
outfile.write(">%s" % (eol_,))
|
|
995
|
+
self.exportChildren(
|
|
996
|
+
outfile,
|
|
997
|
+
level + 1,
|
|
998
|
+
namespace_="sbgn:",
|
|
999
|
+
name_="point",
|
|
1000
|
+
pretty_print=pretty_print,
|
|
1001
|
+
)
|
|
1002
|
+
showIndent(outfile, level, pretty_print)
|
|
1003
|
+
outfile.write("</%s%s>%s" % (namespace_, name_, eol_))
|
|
1004
|
+
else:
|
|
1005
|
+
outfile.write("/>%s" % (eol_,))
|
|
1006
|
+
|
|
1007
|
+
def exportAttributes(
|
|
1008
|
+
self, outfile, level, already_processed, namespace_="sbgn:", name_="point"
|
|
1009
|
+
):
|
|
1010
|
+
super(point, self).exportAttributes(
|
|
1011
|
+
outfile, level, already_processed, namespace_, name_="point"
|
|
1012
|
+
)
|
|
1013
|
+
if self.x is not None and "x" not in already_processed:
|
|
1014
|
+
already_processed.add("x")
|
|
1015
|
+
outfile.write(' x="%s"' % self.gds_format_float(self.x, input_name="x"))
|
|
1016
|
+
if self.y is not None and "y" not in already_processed:
|
|
1017
|
+
already_processed.add("y")
|
|
1018
|
+
outfile.write(' y="%s"' % self.gds_format_float(self.y, input_name="y"))
|
|
1019
|
+
|
|
1020
|
+
def exportChildren(
|
|
1021
|
+
self,
|
|
1022
|
+
outfile,
|
|
1023
|
+
level,
|
|
1024
|
+
namespace_="sbgn:",
|
|
1025
|
+
name_="point",
|
|
1026
|
+
fromsubclass_=False,
|
|
1027
|
+
pretty_print=True,
|
|
1028
|
+
):
|
|
1029
|
+
super(point, self).exportChildren(
|
|
1030
|
+
outfile, level, namespace_, name_, True, pretty_print=pretty_print
|
|
1031
|
+
)
|
|
1032
|
+
|
|
1033
|
+
def build(self, node):
|
|
1034
|
+
already_processed = set()
|
|
1035
|
+
self.buildAttributes(node, node.attrib, already_processed)
|
|
1036
|
+
for child in node:
|
|
1037
|
+
nodeName_ = Tag_pattern_.match(child.tag).groups()[-1]
|
|
1038
|
+
self.buildChildren(child, node, nodeName_)
|
|
1039
|
+
return self
|
|
1040
|
+
|
|
1041
|
+
def buildAttributes(self, node, attrs, already_processed):
|
|
1042
|
+
value = find_attr_value_("x", node)
|
|
1043
|
+
if value is not None and "x" not in already_processed:
|
|
1044
|
+
already_processed.add("x")
|
|
1045
|
+
try:
|
|
1046
|
+
self.x = float(value)
|
|
1047
|
+
except ValueError as exp:
|
|
1048
|
+
raise ValueError("Bad float/double attribute (x): %s" % exp)
|
|
1049
|
+
value = find_attr_value_("y", node)
|
|
1050
|
+
if value is not None and "y" not in already_processed:
|
|
1051
|
+
already_processed.add("y")
|
|
1052
|
+
try:
|
|
1053
|
+
self.y = float(value)
|
|
1054
|
+
except ValueError as exp:
|
|
1055
|
+
raise ValueError("Bad float/double attribute (y): %s" % exp)
|
|
1056
|
+
super(point, self).buildAttributes(node, attrs, already_processed)
|
|
1057
|
+
|
|
1058
|
+
def buildChildren(self, child_, node, nodeName_, fromsubclass_=False):
|
|
1059
|
+
super(point, self).buildChildren(child_, node, nodeName_, True)
|
|
1060
|
+
pass
|
|
1061
|
+
|
|
1062
|
+
|
|
1063
|
+
# end class point
|
|
1064
|
+
|
|
1065
|
+
|
|
1066
|
+
class bbox(SBGNBase):
|
|
1067
|
+
"""The bbox element describes a rectangle. This rectangle is defined
|
|
1068
|
+
by: PointAttributes corresponding to the 2D coordinates of the
|
|
1069
|
+
top left corner, width and height attributes. The rectangle
|
|
1070
|
+
corresponds to the outer bounding box of a shape. The shape
|
|
1071
|
+
itself can be irregular (for instance in the case of some
|
|
1072
|
+
compartments). In the case of process nodes, the bounding box
|
|
1073
|
+
only concerns the central glyph (square, or circle), the
|
|
1074
|
+
input/output ports are not included, and neither are the lines
|
|
1075
|
+
connecting them to the central glyph. A bbox is required for all
|
|
1076
|
+
glyphs, and is optional for labels."""
|
|
1077
|
+
|
|
1078
|
+
subclass = None
|
|
1079
|
+
superclass = SBGNBase
|
|
1080
|
+
|
|
1081
|
+
def __init__(self, x=None, y=None, w=None, h=None, notes=None, extension=None):
|
|
1082
|
+
self.original_tagname_ = None
|
|
1083
|
+
super(bbox, self).__init__(
|
|
1084
|
+
notes,
|
|
1085
|
+
extension,
|
|
1086
|
+
)
|
|
1087
|
+
self.w = _cast(float, w)
|
|
1088
|
+
self.h = _cast(float, h)
|
|
1089
|
+
self.x = _cast(float, x)
|
|
1090
|
+
self.y = _cast(float, y)
|
|
1091
|
+
|
|
1092
|
+
def factory(*args_, **kwargs_):
|
|
1093
|
+
if CurrentSubclassModule_ is not None:
|
|
1094
|
+
subclass = getSubclassFromModule_(CurrentSubclassModule_, bbox)
|
|
1095
|
+
if subclass is not None:
|
|
1096
|
+
return subclass(*args_, **kwargs_)
|
|
1097
|
+
if bbox.subclass:
|
|
1098
|
+
return bbox.subclass(*args_, **kwargs_)
|
|
1099
|
+
else:
|
|
1100
|
+
return bbox(*args_, **kwargs_)
|
|
1101
|
+
|
|
1102
|
+
factory = staticmethod(factory)
|
|
1103
|
+
|
|
1104
|
+
def get_w(self):
|
|
1105
|
+
return self.w
|
|
1106
|
+
|
|
1107
|
+
def set_w(self, w):
|
|
1108
|
+
self.w = w
|
|
1109
|
+
|
|
1110
|
+
def get_h(self):
|
|
1111
|
+
return self.h
|
|
1112
|
+
|
|
1113
|
+
def set_h(self, h):
|
|
1114
|
+
self.h = h
|
|
1115
|
+
|
|
1116
|
+
def get_x(self):
|
|
1117
|
+
return self.x
|
|
1118
|
+
|
|
1119
|
+
def set_x(self, x):
|
|
1120
|
+
self.x = x
|
|
1121
|
+
|
|
1122
|
+
def get_y(self):
|
|
1123
|
+
return self.y
|
|
1124
|
+
|
|
1125
|
+
def set_y(self, y):
|
|
1126
|
+
self.y = y
|
|
1127
|
+
|
|
1128
|
+
def hasContent_(self):
|
|
1129
|
+
if super(bbox, self).hasContent_():
|
|
1130
|
+
return True
|
|
1131
|
+
else:
|
|
1132
|
+
return False
|
|
1133
|
+
|
|
1134
|
+
def export(
|
|
1135
|
+
self,
|
|
1136
|
+
outfile,
|
|
1137
|
+
level,
|
|
1138
|
+
namespace_="sbgn:",
|
|
1139
|
+
name_="bbox",
|
|
1140
|
+
namespacedef_='xmlns:sbgn="http://sbgn.org/libsbgn/0.2"',
|
|
1141
|
+
pretty_print=True,
|
|
1142
|
+
):
|
|
1143
|
+
if pretty_print:
|
|
1144
|
+
eol_ = "\n"
|
|
1145
|
+
else:
|
|
1146
|
+
eol_ = ""
|
|
1147
|
+
if self.original_tagname_ is not None:
|
|
1148
|
+
name_ = self.original_tagname_
|
|
1149
|
+
showIndent(outfile, level, pretty_print)
|
|
1150
|
+
outfile.write(
|
|
1151
|
+
"<%s%s%s"
|
|
1152
|
+
% (
|
|
1153
|
+
namespace_,
|
|
1154
|
+
name_,
|
|
1155
|
+
namespacedef_ and " " + namespacedef_ or "",
|
|
1156
|
+
)
|
|
1157
|
+
)
|
|
1158
|
+
already_processed = set()
|
|
1159
|
+
self.exportAttributes(
|
|
1160
|
+
outfile, level, already_processed, namespace_, name_="bbox"
|
|
1161
|
+
)
|
|
1162
|
+
if self.hasContent_():
|
|
1163
|
+
outfile.write(">%s" % (eol_,))
|
|
1164
|
+
self.exportChildren(
|
|
1165
|
+
outfile,
|
|
1166
|
+
level + 1,
|
|
1167
|
+
namespace_="sbgn:",
|
|
1168
|
+
name_="bbox",
|
|
1169
|
+
pretty_print=pretty_print,
|
|
1170
|
+
)
|
|
1171
|
+
showIndent(outfile, level, pretty_print)
|
|
1172
|
+
outfile.write("</%s%s>%s" % (namespace_, name_, eol_))
|
|
1173
|
+
else:
|
|
1174
|
+
outfile.write("/>%s" % (eol_,))
|
|
1175
|
+
|
|
1176
|
+
def exportAttributes(
|
|
1177
|
+
self, outfile, level, already_processed, namespace_="sbgn:", name_="bbox"
|
|
1178
|
+
):
|
|
1179
|
+
super(bbox, self).exportAttributes(
|
|
1180
|
+
outfile, level, already_processed, namespace_, name_="bbox"
|
|
1181
|
+
)
|
|
1182
|
+
if self.w is not None and "w" not in already_processed:
|
|
1183
|
+
already_processed.add("w")
|
|
1184
|
+
outfile.write(' w="%s"' % self.gds_format_float(self.w, input_name="w"))
|
|
1185
|
+
if self.h is not None and "h" not in already_processed:
|
|
1186
|
+
already_processed.add("h")
|
|
1187
|
+
outfile.write(' h="%s"' % self.gds_format_float(self.h, input_name="h"))
|
|
1188
|
+
if self.x is not None and "x" not in already_processed:
|
|
1189
|
+
already_processed.add("x")
|
|
1190
|
+
outfile.write(' x="%s"' % self.gds_format_float(self.x, input_name="x"))
|
|
1191
|
+
if self.y is not None and "y" not in already_processed:
|
|
1192
|
+
already_processed.add("y")
|
|
1193
|
+
outfile.write(' y="%s"' % self.gds_format_float(self.y, input_name="y"))
|
|
1194
|
+
|
|
1195
|
+
def exportChildren(
|
|
1196
|
+
self,
|
|
1197
|
+
outfile,
|
|
1198
|
+
level,
|
|
1199
|
+
namespace_="sbgn:",
|
|
1200
|
+
name_="bbox",
|
|
1201
|
+
fromsubclass_=False,
|
|
1202
|
+
pretty_print=True,
|
|
1203
|
+
):
|
|
1204
|
+
super(bbox, self).exportChildren(
|
|
1205
|
+
outfile, level, namespace_, name_, True, pretty_print=pretty_print
|
|
1206
|
+
)
|
|
1207
|
+
|
|
1208
|
+
def build(self, node):
|
|
1209
|
+
already_processed = set()
|
|
1210
|
+
self.buildAttributes(node, node.attrib, already_processed)
|
|
1211
|
+
for child in node:
|
|
1212
|
+
nodeName_ = Tag_pattern_.match(child.tag).groups()[-1]
|
|
1213
|
+
self.buildChildren(child, node, nodeName_)
|
|
1214
|
+
return self
|
|
1215
|
+
|
|
1216
|
+
def buildAttributes(self, node, attrs, already_processed):
|
|
1217
|
+
value = find_attr_value_("w", node)
|
|
1218
|
+
if value is not None and "w" not in already_processed:
|
|
1219
|
+
already_processed.add("w")
|
|
1220
|
+
try:
|
|
1221
|
+
self.w = float(value)
|
|
1222
|
+
except ValueError as exp:
|
|
1223
|
+
raise ValueError("Bad float/double attribute (w): %s" % exp)
|
|
1224
|
+
value = find_attr_value_("h", node)
|
|
1225
|
+
if value is not None and "h" not in already_processed:
|
|
1226
|
+
already_processed.add("h")
|
|
1227
|
+
try:
|
|
1228
|
+
self.h = float(value)
|
|
1229
|
+
except ValueError as exp:
|
|
1230
|
+
raise ValueError("Bad float/double attribute (h): %s" % exp)
|
|
1231
|
+
value = find_attr_value_("x", node)
|
|
1232
|
+
if value is not None and "x" not in already_processed:
|
|
1233
|
+
already_processed.add("x")
|
|
1234
|
+
try:
|
|
1235
|
+
self.x = float(value)
|
|
1236
|
+
except ValueError as exp:
|
|
1237
|
+
raise ValueError("Bad float/double attribute (x): %s" % exp)
|
|
1238
|
+
value = find_attr_value_("y", node)
|
|
1239
|
+
if value is not None and "y" not in already_processed:
|
|
1240
|
+
already_processed.add("y")
|
|
1241
|
+
try:
|
|
1242
|
+
self.y = float(value)
|
|
1243
|
+
except ValueError as exp:
|
|
1244
|
+
raise ValueError("Bad float/double attribute (y): %s" % exp)
|
|
1245
|
+
super(bbox, self).buildAttributes(node, attrs, already_processed)
|
|
1246
|
+
|
|
1247
|
+
def buildChildren(self, child_, node, nodeName_, fromsubclass_=False):
|
|
1248
|
+
super(bbox, self).buildChildren(child_, node, nodeName_, True)
|
|
1249
|
+
pass
|
|
1250
|
+
|
|
1251
|
+
|
|
1252
|
+
# end class bbox
|
|
1253
|
+
|
|
1254
|
+
|
|
1255
|
+
class label(SBGNBase):
|
|
1256
|
+
"""The label element describes the text accompanying a glyph. The text
|
|
1257
|
+
attribute is mandatory. Its position can be specified by a bbox
|
|
1258
|
+
(optional). Tools are free to display the text in any style
|
|
1259
|
+
(font, font-size, etc.) The bbox element of a label is optional.
|
|
1260
|
+
When no bbox is defined, the bbox of the parent glyph is
|
|
1261
|
+
inherited. The label should be drawn centered horizontally and
|
|
1262
|
+
vertically in the bbox. When the bbox is inherited, the label
|
|
1263
|
+
can freely spill outside (just like it can spill outside its
|
|
1264
|
+
parent glyph). An explicit bbox provides a stronger hint
|
|
1265
|
+
regarding what surface the label should cover. It defines an
|
|
1266
|
+
upper boundary outside of which the label should (ideally) not
|
|
1267
|
+
spill. It also represents a preferred size: the surface covered
|
|
1268
|
+
by the label can be smaller, but should ideally be as close as
|
|
1269
|
+
possible to the bbox. In most glyphs (EPNs, unit of information,
|
|
1270
|
+
etc.), the label is supposed to be centered, so the bbox is
|
|
1271
|
+
usually omitted (unless there's a specific hint to be shared
|
|
1272
|
+
concerning the area the label should ideally cover). However,
|
|
1273
|
+
labels can be drawn anywhere inside compartments or complex, so
|
|
1274
|
+
these should preferably have an explicit bbox. Multi-line labels
|
|
1275
|
+
are allowed. Line breaks are encoded as 
 as specified by
|
|
1276
|
+
the XML standard."""
|
|
1277
|
+
|
|
1278
|
+
subclass = None
|
|
1279
|
+
superclass = SBGNBase
|
|
1280
|
+
|
|
1281
|
+
def __init__(self, notes=None, extension=None, text=None, bbox=None):
|
|
1282
|
+
self.original_tagname_ = None
|
|
1283
|
+
super(label, self).__init__(
|
|
1284
|
+
notes,
|
|
1285
|
+
extension,
|
|
1286
|
+
)
|
|
1287
|
+
self.text = _cast(None, text)
|
|
1288
|
+
self.bbox = bbox
|
|
1289
|
+
|
|
1290
|
+
def factory(*args_, **kwargs_):
|
|
1291
|
+
if CurrentSubclassModule_ is not None:
|
|
1292
|
+
subclass = getSubclassFromModule_(CurrentSubclassModule_, label)
|
|
1293
|
+
if subclass is not None:
|
|
1294
|
+
return subclass(*args_, **kwargs_)
|
|
1295
|
+
if label.subclass:
|
|
1296
|
+
return label.subclass(*args_, **kwargs_)
|
|
1297
|
+
else:
|
|
1298
|
+
return label(*args_, **kwargs_)
|
|
1299
|
+
|
|
1300
|
+
factory = staticmethod(factory)
|
|
1301
|
+
|
|
1302
|
+
def get_bbox(self):
|
|
1303
|
+
return self.bbox
|
|
1304
|
+
|
|
1305
|
+
def set_bbox(self, bbox):
|
|
1306
|
+
self.bbox = bbox
|
|
1307
|
+
|
|
1308
|
+
def get_text(self):
|
|
1309
|
+
return self.text
|
|
1310
|
+
|
|
1311
|
+
def set_text(self, text):
|
|
1312
|
+
self.text = text
|
|
1313
|
+
|
|
1314
|
+
def hasContent_(self):
|
|
1315
|
+
if self.bbox is not None or super(label, self).hasContent_():
|
|
1316
|
+
return True
|
|
1317
|
+
else:
|
|
1318
|
+
return False
|
|
1319
|
+
|
|
1320
|
+
def export(
|
|
1321
|
+
self,
|
|
1322
|
+
outfile,
|
|
1323
|
+
level,
|
|
1324
|
+
namespace_="sbgn:",
|
|
1325
|
+
name_="label",
|
|
1326
|
+
namespacedef_='xmlns:sbgn="http://sbgn.org/libsbgn/0.2"',
|
|
1327
|
+
pretty_print=True,
|
|
1328
|
+
):
|
|
1329
|
+
if pretty_print:
|
|
1330
|
+
eol_ = "\n"
|
|
1331
|
+
else:
|
|
1332
|
+
eol_ = ""
|
|
1333
|
+
if self.original_tagname_ is not None:
|
|
1334
|
+
name_ = self.original_tagname_
|
|
1335
|
+
showIndent(outfile, level, pretty_print)
|
|
1336
|
+
outfile.write(
|
|
1337
|
+
"<%s%s%s"
|
|
1338
|
+
% (
|
|
1339
|
+
namespace_,
|
|
1340
|
+
name_,
|
|
1341
|
+
namespacedef_ and " " + namespacedef_ or "",
|
|
1342
|
+
)
|
|
1343
|
+
)
|
|
1344
|
+
already_processed = set()
|
|
1345
|
+
self.exportAttributes(
|
|
1346
|
+
outfile, level, already_processed, namespace_, name_="label"
|
|
1347
|
+
)
|
|
1348
|
+
if self.hasContent_():
|
|
1349
|
+
outfile.write(">%s" % (eol_,))
|
|
1350
|
+
self.exportChildren(
|
|
1351
|
+
outfile,
|
|
1352
|
+
level + 1,
|
|
1353
|
+
namespace_="sbgn:",
|
|
1354
|
+
name_="label",
|
|
1355
|
+
pretty_print=pretty_print,
|
|
1356
|
+
)
|
|
1357
|
+
showIndent(outfile, level, pretty_print)
|
|
1358
|
+
outfile.write("</%s%s>%s" % (namespace_, name_, eol_))
|
|
1359
|
+
else:
|
|
1360
|
+
outfile.write("/>%s" % (eol_,))
|
|
1361
|
+
|
|
1362
|
+
def exportAttributes(
|
|
1363
|
+
self, outfile, level, already_processed, namespace_="sbgn:", name_="label"
|
|
1364
|
+
):
|
|
1365
|
+
super(label, self).exportAttributes(
|
|
1366
|
+
outfile, level, already_processed, namespace_, name_="label"
|
|
1367
|
+
)
|
|
1368
|
+
if self.text is not None and "text" not in already_processed:
|
|
1369
|
+
already_processed.add("text")
|
|
1370
|
+
outfile.write(
|
|
1371
|
+
" text=%s"
|
|
1372
|
+
% (
|
|
1373
|
+
self.gds_encode(
|
|
1374
|
+
self.gds_format_string(
|
|
1375
|
+
quote_attrib(self.text), input_name="text"
|
|
1376
|
+
)
|
|
1377
|
+
),
|
|
1378
|
+
)
|
|
1379
|
+
)
|
|
1380
|
+
|
|
1381
|
+
def exportChildren(
|
|
1382
|
+
self,
|
|
1383
|
+
outfile,
|
|
1384
|
+
level,
|
|
1385
|
+
namespace_="sbgn:",
|
|
1386
|
+
name_="label",
|
|
1387
|
+
fromsubclass_=False,
|
|
1388
|
+
pretty_print=True,
|
|
1389
|
+
):
|
|
1390
|
+
super(label, self).exportChildren(
|
|
1391
|
+
outfile, level, namespace_, name_, True, pretty_print=pretty_print
|
|
1392
|
+
)
|
|
1393
|
+
if self.bbox is not None:
|
|
1394
|
+
self.bbox.export(
|
|
1395
|
+
outfile,
|
|
1396
|
+
level,
|
|
1397
|
+
namespace_="sbgn:",
|
|
1398
|
+
name_="bbox",
|
|
1399
|
+
pretty_print=pretty_print,
|
|
1400
|
+
)
|
|
1401
|
+
|
|
1402
|
+
def build(self, node):
|
|
1403
|
+
already_processed = set()
|
|
1404
|
+
self.buildAttributes(node, node.attrib, already_processed)
|
|
1405
|
+
for child in node:
|
|
1406
|
+
nodeName_ = Tag_pattern_.match(child.tag).groups()[-1]
|
|
1407
|
+
self.buildChildren(child, node, nodeName_)
|
|
1408
|
+
return self
|
|
1409
|
+
|
|
1410
|
+
def buildAttributes(self, node, attrs, already_processed):
|
|
1411
|
+
value = find_attr_value_("text", node)
|
|
1412
|
+
if value is not None and "text" not in already_processed:
|
|
1413
|
+
already_processed.add("text")
|
|
1414
|
+
self.text = value
|
|
1415
|
+
super(label, self).buildAttributes(node, attrs, already_processed)
|
|
1416
|
+
|
|
1417
|
+
def buildChildren(self, child_, node, nodeName_, fromsubclass_=False):
|
|
1418
|
+
if nodeName_ == "bbox":
|
|
1419
|
+
obj_ = bbox.factory()
|
|
1420
|
+
obj_.build(child_)
|
|
1421
|
+
self.bbox = obj_
|
|
1422
|
+
obj_.original_tagname_ = "bbox"
|
|
1423
|
+
super(label, self).buildChildren(child_, node, nodeName_, True)
|
|
1424
|
+
|
|
1425
|
+
|
|
1426
|
+
# end class label
|
|
1427
|
+
|
|
1428
|
+
|
|
1429
|
+
class sbgn(SBGNBase):
|
|
1430
|
+
"""The sbgn element is the root of any SBGNML document. Currently each
|
|
1431
|
+
document must contain exactly one map element."""
|
|
1432
|
+
|
|
1433
|
+
subclass = None
|
|
1434
|
+
superclass = SBGNBase
|
|
1435
|
+
|
|
1436
|
+
def __init__(self, notes=None, extension=None, map=None):
|
|
1437
|
+
self.original_tagname_ = None
|
|
1438
|
+
super(sbgn, self).__init__(
|
|
1439
|
+
notes,
|
|
1440
|
+
extension,
|
|
1441
|
+
)
|
|
1442
|
+
self.map = map
|
|
1443
|
+
|
|
1444
|
+
def factory(*args_, **kwargs_):
|
|
1445
|
+
if CurrentSubclassModule_ is not None:
|
|
1446
|
+
subclass = getSubclassFromModule_(CurrentSubclassModule_, sbgn)
|
|
1447
|
+
if subclass is not None:
|
|
1448
|
+
return subclass(*args_, **kwargs_)
|
|
1449
|
+
if sbgn.subclass:
|
|
1450
|
+
return sbgn.subclass(*args_, **kwargs_)
|
|
1451
|
+
else:
|
|
1452
|
+
return sbgn(*args_, **kwargs_)
|
|
1453
|
+
|
|
1454
|
+
factory = staticmethod(factory)
|
|
1455
|
+
|
|
1456
|
+
def get_map(self):
|
|
1457
|
+
return self.map
|
|
1458
|
+
|
|
1459
|
+
def set_map(self, map):
|
|
1460
|
+
self.map = map
|
|
1461
|
+
|
|
1462
|
+
def hasContent_(self):
|
|
1463
|
+
if self.map is not None or super(sbgn, self).hasContent_():
|
|
1464
|
+
return True
|
|
1465
|
+
else:
|
|
1466
|
+
return False
|
|
1467
|
+
|
|
1468
|
+
def export(
|
|
1469
|
+
self,
|
|
1470
|
+
outfile,
|
|
1471
|
+
level,
|
|
1472
|
+
namespace_="sbgn:",
|
|
1473
|
+
name_="sbgn",
|
|
1474
|
+
namespacedef_='xmlns:sbgn="http://sbgn.org/libsbgn/0.2"',
|
|
1475
|
+
pretty_print=True,
|
|
1476
|
+
):
|
|
1477
|
+
if pretty_print:
|
|
1478
|
+
eol_ = "\n"
|
|
1479
|
+
else:
|
|
1480
|
+
eol_ = ""
|
|
1481
|
+
if self.original_tagname_ is not None:
|
|
1482
|
+
name_ = self.original_tagname_
|
|
1483
|
+
showIndent(outfile, level, pretty_print)
|
|
1484
|
+
outfile.write(
|
|
1485
|
+
"<%s%s%s"
|
|
1486
|
+
% (
|
|
1487
|
+
namespace_,
|
|
1488
|
+
name_,
|
|
1489
|
+
namespacedef_ and " " + namespacedef_ or "",
|
|
1490
|
+
)
|
|
1491
|
+
)
|
|
1492
|
+
already_processed = set()
|
|
1493
|
+
self.exportAttributes(
|
|
1494
|
+
outfile, level, already_processed, namespace_, name_="sbgn"
|
|
1495
|
+
)
|
|
1496
|
+
if self.hasContent_():
|
|
1497
|
+
outfile.write(">%s" % (eol_,))
|
|
1498
|
+
self.exportChildren(
|
|
1499
|
+
outfile,
|
|
1500
|
+
level + 1,
|
|
1501
|
+
namespace_="sbgn:",
|
|
1502
|
+
name_="sbgn",
|
|
1503
|
+
pretty_print=pretty_print,
|
|
1504
|
+
)
|
|
1505
|
+
showIndent(outfile, level, pretty_print)
|
|
1506
|
+
outfile.write("</%s%s>%s" % (namespace_, name_, eol_))
|
|
1507
|
+
else:
|
|
1508
|
+
outfile.write("/>%s" % (eol_,))
|
|
1509
|
+
|
|
1510
|
+
def exportAttributes(
|
|
1511
|
+
self, outfile, level, already_processed, namespace_="sbgn:", name_="sbgn"
|
|
1512
|
+
):
|
|
1513
|
+
super(sbgn, self).exportAttributes(
|
|
1514
|
+
outfile, level, already_processed, namespace_, name_="sbgn"
|
|
1515
|
+
)
|
|
1516
|
+
|
|
1517
|
+
def exportChildren(
|
|
1518
|
+
self,
|
|
1519
|
+
outfile,
|
|
1520
|
+
level,
|
|
1521
|
+
namespace_="sbgn:",
|
|
1522
|
+
name_="sbgn",
|
|
1523
|
+
fromsubclass_=False,
|
|
1524
|
+
pretty_print=True,
|
|
1525
|
+
):
|
|
1526
|
+
super(sbgn, self).exportChildren(
|
|
1527
|
+
outfile, level, namespace_, name_, True, pretty_print=pretty_print
|
|
1528
|
+
)
|
|
1529
|
+
if self.map is not None:
|
|
1530
|
+
self.map.export(
|
|
1531
|
+
outfile,
|
|
1532
|
+
level,
|
|
1533
|
+
namespace_="sbgn:",
|
|
1534
|
+
name_="map",
|
|
1535
|
+
pretty_print=pretty_print,
|
|
1536
|
+
)
|
|
1537
|
+
|
|
1538
|
+
def build(self, node):
|
|
1539
|
+
already_processed = set()
|
|
1540
|
+
self.buildAttributes(node, node.attrib, already_processed)
|
|
1541
|
+
for child in node:
|
|
1542
|
+
nodeName_ = Tag_pattern_.match(child.tag).groups()[-1]
|
|
1543
|
+
self.buildChildren(child, node, nodeName_)
|
|
1544
|
+
return self
|
|
1545
|
+
|
|
1546
|
+
def buildAttributes(self, node, attrs, already_processed):
|
|
1547
|
+
super(sbgn, self).buildAttributes(node, attrs, already_processed)
|
|
1548
|
+
|
|
1549
|
+
def buildChildren(self, child_, node, nodeName_, fromsubclass_=False):
|
|
1550
|
+
if nodeName_ == "map":
|
|
1551
|
+
obj_ = map.factory()
|
|
1552
|
+
obj_.build(child_)
|
|
1553
|
+
self.map = obj_
|
|
1554
|
+
obj_.original_tagname_ = "map"
|
|
1555
|
+
super(sbgn, self).buildChildren(child_, node, nodeName_, True)
|
|
1556
|
+
|
|
1557
|
+
|
|
1558
|
+
# end class sbgn
|
|
1559
|
+
|
|
1560
|
+
|
|
1561
|
+
class map(SBGNBase):
|
|
1562
|
+
"""The map element describes a single SBGN PD map. It contains a list
|
|
1563
|
+
of glyph elements and a list of arc elements. These lists can be
|
|
1564
|
+
of any size (possibly empty). Language of the map: one of three
|
|
1565
|
+
sublanguages defined by SBGN. Different languages have different
|
|
1566
|
+
restrictions on the usage of sub-elements (that are not encoded
|
|
1567
|
+
in this schema but must be validated with an external validator)"""
|
|
1568
|
+
|
|
1569
|
+
subclass = None
|
|
1570
|
+
superclass = SBGNBase
|
|
1571
|
+
|
|
1572
|
+
def __init__(
|
|
1573
|
+
self,
|
|
1574
|
+
notes=None,
|
|
1575
|
+
extension=None,
|
|
1576
|
+
language=None,
|
|
1577
|
+
bbox=None,
|
|
1578
|
+
glyph=None,
|
|
1579
|
+
arc=None,
|
|
1580
|
+
arcgroup=None,
|
|
1581
|
+
):
|
|
1582
|
+
self.original_tagname_ = None
|
|
1583
|
+
super(map, self).__init__(
|
|
1584
|
+
notes,
|
|
1585
|
+
extension,
|
|
1586
|
+
)
|
|
1587
|
+
self.set_language(language)
|
|
1588
|
+
self.bbox = bbox
|
|
1589
|
+
if glyph is None:
|
|
1590
|
+
self.glyph = []
|
|
1591
|
+
else:
|
|
1592
|
+
self.glyph = glyph
|
|
1593
|
+
if arc is None:
|
|
1594
|
+
self.arc = []
|
|
1595
|
+
else:
|
|
1596
|
+
self.arc = arc
|
|
1597
|
+
if arcgroup is None:
|
|
1598
|
+
self.arcgroup = []
|
|
1599
|
+
else:
|
|
1600
|
+
self.arcgroup = arcgroup
|
|
1601
|
+
|
|
1602
|
+
def factory(*args_, **kwargs_):
|
|
1603
|
+
if CurrentSubclassModule_ is not None:
|
|
1604
|
+
subclass = getSubclassFromModule_(CurrentSubclassModule_, map)
|
|
1605
|
+
if subclass is not None:
|
|
1606
|
+
return subclass(*args_, **kwargs_)
|
|
1607
|
+
if map.subclass:
|
|
1608
|
+
return map.subclass(*args_, **kwargs_)
|
|
1609
|
+
else:
|
|
1610
|
+
return map(*args_, **kwargs_)
|
|
1611
|
+
|
|
1612
|
+
factory = staticmethod(factory)
|
|
1613
|
+
|
|
1614
|
+
def get_bbox(self):
|
|
1615
|
+
return self.bbox
|
|
1616
|
+
|
|
1617
|
+
def set_bbox(self, bbox):
|
|
1618
|
+
self.bbox = bbox
|
|
1619
|
+
|
|
1620
|
+
def get_glyph(self):
|
|
1621
|
+
return self.glyph
|
|
1622
|
+
|
|
1623
|
+
def set_glyph(self, glyph):
|
|
1624
|
+
self.glyph = glyph
|
|
1625
|
+
|
|
1626
|
+
def add_glyph(self, value):
|
|
1627
|
+
self.glyph.append(value)
|
|
1628
|
+
|
|
1629
|
+
def insert_glyph_at(self, index, value):
|
|
1630
|
+
self.glyph.insert(index, value)
|
|
1631
|
+
|
|
1632
|
+
def replace_glyph_at(self, index, value):
|
|
1633
|
+
self.glyph[index] = value
|
|
1634
|
+
|
|
1635
|
+
def get_arc(self):
|
|
1636
|
+
return self.arc
|
|
1637
|
+
|
|
1638
|
+
def set_arc(self, arc):
|
|
1639
|
+
self.arc = arc
|
|
1640
|
+
|
|
1641
|
+
def add_arc(self, value):
|
|
1642
|
+
self.arc.append(value)
|
|
1643
|
+
|
|
1644
|
+
def insert_arc_at(self, index, value):
|
|
1645
|
+
self.arc.insert(index, value)
|
|
1646
|
+
|
|
1647
|
+
def replace_arc_at(self, index, value):
|
|
1648
|
+
self.arc[index] = value
|
|
1649
|
+
|
|
1650
|
+
def get_arcgroup(self):
|
|
1651
|
+
return self.arcgroup
|
|
1652
|
+
|
|
1653
|
+
def set_arcgroup(self, arcgroup):
|
|
1654
|
+
self.arcgroup = arcgroup
|
|
1655
|
+
|
|
1656
|
+
def add_arcgroup(self, value):
|
|
1657
|
+
self.arcgroup.append(value)
|
|
1658
|
+
|
|
1659
|
+
def insert_arcgroup_at(self, index, value):
|
|
1660
|
+
self.arcgroup.insert(index, value)
|
|
1661
|
+
|
|
1662
|
+
def replace_arcgroup_at(self, index, value):
|
|
1663
|
+
self.arcgroup[index] = value
|
|
1664
|
+
|
|
1665
|
+
def get_language(self):
|
|
1666
|
+
"""Get the Language.
|
|
1667
|
+
:return: Language instance.
|
|
1668
|
+
"""
|
|
1669
|
+
return Language(self.language)
|
|
1670
|
+
|
|
1671
|
+
def set_language(self, language):
|
|
1672
|
+
"""Sets the language and checks that within allowed values.
|
|
1673
|
+
:param language:
|
|
1674
|
+
:return:
|
|
1675
|
+
"""
|
|
1676
|
+
if language and not isinstance(language, Language):
|
|
1677
|
+
raise TypeError("language must be of type Language")
|
|
1678
|
+
if language:
|
|
1679
|
+
self.language = _cast(None, language.value)
|
|
1680
|
+
else:
|
|
1681
|
+
self.language = _cast(None, language)
|
|
1682
|
+
|
|
1683
|
+
def hasContent_(self):
|
|
1684
|
+
if (
|
|
1685
|
+
self.bbox is not None
|
|
1686
|
+
or self.glyph
|
|
1687
|
+
or self.arc
|
|
1688
|
+
or self.arcgroup
|
|
1689
|
+
or super(map, self).hasContent_()
|
|
1690
|
+
):
|
|
1691
|
+
return True
|
|
1692
|
+
else:
|
|
1693
|
+
return False
|
|
1694
|
+
|
|
1695
|
+
def export(
|
|
1696
|
+
self,
|
|
1697
|
+
outfile,
|
|
1698
|
+
level,
|
|
1699
|
+
namespace_="sbgn:",
|
|
1700
|
+
name_="map",
|
|
1701
|
+
namespacedef_='xmlns:sbgn="http://sbgn.org/libsbgn/0.2"',
|
|
1702
|
+
pretty_print=True,
|
|
1703
|
+
):
|
|
1704
|
+
if pretty_print:
|
|
1705
|
+
eol_ = "\n"
|
|
1706
|
+
else:
|
|
1707
|
+
eol_ = ""
|
|
1708
|
+
if self.original_tagname_ is not None:
|
|
1709
|
+
name_ = self.original_tagname_
|
|
1710
|
+
showIndent(outfile, level, pretty_print)
|
|
1711
|
+
outfile.write(
|
|
1712
|
+
"<%s%s%s"
|
|
1713
|
+
% (
|
|
1714
|
+
namespace_,
|
|
1715
|
+
name_,
|
|
1716
|
+
namespacedef_ and " " + namespacedef_ or "",
|
|
1717
|
+
)
|
|
1718
|
+
)
|
|
1719
|
+
already_processed = set()
|
|
1720
|
+
self.exportAttributes(
|
|
1721
|
+
outfile, level, already_processed, namespace_, name_="map"
|
|
1722
|
+
)
|
|
1723
|
+
if self.hasContent_():
|
|
1724
|
+
outfile.write(">%s" % (eol_,))
|
|
1725
|
+
self.exportChildren(
|
|
1726
|
+
outfile,
|
|
1727
|
+
level + 1,
|
|
1728
|
+
namespace_="sbgn:",
|
|
1729
|
+
name_="map",
|
|
1730
|
+
pretty_print=pretty_print,
|
|
1731
|
+
)
|
|
1732
|
+
showIndent(outfile, level, pretty_print)
|
|
1733
|
+
outfile.write("</%s%s>%s" % (namespace_, name_, eol_))
|
|
1734
|
+
else:
|
|
1735
|
+
outfile.write("/>%s" % (eol_,))
|
|
1736
|
+
|
|
1737
|
+
def exportAttributes(
|
|
1738
|
+
self, outfile, level, already_processed, namespace_="sbgn:", name_="map"
|
|
1739
|
+
):
|
|
1740
|
+
super(map, self).exportAttributes(
|
|
1741
|
+
outfile, level, already_processed, namespace_, name_="map"
|
|
1742
|
+
)
|
|
1743
|
+
if self.language is not None and "language" not in already_processed:
|
|
1744
|
+
already_processed.add("language")
|
|
1745
|
+
outfile.write(
|
|
1746
|
+
" language=%s"
|
|
1747
|
+
% (
|
|
1748
|
+
self.gds_encode(
|
|
1749
|
+
self.gds_format_string(
|
|
1750
|
+
quote_attrib(self.language), input_name="language"
|
|
1751
|
+
)
|
|
1752
|
+
),
|
|
1753
|
+
)
|
|
1754
|
+
)
|
|
1755
|
+
|
|
1756
|
+
def exportChildren(
|
|
1757
|
+
self,
|
|
1758
|
+
outfile,
|
|
1759
|
+
level,
|
|
1760
|
+
namespace_="sbgn:",
|
|
1761
|
+
name_="map",
|
|
1762
|
+
fromsubclass_=False,
|
|
1763
|
+
pretty_print=True,
|
|
1764
|
+
):
|
|
1765
|
+
super(map, self).exportChildren(
|
|
1766
|
+
outfile, level, namespace_, name_, True, pretty_print=pretty_print
|
|
1767
|
+
)
|
|
1768
|
+
if self.bbox is not None:
|
|
1769
|
+
self.bbox.export(
|
|
1770
|
+
outfile,
|
|
1771
|
+
level,
|
|
1772
|
+
namespace_="sbgn:",
|
|
1773
|
+
name_="bbox",
|
|
1774
|
+
pretty_print=pretty_print,
|
|
1775
|
+
)
|
|
1776
|
+
for glyph_ in self.glyph:
|
|
1777
|
+
glyph_.export(
|
|
1778
|
+
outfile,
|
|
1779
|
+
level,
|
|
1780
|
+
namespace_="sbgn:",
|
|
1781
|
+
name_="glyph",
|
|
1782
|
+
pretty_print=pretty_print,
|
|
1783
|
+
)
|
|
1784
|
+
for arc_ in self.arc:
|
|
1785
|
+
arc_.export(
|
|
1786
|
+
outfile,
|
|
1787
|
+
level,
|
|
1788
|
+
namespace_="sbgn:",
|
|
1789
|
+
name_="arc",
|
|
1790
|
+
pretty_print=pretty_print,
|
|
1791
|
+
)
|
|
1792
|
+
for arcgroup_ in self.arcgroup:
|
|
1793
|
+
arcgroup_.export(
|
|
1794
|
+
outfile,
|
|
1795
|
+
level,
|
|
1796
|
+
namespace_="sbgn:",
|
|
1797
|
+
name_="arcgroup",
|
|
1798
|
+
pretty_print=pretty_print,
|
|
1799
|
+
)
|
|
1800
|
+
|
|
1801
|
+
def build(self, node):
|
|
1802
|
+
already_processed = set()
|
|
1803
|
+
self.buildAttributes(node, node.attrib, already_processed)
|
|
1804
|
+
for child in node:
|
|
1805
|
+
nodeName_ = Tag_pattern_.match(child.tag).groups()[-1]
|
|
1806
|
+
self.buildChildren(child, node, nodeName_)
|
|
1807
|
+
return self
|
|
1808
|
+
|
|
1809
|
+
def buildAttributes(self, node, attrs, already_processed):
|
|
1810
|
+
value = find_attr_value_("language", node)
|
|
1811
|
+
if value is not None and "language" not in already_processed:
|
|
1812
|
+
already_processed.add("language")
|
|
1813
|
+
self.language = value
|
|
1814
|
+
super(map, self).buildAttributes(node, attrs, already_processed)
|
|
1815
|
+
|
|
1816
|
+
def buildChildren(self, child_, node, nodeName_, fromsubclass_=False):
|
|
1817
|
+
if nodeName_ == "bbox":
|
|
1818
|
+
obj_ = bbox.factory()
|
|
1819
|
+
obj_.build(child_)
|
|
1820
|
+
self.bbox = obj_
|
|
1821
|
+
obj_.original_tagname_ = "bbox"
|
|
1822
|
+
elif nodeName_ == "glyph":
|
|
1823
|
+
obj_ = glyph.factory()
|
|
1824
|
+
obj_.build(child_)
|
|
1825
|
+
self.glyph.append(obj_)
|
|
1826
|
+
obj_.original_tagname_ = "glyph"
|
|
1827
|
+
elif nodeName_ == "arc":
|
|
1828
|
+
obj_ = arc.factory()
|
|
1829
|
+
obj_.build(child_)
|
|
1830
|
+
self.arc.append(obj_)
|
|
1831
|
+
obj_.original_tagname_ = "arc"
|
|
1832
|
+
elif nodeName_ == "arcgroup":
|
|
1833
|
+
obj_ = arcgroup.factory()
|
|
1834
|
+
obj_.build(child_)
|
|
1835
|
+
self.arcgroup.append(obj_)
|
|
1836
|
+
obj_.original_tagname_ = "arcgroup"
|
|
1837
|
+
super(map, self).buildChildren(child_, node, nodeName_, True)
|
|
1838
|
+
|
|
1839
|
+
|
|
1840
|
+
# end class map
|
|
1841
|
+
|
|
1842
|
+
|
|
1843
|
+
class port(SBGNBase):
|
|
1844
|
+
"""The port element describes an anchor point which arcs can refer to
|
|
1845
|
+
as a source or target. It consists in: absolute 2D cartesian
|
|
1846
|
+
coordinates (PointAttribute), a unique id attribute. Two port
|
|
1847
|
+
elements are required for process nodes. They represent the
|
|
1848
|
+
extremity of the two "arms" which protrude on both sides of the
|
|
1849
|
+
core of the glyph (= square or circle shape). Other glyphs don't
|
|
1850
|
+
need ports (but can use them if desired). The xsd:ID type is an
|
|
1851
|
+
alphanumeric identifier, starting with a letter. Port IDs often
|
|
1852
|
+
contain the ID of their glyph, followed by a local port number
|
|
1853
|
+
(e.g. glyph4.1, glyph4.2, etc.) However, this style convention
|
|
1854
|
+
is not mandatory, and IDs should never be interpreted as
|
|
1855
|
+
carrying any meaning."""
|
|
1856
|
+
|
|
1857
|
+
subclass = None
|
|
1858
|
+
superclass = SBGNBase
|
|
1859
|
+
|
|
1860
|
+
def __init__(self, notes=None, extension=None, id=None, x=None, y=None):
|
|
1861
|
+
self.original_tagname_ = None
|
|
1862
|
+
super(port, self).__init__(
|
|
1863
|
+
notes,
|
|
1864
|
+
extension,
|
|
1865
|
+
)
|
|
1866
|
+
self.id = _cast(None, id)
|
|
1867
|
+
self.x = _cast(float, x)
|
|
1868
|
+
self.y = _cast(float, y)
|
|
1869
|
+
|
|
1870
|
+
def factory(*args_, **kwargs_):
|
|
1871
|
+
if CurrentSubclassModule_ is not None:
|
|
1872
|
+
subclass = getSubclassFromModule_(CurrentSubclassModule_, port)
|
|
1873
|
+
if subclass is not None:
|
|
1874
|
+
return subclass(*args_, **kwargs_)
|
|
1875
|
+
if port.subclass:
|
|
1876
|
+
return port.subclass(*args_, **kwargs_)
|
|
1877
|
+
else:
|
|
1878
|
+
return port(*args_, **kwargs_)
|
|
1879
|
+
|
|
1880
|
+
factory = staticmethod(factory)
|
|
1881
|
+
|
|
1882
|
+
def get_id(self):
|
|
1883
|
+
return self.id
|
|
1884
|
+
|
|
1885
|
+
def set_id(self, id):
|
|
1886
|
+
self.id = id
|
|
1887
|
+
|
|
1888
|
+
def get_x(self):
|
|
1889
|
+
return self.x
|
|
1890
|
+
|
|
1891
|
+
def set_x(self, x):
|
|
1892
|
+
self.x = x
|
|
1893
|
+
|
|
1894
|
+
def get_y(self):
|
|
1895
|
+
return self.y
|
|
1896
|
+
|
|
1897
|
+
def set_y(self, y):
|
|
1898
|
+
self.y = y
|
|
1899
|
+
|
|
1900
|
+
def hasContent_(self):
|
|
1901
|
+
if super(port, self).hasContent_():
|
|
1902
|
+
return True
|
|
1903
|
+
else:
|
|
1904
|
+
return False
|
|
1905
|
+
|
|
1906
|
+
def export(
|
|
1907
|
+
self,
|
|
1908
|
+
outfile,
|
|
1909
|
+
level,
|
|
1910
|
+
namespace_="sbgn:",
|
|
1911
|
+
name_="port",
|
|
1912
|
+
namespacedef_='xmlns:sbgn="http://sbgn.org/libsbgn/0.2"',
|
|
1913
|
+
pretty_print=True,
|
|
1914
|
+
):
|
|
1915
|
+
if pretty_print:
|
|
1916
|
+
eol_ = "\n"
|
|
1917
|
+
else:
|
|
1918
|
+
eol_ = ""
|
|
1919
|
+
if self.original_tagname_ is not None:
|
|
1920
|
+
name_ = self.original_tagname_
|
|
1921
|
+
showIndent(outfile, level, pretty_print)
|
|
1922
|
+
outfile.write(
|
|
1923
|
+
"<%s%s%s"
|
|
1924
|
+
% (
|
|
1925
|
+
namespace_,
|
|
1926
|
+
name_,
|
|
1927
|
+
namespacedef_ and " " + namespacedef_ or "",
|
|
1928
|
+
)
|
|
1929
|
+
)
|
|
1930
|
+
already_processed = set()
|
|
1931
|
+
self.exportAttributes(
|
|
1932
|
+
outfile, level, already_processed, namespace_, name_="port"
|
|
1933
|
+
)
|
|
1934
|
+
if self.hasContent_():
|
|
1935
|
+
outfile.write(">%s" % (eol_,))
|
|
1936
|
+
self.exportChildren(
|
|
1937
|
+
outfile,
|
|
1938
|
+
level + 1,
|
|
1939
|
+
namespace_="sbgn:",
|
|
1940
|
+
name_="port",
|
|
1941
|
+
pretty_print=pretty_print,
|
|
1942
|
+
)
|
|
1943
|
+
showIndent(outfile, level, pretty_print)
|
|
1944
|
+
outfile.write("</%s%s>%s" % (namespace_, name_, eol_))
|
|
1945
|
+
else:
|
|
1946
|
+
outfile.write("/>%s" % (eol_,))
|
|
1947
|
+
|
|
1948
|
+
def exportAttributes(
|
|
1949
|
+
self, outfile, level, already_processed, namespace_="sbgn:", name_="port"
|
|
1950
|
+
):
|
|
1951
|
+
super(port, self).exportAttributes(
|
|
1952
|
+
outfile, level, already_processed, namespace_, name_="port"
|
|
1953
|
+
)
|
|
1954
|
+
if self.id is not None and "id" not in already_processed:
|
|
1955
|
+
already_processed.add("id")
|
|
1956
|
+
outfile.write(
|
|
1957
|
+
" id=%s"
|
|
1958
|
+
% (
|
|
1959
|
+
self.gds_encode(
|
|
1960
|
+
self.gds_format_string(quote_attrib(self.id), input_name="id")
|
|
1961
|
+
),
|
|
1962
|
+
)
|
|
1963
|
+
)
|
|
1964
|
+
if self.x is not None and "x" not in already_processed:
|
|
1965
|
+
already_processed.add("x")
|
|
1966
|
+
outfile.write(' x="%s"' % self.gds_format_float(self.x, input_name="x"))
|
|
1967
|
+
if self.y is not None and "y" not in already_processed:
|
|
1968
|
+
already_processed.add("y")
|
|
1969
|
+
outfile.write(' y="%s"' % self.gds_format_float(self.y, input_name="y"))
|
|
1970
|
+
|
|
1971
|
+
def exportChildren(
|
|
1972
|
+
self,
|
|
1973
|
+
outfile,
|
|
1974
|
+
level,
|
|
1975
|
+
namespace_="sbgn:",
|
|
1976
|
+
name_="port",
|
|
1977
|
+
fromsubclass_=False,
|
|
1978
|
+
pretty_print=True,
|
|
1979
|
+
):
|
|
1980
|
+
super(port, self).exportChildren(
|
|
1981
|
+
outfile, level, namespace_, name_, True, pretty_print=pretty_print
|
|
1982
|
+
)
|
|
1983
|
+
|
|
1984
|
+
def build(self, node):
|
|
1985
|
+
already_processed = set()
|
|
1986
|
+
self.buildAttributes(node, node.attrib, already_processed)
|
|
1987
|
+
for child in node:
|
|
1988
|
+
nodeName_ = Tag_pattern_.match(child.tag).groups()[-1]
|
|
1989
|
+
self.buildChildren(child, node, nodeName_)
|
|
1990
|
+
return self
|
|
1991
|
+
|
|
1992
|
+
def buildAttributes(self, node, attrs, already_processed):
|
|
1993
|
+
value = find_attr_value_("id", node)
|
|
1994
|
+
if value is not None and "id" not in already_processed:
|
|
1995
|
+
already_processed.add("id")
|
|
1996
|
+
self.id = value
|
|
1997
|
+
value = find_attr_value_("x", node)
|
|
1998
|
+
if value is not None and "x" not in already_processed:
|
|
1999
|
+
already_processed.add("x")
|
|
2000
|
+
try:
|
|
2001
|
+
self.x = float(value)
|
|
2002
|
+
except ValueError as exp:
|
|
2003
|
+
raise ValueError("Bad float/double attribute (x): %s" % exp)
|
|
2004
|
+
value = find_attr_value_("y", node)
|
|
2005
|
+
if value is not None and "y" not in already_processed:
|
|
2006
|
+
already_processed.add("y")
|
|
2007
|
+
try:
|
|
2008
|
+
self.y = float(value)
|
|
2009
|
+
except ValueError as exp:
|
|
2010
|
+
raise ValueError("Bad float/double attribute (y): %s" % exp)
|
|
2011
|
+
super(port, self).buildAttributes(node, attrs, already_processed)
|
|
2012
|
+
|
|
2013
|
+
def buildChildren(self, child_, node, nodeName_, fromsubclass_=False):
|
|
2014
|
+
super(port, self).buildChildren(child_, node, nodeName_, True)
|
|
2015
|
+
pass
|
|
2016
|
+
|
|
2017
|
+
|
|
2018
|
+
# end class port
|
|
2019
|
+
|
|
2020
|
+
|
|
2021
|
+
class glyph(SBGNBase):
|
|
2022
|
+
"""The glyph element is: either a stand-alone, high-level SBGN glyph
|
|
2023
|
+
(EPN, PN, compartment, etc), or a sub-glyph (state variable,
|
|
2024
|
+
unit of information, inside of a complex, ...) In the first
|
|
2025
|
+
case, it appears directly in the glyph list of the map. In the
|
|
2026
|
+
second case, it is a child of another glyph element. The text
|
|
2027
|
+
inside a glyph is described: either by a label element
|
|
2028
|
+
(optional) [process nodes can't have one], or by a state element
|
|
2029
|
+
(optional) [for state variables only]. The class attribute
|
|
2030
|
+
defines the semantic of the glyph, and influences: the way that
|
|
2031
|
+
glyph should be rendered, the overall syntactic validity of the
|
|
2032
|
+
map. The various classes encompass the following PD SBGN
|
|
2033
|
+
elements: Entity Pool Nodes (EPN), Process Nodes (PN), Logic
|
|
2034
|
+
Operator Nodes, Sub-glyphs on Nodes (State Variable, Unit of
|
|
2035
|
+
Information), Sub-glyphs on Arcs (Stoichiometry Label), Other
|
|
2036
|
+
glyphs (Compartment, Submap, Tag, Terminal). And the following
|
|
2037
|
+
ER SBGN elements Entities (Entity, Outcome) Other (Annotation,
|
|
2038
|
+
Phenotype) Auxiliary on glyps (Existence, Location) Auxiliary on
|
|
2039
|
+
arcs (Cardinality) Delay operator implicit xor The orientation
|
|
2040
|
+
attribute is used to express how to draw asymmetric glyphs. In
|
|
2041
|
+
PD, the orientation of Process Nodes is either horizontal or
|
|
2042
|
+
vertical. It refers to an (imaginary) line connecting the two
|
|
2043
|
+
in/out sides of the PN. In PD, the orientation of Tags and
|
|
2044
|
+
Terminals can be left, right, up or down. It refers to the
|
|
2045
|
+
direction the arrow side of the glyph is pointing at. The xsd:ID
|
|
2046
|
+
type is an alphanumeric identifier, starting with a letter. It
|
|
2047
|
+
is recommended to generate meaningless IDs (e.g. "glyph1234")
|
|
2048
|
+
and avoid IDs with a meaning (e.g. "epn_ethanol") Reference to
|
|
2049
|
+
the ID of the compartment that this glyph is part of. Only use
|
|
2050
|
+
this if there is at least one explicit compartment present in
|
|
2051
|
+
the diagram. Compartments are only used in PD and AF, and thus
|
|
2052
|
+
this attribute as well. For PD, this should be used only for
|
|
2053
|
+
EPN's. In case there are no compartments, entities that can have
|
|
2054
|
+
a location, such as EPN's, are implicit member of an invisible
|
|
2055
|
+
compartment that encompasses the whole map. In that case, this
|
|
2056
|
+
attribute must be omitted. The compartment order attribute can
|
|
2057
|
+
be used to define a drawing order for compartments. It enables
|
|
2058
|
+
tools to draw compartments in the correct order especially in
|
|
2059
|
+
the case of overlapping compartments. Compartments are only used
|
|
2060
|
+
in PD and AF, and thus this attribute as well. The attribute is
|
|
2061
|
+
of type float, the attribute value has not to be unique.
|
|
2062
|
+
Compartments with higher compartment order are drawn on top. The
|
|
2063
|
+
attribute is optional and should only be used for compartments."""
|
|
2064
|
+
|
|
2065
|
+
subclass = None
|
|
2066
|
+
superclass = SBGNBase
|
|
2067
|
+
|
|
2068
|
+
def __init__(
|
|
2069
|
+
self,
|
|
2070
|
+
notes=None,
|
|
2071
|
+
extension=None,
|
|
2072
|
+
class_=None,
|
|
2073
|
+
orientation=Orientation.HORIZONTAL,
|
|
2074
|
+
id=None,
|
|
2075
|
+
compartmentRef=None,
|
|
2076
|
+
compartmentOrder=None,
|
|
2077
|
+
label=None,
|
|
2078
|
+
state=None,
|
|
2079
|
+
clone=None,
|
|
2080
|
+
callout=None,
|
|
2081
|
+
entity=None,
|
|
2082
|
+
bbox=None,
|
|
2083
|
+
glyph_member=None,
|
|
2084
|
+
port=None,
|
|
2085
|
+
):
|
|
2086
|
+
self.original_tagname_ = None
|
|
2087
|
+
super(glyph, self).__init__(
|
|
2088
|
+
notes,
|
|
2089
|
+
extension,
|
|
2090
|
+
)
|
|
2091
|
+
self.set_class(class_)
|
|
2092
|
+
self.set_orientation(orientation)
|
|
2093
|
+
self.id = _cast(None, id)
|
|
2094
|
+
self.compartmentRef = _cast(None, compartmentRef)
|
|
2095
|
+
self.compartmentOrder = _cast(float, compartmentOrder)
|
|
2096
|
+
self.label = label
|
|
2097
|
+
self.state = state
|
|
2098
|
+
self.clone = clone
|
|
2099
|
+
self.callout = callout
|
|
2100
|
+
self.entity = entity
|
|
2101
|
+
self.bbox = bbox
|
|
2102
|
+
if glyph_member is None:
|
|
2103
|
+
self.glyph = []
|
|
2104
|
+
else:
|
|
2105
|
+
self.glyph = glyph_member
|
|
2106
|
+
if port is None:
|
|
2107
|
+
self.port = []
|
|
2108
|
+
else:
|
|
2109
|
+
self.port = port
|
|
2110
|
+
|
|
2111
|
+
def factory(*args_, **kwargs_):
|
|
2112
|
+
if CurrentSubclassModule_ is not None:
|
|
2113
|
+
subclass = getSubclassFromModule_(CurrentSubclassModule_, glyph)
|
|
2114
|
+
if subclass is not None:
|
|
2115
|
+
return subclass(*args_, **kwargs_)
|
|
2116
|
+
if glyph.subclass:
|
|
2117
|
+
return glyph.subclass(*args_, **kwargs_)
|
|
2118
|
+
else:
|
|
2119
|
+
return glyph(*args_, **kwargs_)
|
|
2120
|
+
|
|
2121
|
+
factory = staticmethod(factory)
|
|
2122
|
+
|
|
2123
|
+
def get_label(self):
|
|
2124
|
+
return self.label
|
|
2125
|
+
|
|
2126
|
+
def set_label(self, label):
|
|
2127
|
+
self.label = label
|
|
2128
|
+
|
|
2129
|
+
def get_state(self):
|
|
2130
|
+
return self.state
|
|
2131
|
+
|
|
2132
|
+
def set_state(self, state):
|
|
2133
|
+
self.state = state
|
|
2134
|
+
|
|
2135
|
+
def get_clone(self):
|
|
2136
|
+
return self.clone
|
|
2137
|
+
|
|
2138
|
+
def set_clone(self, clone):
|
|
2139
|
+
self.clone = clone
|
|
2140
|
+
|
|
2141
|
+
def get_callout(self):
|
|
2142
|
+
return self.callout
|
|
2143
|
+
|
|
2144
|
+
def set_callout(self, callout):
|
|
2145
|
+
self.callout = callout
|
|
2146
|
+
|
|
2147
|
+
def get_entity(self):
|
|
2148
|
+
return self.entity
|
|
2149
|
+
|
|
2150
|
+
def set_entity(self, entity):
|
|
2151
|
+
self.entity = entity
|
|
2152
|
+
|
|
2153
|
+
def get_bbox(self):
|
|
2154
|
+
return self.bbox
|
|
2155
|
+
|
|
2156
|
+
def set_bbox(self, bbox):
|
|
2157
|
+
self.bbox = bbox
|
|
2158
|
+
|
|
2159
|
+
def get_glyph(self):
|
|
2160
|
+
return self.glyph
|
|
2161
|
+
|
|
2162
|
+
def set_glyph(self, glyph):
|
|
2163
|
+
self.glyph = glyph
|
|
2164
|
+
|
|
2165
|
+
def add_glyph(self, value):
|
|
2166
|
+
self.glyph.append(value)
|
|
2167
|
+
|
|
2168
|
+
def insert_glyph_at(self, index, value):
|
|
2169
|
+
self.glyph.insert(index, value)
|
|
2170
|
+
|
|
2171
|
+
def replace_glyph_at(self, index, value):
|
|
2172
|
+
self.glyph[index] = value
|
|
2173
|
+
|
|
2174
|
+
def get_port(self):
|
|
2175
|
+
return self.port
|
|
2176
|
+
|
|
2177
|
+
def set_port(self, port):
|
|
2178
|
+
self.port = port
|
|
2179
|
+
|
|
2180
|
+
def add_port(self, value):
|
|
2181
|
+
self.port.append(value)
|
|
2182
|
+
|
|
2183
|
+
def insert_port_at(self, index, value):
|
|
2184
|
+
self.port.insert(index, value)
|
|
2185
|
+
|
|
2186
|
+
def replace_port_at(self, index, value):
|
|
2187
|
+
self.port[index] = value
|
|
2188
|
+
|
|
2189
|
+
def get_class(self):
|
|
2190
|
+
"""Get the Language.
|
|
2191
|
+
:return: Language instance.
|
|
2192
|
+
"""
|
|
2193
|
+
return GlyphClass(self.class_)
|
|
2194
|
+
|
|
2195
|
+
def set_class(self, class_):
|
|
2196
|
+
"""Sets the class and checks that in allowed GlyphClasses
|
|
2197
|
+
:param class_:
|
|
2198
|
+
:return:
|
|
2199
|
+
"""
|
|
2200
|
+
if class_ and not isinstance(class_, GlyphClass):
|
|
2201
|
+
raise TypeError("class must be of type GlyphClass")
|
|
2202
|
+
if class_:
|
|
2203
|
+
self.class_ = _cast(None, class_.value)
|
|
2204
|
+
else:
|
|
2205
|
+
self.class_ = _cast(None, class_)
|
|
2206
|
+
|
|
2207
|
+
def get_orientation(self):
|
|
2208
|
+
"""Get orientation.
|
|
2209
|
+
:return: Orientation instance.
|
|
2210
|
+
"""
|
|
2211
|
+
return Orientation(self.orientation)
|
|
2212
|
+
|
|
2213
|
+
def set_orientation(self, orientation):
|
|
2214
|
+
"""Sets orientation and checks that allowed Orientation.
|
|
2215
|
+
|
|
2216
|
+
:param orientation:
|
|
2217
|
+
:return:
|
|
2218
|
+
"""
|
|
2219
|
+
if not isinstance(orientation, Orientation):
|
|
2220
|
+
raise TypeError("orientation must be of type Orientation")
|
|
2221
|
+
self.orientation = _cast(None, orientation.value)
|
|
2222
|
+
|
|
2223
|
+
def get_id(self):
|
|
2224
|
+
return self.id
|
|
2225
|
+
|
|
2226
|
+
def set_id(self, id):
|
|
2227
|
+
self.id = id
|
|
2228
|
+
|
|
2229
|
+
def get_compartmentRef(self):
|
|
2230
|
+
return self.compartmentRef
|
|
2231
|
+
|
|
2232
|
+
def set_compartmentRef(self, compartmentRef):
|
|
2233
|
+
self.compartmentRef = compartmentRef
|
|
2234
|
+
|
|
2235
|
+
def get_compartmentOrder(self):
|
|
2236
|
+
return self.compartmentOrder
|
|
2237
|
+
|
|
2238
|
+
def set_compartmentOrder(self, compartmentOrder):
|
|
2239
|
+
self.compartmentOrder = compartmentOrder
|
|
2240
|
+
|
|
2241
|
+
def hasContent_(self):
|
|
2242
|
+
if (
|
|
2243
|
+
self.label is not None
|
|
2244
|
+
or self.state is not None
|
|
2245
|
+
or self.clone is not None
|
|
2246
|
+
or self.callout is not None
|
|
2247
|
+
or self.entity is not None
|
|
2248
|
+
or self.bbox is not None
|
|
2249
|
+
or self.glyph
|
|
2250
|
+
or self.port
|
|
2251
|
+
or super(glyph, self).hasContent_()
|
|
2252
|
+
):
|
|
2253
|
+
return True
|
|
2254
|
+
else:
|
|
2255
|
+
return False
|
|
2256
|
+
|
|
2257
|
+
def export(
|
|
2258
|
+
self,
|
|
2259
|
+
outfile,
|
|
2260
|
+
level,
|
|
2261
|
+
namespace_="sbgn:",
|
|
2262
|
+
name_="glyph",
|
|
2263
|
+
namespacedef_='xmlns:sbgn="http://sbgn.org/libsbgn/0.2"',
|
|
2264
|
+
pretty_print=True,
|
|
2265
|
+
):
|
|
2266
|
+
if pretty_print:
|
|
2267
|
+
eol_ = "\n"
|
|
2268
|
+
else:
|
|
2269
|
+
eol_ = ""
|
|
2270
|
+
if self.original_tagname_ is not None:
|
|
2271
|
+
name_ = self.original_tagname_
|
|
2272
|
+
showIndent(outfile, level, pretty_print)
|
|
2273
|
+
outfile.write(
|
|
2274
|
+
"<%s%s%s"
|
|
2275
|
+
% (
|
|
2276
|
+
namespace_,
|
|
2277
|
+
name_,
|
|
2278
|
+
namespacedef_ and " " + namespacedef_ or "",
|
|
2279
|
+
)
|
|
2280
|
+
)
|
|
2281
|
+
already_processed = set()
|
|
2282
|
+
self.exportAttributes(
|
|
2283
|
+
outfile, level, already_processed, namespace_, name_="glyph"
|
|
2284
|
+
)
|
|
2285
|
+
if self.hasContent_():
|
|
2286
|
+
outfile.write(">%s" % (eol_,))
|
|
2287
|
+
self.exportChildren(
|
|
2288
|
+
outfile,
|
|
2289
|
+
level + 1,
|
|
2290
|
+
namespace_="sbgn:",
|
|
2291
|
+
name_="glyph",
|
|
2292
|
+
pretty_print=pretty_print,
|
|
2293
|
+
)
|
|
2294
|
+
showIndent(outfile, level, pretty_print)
|
|
2295
|
+
outfile.write("</%s%s>%s" % (namespace_, name_, eol_))
|
|
2296
|
+
else:
|
|
2297
|
+
outfile.write("/>%s" % (eol_,))
|
|
2298
|
+
|
|
2299
|
+
def exportAttributes(
|
|
2300
|
+
self, outfile, level, already_processed, namespace_="sbgn:", name_="glyph"
|
|
2301
|
+
):
|
|
2302
|
+
super(glyph, self).exportAttributes(
|
|
2303
|
+
outfile, level, already_processed, namespace_, name_="glyph"
|
|
2304
|
+
)
|
|
2305
|
+
if self.class_ is not None and "class_" not in already_processed:
|
|
2306
|
+
already_processed.add("class_")
|
|
2307
|
+
outfile.write(
|
|
2308
|
+
" class=%s"
|
|
2309
|
+
% (
|
|
2310
|
+
self.gds_encode(
|
|
2311
|
+
self.gds_format_string(
|
|
2312
|
+
quote_attrib(self.class_), input_name="class"
|
|
2313
|
+
)
|
|
2314
|
+
),
|
|
2315
|
+
)
|
|
2316
|
+
)
|
|
2317
|
+
if self.orientation != "horizontal" and "orientation" not in already_processed:
|
|
2318
|
+
already_processed.add("orientation")
|
|
2319
|
+
outfile.write(
|
|
2320
|
+
" orientation=%s"
|
|
2321
|
+
% (
|
|
2322
|
+
self.gds_encode(
|
|
2323
|
+
self.gds_format_string(
|
|
2324
|
+
quote_attrib(self.orientation), input_name="orientation"
|
|
2325
|
+
)
|
|
2326
|
+
),
|
|
2327
|
+
)
|
|
2328
|
+
)
|
|
2329
|
+
if self.id is not None and "id" not in already_processed:
|
|
2330
|
+
already_processed.add("id")
|
|
2331
|
+
outfile.write(
|
|
2332
|
+
" id=%s"
|
|
2333
|
+
% (
|
|
2334
|
+
self.gds_encode(
|
|
2335
|
+
self.gds_format_string(quote_attrib(self.id), input_name="id")
|
|
2336
|
+
),
|
|
2337
|
+
)
|
|
2338
|
+
)
|
|
2339
|
+
if (
|
|
2340
|
+
self.compartmentRef is not None
|
|
2341
|
+
and "compartmentRef" not in already_processed
|
|
2342
|
+
):
|
|
2343
|
+
already_processed.add("compartmentRef")
|
|
2344
|
+
outfile.write(
|
|
2345
|
+
" compartmentRef=%s"
|
|
2346
|
+
% (
|
|
2347
|
+
self.gds_encode(
|
|
2348
|
+
self.gds_format_string(
|
|
2349
|
+
quote_attrib(self.compartmentRef),
|
|
2350
|
+
input_name="compartmentRef",
|
|
2351
|
+
)
|
|
2352
|
+
),
|
|
2353
|
+
)
|
|
2354
|
+
)
|
|
2355
|
+
if (
|
|
2356
|
+
self.compartmentOrder is not None
|
|
2357
|
+
and "compartmentOrder" not in already_processed
|
|
2358
|
+
):
|
|
2359
|
+
already_processed.add("compartmentOrder")
|
|
2360
|
+
outfile.write(
|
|
2361
|
+
' compartmentOrder="%s"'
|
|
2362
|
+
% self.gds_format_float(
|
|
2363
|
+
self.compartmentOrder, input_name="compartmentOrder"
|
|
2364
|
+
)
|
|
2365
|
+
)
|
|
2366
|
+
|
|
2367
|
+
def exportChildren(
|
|
2368
|
+
self,
|
|
2369
|
+
outfile,
|
|
2370
|
+
level,
|
|
2371
|
+
namespace_="sbgn:",
|
|
2372
|
+
name_="glyph",
|
|
2373
|
+
fromsubclass_=False,
|
|
2374
|
+
pretty_print=True,
|
|
2375
|
+
):
|
|
2376
|
+
super(glyph, self).exportChildren(
|
|
2377
|
+
outfile, level, namespace_, name_, True, pretty_print=pretty_print
|
|
2378
|
+
)
|
|
2379
|
+
if self.label is not None:
|
|
2380
|
+
self.label.export(
|
|
2381
|
+
outfile,
|
|
2382
|
+
level,
|
|
2383
|
+
namespace_="sbgn:",
|
|
2384
|
+
name_="label",
|
|
2385
|
+
pretty_print=pretty_print,
|
|
2386
|
+
)
|
|
2387
|
+
if self.state is not None:
|
|
2388
|
+
self.state.export(
|
|
2389
|
+
outfile, level, namespace_, name_="state", pretty_print=pretty_print
|
|
2390
|
+
)
|
|
2391
|
+
if self.clone is not None:
|
|
2392
|
+
self.clone.export(
|
|
2393
|
+
outfile, level, namespace_, name_="clone", pretty_print=pretty_print
|
|
2394
|
+
)
|
|
2395
|
+
if self.callout is not None:
|
|
2396
|
+
self.callout.export(
|
|
2397
|
+
outfile, level, namespace_, name_="callout", pretty_print=pretty_print
|
|
2398
|
+
)
|
|
2399
|
+
if self.entity is not None:
|
|
2400
|
+
self.entity.export(
|
|
2401
|
+
outfile, level, namespace_, name_="entity", pretty_print=pretty_print
|
|
2402
|
+
)
|
|
2403
|
+
if self.bbox is not None:
|
|
2404
|
+
self.bbox.export(
|
|
2405
|
+
outfile,
|
|
2406
|
+
level,
|
|
2407
|
+
namespace_="sbgn:",
|
|
2408
|
+
name_="bbox",
|
|
2409
|
+
pretty_print=pretty_print,
|
|
2410
|
+
)
|
|
2411
|
+
for glyph_ in self.glyph:
|
|
2412
|
+
glyph_.export(
|
|
2413
|
+
outfile,
|
|
2414
|
+
level,
|
|
2415
|
+
namespace_="sbgn:",
|
|
2416
|
+
name_="glyph",
|
|
2417
|
+
pretty_print=pretty_print,
|
|
2418
|
+
)
|
|
2419
|
+
for port_ in self.port:
|
|
2420
|
+
port_.export(
|
|
2421
|
+
outfile,
|
|
2422
|
+
level,
|
|
2423
|
+
namespace_="sbgn:",
|
|
2424
|
+
name_="port",
|
|
2425
|
+
pretty_print=pretty_print,
|
|
2426
|
+
)
|
|
2427
|
+
|
|
2428
|
+
def build(self, node):
|
|
2429
|
+
already_processed = set()
|
|
2430
|
+
self.buildAttributes(node, node.attrib, already_processed)
|
|
2431
|
+
for child in node:
|
|
2432
|
+
nodeName_ = Tag_pattern_.match(child.tag).groups()[-1]
|
|
2433
|
+
self.buildChildren(child, node, nodeName_)
|
|
2434
|
+
return self
|
|
2435
|
+
|
|
2436
|
+
def buildAttributes(self, node, attrs, already_processed):
|
|
2437
|
+
value = find_attr_value_("class", node)
|
|
2438
|
+
if value is not None and "class" not in already_processed:
|
|
2439
|
+
already_processed.add("class")
|
|
2440
|
+
self.class_ = value
|
|
2441
|
+
value = find_attr_value_("orientation", node)
|
|
2442
|
+
if value is not None and "orientation" not in already_processed:
|
|
2443
|
+
already_processed.add("orientation")
|
|
2444
|
+
self.orientation = value
|
|
2445
|
+
value = find_attr_value_("id", node)
|
|
2446
|
+
if value is not None and "id" not in already_processed:
|
|
2447
|
+
already_processed.add("id")
|
|
2448
|
+
self.id = value
|
|
2449
|
+
value = find_attr_value_("compartmentRef", node)
|
|
2450
|
+
if value is not None and "compartmentRef" not in already_processed:
|
|
2451
|
+
already_processed.add("compartmentRef")
|
|
2452
|
+
self.compartmentRef = value
|
|
2453
|
+
value = find_attr_value_("compartmentOrder", node)
|
|
2454
|
+
if value is not None and "compartmentOrder" not in already_processed:
|
|
2455
|
+
already_processed.add("compartmentOrder")
|
|
2456
|
+
try:
|
|
2457
|
+
self.compartmentOrder = float(value)
|
|
2458
|
+
except ValueError as exp:
|
|
2459
|
+
raise ValueError(
|
|
2460
|
+
"Bad float/double attribute (compartmentOrder): %s" % exp
|
|
2461
|
+
)
|
|
2462
|
+
super(glyph, self).buildAttributes(node, attrs, already_processed)
|
|
2463
|
+
|
|
2464
|
+
def buildChildren(self, child_, node, nodeName_, fromsubclass_=False):
|
|
2465
|
+
if nodeName_ == "label":
|
|
2466
|
+
obj_ = label.factory()
|
|
2467
|
+
obj_.build(child_)
|
|
2468
|
+
self.label = obj_
|
|
2469
|
+
obj_.original_tagname_ = "label"
|
|
2470
|
+
elif nodeName_ == "state":
|
|
2471
|
+
obj_ = stateType.factory()
|
|
2472
|
+
obj_.build(child_)
|
|
2473
|
+
self.state = obj_
|
|
2474
|
+
obj_.original_tagname_ = "state"
|
|
2475
|
+
elif nodeName_ == "clone":
|
|
2476
|
+
obj_ = cloneType.factory()
|
|
2477
|
+
obj_.build(child_)
|
|
2478
|
+
self.clone = obj_
|
|
2479
|
+
obj_.original_tagname_ = "clone"
|
|
2480
|
+
elif nodeName_ == "callout":
|
|
2481
|
+
obj_ = calloutType.factory()
|
|
2482
|
+
obj_.build(child_)
|
|
2483
|
+
self.callout = obj_
|
|
2484
|
+
obj_.original_tagname_ = "callout"
|
|
2485
|
+
elif nodeName_ == "entity":
|
|
2486
|
+
obj_ = entityType.factory()
|
|
2487
|
+
obj_.build(child_)
|
|
2488
|
+
self.entity = obj_
|
|
2489
|
+
obj_.original_tagname_ = "entity"
|
|
2490
|
+
elif nodeName_ == "bbox":
|
|
2491
|
+
obj_ = bbox.factory()
|
|
2492
|
+
obj_.build(child_)
|
|
2493
|
+
self.bbox = obj_
|
|
2494
|
+
obj_.original_tagname_ = "bbox"
|
|
2495
|
+
elif nodeName_ == "glyph":
|
|
2496
|
+
obj_ = glyph.factory()
|
|
2497
|
+
obj_.build(child_)
|
|
2498
|
+
self.glyph.append(obj_)
|
|
2499
|
+
obj_.original_tagname_ = "glyph"
|
|
2500
|
+
elif nodeName_ == "port":
|
|
2501
|
+
obj_ = port.factory()
|
|
2502
|
+
obj_.build(child_)
|
|
2503
|
+
self.port.append(obj_)
|
|
2504
|
+
obj_.original_tagname_ = "port"
|
|
2505
|
+
super(glyph, self).buildChildren(child_, node, nodeName_, True)
|
|
2506
|
+
|
|
2507
|
+
|
|
2508
|
+
# end class glyph
|
|
2509
|
+
|
|
2510
|
+
|
|
2511
|
+
class arcgroup(SBGNBase):
|
|
2512
|
+
"""The arc group describes a set of arcs and glyphs that together have
|
|
2513
|
+
a relation. For example For ER: interaction arcs around an
|
|
2514
|
+
interaction glyph, ... Note that, in spite of the name, an
|
|
2515
|
+
arcgroup contains both arcs and glyphs. The class attribute
|
|
2516
|
+
defines the semantic of the arcgroup."""
|
|
2517
|
+
|
|
2518
|
+
subclass = None
|
|
2519
|
+
superclass = SBGNBase
|
|
2520
|
+
|
|
2521
|
+
def __init__(self, notes=None, extension=None, class_=None, glyph=None, arc=None):
|
|
2522
|
+
self.original_tagname_ = None
|
|
2523
|
+
super(arcgroup, self).__init__(
|
|
2524
|
+
notes,
|
|
2525
|
+
extension,
|
|
2526
|
+
)
|
|
2527
|
+
self.class_ = _cast(None, class_)
|
|
2528
|
+
if glyph is None:
|
|
2529
|
+
self.glyph = []
|
|
2530
|
+
else:
|
|
2531
|
+
self.glyph = glyph
|
|
2532
|
+
if arc is None:
|
|
2533
|
+
self.arc = []
|
|
2534
|
+
else:
|
|
2535
|
+
self.arc = arc
|
|
2536
|
+
|
|
2537
|
+
def factory(*args_, **kwargs_):
|
|
2538
|
+
if CurrentSubclassModule_ is not None:
|
|
2539
|
+
subclass = getSubclassFromModule_(CurrentSubclassModule_, arcgroup)
|
|
2540
|
+
if subclass is not None:
|
|
2541
|
+
return subclass(*args_, **kwargs_)
|
|
2542
|
+
if arcgroup.subclass:
|
|
2543
|
+
return arcgroup.subclass(*args_, **kwargs_)
|
|
2544
|
+
else:
|
|
2545
|
+
return arcgroup(*args_, **kwargs_)
|
|
2546
|
+
|
|
2547
|
+
factory = staticmethod(factory)
|
|
2548
|
+
|
|
2549
|
+
def get_glyph(self):
|
|
2550
|
+
return self.glyph
|
|
2551
|
+
|
|
2552
|
+
def set_glyph(self, glyph):
|
|
2553
|
+
self.glyph = glyph
|
|
2554
|
+
|
|
2555
|
+
def add_glyph(self, value):
|
|
2556
|
+
self.glyph.append(value)
|
|
2557
|
+
|
|
2558
|
+
def insert_glyph_at(self, index, value):
|
|
2559
|
+
self.glyph.insert(index, value)
|
|
2560
|
+
|
|
2561
|
+
def replace_glyph_at(self, index, value):
|
|
2562
|
+
self.glyph[index] = value
|
|
2563
|
+
|
|
2564
|
+
def get_arc(self):
|
|
2565
|
+
return self.arc
|
|
2566
|
+
|
|
2567
|
+
def set_arc(self, arc):
|
|
2568
|
+
self.arc = arc
|
|
2569
|
+
|
|
2570
|
+
def add_arc(self, value):
|
|
2571
|
+
self.arc.append(value)
|
|
2572
|
+
|
|
2573
|
+
def insert_arc_at(self, index, value):
|
|
2574
|
+
self.arc.insert(index, value)
|
|
2575
|
+
|
|
2576
|
+
def replace_arc_at(self, index, value):
|
|
2577
|
+
self.arc[index] = value
|
|
2578
|
+
|
|
2579
|
+
def get_class(self):
|
|
2580
|
+
return self.class_
|
|
2581
|
+
|
|
2582
|
+
def set_class(self, class_):
|
|
2583
|
+
self.class_ = class_
|
|
2584
|
+
|
|
2585
|
+
def hasContent_(self):
|
|
2586
|
+
if self.glyph or self.arc or super(arcgroup, self).hasContent_():
|
|
2587
|
+
return True
|
|
2588
|
+
else:
|
|
2589
|
+
return False
|
|
2590
|
+
|
|
2591
|
+
def export(
|
|
2592
|
+
self,
|
|
2593
|
+
outfile,
|
|
2594
|
+
level,
|
|
2595
|
+
namespace_="sbgn:",
|
|
2596
|
+
name_="arcgroup",
|
|
2597
|
+
namespacedef_='xmlns:sbgn="http://sbgn.org/libsbgn/0.2"',
|
|
2598
|
+
pretty_print=True,
|
|
2599
|
+
):
|
|
2600
|
+
if pretty_print:
|
|
2601
|
+
eol_ = "\n"
|
|
2602
|
+
else:
|
|
2603
|
+
eol_ = ""
|
|
2604
|
+
if self.original_tagname_ is not None:
|
|
2605
|
+
name_ = self.original_tagname_
|
|
2606
|
+
showIndent(outfile, level, pretty_print)
|
|
2607
|
+
outfile.write(
|
|
2608
|
+
"<%s%s%s"
|
|
2609
|
+
% (
|
|
2610
|
+
namespace_,
|
|
2611
|
+
name_,
|
|
2612
|
+
namespacedef_ and " " + namespacedef_ or "",
|
|
2613
|
+
)
|
|
2614
|
+
)
|
|
2615
|
+
already_processed = set()
|
|
2616
|
+
self.exportAttributes(
|
|
2617
|
+
outfile, level, already_processed, namespace_, name_="arcgroup"
|
|
2618
|
+
)
|
|
2619
|
+
if self.hasContent_():
|
|
2620
|
+
outfile.write(">%s" % (eol_,))
|
|
2621
|
+
self.exportChildren(
|
|
2622
|
+
outfile,
|
|
2623
|
+
level + 1,
|
|
2624
|
+
namespace_="sbgn:",
|
|
2625
|
+
name_="arcgroup",
|
|
2626
|
+
pretty_print=pretty_print,
|
|
2627
|
+
)
|
|
2628
|
+
showIndent(outfile, level, pretty_print)
|
|
2629
|
+
outfile.write("</%s%s>%s" % (namespace_, name_, eol_))
|
|
2630
|
+
else:
|
|
2631
|
+
outfile.write("/>%s" % (eol_,))
|
|
2632
|
+
|
|
2633
|
+
def exportAttributes(
|
|
2634
|
+
self, outfile, level, already_processed, namespace_="sbgn:", name_="arcgroup"
|
|
2635
|
+
):
|
|
2636
|
+
super(arcgroup, self).exportAttributes(
|
|
2637
|
+
outfile, level, already_processed, namespace_, name_="arcgroup"
|
|
2638
|
+
)
|
|
2639
|
+
if self.class_ is not None and "class_" not in already_processed:
|
|
2640
|
+
already_processed.add("class_")
|
|
2641
|
+
outfile.write(
|
|
2642
|
+
" class=%s"
|
|
2643
|
+
% (
|
|
2644
|
+
self.gds_encode(
|
|
2645
|
+
self.gds_format_string(
|
|
2646
|
+
quote_attrib(self.class_), input_name="class"
|
|
2647
|
+
)
|
|
2648
|
+
),
|
|
2649
|
+
)
|
|
2650
|
+
)
|
|
2651
|
+
|
|
2652
|
+
def exportChildren(
|
|
2653
|
+
self,
|
|
2654
|
+
outfile,
|
|
2655
|
+
level,
|
|
2656
|
+
namespace_="sbgn:",
|
|
2657
|
+
name_="arcgroup",
|
|
2658
|
+
fromsubclass_=False,
|
|
2659
|
+
pretty_print=True,
|
|
2660
|
+
):
|
|
2661
|
+
super(arcgroup, self).exportChildren(
|
|
2662
|
+
outfile, level, namespace_, name_, True, pretty_print=pretty_print
|
|
2663
|
+
)
|
|
2664
|
+
for glyph_ in self.glyph:
|
|
2665
|
+
glyph_.export(
|
|
2666
|
+
outfile,
|
|
2667
|
+
level,
|
|
2668
|
+
namespace_="sbgn:",
|
|
2669
|
+
name_="glyph",
|
|
2670
|
+
pretty_print=pretty_print,
|
|
2671
|
+
)
|
|
2672
|
+
for arc_ in self.arc:
|
|
2673
|
+
arc_.export(
|
|
2674
|
+
outfile,
|
|
2675
|
+
level,
|
|
2676
|
+
namespace_="sbgn:",
|
|
2677
|
+
name_="arc",
|
|
2678
|
+
pretty_print=pretty_print,
|
|
2679
|
+
)
|
|
2680
|
+
|
|
2681
|
+
def build(self, node):
|
|
2682
|
+
already_processed = set()
|
|
2683
|
+
self.buildAttributes(node, node.attrib, already_processed)
|
|
2684
|
+
for child in node:
|
|
2685
|
+
nodeName_ = Tag_pattern_.match(child.tag).groups()[-1]
|
|
2686
|
+
self.buildChildren(child, node, nodeName_)
|
|
2687
|
+
return self
|
|
2688
|
+
|
|
2689
|
+
def buildAttributes(self, node, attrs, already_processed):
|
|
2690
|
+
value = find_attr_value_("class", node)
|
|
2691
|
+
if value is not None and "class" not in already_processed:
|
|
2692
|
+
already_processed.add("class")
|
|
2693
|
+
self.class_ = value
|
|
2694
|
+
super(arcgroup, self).buildAttributes(node, attrs, already_processed)
|
|
2695
|
+
|
|
2696
|
+
def buildChildren(self, child_, node, nodeName_, fromsubclass_=False):
|
|
2697
|
+
if nodeName_ == "glyph":
|
|
2698
|
+
obj_ = glyph.factory()
|
|
2699
|
+
obj_.build(child_)
|
|
2700
|
+
self.glyph.append(obj_)
|
|
2701
|
+
obj_.original_tagname_ = "glyph"
|
|
2702
|
+
elif nodeName_ == "arc":
|
|
2703
|
+
obj_ = arc.factory()
|
|
2704
|
+
obj_.build(child_)
|
|
2705
|
+
self.arc.append(obj_)
|
|
2706
|
+
obj_.original_tagname_ = "arc"
|
|
2707
|
+
super(arcgroup, self).buildChildren(child_, node, nodeName_, True)
|
|
2708
|
+
|
|
2709
|
+
|
|
2710
|
+
# end class arcgroup
|
|
2711
|
+
|
|
2712
|
+
|
|
2713
|
+
class arc(SBGNBase):
|
|
2714
|
+
"""The arc element describes an SBGN arc between two SBGN nodes. It
|
|
2715
|
+
contains: For PD: an optional stoichiometry marker, For ER: an
|
|
2716
|
+
optional cardinality marker, zero or more ports (influence
|
|
2717
|
+
targets), and zero or more outcomes, a mandatory source and
|
|
2718
|
+
target (glyph or port), a geometric description of its whole
|
|
2719
|
+
path, from start to end. This path can involve any number of
|
|
2720
|
+
straight lines or quadratic/cubic Bezier curves. The class
|
|
2721
|
+
attribute defines the semantic of the arc, and influences: the
|
|
2722
|
+
way that arc should be rendered, the overall syntactic validity
|
|
2723
|
+
of the map. The various classes encompass all possible types of
|
|
2724
|
+
SBGN arcs: production and consumption arcs, all types of
|
|
2725
|
+
modification arcs, logic arcs, equivalence arcs. To express a
|
|
2726
|
+
reversible reaction, use production arcs on both sides of the
|
|
2727
|
+
Process Node. The xsd:ID type is an alphanumeric identifier,
|
|
2728
|
+
starting with a letter. The source attribute can refer: either
|
|
2729
|
+
to the id of a glyph, or to the id of a port on a glyph. The
|
|
2730
|
+
target attribute can refer: either to the id of a glyph, or to
|
|
2731
|
+
the id of a port on a glyph."""
|
|
2732
|
+
|
|
2733
|
+
subclass = None
|
|
2734
|
+
superclass = SBGNBase
|
|
2735
|
+
|
|
2736
|
+
def __init__(
|
|
2737
|
+
self,
|
|
2738
|
+
notes=None,
|
|
2739
|
+
extension=None,
|
|
2740
|
+
class_=None,
|
|
2741
|
+
id=None,
|
|
2742
|
+
source=None,
|
|
2743
|
+
target=None,
|
|
2744
|
+
glyph=None,
|
|
2745
|
+
port=None,
|
|
2746
|
+
start=None,
|
|
2747
|
+
next=None,
|
|
2748
|
+
end=None,
|
|
2749
|
+
):
|
|
2750
|
+
self.original_tagname_ = None
|
|
2751
|
+
super(arc, self).__init__(
|
|
2752
|
+
notes,
|
|
2753
|
+
extension,
|
|
2754
|
+
)
|
|
2755
|
+
self.set_class(class_)
|
|
2756
|
+
self.id = _cast(None, id)
|
|
2757
|
+
self.source = _cast(None, source)
|
|
2758
|
+
self.target = _cast(None, target)
|
|
2759
|
+
if glyph is None:
|
|
2760
|
+
self.glyph = []
|
|
2761
|
+
else:
|
|
2762
|
+
self.glyph = glyph
|
|
2763
|
+
if port is None:
|
|
2764
|
+
self.port = []
|
|
2765
|
+
else:
|
|
2766
|
+
self.port = port
|
|
2767
|
+
self.start = start
|
|
2768
|
+
if next is None:
|
|
2769
|
+
self.next = []
|
|
2770
|
+
else:
|
|
2771
|
+
self.next = next
|
|
2772
|
+
self.end = end
|
|
2773
|
+
|
|
2774
|
+
def factory(*args_, **kwargs_):
|
|
2775
|
+
if CurrentSubclassModule_ is not None:
|
|
2776
|
+
subclass = getSubclassFromModule_(CurrentSubclassModule_, arc)
|
|
2777
|
+
if subclass is not None:
|
|
2778
|
+
return subclass(*args_, **kwargs_)
|
|
2779
|
+
if arc.subclass:
|
|
2780
|
+
return arc.subclass(*args_, **kwargs_)
|
|
2781
|
+
else:
|
|
2782
|
+
return arc(*args_, **kwargs_)
|
|
2783
|
+
|
|
2784
|
+
factory = staticmethod(factory)
|
|
2785
|
+
|
|
2786
|
+
def get_glyph(self):
|
|
2787
|
+
return self.glyph
|
|
2788
|
+
|
|
2789
|
+
def set_glyph(self, glyph):
|
|
2790
|
+
self.glyph = glyph
|
|
2791
|
+
|
|
2792
|
+
def add_glyph(self, value):
|
|
2793
|
+
self.glyph.append(value)
|
|
2794
|
+
|
|
2795
|
+
def insert_glyph_at(self, index, value):
|
|
2796
|
+
self.glyph.insert(index, value)
|
|
2797
|
+
|
|
2798
|
+
def replace_glyph_at(self, index, value):
|
|
2799
|
+
self.glyph[index] = value
|
|
2800
|
+
|
|
2801
|
+
def get_port(self):
|
|
2802
|
+
return self.port
|
|
2803
|
+
|
|
2804
|
+
def set_port(self, port):
|
|
2805
|
+
self.port = port
|
|
2806
|
+
|
|
2807
|
+
def add_port(self, value):
|
|
2808
|
+
self.port.append(value)
|
|
2809
|
+
|
|
2810
|
+
def insert_port_at(self, index, value):
|
|
2811
|
+
self.port.insert(index, value)
|
|
2812
|
+
|
|
2813
|
+
def replace_port_at(self, index, value):
|
|
2814
|
+
self.port[index] = value
|
|
2815
|
+
|
|
2816
|
+
def get_start(self):
|
|
2817
|
+
return self.start
|
|
2818
|
+
|
|
2819
|
+
def set_start(self, start):
|
|
2820
|
+
self.start = start
|
|
2821
|
+
|
|
2822
|
+
def get_next(self):
|
|
2823
|
+
return self.next
|
|
2824
|
+
|
|
2825
|
+
def set_next(self, next):
|
|
2826
|
+
self.next = next
|
|
2827
|
+
|
|
2828
|
+
def add_next(self, value):
|
|
2829
|
+
self.next.append(value)
|
|
2830
|
+
|
|
2831
|
+
def insert_next_at(self, index, value):
|
|
2832
|
+
self.next.insert(index, value)
|
|
2833
|
+
|
|
2834
|
+
def replace_next_at(self, index, value):
|
|
2835
|
+
self.next[index] = value
|
|
2836
|
+
|
|
2837
|
+
def get_end(self):
|
|
2838
|
+
return self.end
|
|
2839
|
+
|
|
2840
|
+
def set_end(self, end):
|
|
2841
|
+
self.end = end
|
|
2842
|
+
|
|
2843
|
+
def get_class(self):
|
|
2844
|
+
"""Get the ArcClass."""
|
|
2845
|
+
return ArcClass(self.class_)
|
|
2846
|
+
|
|
2847
|
+
def set_class(self, class_):
|
|
2848
|
+
"""Set the ArcClass.
|
|
2849
|
+
:param class_:
|
|
2850
|
+
:return:
|
|
2851
|
+
"""
|
|
2852
|
+
if class_ and not isinstance(class_, ArcClass):
|
|
2853
|
+
raise TypeError("class must be of type ArcClass")
|
|
2854
|
+
if class_:
|
|
2855
|
+
self.class_ = _cast(None, class_.value)
|
|
2856
|
+
else:
|
|
2857
|
+
self.class_ = _cast(None, class_)
|
|
2858
|
+
|
|
2859
|
+
def get_id(self):
|
|
2860
|
+
return self.id
|
|
2861
|
+
|
|
2862
|
+
def set_id(self, id):
|
|
2863
|
+
self.id = id
|
|
2864
|
+
|
|
2865
|
+
def get_source(self):
|
|
2866
|
+
return self.source
|
|
2867
|
+
|
|
2868
|
+
def set_source(self, source):
|
|
2869
|
+
self.source = source
|
|
2870
|
+
|
|
2871
|
+
def get_target(self):
|
|
2872
|
+
return self.target
|
|
2873
|
+
|
|
2874
|
+
def set_target(self, target):
|
|
2875
|
+
self.target = target
|
|
2876
|
+
|
|
2877
|
+
def hasContent_(self):
|
|
2878
|
+
if (
|
|
2879
|
+
self.glyph
|
|
2880
|
+
or self.port
|
|
2881
|
+
or self.start is not None
|
|
2882
|
+
or self.next
|
|
2883
|
+
or self.end is not None
|
|
2884
|
+
or super(arc, self).hasContent_()
|
|
2885
|
+
):
|
|
2886
|
+
return True
|
|
2887
|
+
else:
|
|
2888
|
+
return False
|
|
2889
|
+
|
|
2890
|
+
def export(
|
|
2891
|
+
self,
|
|
2892
|
+
outfile,
|
|
2893
|
+
level,
|
|
2894
|
+
namespace_="sbgn:",
|
|
2895
|
+
name_="arc",
|
|
2896
|
+
namespacedef_='xmlns:sbgn="http://sbgn.org/libsbgn/0.2"',
|
|
2897
|
+
pretty_print=True,
|
|
2898
|
+
):
|
|
2899
|
+
if pretty_print:
|
|
2900
|
+
eol_ = "\n"
|
|
2901
|
+
else:
|
|
2902
|
+
eol_ = ""
|
|
2903
|
+
if self.original_tagname_ is not None:
|
|
2904
|
+
name_ = self.original_tagname_
|
|
2905
|
+
showIndent(outfile, level, pretty_print)
|
|
2906
|
+
outfile.write(
|
|
2907
|
+
"<%s%s%s"
|
|
2908
|
+
% (
|
|
2909
|
+
namespace_,
|
|
2910
|
+
name_,
|
|
2911
|
+
namespacedef_ and " " + namespacedef_ or "",
|
|
2912
|
+
)
|
|
2913
|
+
)
|
|
2914
|
+
already_processed = set()
|
|
2915
|
+
self.exportAttributes(
|
|
2916
|
+
outfile, level, already_processed, namespace_, name_="arc"
|
|
2917
|
+
)
|
|
2918
|
+
if self.hasContent_():
|
|
2919
|
+
outfile.write(">%s" % (eol_,))
|
|
2920
|
+
self.exportChildren(
|
|
2921
|
+
outfile,
|
|
2922
|
+
level + 1,
|
|
2923
|
+
namespace_="sbgn:",
|
|
2924
|
+
name_="arc",
|
|
2925
|
+
pretty_print=pretty_print,
|
|
2926
|
+
)
|
|
2927
|
+
showIndent(outfile, level, pretty_print)
|
|
2928
|
+
outfile.write("</%s%s>%s" % (namespace_, name_, eol_))
|
|
2929
|
+
else:
|
|
2930
|
+
outfile.write("/>%s" % (eol_,))
|
|
2931
|
+
|
|
2932
|
+
def exportAttributes(
|
|
2933
|
+
self, outfile, level, already_processed, namespace_="sbgn:", name_="arc"
|
|
2934
|
+
):
|
|
2935
|
+
super(arc, self).exportAttributes(
|
|
2936
|
+
outfile, level, already_processed, namespace_, name_="arc"
|
|
2937
|
+
)
|
|
2938
|
+
if self.class_ is not None and "class_" not in already_processed:
|
|
2939
|
+
already_processed.add("class_")
|
|
2940
|
+
outfile.write(
|
|
2941
|
+
" class=%s"
|
|
2942
|
+
% (
|
|
2943
|
+
self.gds_encode(
|
|
2944
|
+
self.gds_format_string(
|
|
2945
|
+
quote_attrib(self.class_), input_name="class"
|
|
2946
|
+
)
|
|
2947
|
+
),
|
|
2948
|
+
)
|
|
2949
|
+
)
|
|
2950
|
+
if self.id is not None and "id" not in already_processed:
|
|
2951
|
+
already_processed.add("id")
|
|
2952
|
+
outfile.write(
|
|
2953
|
+
" id=%s"
|
|
2954
|
+
% (
|
|
2955
|
+
self.gds_encode(
|
|
2956
|
+
self.gds_format_string(quote_attrib(self.id), input_name="id")
|
|
2957
|
+
),
|
|
2958
|
+
)
|
|
2959
|
+
)
|
|
2960
|
+
if self.source is not None and "source" not in already_processed:
|
|
2961
|
+
already_processed.add("source")
|
|
2962
|
+
outfile.write(
|
|
2963
|
+
" source=%s"
|
|
2964
|
+
% (
|
|
2965
|
+
self.gds_encode(
|
|
2966
|
+
self.gds_format_string(
|
|
2967
|
+
quote_attrib(self.source), input_name="source"
|
|
2968
|
+
)
|
|
2969
|
+
),
|
|
2970
|
+
)
|
|
2971
|
+
)
|
|
2972
|
+
if self.target is not None and "target" not in already_processed:
|
|
2973
|
+
already_processed.add("target")
|
|
2974
|
+
outfile.write(
|
|
2975
|
+
" target=%s"
|
|
2976
|
+
% (
|
|
2977
|
+
self.gds_encode(
|
|
2978
|
+
self.gds_format_string(
|
|
2979
|
+
quote_attrib(self.target), input_name="target"
|
|
2980
|
+
)
|
|
2981
|
+
),
|
|
2982
|
+
)
|
|
2983
|
+
)
|
|
2984
|
+
|
|
2985
|
+
def exportChildren(
|
|
2986
|
+
self,
|
|
2987
|
+
outfile,
|
|
2988
|
+
level,
|
|
2989
|
+
namespace_="sbgn:",
|
|
2990
|
+
name_="arc",
|
|
2991
|
+
fromsubclass_=False,
|
|
2992
|
+
pretty_print=True,
|
|
2993
|
+
):
|
|
2994
|
+
super(arc, self).exportChildren(
|
|
2995
|
+
outfile, level, namespace_, name_, True, pretty_print=pretty_print
|
|
2996
|
+
)
|
|
2997
|
+
for glyph_ in self.glyph:
|
|
2998
|
+
glyph_.export(
|
|
2999
|
+
outfile,
|
|
3000
|
+
level,
|
|
3001
|
+
namespace_="sbgn:",
|
|
3002
|
+
name_="glyph",
|
|
3003
|
+
pretty_print=pretty_print,
|
|
3004
|
+
)
|
|
3005
|
+
for port_ in self.port:
|
|
3006
|
+
port_.export(
|
|
3007
|
+
outfile,
|
|
3008
|
+
level,
|
|
3009
|
+
namespace_="sbgn:",
|
|
3010
|
+
name_="port",
|
|
3011
|
+
pretty_print=pretty_print,
|
|
3012
|
+
)
|
|
3013
|
+
if self.start is not None:
|
|
3014
|
+
self.start.export(
|
|
3015
|
+
outfile, level, namespace_, name_="start", pretty_print=pretty_print
|
|
3016
|
+
)
|
|
3017
|
+
for next_ in self.next:
|
|
3018
|
+
next_.export(
|
|
3019
|
+
outfile, level, namespace_, name_="next", pretty_print=pretty_print
|
|
3020
|
+
)
|
|
3021
|
+
if self.end is not None:
|
|
3022
|
+
self.end.export(
|
|
3023
|
+
outfile, level, namespace_, name_="end", pretty_print=pretty_print
|
|
3024
|
+
)
|
|
3025
|
+
|
|
3026
|
+
def build(self, node):
|
|
3027
|
+
already_processed = set()
|
|
3028
|
+
self.buildAttributes(node, node.attrib, already_processed)
|
|
3029
|
+
for child in node:
|
|
3030
|
+
nodeName_ = Tag_pattern_.match(child.tag).groups()[-1]
|
|
3031
|
+
self.buildChildren(child, node, nodeName_)
|
|
3032
|
+
return self
|
|
3033
|
+
|
|
3034
|
+
def buildAttributes(self, node, attrs, already_processed):
|
|
3035
|
+
value = find_attr_value_("class", node)
|
|
3036
|
+
if value is not None and "class" not in already_processed:
|
|
3037
|
+
already_processed.add("class")
|
|
3038
|
+
self.class_ = value
|
|
3039
|
+
value = find_attr_value_("id", node)
|
|
3040
|
+
if value is not None and "id" not in already_processed:
|
|
3041
|
+
already_processed.add("id")
|
|
3042
|
+
self.id = value
|
|
3043
|
+
value = find_attr_value_("source", node)
|
|
3044
|
+
if value is not None and "source" not in already_processed:
|
|
3045
|
+
already_processed.add("source")
|
|
3046
|
+
self.source = value
|
|
3047
|
+
value = find_attr_value_("target", node)
|
|
3048
|
+
if value is not None and "target" not in already_processed:
|
|
3049
|
+
already_processed.add("target")
|
|
3050
|
+
self.target = value
|
|
3051
|
+
super(arc, self).buildAttributes(node, attrs, already_processed)
|
|
3052
|
+
|
|
3053
|
+
def buildChildren(self, child_, node, nodeName_, fromsubclass_=False):
|
|
3054
|
+
if nodeName_ == "glyph":
|
|
3055
|
+
obj_ = glyph.factory()
|
|
3056
|
+
obj_.build(child_)
|
|
3057
|
+
self.glyph.append(obj_)
|
|
3058
|
+
obj_.original_tagname_ = "glyph"
|
|
3059
|
+
elif nodeName_ == "port":
|
|
3060
|
+
obj_ = port.factory()
|
|
3061
|
+
obj_.build(child_)
|
|
3062
|
+
self.port.append(obj_)
|
|
3063
|
+
obj_.original_tagname_ = "port"
|
|
3064
|
+
elif nodeName_ == "start":
|
|
3065
|
+
obj_ = startType.factory()
|
|
3066
|
+
obj_.build(child_)
|
|
3067
|
+
self.start = obj_
|
|
3068
|
+
obj_.original_tagname_ = "start"
|
|
3069
|
+
elif nodeName_ == "next":
|
|
3070
|
+
obj_ = nextType.factory()
|
|
3071
|
+
obj_.build(child_)
|
|
3072
|
+
self.next.append(obj_)
|
|
3073
|
+
obj_.original_tagname_ = "next"
|
|
3074
|
+
elif nodeName_ == "end":
|
|
3075
|
+
obj_ = endType.factory()
|
|
3076
|
+
obj_.build(child_)
|
|
3077
|
+
self.end = obj_
|
|
3078
|
+
obj_.original_tagname_ = "end"
|
|
3079
|
+
super(arc, self).buildChildren(child_, node, nodeName_, True)
|
|
3080
|
+
|
|
3081
|
+
|
|
3082
|
+
# end class arc
|
|
3083
|
+
|
|
3084
|
+
|
|
3085
|
+
class notesType(GeneratedsSuper):
|
|
3086
|
+
subclass = None
|
|
3087
|
+
superclass = None
|
|
3088
|
+
|
|
3089
|
+
def __init__(self, anytypeobjs_=None):
|
|
3090
|
+
self.original_tagname_ = None
|
|
3091
|
+
if anytypeobjs_ is None:
|
|
3092
|
+
self.anytypeobjs_ = []
|
|
3093
|
+
else:
|
|
3094
|
+
self.anytypeobjs_ = anytypeobjs_
|
|
3095
|
+
|
|
3096
|
+
def factory(*args_, **kwargs_):
|
|
3097
|
+
if CurrentSubclassModule_ is not None:
|
|
3098
|
+
subclass = getSubclassFromModule_(CurrentSubclassModule_, notesType)
|
|
3099
|
+
if subclass is not None:
|
|
3100
|
+
return subclass(*args_, **kwargs_)
|
|
3101
|
+
if notesType.subclass:
|
|
3102
|
+
return notesType.subclass(*args_, **kwargs_)
|
|
3103
|
+
else:
|
|
3104
|
+
return notesType(*args_, **kwargs_)
|
|
3105
|
+
|
|
3106
|
+
factory = staticmethod(factory)
|
|
3107
|
+
|
|
3108
|
+
def get_anytypeobjs_(self):
|
|
3109
|
+
return self.anytypeobjs_
|
|
3110
|
+
|
|
3111
|
+
def set_anytypeobjs_(self, anytypeobjs_):
|
|
3112
|
+
self.anytypeobjs_ = anytypeobjs_
|
|
3113
|
+
|
|
3114
|
+
def add_anytypeobjs_(self, value):
|
|
3115
|
+
self.anytypeobjs_.append(value)
|
|
3116
|
+
|
|
3117
|
+
def insert_anytypeobjs_(self, index, value):
|
|
3118
|
+
self._anytypeobjs_[index] = value
|
|
3119
|
+
|
|
3120
|
+
def hasContent_(self):
|
|
3121
|
+
if self.anytypeobjs_:
|
|
3122
|
+
return True
|
|
3123
|
+
else:
|
|
3124
|
+
return False
|
|
3125
|
+
|
|
3126
|
+
def export(
|
|
3127
|
+
self,
|
|
3128
|
+
outfile,
|
|
3129
|
+
level,
|
|
3130
|
+
namespace_="sbgn:",
|
|
3131
|
+
name_="notesType",
|
|
3132
|
+
namespacedef_='xmlns:sbgn="http://sbgn.org/libsbgn/0.2"',
|
|
3133
|
+
pretty_print=True,
|
|
3134
|
+
):
|
|
3135
|
+
if pretty_print:
|
|
3136
|
+
eol_ = "\n"
|
|
3137
|
+
else:
|
|
3138
|
+
eol_ = ""
|
|
3139
|
+
if self.original_tagname_ is not None:
|
|
3140
|
+
name_ = self.original_tagname_
|
|
3141
|
+
showIndent(outfile, level, pretty_print)
|
|
3142
|
+
outfile.write(
|
|
3143
|
+
"<%s%s%s"
|
|
3144
|
+
% (
|
|
3145
|
+
namespace_,
|
|
3146
|
+
name_,
|
|
3147
|
+
namespacedef_ and " " + namespacedef_ or "",
|
|
3148
|
+
)
|
|
3149
|
+
)
|
|
3150
|
+
already_processed = set()
|
|
3151
|
+
self.exportAttributes(
|
|
3152
|
+
outfile, level, already_processed, namespace_, name_="notesType"
|
|
3153
|
+
)
|
|
3154
|
+
if self.hasContent_():
|
|
3155
|
+
outfile.write(">%s" % (eol_,))
|
|
3156
|
+
self.exportChildren(
|
|
3157
|
+
outfile,
|
|
3158
|
+
level + 1,
|
|
3159
|
+
namespace_="sbgn:",
|
|
3160
|
+
name_="notesType",
|
|
3161
|
+
pretty_print=pretty_print,
|
|
3162
|
+
)
|
|
3163
|
+
showIndent(outfile, level, pretty_print)
|
|
3164
|
+
outfile.write("</%s%s>%s" % (namespace_, name_, eol_))
|
|
3165
|
+
else:
|
|
3166
|
+
outfile.write("/>%s" % (eol_,))
|
|
3167
|
+
|
|
3168
|
+
def exportAttributes(
|
|
3169
|
+
self, outfile, level, already_processed, namespace_="sbgn:", name_="notesType"
|
|
3170
|
+
):
|
|
3171
|
+
pass
|
|
3172
|
+
|
|
3173
|
+
def exportChildren(
|
|
3174
|
+
self,
|
|
3175
|
+
outfile,
|
|
3176
|
+
level,
|
|
3177
|
+
namespace_="sbgn:",
|
|
3178
|
+
name_="notesType",
|
|
3179
|
+
fromsubclass_=False,
|
|
3180
|
+
pretty_print=True,
|
|
3181
|
+
):
|
|
3182
|
+
for obj_ in self.anytypeobjs_:
|
|
3183
|
+
obj_.export(outfile, level, namespace_, pretty_print=pretty_print)
|
|
3184
|
+
|
|
3185
|
+
def build(self, node):
|
|
3186
|
+
already_processed = set()
|
|
3187
|
+
self.buildAttributes(node, node.attrib, already_processed)
|
|
3188
|
+
for child in node:
|
|
3189
|
+
nodeName_ = Tag_pattern_.match(child.tag).groups()[-1]
|
|
3190
|
+
self.buildChildren(child, node, nodeName_)
|
|
3191
|
+
return self
|
|
3192
|
+
|
|
3193
|
+
def buildAttributes(self, node, attrs, already_processed):
|
|
3194
|
+
pass
|
|
3195
|
+
|
|
3196
|
+
def buildChildren(self, child_, node, nodeName_, fromsubclass_=False):
|
|
3197
|
+
obj_ = self.gds_build_any(child_, "notesType")
|
|
3198
|
+
if obj_ is not None:
|
|
3199
|
+
self.add_anytypeobjs_(obj_)
|
|
3200
|
+
|
|
3201
|
+
|
|
3202
|
+
# end class notesType
|
|
3203
|
+
|
|
3204
|
+
|
|
3205
|
+
class extensionType(GeneratedsSuper):
|
|
3206
|
+
subclass = None
|
|
3207
|
+
superclass = None
|
|
3208
|
+
|
|
3209
|
+
def __init__(self, anytypeobjs_=None):
|
|
3210
|
+
self.original_tagname_ = None
|
|
3211
|
+
if anytypeobjs_ is None:
|
|
3212
|
+
self.anytypeobjs_ = []
|
|
3213
|
+
else:
|
|
3214
|
+
self.anytypeobjs_ = anytypeobjs_
|
|
3215
|
+
|
|
3216
|
+
def factory(*args_, **kwargs_):
|
|
3217
|
+
if CurrentSubclassModule_ is not None:
|
|
3218
|
+
subclass = getSubclassFromModule_(CurrentSubclassModule_, extensionType)
|
|
3219
|
+
if subclass is not None:
|
|
3220
|
+
return subclass(*args_, **kwargs_)
|
|
3221
|
+
if extensionType.subclass:
|
|
3222
|
+
return extensionType.subclass(*args_, **kwargs_)
|
|
3223
|
+
else:
|
|
3224
|
+
return extensionType(*args_, **kwargs_)
|
|
3225
|
+
|
|
3226
|
+
factory = staticmethod(factory)
|
|
3227
|
+
|
|
3228
|
+
def get_anytypeobjs_(self):
|
|
3229
|
+
return self.anytypeobjs_
|
|
3230
|
+
|
|
3231
|
+
def set_anytypeobjs_(self, anytypeobjs_):
|
|
3232
|
+
self.anytypeobjs_ = anytypeobjs_
|
|
3233
|
+
|
|
3234
|
+
def add_anytypeobjs_(self, value):
|
|
3235
|
+
self.anytypeobjs_.append(value)
|
|
3236
|
+
|
|
3237
|
+
def insert_anytypeobjs_(self, index, value):
|
|
3238
|
+
self._anytypeobjs_[index] = value
|
|
3239
|
+
|
|
3240
|
+
def hasContent_(self):
|
|
3241
|
+
if self.anytypeobjs_:
|
|
3242
|
+
return True
|
|
3243
|
+
else:
|
|
3244
|
+
return False
|
|
3245
|
+
|
|
3246
|
+
def export(
|
|
3247
|
+
self,
|
|
3248
|
+
outfile,
|
|
3249
|
+
level,
|
|
3250
|
+
namespace_="sbgn:",
|
|
3251
|
+
name_="extensionType",
|
|
3252
|
+
namespacedef_='xmlns:sbgn="http://sbgn.org/libsbgn/0.2"',
|
|
3253
|
+
pretty_print=True,
|
|
3254
|
+
):
|
|
3255
|
+
if pretty_print:
|
|
3256
|
+
eol_ = "\n"
|
|
3257
|
+
else:
|
|
3258
|
+
eol_ = ""
|
|
3259
|
+
if self.original_tagname_ is not None:
|
|
3260
|
+
name_ = self.original_tagname_
|
|
3261
|
+
showIndent(outfile, level, pretty_print)
|
|
3262
|
+
outfile.write(
|
|
3263
|
+
"<%s%s%s"
|
|
3264
|
+
% (
|
|
3265
|
+
namespace_,
|
|
3266
|
+
name_,
|
|
3267
|
+
namespacedef_ and " " + namespacedef_ or "",
|
|
3268
|
+
)
|
|
3269
|
+
)
|
|
3270
|
+
already_processed = set()
|
|
3271
|
+
self.exportAttributes(
|
|
3272
|
+
outfile, level, already_processed, namespace_, name_="extensionType"
|
|
3273
|
+
)
|
|
3274
|
+
if self.hasContent_():
|
|
3275
|
+
outfile.write(">%s" % (eol_,))
|
|
3276
|
+
self.exportChildren(
|
|
3277
|
+
outfile,
|
|
3278
|
+
level + 1,
|
|
3279
|
+
namespace_="sbgn:",
|
|
3280
|
+
name_="extensionType",
|
|
3281
|
+
pretty_print=pretty_print,
|
|
3282
|
+
)
|
|
3283
|
+
showIndent(outfile, level, pretty_print)
|
|
3284
|
+
outfile.write("</%s%s>%s" % (namespace_, name_, eol_))
|
|
3285
|
+
else:
|
|
3286
|
+
outfile.write("/>%s" % (eol_,))
|
|
3287
|
+
|
|
3288
|
+
def exportAttributes(
|
|
3289
|
+
self,
|
|
3290
|
+
outfile,
|
|
3291
|
+
level,
|
|
3292
|
+
already_processed,
|
|
3293
|
+
namespace_="sbgn:",
|
|
3294
|
+
name_="extensionType",
|
|
3295
|
+
):
|
|
3296
|
+
pass
|
|
3297
|
+
|
|
3298
|
+
def exportChildren(
|
|
3299
|
+
self,
|
|
3300
|
+
outfile,
|
|
3301
|
+
level,
|
|
3302
|
+
namespace_="sbgn:",
|
|
3303
|
+
name_="extensionType",
|
|
3304
|
+
fromsubclass_=False,
|
|
3305
|
+
pretty_print=True,
|
|
3306
|
+
):
|
|
3307
|
+
for obj_ in self.anytypeobjs_:
|
|
3308
|
+
obj_.export(outfile, level, namespace_, pretty_print=pretty_print)
|
|
3309
|
+
|
|
3310
|
+
def build(self, node):
|
|
3311
|
+
already_processed = set()
|
|
3312
|
+
self.buildAttributes(node, node.attrib, already_processed)
|
|
3313
|
+
for child in node:
|
|
3314
|
+
nodeName_ = Tag_pattern_.match(child.tag).groups()[-1]
|
|
3315
|
+
self.buildChildren(child, node, nodeName_)
|
|
3316
|
+
return self
|
|
3317
|
+
|
|
3318
|
+
def buildAttributes(self, node, attrs, already_processed):
|
|
3319
|
+
pass
|
|
3320
|
+
|
|
3321
|
+
def buildChildren(self, child_, node, nodeName_, fromsubclass_=False):
|
|
3322
|
+
obj_ = self.gds_build_any(child_, "extensionType")
|
|
3323
|
+
if obj_ is not None:
|
|
3324
|
+
self.add_anytypeobjs_(obj_)
|
|
3325
|
+
|
|
3326
|
+
|
|
3327
|
+
# end class extensionType
|
|
3328
|
+
|
|
3329
|
+
|
|
3330
|
+
class stateType(GeneratedsSuper):
|
|
3331
|
+
"""The value attribute represents the state of the variable. It can be:
|
|
3332
|
+
either from a predefined set of string (P, S, etc.) which
|
|
3333
|
+
correspond to specific SBO terms (cf. SBGN specs), or any
|
|
3334
|
+
arbitrary string. The variable attribute describes the site
|
|
3335
|
+
where the modification described by the value attribute occurs.
|
|
3336
|
+
It is: optional when there is only one state variable on the
|
|
3337
|
+
parent EPN, required when there is more than one state variable
|
|
3338
|
+
the parent EPN."""
|
|
3339
|
+
|
|
3340
|
+
subclass = None
|
|
3341
|
+
superclass = None
|
|
3342
|
+
|
|
3343
|
+
def __init__(self, value=None, variable=None):
|
|
3344
|
+
self.original_tagname_ = None
|
|
3345
|
+
self.value = _cast(None, value)
|
|
3346
|
+
self.variable = _cast(None, variable)
|
|
3347
|
+
|
|
3348
|
+
def factory(*args_, **kwargs_):
|
|
3349
|
+
if CurrentSubclassModule_ is not None:
|
|
3350
|
+
subclass = getSubclassFromModule_(CurrentSubclassModule_, stateType)
|
|
3351
|
+
if subclass is not None:
|
|
3352
|
+
return subclass(*args_, **kwargs_)
|
|
3353
|
+
if stateType.subclass:
|
|
3354
|
+
return stateType.subclass(*args_, **kwargs_)
|
|
3355
|
+
else:
|
|
3356
|
+
return stateType(*args_, **kwargs_)
|
|
3357
|
+
|
|
3358
|
+
factory = staticmethod(factory)
|
|
3359
|
+
|
|
3360
|
+
def get_value(self):
|
|
3361
|
+
return self.value
|
|
3362
|
+
|
|
3363
|
+
def set_value(self, value):
|
|
3364
|
+
self.value = value
|
|
3365
|
+
|
|
3366
|
+
def get_variable(self):
|
|
3367
|
+
return self.variable
|
|
3368
|
+
|
|
3369
|
+
def set_variable(self, variable):
|
|
3370
|
+
self.variable = variable
|
|
3371
|
+
|
|
3372
|
+
def hasContent_(self):
|
|
3373
|
+
if ():
|
|
3374
|
+
return True
|
|
3375
|
+
else:
|
|
3376
|
+
return False
|
|
3377
|
+
|
|
3378
|
+
def export(
|
|
3379
|
+
self,
|
|
3380
|
+
outfile,
|
|
3381
|
+
level,
|
|
3382
|
+
namespace_="sbgn:",
|
|
3383
|
+
name_="stateType",
|
|
3384
|
+
namespacedef_='xmlns:sbgn="http://sbgn.org/libsbgn/0.2"',
|
|
3385
|
+
pretty_print=True,
|
|
3386
|
+
):
|
|
3387
|
+
if pretty_print:
|
|
3388
|
+
eol_ = "\n"
|
|
3389
|
+
else:
|
|
3390
|
+
eol_ = ""
|
|
3391
|
+
if self.original_tagname_ is not None:
|
|
3392
|
+
name_ = self.original_tagname_
|
|
3393
|
+
showIndent(outfile, level, pretty_print)
|
|
3394
|
+
outfile.write(
|
|
3395
|
+
"<%s%s%s"
|
|
3396
|
+
% (
|
|
3397
|
+
namespace_,
|
|
3398
|
+
name_,
|
|
3399
|
+
namespacedef_ and " " + namespacedef_ or "",
|
|
3400
|
+
)
|
|
3401
|
+
)
|
|
3402
|
+
already_processed = set()
|
|
3403
|
+
self.exportAttributes(
|
|
3404
|
+
outfile, level, already_processed, namespace_, name_="stateType"
|
|
3405
|
+
)
|
|
3406
|
+
if self.hasContent_():
|
|
3407
|
+
outfile.write(">%s" % (eol_,))
|
|
3408
|
+
self.exportChildren(
|
|
3409
|
+
outfile,
|
|
3410
|
+
level + 1,
|
|
3411
|
+
namespace_="sbgn:",
|
|
3412
|
+
name_="stateType",
|
|
3413
|
+
pretty_print=pretty_print,
|
|
3414
|
+
)
|
|
3415
|
+
outfile.write("</%s%s>%s" % (namespace_, name_, eol_))
|
|
3416
|
+
else:
|
|
3417
|
+
outfile.write("/>%s" % (eol_,))
|
|
3418
|
+
|
|
3419
|
+
def exportAttributes(
|
|
3420
|
+
self, outfile, level, already_processed, namespace_="sbgn:", name_="stateType"
|
|
3421
|
+
):
|
|
3422
|
+
if self.value is not None and "value" not in already_processed:
|
|
3423
|
+
already_processed.add("value")
|
|
3424
|
+
outfile.write(
|
|
3425
|
+
" value=%s"
|
|
3426
|
+
% (
|
|
3427
|
+
self.gds_encode(
|
|
3428
|
+
self.gds_format_string(
|
|
3429
|
+
quote_attrib(self.value), input_name="value"
|
|
3430
|
+
)
|
|
3431
|
+
),
|
|
3432
|
+
)
|
|
3433
|
+
)
|
|
3434
|
+
if self.variable is not None and "variable" not in already_processed:
|
|
3435
|
+
already_processed.add("variable")
|
|
3436
|
+
outfile.write(
|
|
3437
|
+
" variable=%s"
|
|
3438
|
+
% (
|
|
3439
|
+
self.gds_encode(
|
|
3440
|
+
self.gds_format_string(
|
|
3441
|
+
quote_attrib(self.variable), input_name="variable"
|
|
3442
|
+
)
|
|
3443
|
+
),
|
|
3444
|
+
)
|
|
3445
|
+
)
|
|
3446
|
+
|
|
3447
|
+
def exportChildren(
|
|
3448
|
+
self,
|
|
3449
|
+
outfile,
|
|
3450
|
+
level,
|
|
3451
|
+
namespace_="sbgn:",
|
|
3452
|
+
name_="stateType",
|
|
3453
|
+
fromsubclass_=False,
|
|
3454
|
+
pretty_print=True,
|
|
3455
|
+
):
|
|
3456
|
+
pass
|
|
3457
|
+
|
|
3458
|
+
def build(self, node):
|
|
3459
|
+
already_processed = set()
|
|
3460
|
+
self.buildAttributes(node, node.attrib, already_processed)
|
|
3461
|
+
for child in node:
|
|
3462
|
+
nodeName_ = Tag_pattern_.match(child.tag).groups()[-1]
|
|
3463
|
+
self.buildChildren(child, node, nodeName_)
|
|
3464
|
+
return self
|
|
3465
|
+
|
|
3466
|
+
def buildAttributes(self, node, attrs, already_processed):
|
|
3467
|
+
value = find_attr_value_("value", node)
|
|
3468
|
+
if value is not None and "value" not in already_processed:
|
|
3469
|
+
already_processed.add("value")
|
|
3470
|
+
self.value = value
|
|
3471
|
+
value = find_attr_value_("variable", node)
|
|
3472
|
+
if value is not None and "variable" not in already_processed:
|
|
3473
|
+
already_processed.add("variable")
|
|
3474
|
+
self.variable = value
|
|
3475
|
+
|
|
3476
|
+
def buildChildren(self, child_, node, nodeName_, fromsubclass_=False):
|
|
3477
|
+
pass
|
|
3478
|
+
|
|
3479
|
+
|
|
3480
|
+
# end class stateType
|
|
3481
|
+
|
|
3482
|
+
|
|
3483
|
+
class cloneType(GeneratedsSuper):
|
|
3484
|
+
subclass = None
|
|
3485
|
+
superclass = None
|
|
3486
|
+
|
|
3487
|
+
def __init__(self, label=None):
|
|
3488
|
+
self.original_tagname_ = None
|
|
3489
|
+
self.label = label
|
|
3490
|
+
|
|
3491
|
+
def factory(*args_, **kwargs_):
|
|
3492
|
+
if CurrentSubclassModule_ is not None:
|
|
3493
|
+
subclass = getSubclassFromModule_(CurrentSubclassModule_, cloneType)
|
|
3494
|
+
if subclass is not None:
|
|
3495
|
+
return subclass(*args_, **kwargs_)
|
|
3496
|
+
if cloneType.subclass:
|
|
3497
|
+
return cloneType.subclass(*args_, **kwargs_)
|
|
3498
|
+
else:
|
|
3499
|
+
return cloneType(*args_, **kwargs_)
|
|
3500
|
+
|
|
3501
|
+
factory = staticmethod(factory)
|
|
3502
|
+
|
|
3503
|
+
def get_label(self):
|
|
3504
|
+
return self.label
|
|
3505
|
+
|
|
3506
|
+
def set_label(self, label):
|
|
3507
|
+
self.label = label
|
|
3508
|
+
|
|
3509
|
+
def hasContent_(self):
|
|
3510
|
+
if self.label is not None:
|
|
3511
|
+
return True
|
|
3512
|
+
else:
|
|
3513
|
+
return False
|
|
3514
|
+
|
|
3515
|
+
def export(
|
|
3516
|
+
self,
|
|
3517
|
+
outfile,
|
|
3518
|
+
level,
|
|
3519
|
+
namespace_="sbgn:",
|
|
3520
|
+
name_="cloneType",
|
|
3521
|
+
namespacedef_='xmlns:sbgn="http://sbgn.org/libsbgn/0.2"',
|
|
3522
|
+
pretty_print=True,
|
|
3523
|
+
):
|
|
3524
|
+
if pretty_print:
|
|
3525
|
+
eol_ = "\n"
|
|
3526
|
+
else:
|
|
3527
|
+
eol_ = ""
|
|
3528
|
+
if self.original_tagname_ is not None:
|
|
3529
|
+
name_ = self.original_tagname_
|
|
3530
|
+
showIndent(outfile, level, pretty_print)
|
|
3531
|
+
outfile.write(
|
|
3532
|
+
"<%s%s%s"
|
|
3533
|
+
% (
|
|
3534
|
+
namespace_,
|
|
3535
|
+
name_,
|
|
3536
|
+
namespacedef_ and " " + namespacedef_ or "",
|
|
3537
|
+
)
|
|
3538
|
+
)
|
|
3539
|
+
already_processed = set()
|
|
3540
|
+
self.exportAttributes(
|
|
3541
|
+
outfile, level, already_processed, namespace_, name_="cloneType"
|
|
3542
|
+
)
|
|
3543
|
+
if self.hasContent_():
|
|
3544
|
+
outfile.write(">%s" % (eol_,))
|
|
3545
|
+
self.exportChildren(
|
|
3546
|
+
outfile,
|
|
3547
|
+
level + 1,
|
|
3548
|
+
namespace_="sbgn:",
|
|
3549
|
+
name_="cloneType",
|
|
3550
|
+
pretty_print=pretty_print,
|
|
3551
|
+
)
|
|
3552
|
+
showIndent(outfile, level, pretty_print)
|
|
3553
|
+
outfile.write("</%s%s>%s" % (namespace_, name_, eol_))
|
|
3554
|
+
else:
|
|
3555
|
+
outfile.write("/>%s" % (eol_,))
|
|
3556
|
+
|
|
3557
|
+
def exportAttributes(
|
|
3558
|
+
self, outfile, level, already_processed, namespace_="sbgn:", name_="cloneType"
|
|
3559
|
+
):
|
|
3560
|
+
pass
|
|
3561
|
+
|
|
3562
|
+
def exportChildren(
|
|
3563
|
+
self,
|
|
3564
|
+
outfile,
|
|
3565
|
+
level,
|
|
3566
|
+
namespace_="sbgn:",
|
|
3567
|
+
name_="cloneType",
|
|
3568
|
+
fromsubclass_=False,
|
|
3569
|
+
pretty_print=True,
|
|
3570
|
+
):
|
|
3571
|
+
if self.label is not None:
|
|
3572
|
+
self.label.export(
|
|
3573
|
+
outfile,
|
|
3574
|
+
level,
|
|
3575
|
+
namespace_="sbgn:",
|
|
3576
|
+
name_="label",
|
|
3577
|
+
pretty_print=pretty_print,
|
|
3578
|
+
)
|
|
3579
|
+
|
|
3580
|
+
def build(self, node):
|
|
3581
|
+
already_processed = set()
|
|
3582
|
+
self.buildAttributes(node, node.attrib, already_processed)
|
|
3583
|
+
for child in node:
|
|
3584
|
+
nodeName_ = Tag_pattern_.match(child.tag).groups()[-1]
|
|
3585
|
+
self.buildChildren(child, node, nodeName_)
|
|
3586
|
+
return self
|
|
3587
|
+
|
|
3588
|
+
def buildAttributes(self, node, attrs, already_processed):
|
|
3589
|
+
pass
|
|
3590
|
+
|
|
3591
|
+
def buildChildren(self, child_, node, nodeName_, fromsubclass_=False):
|
|
3592
|
+
if nodeName_ == "label":
|
|
3593
|
+
obj_ = label.factory()
|
|
3594
|
+
obj_.build(child_)
|
|
3595
|
+
self.label = obj_
|
|
3596
|
+
obj_.original_tagname_ = "label"
|
|
3597
|
+
|
|
3598
|
+
|
|
3599
|
+
# end class cloneType
|
|
3600
|
+
|
|
3601
|
+
|
|
3602
|
+
class calloutType(GeneratedsSuper):
|
|
3603
|
+
subclass = None
|
|
3604
|
+
superclass = None
|
|
3605
|
+
|
|
3606
|
+
def __init__(self, target=None, point=None):
|
|
3607
|
+
self.original_tagname_ = None
|
|
3608
|
+
self.target = _cast(None, target)
|
|
3609
|
+
self.point = point
|
|
3610
|
+
|
|
3611
|
+
def factory(*args_, **kwargs_):
|
|
3612
|
+
if CurrentSubclassModule_ is not None:
|
|
3613
|
+
subclass = getSubclassFromModule_(CurrentSubclassModule_, calloutType)
|
|
3614
|
+
if subclass is not None:
|
|
3615
|
+
return subclass(*args_, **kwargs_)
|
|
3616
|
+
if calloutType.subclass:
|
|
3617
|
+
return calloutType.subclass(*args_, **kwargs_)
|
|
3618
|
+
else:
|
|
3619
|
+
return calloutType(*args_, **kwargs_)
|
|
3620
|
+
|
|
3621
|
+
factory = staticmethod(factory)
|
|
3622
|
+
|
|
3623
|
+
def get_point(self):
|
|
3624
|
+
return self.point
|
|
3625
|
+
|
|
3626
|
+
def set_point(self, point):
|
|
3627
|
+
self.point = point
|
|
3628
|
+
|
|
3629
|
+
def get_target(self):
|
|
3630
|
+
return self.target
|
|
3631
|
+
|
|
3632
|
+
def set_target(self, target):
|
|
3633
|
+
if isinstance(target, glyph):
|
|
3634
|
+
self.target = target.get_id()
|
|
3635
|
+
else:
|
|
3636
|
+
self.target = target
|
|
3637
|
+
|
|
3638
|
+
def hasContent_(self):
|
|
3639
|
+
if self.point is not None:
|
|
3640
|
+
return True
|
|
3641
|
+
else:
|
|
3642
|
+
return False
|
|
3643
|
+
|
|
3644
|
+
def export(
|
|
3645
|
+
self,
|
|
3646
|
+
outfile,
|
|
3647
|
+
level,
|
|
3648
|
+
namespace_="sbgn:",
|
|
3649
|
+
name_="calloutType",
|
|
3650
|
+
namespacedef_='xmlns:sbgn="http://sbgn.org/libsbgn/0.2"',
|
|
3651
|
+
pretty_print=True,
|
|
3652
|
+
):
|
|
3653
|
+
if pretty_print:
|
|
3654
|
+
eol_ = "\n"
|
|
3655
|
+
else:
|
|
3656
|
+
eol_ = ""
|
|
3657
|
+
if self.original_tagname_ is not None:
|
|
3658
|
+
name_ = self.original_tagname_
|
|
3659
|
+
showIndent(outfile, level, pretty_print)
|
|
3660
|
+
outfile.write(
|
|
3661
|
+
"<%s%s%s"
|
|
3662
|
+
% (
|
|
3663
|
+
namespace_,
|
|
3664
|
+
name_,
|
|
3665
|
+
namespacedef_ and " " + namespacedef_ or "",
|
|
3666
|
+
)
|
|
3667
|
+
)
|
|
3668
|
+
already_processed = set()
|
|
3669
|
+
self.exportAttributes(
|
|
3670
|
+
outfile, level, already_processed, namespace_, name_="calloutType"
|
|
3671
|
+
)
|
|
3672
|
+
if self.hasContent_():
|
|
3673
|
+
outfile.write(">%s" % (eol_,))
|
|
3674
|
+
self.exportChildren(
|
|
3675
|
+
outfile,
|
|
3676
|
+
level + 1,
|
|
3677
|
+
namespace_="sbgn:",
|
|
3678
|
+
name_="calloutType",
|
|
3679
|
+
pretty_print=pretty_print,
|
|
3680
|
+
)
|
|
3681
|
+
showIndent(outfile, level, pretty_print)
|
|
3682
|
+
outfile.write("</%s%s>%s" % (namespace_, name_, eol_))
|
|
3683
|
+
else:
|
|
3684
|
+
outfile.write("/>%s" % (eol_,))
|
|
3685
|
+
|
|
3686
|
+
def exportAttributes(
|
|
3687
|
+
self, outfile, level, already_processed, namespace_="sbgn:", name_="calloutType"
|
|
3688
|
+
):
|
|
3689
|
+
if self.target is not None and "target" not in already_processed:
|
|
3690
|
+
already_processed.add("target")
|
|
3691
|
+
outfile.write(
|
|
3692
|
+
" target=%s"
|
|
3693
|
+
% (
|
|
3694
|
+
self.gds_encode(
|
|
3695
|
+
self.gds_format_string(
|
|
3696
|
+
quote_attrib(self.target), input_name="target"
|
|
3697
|
+
)
|
|
3698
|
+
),
|
|
3699
|
+
)
|
|
3700
|
+
)
|
|
3701
|
+
|
|
3702
|
+
def exportChildren(
|
|
3703
|
+
self,
|
|
3704
|
+
outfile,
|
|
3705
|
+
level,
|
|
3706
|
+
namespace_="sbgn:",
|
|
3707
|
+
name_="calloutType",
|
|
3708
|
+
fromsubclass_=False,
|
|
3709
|
+
pretty_print=True,
|
|
3710
|
+
):
|
|
3711
|
+
if self.point is not None:
|
|
3712
|
+
self.point.export(
|
|
3713
|
+
outfile,
|
|
3714
|
+
level,
|
|
3715
|
+
namespace_="sbgn:",
|
|
3716
|
+
name_="point",
|
|
3717
|
+
pretty_print=pretty_print,
|
|
3718
|
+
)
|
|
3719
|
+
|
|
3720
|
+
def build(self, node):
|
|
3721
|
+
already_processed = set()
|
|
3722
|
+
self.buildAttributes(node, node.attrib, already_processed)
|
|
3723
|
+
for child in node:
|
|
3724
|
+
nodeName_ = Tag_pattern_.match(child.tag).groups()[-1]
|
|
3725
|
+
self.buildChildren(child, node, nodeName_)
|
|
3726
|
+
return self
|
|
3727
|
+
|
|
3728
|
+
def buildAttributes(self, node, attrs, already_processed):
|
|
3729
|
+
value = find_attr_value_("target", node)
|
|
3730
|
+
if value is not None and "target" not in already_processed:
|
|
3731
|
+
already_processed.add("target")
|
|
3732
|
+
self.target = value
|
|
3733
|
+
|
|
3734
|
+
def buildChildren(self, child_, node, nodeName_, fromsubclass_=False):
|
|
3735
|
+
if nodeName_ == "point":
|
|
3736
|
+
obj_ = point.factory()
|
|
3737
|
+
obj_.build(child_)
|
|
3738
|
+
self.point = obj_
|
|
3739
|
+
obj_.original_tagname_ = "point"
|
|
3740
|
+
|
|
3741
|
+
|
|
3742
|
+
# end class calloutType
|
|
3743
|
+
|
|
3744
|
+
|
|
3745
|
+
class entityType(GeneratedsSuper):
|
|
3746
|
+
subclass = None
|
|
3747
|
+
superclass = None
|
|
3748
|
+
|
|
3749
|
+
def __init__(self, name=None):
|
|
3750
|
+
self.original_tagname_ = None
|
|
3751
|
+
self.name = _cast(None, name)
|
|
3752
|
+
|
|
3753
|
+
def factory(*args_, **kwargs_):
|
|
3754
|
+
if CurrentSubclassModule_ is not None:
|
|
3755
|
+
subclass = getSubclassFromModule_(CurrentSubclassModule_, entityType)
|
|
3756
|
+
if subclass is not None:
|
|
3757
|
+
return subclass(*args_, **kwargs_)
|
|
3758
|
+
if entityType.subclass:
|
|
3759
|
+
return entityType.subclass(*args_, **kwargs_)
|
|
3760
|
+
else:
|
|
3761
|
+
return entityType(*args_, **kwargs_)
|
|
3762
|
+
|
|
3763
|
+
factory = staticmethod(factory)
|
|
3764
|
+
|
|
3765
|
+
def get_name(self):
|
|
3766
|
+
return self.name
|
|
3767
|
+
|
|
3768
|
+
def set_name(self, name):
|
|
3769
|
+
self.name = name
|
|
3770
|
+
|
|
3771
|
+
def hasContent_(self):
|
|
3772
|
+
if ():
|
|
3773
|
+
return True
|
|
3774
|
+
else:
|
|
3775
|
+
return False
|
|
3776
|
+
|
|
3777
|
+
def export(
|
|
3778
|
+
self,
|
|
3779
|
+
outfile,
|
|
3780
|
+
level,
|
|
3781
|
+
namespace_="sbgn:",
|
|
3782
|
+
name_="entityType",
|
|
3783
|
+
namespacedef_='xmlns:sbgn="http://sbgn.org/libsbgn/0.2"',
|
|
3784
|
+
pretty_print=True,
|
|
3785
|
+
):
|
|
3786
|
+
if pretty_print:
|
|
3787
|
+
eol_ = "\n"
|
|
3788
|
+
else:
|
|
3789
|
+
eol_ = ""
|
|
3790
|
+
if self.original_tagname_ is not None:
|
|
3791
|
+
name_ = self.original_tagname_
|
|
3792
|
+
showIndent(outfile, level, pretty_print)
|
|
3793
|
+
outfile.write(
|
|
3794
|
+
"<%s%s%s"
|
|
3795
|
+
% (
|
|
3796
|
+
namespace_,
|
|
3797
|
+
name_,
|
|
3798
|
+
namespacedef_ and " " + namespacedef_ or "",
|
|
3799
|
+
)
|
|
3800
|
+
)
|
|
3801
|
+
already_processed = set()
|
|
3802
|
+
self.exportAttributes(
|
|
3803
|
+
outfile, level, already_processed, namespace_, name_="entityType"
|
|
3804
|
+
)
|
|
3805
|
+
if self.hasContent_():
|
|
3806
|
+
outfile.write(">%s" % (eol_,))
|
|
3807
|
+
self.exportChildren(
|
|
3808
|
+
outfile,
|
|
3809
|
+
level + 1,
|
|
3810
|
+
namespace_="sbgn:",
|
|
3811
|
+
name_="entityType",
|
|
3812
|
+
pretty_print=pretty_print,
|
|
3813
|
+
)
|
|
3814
|
+
outfile.write("</%s%s>%s" % (namespace_, name_, eol_))
|
|
3815
|
+
else:
|
|
3816
|
+
outfile.write("/>%s" % (eol_,))
|
|
3817
|
+
|
|
3818
|
+
def exportAttributes(
|
|
3819
|
+
self, outfile, level, already_processed, namespace_="sbgn:", name_="entityType"
|
|
3820
|
+
):
|
|
3821
|
+
if self.name is not None and "name" not in already_processed:
|
|
3822
|
+
already_processed.add("name")
|
|
3823
|
+
outfile.write(
|
|
3824
|
+
" name=%s"
|
|
3825
|
+
% (
|
|
3826
|
+
self.gds_encode(
|
|
3827
|
+
self.gds_format_string(
|
|
3828
|
+
quote_attrib(self.name), input_name="name"
|
|
3829
|
+
)
|
|
3830
|
+
),
|
|
3831
|
+
)
|
|
3832
|
+
)
|
|
3833
|
+
|
|
3834
|
+
def exportChildren(
|
|
3835
|
+
self,
|
|
3836
|
+
outfile,
|
|
3837
|
+
level,
|
|
3838
|
+
namespace_="sbgn:",
|
|
3839
|
+
name_="entityType",
|
|
3840
|
+
fromsubclass_=False,
|
|
3841
|
+
pretty_print=True,
|
|
3842
|
+
):
|
|
3843
|
+
pass
|
|
3844
|
+
|
|
3845
|
+
def build(self, node):
|
|
3846
|
+
already_processed = set()
|
|
3847
|
+
self.buildAttributes(node, node.attrib, already_processed)
|
|
3848
|
+
for child in node:
|
|
3849
|
+
nodeName_ = Tag_pattern_.match(child.tag).groups()[-1]
|
|
3850
|
+
self.buildChildren(child, node, nodeName_)
|
|
3851
|
+
return self
|
|
3852
|
+
|
|
3853
|
+
def buildAttributes(self, node, attrs, already_processed):
|
|
3854
|
+
value = find_attr_value_("name", node)
|
|
3855
|
+
if value is not None and "name" not in already_processed:
|
|
3856
|
+
already_processed.add("name")
|
|
3857
|
+
self.name = value
|
|
3858
|
+
|
|
3859
|
+
def buildChildren(self, child_, node, nodeName_, fromsubclass_=False):
|
|
3860
|
+
pass
|
|
3861
|
+
|
|
3862
|
+
|
|
3863
|
+
# end class entityType
|
|
3864
|
+
|
|
3865
|
+
|
|
3866
|
+
class startType(GeneratedsSuper):
|
|
3867
|
+
subclass = None
|
|
3868
|
+
superclass = None
|
|
3869
|
+
|
|
3870
|
+
def __init__(self, x=None, y=None):
|
|
3871
|
+
self.original_tagname_ = None
|
|
3872
|
+
self.x = _cast(float, x)
|
|
3873
|
+
self.y = _cast(float, y)
|
|
3874
|
+
|
|
3875
|
+
def factory(*args_, **kwargs_):
|
|
3876
|
+
if CurrentSubclassModule_ is not None:
|
|
3877
|
+
subclass = getSubclassFromModule_(CurrentSubclassModule_, startType)
|
|
3878
|
+
if subclass is not None:
|
|
3879
|
+
return subclass(*args_, **kwargs_)
|
|
3880
|
+
if startType.subclass:
|
|
3881
|
+
return startType.subclass(*args_, **kwargs_)
|
|
3882
|
+
else:
|
|
3883
|
+
return startType(*args_, **kwargs_)
|
|
3884
|
+
|
|
3885
|
+
factory = staticmethod(factory)
|
|
3886
|
+
|
|
3887
|
+
def get_x(self):
|
|
3888
|
+
return self.x
|
|
3889
|
+
|
|
3890
|
+
def set_x(self, x):
|
|
3891
|
+
self.x = x
|
|
3892
|
+
|
|
3893
|
+
def get_y(self):
|
|
3894
|
+
return self.y
|
|
3895
|
+
|
|
3896
|
+
def set_y(self, y):
|
|
3897
|
+
self.y = y
|
|
3898
|
+
|
|
3899
|
+
def hasContent_(self):
|
|
3900
|
+
if ():
|
|
3901
|
+
return True
|
|
3902
|
+
else:
|
|
3903
|
+
return False
|
|
3904
|
+
|
|
3905
|
+
def export(
|
|
3906
|
+
self,
|
|
3907
|
+
outfile,
|
|
3908
|
+
level,
|
|
3909
|
+
namespace_="sbgn:",
|
|
3910
|
+
name_="startType",
|
|
3911
|
+
namespacedef_='xmlns:sbgn="http://sbgn.org/libsbgn/0.2"',
|
|
3912
|
+
pretty_print=True,
|
|
3913
|
+
):
|
|
3914
|
+
if pretty_print:
|
|
3915
|
+
eol_ = "\n"
|
|
3916
|
+
else:
|
|
3917
|
+
eol_ = ""
|
|
3918
|
+
if self.original_tagname_ is not None:
|
|
3919
|
+
name_ = self.original_tagname_
|
|
3920
|
+
showIndent(outfile, level, pretty_print)
|
|
3921
|
+
outfile.write(
|
|
3922
|
+
"<%s%s%s"
|
|
3923
|
+
% (
|
|
3924
|
+
namespace_,
|
|
3925
|
+
name_,
|
|
3926
|
+
namespacedef_ and " " + namespacedef_ or "",
|
|
3927
|
+
)
|
|
3928
|
+
)
|
|
3929
|
+
already_processed = set()
|
|
3930
|
+
self.exportAttributes(
|
|
3931
|
+
outfile, level, already_processed, namespace_, name_="startType"
|
|
3932
|
+
)
|
|
3933
|
+
if self.hasContent_():
|
|
3934
|
+
outfile.write(">%s" % (eol_,))
|
|
3935
|
+
self.exportChildren(
|
|
3936
|
+
outfile,
|
|
3937
|
+
level + 1,
|
|
3938
|
+
namespace_="sbgn:",
|
|
3939
|
+
name_="startType",
|
|
3940
|
+
pretty_print=pretty_print,
|
|
3941
|
+
)
|
|
3942
|
+
outfile.write("</%s%s>%s" % (namespace_, name_, eol_))
|
|
3943
|
+
else:
|
|
3944
|
+
outfile.write("/>%s" % (eol_,))
|
|
3945
|
+
|
|
3946
|
+
def exportAttributes(
|
|
3947
|
+
self, outfile, level, already_processed, namespace_="sbgn:", name_="startType"
|
|
3948
|
+
):
|
|
3949
|
+
if self.x is not None and "x" not in already_processed:
|
|
3950
|
+
already_processed.add("x")
|
|
3951
|
+
outfile.write(' x="%s"' % self.gds_format_float(self.x, input_name="x"))
|
|
3952
|
+
if self.y is not None and "y" not in already_processed:
|
|
3953
|
+
already_processed.add("y")
|
|
3954
|
+
outfile.write(' y="%s"' % self.gds_format_float(self.y, input_name="y"))
|
|
3955
|
+
|
|
3956
|
+
def exportChildren(
|
|
3957
|
+
self,
|
|
3958
|
+
outfile,
|
|
3959
|
+
level,
|
|
3960
|
+
namespace_="sbgn:",
|
|
3961
|
+
name_="startType",
|
|
3962
|
+
fromsubclass_=False,
|
|
3963
|
+
pretty_print=True,
|
|
3964
|
+
):
|
|
3965
|
+
pass
|
|
3966
|
+
|
|
3967
|
+
def build(self, node):
|
|
3968
|
+
already_processed = set()
|
|
3969
|
+
self.buildAttributes(node, node.attrib, already_processed)
|
|
3970
|
+
for child in node:
|
|
3971
|
+
nodeName_ = Tag_pattern_.match(child.tag).groups()[-1]
|
|
3972
|
+
self.buildChildren(child, node, nodeName_)
|
|
3973
|
+
return self
|
|
3974
|
+
|
|
3975
|
+
def buildAttributes(self, node, attrs, already_processed):
|
|
3976
|
+
value = find_attr_value_("x", node)
|
|
3977
|
+
if value is not None and "x" not in already_processed:
|
|
3978
|
+
already_processed.add("x")
|
|
3979
|
+
try:
|
|
3980
|
+
self.x = float(value)
|
|
3981
|
+
except ValueError as exp:
|
|
3982
|
+
raise ValueError("Bad float/double attribute (x): %s" % exp)
|
|
3983
|
+
value = find_attr_value_("y", node)
|
|
3984
|
+
if value is not None and "y" not in already_processed:
|
|
3985
|
+
already_processed.add("y")
|
|
3986
|
+
try:
|
|
3987
|
+
self.y = float(value)
|
|
3988
|
+
except ValueError as exp:
|
|
3989
|
+
raise ValueError("Bad float/double attribute (y): %s" % exp)
|
|
3990
|
+
|
|
3991
|
+
def buildChildren(self, child_, node, nodeName_, fromsubclass_=False):
|
|
3992
|
+
pass
|
|
3993
|
+
|
|
3994
|
+
|
|
3995
|
+
# end class startType
|
|
3996
|
+
|
|
3997
|
+
|
|
3998
|
+
class nextType(GeneratedsSuper):
|
|
3999
|
+
"""List of control points, used when the path describes a curve. The
|
|
4000
|
+
number of points describes the degree of the Bezier curve:
|
|
4001
|
+
linear (0), quadratic (1) or cubic (2)"""
|
|
4002
|
+
|
|
4003
|
+
subclass = None
|
|
4004
|
+
superclass = None
|
|
4005
|
+
|
|
4006
|
+
def __init__(self, x=None, y=None, point=None):
|
|
4007
|
+
self.original_tagname_ = None
|
|
4008
|
+
self.x = _cast(float, x)
|
|
4009
|
+
self.y = _cast(float, y)
|
|
4010
|
+
if point is None:
|
|
4011
|
+
self.point = []
|
|
4012
|
+
else:
|
|
4013
|
+
self.point = point
|
|
4014
|
+
|
|
4015
|
+
def factory(*args_, **kwargs_):
|
|
4016
|
+
if CurrentSubclassModule_ is not None:
|
|
4017
|
+
subclass = getSubclassFromModule_(CurrentSubclassModule_, nextType)
|
|
4018
|
+
if subclass is not None:
|
|
4019
|
+
return subclass(*args_, **kwargs_)
|
|
4020
|
+
if nextType.subclass:
|
|
4021
|
+
return nextType.subclass(*args_, **kwargs_)
|
|
4022
|
+
else:
|
|
4023
|
+
return nextType(*args_, **kwargs_)
|
|
4024
|
+
|
|
4025
|
+
factory = staticmethod(factory)
|
|
4026
|
+
|
|
4027
|
+
def get_point(self):
|
|
4028
|
+
return self.point
|
|
4029
|
+
|
|
4030
|
+
def set_point(self, point):
|
|
4031
|
+
self.point = point
|
|
4032
|
+
|
|
4033
|
+
def add_point(self, value):
|
|
4034
|
+
self.point.append(value)
|
|
4035
|
+
|
|
4036
|
+
def insert_point_at(self, index, value):
|
|
4037
|
+
self.point.insert(index, value)
|
|
4038
|
+
|
|
4039
|
+
def replace_point_at(self, index, value):
|
|
4040
|
+
self.point[index] = value
|
|
4041
|
+
|
|
4042
|
+
def get_x(self):
|
|
4043
|
+
return self.x
|
|
4044
|
+
|
|
4045
|
+
def set_x(self, x):
|
|
4046
|
+
self.x = x
|
|
4047
|
+
|
|
4048
|
+
def get_y(self):
|
|
4049
|
+
return self.y
|
|
4050
|
+
|
|
4051
|
+
def set_y(self, y):
|
|
4052
|
+
self.y = y
|
|
4053
|
+
|
|
4054
|
+
def hasContent_(self):
|
|
4055
|
+
if self.point:
|
|
4056
|
+
return True
|
|
4057
|
+
else:
|
|
4058
|
+
return False
|
|
4059
|
+
|
|
4060
|
+
def export(
|
|
4061
|
+
self,
|
|
4062
|
+
outfile,
|
|
4063
|
+
level,
|
|
4064
|
+
namespace_="sbgn:",
|
|
4065
|
+
name_="nextType",
|
|
4066
|
+
namespacedef_='xmlns:sbgn="http://sbgn.org/libsbgn/0.2"',
|
|
4067
|
+
pretty_print=True,
|
|
4068
|
+
):
|
|
4069
|
+
if pretty_print:
|
|
4070
|
+
eol_ = "\n"
|
|
4071
|
+
else:
|
|
4072
|
+
eol_ = ""
|
|
4073
|
+
if self.original_tagname_ is not None:
|
|
4074
|
+
name_ = self.original_tagname_
|
|
4075
|
+
showIndent(outfile, level, pretty_print)
|
|
4076
|
+
outfile.write(
|
|
4077
|
+
"<%s%s%s"
|
|
4078
|
+
% (
|
|
4079
|
+
namespace_,
|
|
4080
|
+
name_,
|
|
4081
|
+
namespacedef_ and " " + namespacedef_ or "",
|
|
4082
|
+
)
|
|
4083
|
+
)
|
|
4084
|
+
already_processed = set()
|
|
4085
|
+
self.exportAttributes(
|
|
4086
|
+
outfile, level, already_processed, namespace_, name_="nextType"
|
|
4087
|
+
)
|
|
4088
|
+
if self.hasContent_():
|
|
4089
|
+
outfile.write(">%s" % (eol_,))
|
|
4090
|
+
self.exportChildren(
|
|
4091
|
+
outfile,
|
|
4092
|
+
level + 1,
|
|
4093
|
+
namespace_="sbgn:",
|
|
4094
|
+
name_="nextType",
|
|
4095
|
+
pretty_print=pretty_print,
|
|
4096
|
+
)
|
|
4097
|
+
showIndent(outfile, level, pretty_print)
|
|
4098
|
+
outfile.write("</%s%s>%s" % (namespace_, name_, eol_))
|
|
4099
|
+
else:
|
|
4100
|
+
outfile.write("/>%s" % (eol_,))
|
|
4101
|
+
|
|
4102
|
+
def exportAttributes(
|
|
4103
|
+
self, outfile, level, already_processed, namespace_="sbgn:", name_="nextType"
|
|
4104
|
+
):
|
|
4105
|
+
if self.x is not None and "x" not in already_processed:
|
|
4106
|
+
already_processed.add("x")
|
|
4107
|
+
outfile.write(' x="%s"' % self.gds_format_float(self.x, input_name="x"))
|
|
4108
|
+
if self.y is not None and "y" not in already_processed:
|
|
4109
|
+
already_processed.add("y")
|
|
4110
|
+
outfile.write(' y="%s"' % self.gds_format_float(self.y, input_name="y"))
|
|
4111
|
+
|
|
4112
|
+
def exportChildren(
|
|
4113
|
+
self,
|
|
4114
|
+
outfile,
|
|
4115
|
+
level,
|
|
4116
|
+
namespace_="sbgn:",
|
|
4117
|
+
name_="nextType",
|
|
4118
|
+
fromsubclass_=False,
|
|
4119
|
+
pretty_print=True,
|
|
4120
|
+
):
|
|
4121
|
+
for point_ in self.point:
|
|
4122
|
+
point_.export(
|
|
4123
|
+
outfile,
|
|
4124
|
+
level,
|
|
4125
|
+
namespace_="sbgn:",
|
|
4126
|
+
name_="point",
|
|
4127
|
+
pretty_print=pretty_print,
|
|
4128
|
+
)
|
|
4129
|
+
|
|
4130
|
+
def build(self, node):
|
|
4131
|
+
already_processed = set()
|
|
4132
|
+
self.buildAttributes(node, node.attrib, already_processed)
|
|
4133
|
+
for child in node:
|
|
4134
|
+
nodeName_ = Tag_pattern_.match(child.tag).groups()[-1]
|
|
4135
|
+
self.buildChildren(child, node, nodeName_)
|
|
4136
|
+
return self
|
|
4137
|
+
|
|
4138
|
+
def buildAttributes(self, node, attrs, already_processed):
|
|
4139
|
+
value = find_attr_value_("x", node)
|
|
4140
|
+
if value is not None and "x" not in already_processed:
|
|
4141
|
+
already_processed.add("x")
|
|
4142
|
+
try:
|
|
4143
|
+
self.x = float(value)
|
|
4144
|
+
except ValueError as exp:
|
|
4145
|
+
raise ValueError("Bad float/double attribute (x): %s" % exp)
|
|
4146
|
+
value = find_attr_value_("y", node)
|
|
4147
|
+
if value is not None and "y" not in already_processed:
|
|
4148
|
+
already_processed.add("y")
|
|
4149
|
+
try:
|
|
4150
|
+
self.y = float(value)
|
|
4151
|
+
except ValueError as exp:
|
|
4152
|
+
raise ValueError("Bad float/double attribute (y): %s" % exp)
|
|
4153
|
+
|
|
4154
|
+
def buildChildren(self, child_, node, nodeName_, fromsubclass_=False):
|
|
4155
|
+
if nodeName_ == "point":
|
|
4156
|
+
obj_ = point.factory()
|
|
4157
|
+
obj_.build(child_)
|
|
4158
|
+
self.point.append(obj_)
|
|
4159
|
+
obj_.original_tagname_ = "point"
|
|
4160
|
+
|
|
4161
|
+
|
|
4162
|
+
# end class nextType
|
|
4163
|
+
|
|
4164
|
+
|
|
4165
|
+
class endType(GeneratedsSuper):
|
|
4166
|
+
"""List of control points, used when the path describes a curve. The
|
|
4167
|
+
number of points describes the degree of the Bezier curve:
|
|
4168
|
+
linear (0), quadratic (1) or cubic (2)"""
|
|
4169
|
+
|
|
4170
|
+
subclass = None
|
|
4171
|
+
superclass = None
|
|
4172
|
+
|
|
4173
|
+
def __init__(self, x=None, y=None, point=None):
|
|
4174
|
+
self.original_tagname_ = None
|
|
4175
|
+
self.x = _cast(float, x)
|
|
4176
|
+
self.y = _cast(float, y)
|
|
4177
|
+
if point is None:
|
|
4178
|
+
self.point = []
|
|
4179
|
+
else:
|
|
4180
|
+
self.point = point
|
|
4181
|
+
|
|
4182
|
+
def factory(*args_, **kwargs_):
|
|
4183
|
+
if CurrentSubclassModule_ is not None:
|
|
4184
|
+
subclass = getSubclassFromModule_(CurrentSubclassModule_, endType)
|
|
4185
|
+
if subclass is not None:
|
|
4186
|
+
return subclass(*args_, **kwargs_)
|
|
4187
|
+
if endType.subclass:
|
|
4188
|
+
return endType.subclass(*args_, **kwargs_)
|
|
4189
|
+
else:
|
|
4190
|
+
return endType(*args_, **kwargs_)
|
|
4191
|
+
|
|
4192
|
+
factory = staticmethod(factory)
|
|
4193
|
+
|
|
4194
|
+
def get_point(self):
|
|
4195
|
+
return self.point
|
|
4196
|
+
|
|
4197
|
+
def set_point(self, point):
|
|
4198
|
+
self.point = point
|
|
4199
|
+
|
|
4200
|
+
def add_point(self, value):
|
|
4201
|
+
self.point.append(value)
|
|
4202
|
+
|
|
4203
|
+
def insert_point_at(self, index, value):
|
|
4204
|
+
self.point.insert(index, value)
|
|
4205
|
+
|
|
4206
|
+
def replace_point_at(self, index, value):
|
|
4207
|
+
self.point[index] = value
|
|
4208
|
+
|
|
4209
|
+
def get_x(self):
|
|
4210
|
+
return self.x
|
|
4211
|
+
|
|
4212
|
+
def set_x(self, x):
|
|
4213
|
+
self.x = x
|
|
4214
|
+
|
|
4215
|
+
def get_y(self):
|
|
4216
|
+
return self.y
|
|
4217
|
+
|
|
4218
|
+
def set_y(self, y):
|
|
4219
|
+
self.y = y
|
|
4220
|
+
|
|
4221
|
+
def hasContent_(self):
|
|
4222
|
+
if self.point:
|
|
4223
|
+
return True
|
|
4224
|
+
else:
|
|
4225
|
+
return False
|
|
4226
|
+
|
|
4227
|
+
def export(
|
|
4228
|
+
self,
|
|
4229
|
+
outfile,
|
|
4230
|
+
level,
|
|
4231
|
+
namespace_="sbgn:",
|
|
4232
|
+
name_="endType",
|
|
4233
|
+
namespacedef_='xmlns:sbgn="http://sbgn.org/libsbgn/0.2"',
|
|
4234
|
+
pretty_print=True,
|
|
4235
|
+
):
|
|
4236
|
+
if pretty_print:
|
|
4237
|
+
eol_ = "\n"
|
|
4238
|
+
else:
|
|
4239
|
+
eol_ = ""
|
|
4240
|
+
if self.original_tagname_ is not None:
|
|
4241
|
+
name_ = self.original_tagname_
|
|
4242
|
+
showIndent(outfile, level, pretty_print)
|
|
4243
|
+
outfile.write(
|
|
4244
|
+
"<%s%s%s"
|
|
4245
|
+
% (
|
|
4246
|
+
namespace_,
|
|
4247
|
+
name_,
|
|
4248
|
+
namespacedef_ and " " + namespacedef_ or "",
|
|
4249
|
+
)
|
|
4250
|
+
)
|
|
4251
|
+
already_processed = set()
|
|
4252
|
+
self.exportAttributes(
|
|
4253
|
+
outfile, level, already_processed, namespace_, name_="endType"
|
|
4254
|
+
)
|
|
4255
|
+
if self.hasContent_():
|
|
4256
|
+
outfile.write(">%s" % (eol_,))
|
|
4257
|
+
self.exportChildren(
|
|
4258
|
+
outfile,
|
|
4259
|
+
level + 1,
|
|
4260
|
+
namespace_="sbgn:",
|
|
4261
|
+
name_="endType",
|
|
4262
|
+
pretty_print=pretty_print,
|
|
4263
|
+
)
|
|
4264
|
+
showIndent(outfile, level, pretty_print)
|
|
4265
|
+
outfile.write("</%s%s>%s" % (namespace_, name_, eol_))
|
|
4266
|
+
else:
|
|
4267
|
+
outfile.write("/>%s" % (eol_,))
|
|
4268
|
+
|
|
4269
|
+
def exportAttributes(
|
|
4270
|
+
self, outfile, level, already_processed, namespace_="sbgn:", name_="endType"
|
|
4271
|
+
):
|
|
4272
|
+
if self.x is not None and "x" not in already_processed:
|
|
4273
|
+
already_processed.add("x")
|
|
4274
|
+
outfile.write(' x="%s"' % self.gds_format_float(self.x, input_name="x"))
|
|
4275
|
+
if self.y is not None and "y" not in already_processed:
|
|
4276
|
+
already_processed.add("y")
|
|
4277
|
+
outfile.write(' y="%s"' % self.gds_format_float(self.y, input_name="y"))
|
|
4278
|
+
|
|
4279
|
+
def exportChildren(
|
|
4280
|
+
self,
|
|
4281
|
+
outfile,
|
|
4282
|
+
level,
|
|
4283
|
+
namespace_="sbgn:",
|
|
4284
|
+
name_="endType",
|
|
4285
|
+
fromsubclass_=False,
|
|
4286
|
+
pretty_print=True,
|
|
4287
|
+
):
|
|
4288
|
+
for point_ in self.point:
|
|
4289
|
+
point_.export(
|
|
4290
|
+
outfile,
|
|
4291
|
+
level,
|
|
4292
|
+
namespace_="sbgn:",
|
|
4293
|
+
name_="point",
|
|
4294
|
+
pretty_print=pretty_print,
|
|
4295
|
+
)
|
|
4296
|
+
|
|
4297
|
+
def build(self, node):
|
|
4298
|
+
already_processed = set()
|
|
4299
|
+
self.buildAttributes(node, node.attrib, already_processed)
|
|
4300
|
+
for child in node:
|
|
4301
|
+
nodeName_ = Tag_pattern_.match(child.tag).groups()[-1]
|
|
4302
|
+
self.buildChildren(child, node, nodeName_)
|
|
4303
|
+
return self
|
|
4304
|
+
|
|
4305
|
+
def buildAttributes(self, node, attrs, already_processed):
|
|
4306
|
+
value = find_attr_value_("x", node)
|
|
4307
|
+
if value is not None and "x" not in already_processed:
|
|
4308
|
+
already_processed.add("x")
|
|
4309
|
+
try:
|
|
4310
|
+
self.x = float(value)
|
|
4311
|
+
except ValueError as exp:
|
|
4312
|
+
raise ValueError("Bad float/double attribute (x): %s" % exp)
|
|
4313
|
+
value = find_attr_value_("y", node)
|
|
4314
|
+
if value is not None and "y" not in already_processed:
|
|
4315
|
+
already_processed.add("y")
|
|
4316
|
+
try:
|
|
4317
|
+
self.y = float(value)
|
|
4318
|
+
except ValueError as exp:
|
|
4319
|
+
raise ValueError("Bad float/double attribute (y): %s" % exp)
|
|
4320
|
+
|
|
4321
|
+
def buildChildren(self, child_, node, nodeName_, fromsubclass_=False):
|
|
4322
|
+
if nodeName_ == "point":
|
|
4323
|
+
obj_ = point.factory()
|
|
4324
|
+
obj_.build(child_)
|
|
4325
|
+
self.point.append(obj_)
|
|
4326
|
+
obj_.original_tagname_ = "point"
|
|
4327
|
+
|
|
4328
|
+
|
|
4329
|
+
# end class endType
|
|
4330
|
+
|
|
4331
|
+
|
|
4332
|
+
GDSClassesMapping = {
|
|
4333
|
+
"callout": calloutType,
|
|
4334
|
+
"clone": cloneType,
|
|
4335
|
+
"end": endType,
|
|
4336
|
+
"entity": entityType,
|
|
4337
|
+
"extension": extensionType,
|
|
4338
|
+
"next": nextType,
|
|
4339
|
+
"notes": notesType,
|
|
4340
|
+
"start": startType,
|
|
4341
|
+
"state": stateType,
|
|
4342
|
+
}
|
|
4343
|
+
|
|
4344
|
+
|
|
4345
|
+
USAGE_TEXT = """
|
|
4346
|
+
Usage: python <Parser>.py [ -s ] <in_xml_file>
|
|
4347
|
+
"""
|
|
4348
|
+
|
|
4349
|
+
|
|
4350
|
+
def usage():
|
|
4351
|
+
print(USAGE_TEXT)
|
|
4352
|
+
sys.exit(1)
|
|
4353
|
+
|
|
4354
|
+
|
|
4355
|
+
def get_root_tag(node):
|
|
4356
|
+
tag = Tag_pattern_.match(node.tag).groups()[-1]
|
|
4357
|
+
rootClass = GDSClassesMapping.get(tag)
|
|
4358
|
+
if rootClass is None:
|
|
4359
|
+
rootClass = globals().get(tag)
|
|
4360
|
+
return tag, rootClass
|
|
4361
|
+
|
|
4362
|
+
|
|
4363
|
+
def parse(inFileName, silence=False):
|
|
4364
|
+
parser = None
|
|
4365
|
+
doc = parsexml_(inFileName, parser)
|
|
4366
|
+
rootNode = doc.getroot()
|
|
4367
|
+
rootTag, rootClass = get_root_tag(rootNode)
|
|
4368
|
+
if rootClass is None:
|
|
4369
|
+
rootTag = "SBGNBase"
|
|
4370
|
+
rootClass = SBGNBase
|
|
4371
|
+
rootObj = rootClass.factory()
|
|
4372
|
+
rootObj.build(rootNode)
|
|
4373
|
+
# Enable Python to collect the space used by the DOM.
|
|
4374
|
+
doc = None
|
|
4375
|
+
if not silence:
|
|
4376
|
+
sys.stdout.write('<?xml version="1.0" ?>\n')
|
|
4377
|
+
rootObj.export(
|
|
4378
|
+
sys.stdout,
|
|
4379
|
+
0,
|
|
4380
|
+
name_=rootTag,
|
|
4381
|
+
namespacedef_='xmlns:sbgn="http://sbgn.org/libsbgn/0.2"',
|
|
4382
|
+
pretty_print=True,
|
|
4383
|
+
)
|
|
4384
|
+
return rootObj
|
|
4385
|
+
|
|
4386
|
+
|
|
4387
|
+
def parseEtree(inFileName, silence=False):
|
|
4388
|
+
parser = None
|
|
4389
|
+
doc = parsexml_(inFileName, parser)
|
|
4390
|
+
rootNode = doc.getroot()
|
|
4391
|
+
rootTag, rootClass = get_root_tag(rootNode)
|
|
4392
|
+
if rootClass is None:
|
|
4393
|
+
rootTag = "SBGNBase"
|
|
4394
|
+
rootClass = SBGNBase
|
|
4395
|
+
rootObj = rootClass.factory()
|
|
4396
|
+
rootObj.build(rootNode)
|
|
4397
|
+
# Enable Python to collect the space used by the DOM.
|
|
4398
|
+
doc = None
|
|
4399
|
+
mapping = {}
|
|
4400
|
+
rootElement = rootObj.to_etree(None, name_=rootTag, mapping_=mapping)
|
|
4401
|
+
reverse_mapping = rootObj.gds_reverse_node_mapping(mapping)
|
|
4402
|
+
if not silence:
|
|
4403
|
+
content = etree_.tostring(
|
|
4404
|
+
rootElement, pretty_print=True, xml_declaration=True, encoding="utf-8"
|
|
4405
|
+
)
|
|
4406
|
+
sys.stdout.write(content)
|
|
4407
|
+
sys.stdout.write("\n")
|
|
4408
|
+
return rootObj, rootElement, mapping, reverse_mapping
|
|
4409
|
+
|
|
4410
|
+
|
|
4411
|
+
def parseString(inString, silence=False):
|
|
4412
|
+
from StringIO import StringIO
|
|
4413
|
+
|
|
4414
|
+
parser = None
|
|
4415
|
+
doc = parsexml_(StringIO(inString), parser)
|
|
4416
|
+
rootNode = doc.getroot()
|
|
4417
|
+
rootTag, rootClass = get_root_tag(rootNode)
|
|
4418
|
+
if rootClass is None:
|
|
4419
|
+
rootTag = "SBGNBase"
|
|
4420
|
+
rootClass = SBGNBase
|
|
4421
|
+
rootObj = rootClass.factory()
|
|
4422
|
+
rootObj.build(rootNode)
|
|
4423
|
+
# Enable Python to collect the space used by the DOM.
|
|
4424
|
+
doc = None
|
|
4425
|
+
if not silence:
|
|
4426
|
+
sys.stdout.write('<?xml version="1.0" ?>\n')
|
|
4427
|
+
rootObj.export(
|
|
4428
|
+
sys.stdout,
|
|
4429
|
+
0,
|
|
4430
|
+
name_=rootTag,
|
|
4431
|
+
namespacedef_='xmlns:sbgn="http://sbgn.org/libsbgn/0.2"',
|
|
4432
|
+
)
|
|
4433
|
+
return rootObj
|
|
4434
|
+
|
|
4435
|
+
|
|
4436
|
+
def parseLiteral(inFileName, silence=False):
|
|
4437
|
+
parser = None
|
|
4438
|
+
doc = parsexml_(inFileName, parser)
|
|
4439
|
+
rootNode = doc.getroot()
|
|
4440
|
+
rootTag, rootClass = get_root_tag(rootNode)
|
|
4441
|
+
if rootClass is None:
|
|
4442
|
+
rootTag = "SBGNBase"
|
|
4443
|
+
rootClass = SBGNBase
|
|
4444
|
+
rootObj = rootClass.factory()
|
|
4445
|
+
rootObj.build(rootNode)
|
|
4446
|
+
# Enable Python to collect the space used by the DOM.
|
|
4447
|
+
doc = None
|
|
4448
|
+
if not silence:
|
|
4449
|
+
sys.stdout.write("#from libsbgn import *\n\n")
|
|
4450
|
+
sys.stdout.write("import libsbgn as model_\n\n")
|
|
4451
|
+
sys.stdout.write("rootObj = model_.rootClass(\n")
|
|
4452
|
+
rootObj.exportLiteral(sys.stdout, 0, name_=rootTag)
|
|
4453
|
+
sys.stdout.write(")\n")
|
|
4454
|
+
return rootObj
|
|
4455
|
+
|
|
4456
|
+
|
|
4457
|
+
def main():
|
|
4458
|
+
args = sys.argv[1:]
|
|
4459
|
+
if len(args) == 1:
|
|
4460
|
+
parse(args[0])
|
|
4461
|
+
else:
|
|
4462
|
+
usage()
|
|
4463
|
+
|
|
4464
|
+
|
|
4465
|
+
if __name__ == "__main__":
|
|
4466
|
+
# import pdb; pdb.set_trace()
|
|
4467
|
+
main()
|
|
4468
|
+
|
|
4469
|
+
|
|
4470
|
+
__all__ = [
|
|
4471
|
+
"SBGNBase",
|
|
4472
|
+
"arc",
|
|
4473
|
+
"arcgroup",
|
|
4474
|
+
"bbox",
|
|
4475
|
+
"calloutType",
|
|
4476
|
+
"cloneType",
|
|
4477
|
+
"endType",
|
|
4478
|
+
"entityType",
|
|
4479
|
+
"extensionType",
|
|
4480
|
+
"glyph",
|
|
4481
|
+
"label",
|
|
4482
|
+
"map",
|
|
4483
|
+
"nextType",
|
|
4484
|
+
"notesType",
|
|
4485
|
+
"point",
|
|
4486
|
+
"port",
|
|
4487
|
+
"sbgn",
|
|
4488
|
+
"startType",
|
|
4489
|
+
"stateType",
|
|
4490
|
+
]
|