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/libsbgnSubs.py
ADDED
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Overwritten classes (Notes & Extension)
|
|
3
|
+
"""
|
|
4
|
+
|
|
5
|
+
try:
|
|
6
|
+
from lxml import etree as etree_
|
|
7
|
+
except ImportError:
|
|
8
|
+
from xml.etree import ElementTree as etree_
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
import libsbgnpy.libsbgn as supermod
|
|
12
|
+
from libsbgnpy.libsbgn import showIndent
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def _process_xml_input(input):
|
|
16
|
+
"""Helper function for input to Notes and Extension.
|
|
17
|
+
|
|
18
|
+
:param input: xml_string
|
|
19
|
+
:return: anytypeobjs_
|
|
20
|
+
"""
|
|
21
|
+
anytypeobjs_ = None
|
|
22
|
+
if input is not None:
|
|
23
|
+
anytypeobjs_ = input.strip()
|
|
24
|
+
return anytypeobjs_
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
class _Information(object):
|
|
28
|
+
def __str__(self):
|
|
29
|
+
if type(self.anytypeobjs_) in (list, tuple):
|
|
30
|
+
return str(self.anytypeobjs_[0])
|
|
31
|
+
else:
|
|
32
|
+
return str(self.anytypeobjs_)
|
|
33
|
+
|
|
34
|
+
def hasContent_(self):
|
|
35
|
+
return self.anytypeobjs_ is not None
|
|
36
|
+
|
|
37
|
+
def export(
|
|
38
|
+
self,
|
|
39
|
+
outfile,
|
|
40
|
+
level,
|
|
41
|
+
namespace_="sbgn:",
|
|
42
|
+
name_=None,
|
|
43
|
+
namespacedef_='xmlns:sbgn="http://sbgn.org/libsbgn/0.2"',
|
|
44
|
+
pretty_print=True,
|
|
45
|
+
):
|
|
46
|
+
"""Custom export function.
|
|
47
|
+
|
|
48
|
+
Necessary to provide handling for the xsd:any.
|
|
49
|
+
"""
|
|
50
|
+
name_ = self.__class__.__name__.lower()
|
|
51
|
+
if pretty_print:
|
|
52
|
+
eol_ = "\n"
|
|
53
|
+
else:
|
|
54
|
+
eol_ = ""
|
|
55
|
+
|
|
56
|
+
if self.hasContent_():
|
|
57
|
+
# notes defined as sequence, so handle the normal case of just having string
|
|
58
|
+
notes_items = self.anytypeobjs_
|
|
59
|
+
if type(self.anytypeobjs_) not in [list, tuple]:
|
|
60
|
+
notes_items = [notes_items]
|
|
61
|
+
showIndent(outfile, level, pretty_print)
|
|
62
|
+
outfile.write(
|
|
63
|
+
"<%s%s%s>%s"
|
|
64
|
+
% (namespace_, name_, namespacedef_ and " " + namespacedef_ or "", eol_)
|
|
65
|
+
)
|
|
66
|
+
for obj_ in notes_items:
|
|
67
|
+
showIndent(outfile, level, pretty_print)
|
|
68
|
+
outfile.write("%s%s" % (obj_, eol_))
|
|
69
|
+
showIndent(outfile, level, pretty_print)
|
|
70
|
+
outfile.write(
|
|
71
|
+
"</%s%s%s>%s"
|
|
72
|
+
% (namespace_, name_, namespacedef_ and " " + namespacedef_ or "", eol_)
|
|
73
|
+
)
|
|
74
|
+
|
|
75
|
+
def buildChildren(self, child_, node, nodeName_, fromsubclass_=False):
|
|
76
|
+
"""Custom build function.
|
|
77
|
+
|
|
78
|
+
Necessary to provide handling for the xsd:any.
|
|
79
|
+
"""
|
|
80
|
+
# This is the lxml.etree._Element, in first version going via strings
|
|
81
|
+
obj_ = etree_.tostring(child_, pretty_print=False, encoding="unicode")
|
|
82
|
+
# print('obj_', obj_)
|
|
83
|
+
if obj_ is not None:
|
|
84
|
+
self.add_anytypeobjs_(obj_)
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
class Notes(_Information, supermod.notesType):
|
|
88
|
+
"""SBGN Notes class.
|
|
89
|
+
|
|
90
|
+
The optional SBGN element named 'notes', present on every major SBGN
|
|
91
|
+
component type, is intended as a place for storing optional
|
|
92
|
+
information intended to be seen by humans. An example use of the
|
|
93
|
+
'notes' element would be to contain formatted user comments about the
|
|
94
|
+
model element in which the 'notes' element is enclosed. Every object
|
|
95
|
+
derived directly or indirectly from type SBase can have a separate
|
|
96
|
+
value for 'notes', allowing users considerable freedom when adding
|
|
97
|
+
comments to their models.
|
|
98
|
+
|
|
99
|
+
The format of 'notes' elements must be XHTML 1.0 (http://www.w3.org/1999/xhtml).
|
|
100
|
+
"""
|
|
101
|
+
|
|
102
|
+
def __init__(self, xml_string=None):
|
|
103
|
+
super(Notes, self).__init__(
|
|
104
|
+
_process_xml_input(xml_string),
|
|
105
|
+
)
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
supermod.notesType.subclass = Notes
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
class Extension(_Information, supermod.extensionType):
|
|
112
|
+
"""SBGN Extension class.
|
|
113
|
+
|
|
114
|
+
Any well-formed XML content, and with each top-level element placed in a unique XML namespace; see text.
|
|
115
|
+
Whereas Notes is a container for content to be shown directly to humans, Extension is a container for
|
|
116
|
+
optional software-generated content not meant to be shown to humans. Every SBGN object can
|
|
117
|
+
have its own Extension object instance. In XML, the Extension content type is any, allowing essentially
|
|
118
|
+
arbitrary well-formed XML data content.
|
|
119
|
+
"""
|
|
120
|
+
|
|
121
|
+
def __init__(self, xml_string=None):
|
|
122
|
+
super(Extension, self).__init__(
|
|
123
|
+
_process_xml_input(xml_string),
|
|
124
|
+
)
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
supermod.extensionType.subclass = Extension
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
"""
|
|
3
|
+
Definition of Language, GlyphClass and ArcClass types.
|
|
4
|
+
Created manually from schema file.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from enum import Enum, unique
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
@unique
|
|
11
|
+
class Language(Enum):
|
|
12
|
+
"""
|
|
13
|
+
Enum representing the three languages of SBGN.
|
|
14
|
+
"""
|
|
15
|
+
|
|
16
|
+
AF = "activity flow"
|
|
17
|
+
ER = "entity relationship"
|
|
18
|
+
PD = "process description"
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
@unique
|
|
22
|
+
class Orientation(Enum):
|
|
23
|
+
HORIZONTAL = "horizontal"
|
|
24
|
+
VERTICAL = "vertical"
|
|
25
|
+
UP = "up"
|
|
26
|
+
DOWN = "down"
|
|
27
|
+
RIGHT = "right"
|
|
28
|
+
LEFT = "left"
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
@unique
|
|
32
|
+
class GlyphClass(Enum):
|
|
33
|
+
"""
|
|
34
|
+
Enumeration with all possible values for the class attribute of Glyphs in SBGN-ML.
|
|
35
|
+
This includes both top-level glyphs and sub-glyphs.
|
|
36
|
+
"""
|
|
37
|
+
|
|
38
|
+
# glyphs
|
|
39
|
+
UNSPECIFIED_ENTITY = "unspecified entity"
|
|
40
|
+
SIMPLE_CHEMICAL = "simple chemical"
|
|
41
|
+
MACROMOLECULE = "macromolecule"
|
|
42
|
+
NUCLEIC_ACID_FEATURE = "nucleic acid feature"
|
|
43
|
+
SIMPLE_CHEMICAL_MULTIMER = "simple chemical multimer"
|
|
44
|
+
MACROMOLECULE_MULTIMER = "macromolecule multimer"
|
|
45
|
+
NUCLEIC_ACID_FEATURE_MULTIMER = "nucleic acid feature multimer"
|
|
46
|
+
COMPLEX = "complex"
|
|
47
|
+
COMPLEX_MULTIMER = "complex multimer"
|
|
48
|
+
SOURCE_AND_SINK = "source and sink"
|
|
49
|
+
PERTURBATION = "perturbation"
|
|
50
|
+
BIOLOGICAL_ACTIVITY = "biological activity"
|
|
51
|
+
PERTURBING_AGENT = "perturbing agent"
|
|
52
|
+
COMPARTMENT = "compartment"
|
|
53
|
+
SUBMAP = "submap"
|
|
54
|
+
TAG = "tag"
|
|
55
|
+
TERMINAL = "terminal"
|
|
56
|
+
PROCESS = "process"
|
|
57
|
+
OMITTED_PROCESS = "omitted process"
|
|
58
|
+
UNCERTAIN_PROCESS = "uncertain process"
|
|
59
|
+
ASSOCIATION = "association"
|
|
60
|
+
DISSOCIATION = "dissociation"
|
|
61
|
+
PHENOTYPE = "phenotype"
|
|
62
|
+
AND = "and"
|
|
63
|
+
OR = "or"
|
|
64
|
+
NOT = "not"
|
|
65
|
+
STATE_VARIABLE = "state variable"
|
|
66
|
+
UNIT_OF_INFORMATION = "unit of information"
|
|
67
|
+
|
|
68
|
+
# @deprecated
|
|
69
|
+
# By mistake, we used STOICHIOMETRY in instead of {@link CARDINALITY} in LibSBGN M1.
|
|
70
|
+
# We keep this constant here to support reading old documents.
|
|
71
|
+
# This constant will be removed in LibSBGN M3.
|
|
72
|
+
STOICHIOMETRY = "stoichiometry"
|
|
73
|
+
ENTITY = "entity"
|
|
74
|
+
OUTCOME = "outcome"
|
|
75
|
+
|
|
76
|
+
# @deprecated
|
|
77
|
+
# Observable was used in old versions of SBGN, but has been replaced with {@link PHENOTYPE}.
|
|
78
|
+
# However, because older versions of SBGN are supported by LibSBGN, this constant will never be removed.
|
|
79
|
+
OBSERVABLE = "observable"
|
|
80
|
+
INTERACTION = "interaction"
|
|
81
|
+
ANNOTATION = "annotation"
|
|
82
|
+
VARIABLE_VALUE = "variable value"
|
|
83
|
+
IMPLICIT_XOR = "implicit xor"
|
|
84
|
+
DELAY = "delay"
|
|
85
|
+
EXISTENCE = "existence"
|
|
86
|
+
LOCATION = "location"
|
|
87
|
+
CARDINALITY = "cardinality"
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
@unique
|
|
91
|
+
class ArcClass(Enum):
|
|
92
|
+
"""
|
|
93
|
+
Enumeration with all possible values for the class attribute of Arcs in SBGN-ML.
|
|
94
|
+
"""
|
|
95
|
+
|
|
96
|
+
# arcs
|
|
97
|
+
PRODUCTION = "production"
|
|
98
|
+
CONSUMPTION = "consumption"
|
|
99
|
+
CATALYSIS = "catalysis"
|
|
100
|
+
MODULATION = "modulation"
|
|
101
|
+
STIMULATION = "stimulation"
|
|
102
|
+
INHIBITION = "inhibition"
|
|
103
|
+
ASSIGNMENT = "assignment"
|
|
104
|
+
INTERACTION = "interaction"
|
|
105
|
+
ABSOLUTE_INHIBITION = "absolute inhibition"
|
|
106
|
+
ABSOLUTE_STIMULATION = "absolute stimulation"
|
|
107
|
+
POSITIVE_INFLUENCE = "positive influence"
|
|
108
|
+
NEGATIVE_INFLUENCE = "negative influence"
|
|
109
|
+
UNKNOWN_INFLUENCE = "unknown influence"
|
|
110
|
+
EQUIVALENCE_ARC = "equivalence arc"
|
|
111
|
+
NECESSARY_STIMULATION = "necessary stimulation"
|
|
112
|
+
LOGIC_ARC = "logic arc"
|
libsbgnpy/render.py
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Helper functions for rendering SBGN.
|
|
3
|
+
|
|
4
|
+
Currently uses the webservice provided at "http://sysbioapps.dyndns.org/Layout/GenerateImage".
|
|
5
|
+
For documentation see
|
|
6
|
+
http://sysbioapps.dyndns.org/Home/Services
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
import tempfile
|
|
10
|
+
from pathlib import Path
|
|
11
|
+
import requests
|
|
12
|
+
|
|
13
|
+
from libsbgnpy import utils
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
RENDER_URL = "http://sysbioapps.spdns.org/Layout"
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
def render_sbgn(sbgn, image_file: Path, file_format: str = "png") -> None:
|
|
20
|
+
"""Render given sbgn object to image.
|
|
21
|
+
|
|
22
|
+
Currently supports the following file_formats:
|
|
23
|
+
- "png"
|
|
24
|
+
The image file must end in .file_format, e.g. in '.png'
|
|
25
|
+
|
|
26
|
+
Performs a request analogue to:
|
|
27
|
+
curl -X POST -F file=@".\BorisEJB.xml" http://sysbioapps.spdns.org/Layout/GenerateImage -o out.png
|
|
28
|
+
|
|
29
|
+
:param sbgn: sbgn object
|
|
30
|
+
:param image_file: image to create
|
|
31
|
+
:return: None
|
|
32
|
+
"""
|
|
33
|
+
if file_format != "png":
|
|
34
|
+
raise ValueError("Only png rendering supported.")
|
|
35
|
+
|
|
36
|
+
if not str(image_file).endswith(f".{file_format}"):
|
|
37
|
+
raise ValueError(
|
|
38
|
+
"The filename must end in <.file_format>, e.g. for png it must end in <.png>."
|
|
39
|
+
)
|
|
40
|
+
|
|
41
|
+
# Create temporary file for request
|
|
42
|
+
with tempfile.TemporaryDirectory(ignore_cleanup_errors=True) as tmp_dir:
|
|
43
|
+
f_in: Path = Path(tmp_dir) / "render.sbgn"
|
|
44
|
+
utils.write_to_file(sbgn, f_in)
|
|
45
|
+
|
|
46
|
+
# Call webservice for rendering
|
|
47
|
+
files = [
|
|
48
|
+
("file", open(f_in, "rb")),
|
|
49
|
+
]
|
|
50
|
+
r = requests.post(f"{RENDER_URL}/GenerateImage", files=files)
|
|
51
|
+
|
|
52
|
+
r.raise_for_status()
|
|
53
|
+
|
|
54
|
+
with open(image_file, "wb") as fd:
|
|
55
|
+
for chunk in r.iter_content(chunk_size=128):
|
|
56
|
+
fd.write(chunk)
|
|
57
|
+
fd.close()
|
|
58
|
+
|
|
59
|
+
print("SBGN rendered:", image_file)
|
|
File without changes
|