This notebook creates a simple model in SBGN. It models an irreversible reacton. The enzyme catalyses an irreversible metabolic process which consumes substrate S1 and produces product P1. The enzyme is a represented as a macromolecule connected to the process glyph by a catalysis arc. The substrate and the product of the biochemical reaction are represented by simple chemical glyphs. Then we renders a graphical representation and print the SBGN xml.
import libsbgnpy.libsbgn as libsbgn
from IPython.display import Image
from libsbgnpy.libsbgnTypes import ArcClass, GlyphClass, Language
from combine_notebooks import RESULTS_DIR
from libsbgnpy import render
import os
Create empty sbgn.
sbgn: libsbgn.sbgn = libsbgn.sbgn()
Create map, set language and set in sbgn.
map = libsbgn.map()
map.set_language(Language.PD)
sbgn.set_map(map)
Create four glyphs. We label three of the glyphs as S1, P1, and enzyme.
g = libsbgn.glyph(class_=GlyphClass.SIMPLE_CHEMICAL, id="glyph0")
g.set_label(libsbgn.label(text="S1"))
g.set_bbox(libsbgn.bbox(y="105.0", x="25.0", h="60.0", w="60.0"))
map.add_glyph(g)
g = libsbgn.glyph(class_=GlyphClass.MACROMOLECULE, id="glyph2")
g.set_label(libsbgn.label(text="enzyme"))
g.set_bbox(libsbgn.bbox(y="30.0", x="115.0", h="40.0", w="80.0"))
map.add_glyph(g)
g = libsbgn.glyph(class_=GlyphClass.PROCESS, id="glyph3")
g.set_bbox(libsbgn.bbox(y="123.0", x="143.0", h="24.0", w="24.0"))
g.add_port(libsbgn.port(y="135.0", x="131.0", id="glyph3.1"))
g.add_port(libsbgn.port(y="135.0", x="179.0", id="glyph3.2"))
map.add_glyph(g)
g = libsbgn.glyph(class_=GlyphClass.SIMPLE_CHEMICAL, id="glyph1")
g.set_label(libsbgn.label(text="P1"))
g.set_bbox(libsbgn.bbox(y="105.0", x="225.0", h="60.0", w="60.0"))
map.add_glyph(g)
Add three arcs linking the glyphs together.
a = libsbgn.arc(class_=ArcClass.CONSUMPTION, target="glyph3.1", source="glyph0", id="arc0")
a.set_start(libsbgn.startType(y="135.0", x="85.0"))
a.set_end(libsbgn.endType(y="135.0", x="131.0"))
map.add_arc(a)
a = libsbgn.arc(class_=ArcClass.CATALYSIS, target="glyph3", source="glyph2", id="arc1")
a.set_start(libsbgn.startType(y="70.0", x="155.0"))
a.set_end(libsbgn.endType(y="123.0", x="155.0"))
map.add_arc(a)
a = libsbgn.arc(class_=ArcClass.PRODUCTION, target="glyph1", source="glyph3.2", id="arc2")
a.set_start(libsbgn.startType(y="135.0", x="179.0"))
a.set_end(libsbgn.endType(y="135.0", x="225.0"))
map.add_arc(a)
Save SBGN model as text and then print that model.
sbgn_path = str(RESULTS_DIR) + "/hello_world_sbgn.sbgn"
os.makedirs(os.path.dirname(sbgn_path), exist_ok=True)
f_out = sbgn_path
sbgn.write_file(f_out)
xml = open(f_out).read()
print(xml)
<?xml version="1.0" encoding="UTF-8"?> <sbgn xmlns="http://sbgn.org/libsbgn/0.2"> <map language="process description"> <glyph class="simple chemical" id="glyph0"> <label text="S1"/> <bbox w="60." h="60." x="25." y="105."/> </glyph> <glyph class="macromolecule" id="glyph2"> <label text="enzyme"/> <bbox w="80." h="40." x="115." y="30."/> </glyph> <glyph class="process" id="glyph3"> <bbox w="24." h="24." x="143." y="123."/> <port id="glyph3.1" x="131." y="135."/> <port id="glyph3.2" x="179." y="135."/> </glyph> <glyph class="simple chemical" id="glyph1"> <label text="P1"/> <bbox w="60." h="60." x="225." y="105."/> </glyph> <arc class="consumption" id="arc0" source="glyph0" target="glyph3.1"> <start x="85." y="135."/> <end x="131." y="135."/> </arc> <arc class="catalysis" id="arc1" source="glyph2" target="glyph3"> <start x="155." y="70."/> <end x="155." y="123."/> </arc> <arc class="production" id="arc2" source="glyph3.2" target="glyph1"> <start x="179." y="135."/> <end x="225." y="135."/> </arc> </map> </sbgn>
Render the SBGN model.
# render SBGN
f_png: str = str(RESULTS_DIR) + '/hello_world_sbgn.png'
os.makedirs(os.path.dirname(f_png), exist_ok=True)
render.render_sbgn(sbgn, image_file=f_png, file_format="png")
Image(f_png, width=300)
SBGN rendered: /home/vboxuser/Documents/compbiolibs/combine-notebooks/results/hello_world_sbgn.png