Last active
September 6, 2023 11:40
-
-
Save cannin/7e35f3fae274370bd0a70c7b1840c743 to your computer and use it in GitHub Desktop.
Use syblars (https://github.com/iVis-at-Bilkent/syblars) to Generate Layout and Render SBGNML to PNG using Python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{"layoutOptions": { | |
"name": "fcose", | |
"randomize": true, | |
"padding": 30 | |
}, | |
"imageOptions": { | |
"format": "png", | |
"background": "transparent", | |
"width": 1280, | |
"height": 1280, | |
"color": "bluescale" | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> | |
<sbgn xmlns="http://sbgn.org/libsbgn/0.3"> | |
<map version="http://identifiers.org/combine.specifications/sbgn.pd.level-1.version-1.3" id="map1"> | |
<glyph id="glyph9" class="macromolecule"> | |
<label text="hexokinase"/> | |
<bbox y="40.0" x="170.0" h="60.0" w="120.0"/> | |
</glyph> | |
<glyph id="glyph0" class="simple chemical"> | |
<label text="glucose"/> | |
<bbox y="140.0" x="90.0" h="60.0" w="60.0"/> | |
</glyph> | |
<glyph id="glyph6" class="simple chemical"> | |
<label text="ATP"/> | |
<clone/> | |
<bbox y="230.0" x="140.0" h="60.0" w="60.0"/> | |
</glyph> | |
<glyph id="glyph8" class="process"> | |
<bbox y="160.0" x="220.0" h="20.0" w="20.0"/> | |
<port id="glyph8.1" y="170.0" x="210.0"/> | |
<port id="glyph8.2" y="170.0" x="250.0"/> | |
</glyph> | |
<glyph id="glyph7" class="simple chemical"> | |
<label text="ADP"/> | |
<clone/> | |
<bbox y="230.0" x="270.0" h="60.0" w="60.0"/> | |
</glyph> | |
<glyph id="glyph12" class="simple chemical"> | |
<label text="ADP"/> | |
<clone/> | |
<bbox y="230.0" x="700.0" h="60.0" w="60.0"/> | |
</glyph> | |
<glyph id="glyph13" class="simple chemical"> | |
<label text="ATP"/> | |
<clone/> | |
<bbox y="230.0" x="570.0" h="60.0" w="60.0"/> | |
</glyph> | |
<glyph id="glyph1" class="simple chemical"> | |
<label text="glucose
6P"/> | |
<bbox y="140.0" x="320.0" h="60.0" w="60.0"/> | |
</glyph> | |
<glyph id="glyph2" class="simple chemical"> | |
<label text="fructose
6P"/> | |
<bbox y="140.0" x="520.0" h="60.0" w="60.0"/> | |
</glyph> | |
<glyph id="glyph15" class="macromolecule"> | |
<label text="triose-P
isomerase"/> | |
<bbox y="140.0" x="1080.0" h="60.0" w="120.0"/> | |
</glyph> | |
<glyph id="glyph3" class="simple chemical"> | |
<label text="fructose
1,6P"/> | |
<bbox y="140.0" x="730.0" h="60.0" w="60.0"/> | |
</glyph> | |
<glyph id="glyph17" class="macromolecule"> | |
<label text="glucose-6P
isomerase"/> | |
<bbox y="40.0" x="380.0" h="60.0" w="120.0"/> | |
</glyph> | |
<glyph id="glyph10" class="process"> | |
<bbox y="160.0" x="430.0" h="20.0" w="20.0"/> | |
<port id="glyph10.1" y="170.0" x="420.0"/> | |
<port id="glyph10.2" y="170.0" x="460.0"/> | |
</glyph> | |
<glyph id="glyph19" class="macromolecule"> | |
<label text="phospho
fructokinase"/> | |
<bbox y="40.0" x="600.0" h="60.0" w="120.0"/> | |
</glyph> | |
<glyph id="glyph11" class="process"> | |
<bbox y="160.0" x="650.0" h="20.0" w="20.0"/> | |
<port id="glyph11.2" y="170.0" x="680.0"/> | |
<port id="glyph11.1" y="170.0" x="640.0"/> | |
</glyph> | |
<glyph id="glyph18" class="macromolecule"> | |
<label text="adolase"/> | |
<bbox y="40.0" x="820.0" h="60.0" w="120.0"/> | |
</glyph> | |
<glyph id="glyph16" class="process"> | |
<bbox y="160.0" x="870.0" h="20.0" w="20.0"/> | |
<port id="glyph16.1" y="170.0" x="860.0"/> | |
<port id="glyph16.2" y="170.0" x="900.0"/> | |
</glyph> | |
<glyph id="glyph22" class="macromolecule"> | |
<label text="GAPDH"/> | |
<bbox y="350.0" x="1080.0" h="60.0" w="120.0"/> | |
</glyph> | |
<glyph id="glyph4" class="simple chemical"> | |
<label text="GA-3P"/> | |
<bbox y="240.0" x="960.0" h="60.0" w="60.0"/> | |
</glyph> | |
<glyph id="glyph23" class="simple chemical"> | |
<label text="Pi"/> | |
<bbox y="280.0" x="880.0" h="60.0" w="60.0"/> | |
</glyph> | |
<glyph id="glyph24" class="simple chemical"> | |
<label text="NAD"/> | |
<bbox y="280.0" x="1050.0" h="60.0" w="60.0"/> | |
</glyph> | |
<glyph id="glyph25" class="simple chemical"> | |
<label text="H+"/> | |
<bbox y="420.0" x="1050.0" h="60.0" w="60.0"/> | |
</glyph> | |
<glyph id="glyph20" orientation="vertical" class="process"> | |
<bbox y="370.0" x="980.0" h="20.0" w="20.0"/> | |
<port id="glyph20.1" y="360.0" x="990.0"/> | |
<port id="glyph20.2" y="400.0" x="990.0"/> | |
</glyph> | |
<glyph id="glyph26" class="simple chemical"> | |
<label text="NADH"/> | |
<bbox y="490.0" x="1050.0" h="60.0" w="60.0"/> | |
</glyph> | |
<glyph id="glyph35" class="macromolecule"> | |
<label text="PGK1"/> | |
<bbox y="540.0" x="820.0" h="60.0" w="120.0"/> | |
</glyph> | |
<glyph id="glyph36" class="macromolecule"> | |
<label text="PG mutase"/> | |
<bbox y="540.0" x="580.0" h="60.0" w="120.0"/> | |
</glyph> | |
<glyph id="glyph37" class="macromolecule"> | |
<label text="enolase"/> | |
<bbox y="540.0" x="350.0" h="60.0" w="120.0"/> | |
</glyph> | |
<glyph id="glyph38" class="macromolecule"> | |
<label text="pyruvate
kinase"/> | |
<bbox y="540.0" x="100.0" h="60.0" w="120.0"/> | |
</glyph> | |
<glyph id="glyph21" class="simple chemical"> | |
<label text="1,3 BPG"/> | |
<bbox y="460.0" x="960.0" h="60.0" w="60.0"/> | |
</glyph> | |
<glyph id="glyph42" class="simple chemical"> | |
<label text="ADP"/> | |
<clone/> | |
<bbox y="390.0" x="910.0" h="60.0" w="60.0"/> | |
</glyph> | |
<glyph id="glyph41" class="simple chemical"> | |
<label text="ATP"/> | |
<clone/> | |
<bbox y="390.0" x="780.0" h="60.0" w="60.0"/> | |
</glyph> | |
<glyph id="glyph31" class="process"> | |
<bbox y="480.0" x="870.0" h="20.0" w="20.0"/> | |
<port id="glyph31.2" y="490.0" x="900.0"/> | |
<port id="glyph31.1" y="490.0" x="860.0"/> | |
</glyph> | |
<glyph id="glyph27" class="simple chemical"> | |
<label text="3 PG"/> | |
<bbox y="460.0" x="720.0" h="60.0" w="60.0"/> | |
</glyph> | |
<glyph id="glyph32" class="process"> | |
<bbox y="480.0" x="630.0" h="20.0" w="20.0"/> | |
<port id="glyph32.2" y="490.0" x="660.0"/> | |
<port id="glyph32.1" y="490.0" x="620.0"/> | |
</glyph> | |
<glyph id="glyph28" class="simple chemical"> | |
<label text="2 PG"/> | |
<bbox y="460.0" x="490.0" h="60.0" w="60.0"/> | |
</glyph> | |
<glyph id="glyph43" class="simple chemical"> | |
<label text="H2O"/> | |
<bbox y="390.0" x="320.0" h="60.0" w="60.0"/> | |
</glyph> | |
<glyph id="glyph33" class="process"> | |
<bbox y="480.0" x="400.0" h="20.0" w="20.0"/> | |
<port id="glyph33.2" y="490.0" x="430.0"/> | |
<port id="glyph33.1" y="490.0" x="390.0"/> | |
</glyph> | |
<glyph id="glyph29" class="simple chemical"> | |
<label text="PEP"/> | |
<bbox y="460.0" x="270.0" h="60.0" w="60.0"/> | |
</glyph> | |
<glyph id="glyph39" class="simple chemical"> | |
<label text="ADP"/> | |
<clone/> | |
<bbox y="390.0" x="210.0" h="60.0" w="60.0"/> | |
</glyph> | |
<glyph id="glyph40" class="simple chemical"> | |
<label text="ATP"/> | |
<clone/> | |
<bbox y="390.0" x="60.0" h="60.0" w="60.0"/> | |
</glyph> | |
<glyph id="glyph34" class="process"> | |
<bbox y="480.0" x="150.0" h="20.0" w="20.0"/> | |
<port id="glyph34.2" y="490.0" x="180.0"/> | |
<port id="glyph34.1" y="490.0" x="140.0"/> | |
</glyph> | |
<glyph id="glyph30" class="simple chemical"> | |
<label text="pyruvate"/> | |
<bbox y="460.0" x="30.0" h="60.0" w="60.0"/> | |
</glyph> | |
<glyph id="glyph14" orientation="vertical" class="process"> | |
<bbox y="160.0" x="980.0" h="20.0" w="20.0"/> | |
<port id="glyph14.2" y="190.0" x="990.0"/> | |
<port id="glyph14.1" y="150.0" x="990.0"/> | |
</glyph> | |
<glyph id="glyph5" class="simple chemical"> | |
<label text="DHA-P"/> | |
<bbox y="40.0" x="960.0" h="60.0" w="60.0"/> | |
</glyph> | |
<arc target="glyph8" source="glyph9" class="catalysis" id="a01"> | |
<start y="100.0" x="230.0"/> | |
<end y="160.0" x="230.0"/> | |
</arc> | |
<arc target="glyph8.1" source="glyph0" class="consumption" id="a02"> | |
<start y="170.0" x="150.0"/> | |
<end y="170.0" x="210.0"/> | |
</arc> | |
<arc target="glyph1" source="glyph8.2" class="production" id="a03"> | |
<start y="170.0" x="250.0"/> | |
<end y="170.0" x="320.0"/> | |
</arc> | |
<arc target="glyph8.1" source="glyph6" class="consumption" id="a04"> | |
<start y="232.58565" x="182.18416"/> | |
<end y="170.0" x="210.0"/> | |
</arc> | |
<arc target="glyph7" source="glyph8.2" class="production" id="a05"> | |
<start y="170.0" x="250.0"/> | |
<end y="236.31943" x="281.5818"/> | |
</arc> | |
<arc target="glyph12" source="glyph11.2" class="production" id="a06"> | |
<start y="170.0" x="680.0"/> | |
<end y="236.31943" x="711.5818"/> | |
</arc> | |
<arc target="glyph11.1" source="glyph13" class="consumption" id="a07"> | |
<start y="232.58565" x="612.18414"/> | |
<end y="170.0" x="640.0"/> | |
</arc> | |
<arc target="glyph10.1" source="glyph1" class="consumption" id="a08"> | |
<start y="170.0" x="380.0"/> | |
<end y="170.0" x="420.0"/> | |
</arc> | |
<arc target="glyph2" source="glyph10.2" class="production" id="a09"> | |
<start y="170.0" x="460.0"/> | |
<end y="170.0" x="520.0"/> | |
</arc> | |
<arc target="glyph11.1" source="glyph2" class="consumption" id="a10"> | |
<start y="170.0" x="580.0"/> | |
<end y="170.0" x="640.0"/> | |
</arc> | |
<arc target="glyph3" source="glyph11.2" class="production" id="a11"> | |
<start y="170.0" x="680.0"/> | |
<end y="170.0" x="730.0"/> | |
</arc> | |
<arc target="glyph4" source="glyph14.2" class="production" id="a12"> | |
<start y="190.0" x="990.0"/> | |
<end y="240.0" x="990.0"/> | |
</arc> | |
<arc target="glyph14" source="glyph15" class="catalysis" id="a13"> | |
<start y="170.0" x="1080.0"/> | |
<end y="170.0" x="1000.0"/> | |
</arc> | |
<arc target="glyph16.1" source="glyph3" class="consumption" id="a14"> | |
<start y="170.0" x="790.0"/> | |
<end y="170.0" x="860.0"/> | |
</arc> | |
<arc target="glyph5" source="glyph16.2" class="production" id="a15"> | |
<start y="170.0" x="900.0"/> | |
<end y="90.18018" x="967.8018"/> | |
</arc> | |
<arc target="glyph4" source="glyph16.2" class="production" id="a16"> | |
<start y="170.0" x="900.0"/> | |
<end y="249.81981" x="967.8018"/> | |
</arc> | |
<arc target="glyph10" source="glyph17" class="catalysis" id="a17"> | |
<start y="100.0" x="440.0"/> | |
<end y="160.0" x="440.0"/> | |
</arc> | |
<arc target="glyph11" source="glyph19" class="catalysis" id="a18"> | |
<start y="100.0" x="660.0"/> | |
<end y="160.0" x="660.0"/> | |
</arc> | |
<arc target="glyph16" source="glyph18" class="catalysis" id="a19"> | |
<start y="100.0" x="880.0"/> | |
<end y="160.0" x="880.0"/> | |
</arc> | |
<arc target="glyph20" source="glyph22" class="catalysis" id="a20"> | |
<start y="380.0" x="1080.0"/> | |
<end y="380.0" x="1000.0"/> | |
</arc> | |
<arc target="glyph20.1" source="glyph4" class="consumption" id="a21"> | |
<start y="300.0" x="990.0"/> | |
<end y="360.0" x="990.0"/> | |
</arc> | |
<arc target="glyph21" source="glyph20.2" class="production" id="a22"> | |
<start y="400.0" x="990.0"/> | |
<end y="460.0" x="990.0"/> | |
</arc> | |
<arc target="glyph20.1" source="glyph23" class="consumption" id="a23"> | |
<start y="325.89996" x="935.43994"/> | |
<end y="360.0" x="990.0"/> | |
</arc> | |
<arc target="glyph20.1" source="glyph24" class="consumption" id="a24"> | |
<start y="324.56927" x="1053.7753"/> | |
<end y="360.0" x="990.0"/> | |
</arc> | |
<arc target="glyph25" source="glyph20.2" class="production" id="a25"> | |
<start y="400.0" x="990.0"/> | |
<end y="431.5818" x="1056.3195"/> | |
</arc> | |
<arc target="glyph26" source="glyph20.2" class="production" id="a26"> | |
<start y="400.0" x="990.0"/> | |
<end y="494.76465" x="1063.7772"/> | |
</arc> | |
<arc target="glyph31" source="glyph35" class="catalysis" id="a27"> | |
<start y="540.0" x="880.0"/> | |
<end y="500.0" x="880.0"/> | |
</arc> | |
<arc target="glyph32" source="glyph36" class="catalysis" id="a28"> | |
<start y="540.0" x="640.0"/> | |
<end y="500.0" x="640.0"/> | |
</arc> | |
<arc target="glyph33" source="glyph37" class="catalysis" id="a29"> | |
<start y="540.0" x="410.0"/> | |
<end y="500.0" x="410.0"/> | |
</arc> | |
<arc target="glyph34" source="glyph38" class="catalysis" id="a30"> | |
<start y="540.0" x="160.0"/> | |
<end y="500.0" x="160.0"/> | |
</arc> | |
<arc target="glyph31.2" source="glyph21" class="consumption" id="a31"> | |
<start y="490.0" x="960.0"/> | |
<end y="490.0" x="900.0"/> | |
</arc> | |
<arc target="glyph31.2" source="glyph42" class="consumption" id="a32"> | |
<start y="446.0473" x="925.11584"/> | |
<end y="490.0" x="900.0"/> | |
</arc> | |
<arc target="glyph41" source="glyph31.1" class="production" id="a33"> | |
<start y="490.0" x="860.0"/> | |
<end y="441.2132" x="831.2132"/> | |
</arc> | |
<arc target="glyph27" source="glyph31.1" class="production" id="a34"> | |
<start y="490.0" x="860.0"/> | |
<end y="490.0" x="780.0"/> | |
</arc> | |
<arc target="glyph32.2" source="glyph27" class="consumption" id="a35"> | |
<start y="490.0" x="720.0"/> | |
<end y="490.0" x="660.0"/> | |
</arc> | |
<arc target="glyph28" source="glyph32.1" class="production" id="a36"> | |
<start y="490.0" x="620.0"/> | |
<end y="490.0" x="550.0"/> | |
</arc> | |
<arc target="glyph33.2" source="glyph28" class="consumption" id="a37"> | |
<start y="490.0" x="490.0"/> | |
<end y="490.0" x="430.0"/> | |
</arc> | |
<arc target="glyph43" source="glyph33.1" class="production" id="a38"> | |
<start y="490.0" x="390.0"/> | |
<end y="442.7777" x="369.52374"/> | |
</arc> | |
<arc target="glyph29" source="glyph33.1" class="production" id="a39"> | |
<start y="490.0" x="390.0"/> | |
<end y="490.0" x="330.0"/> | |
</arc> | |
<arc target="glyph34.2" source="glyph29" class="consumption" id="a40"> | |
<start y="490.0" x="270.0"/> | |
<end y="490.0" x="180.0"/> | |
</arc> | |
<arc target="glyph34.2" source="glyph39" class="consumption" id="a41"> | |
<start y="442.7777" x="220.47626"/> | |
<end y="490.0" x="180.0"/> | |
</arc> | |
<arc target="glyph40" source="glyph34.1" class="production" id="a42"> | |
<start y="490.0" x="140.0"/> | |
<end y="441.2132" x="111.2132"/> | |
</arc> | |
<arc target="glyph30" source="glyph34.1" class="production" id="a43"> | |
<start y="490.0" x="140.0"/> | |
<end y="490.0" x="90.0"/> | |
</arc> | |
<arc target="glyph5" source="glyph14.1" class="production" id="a44"> | |
<start y="150.0" x="990.0"/> | |
<end y="100.0" x="990.0"/> | |
</arc> | |
</map> | |
</sbgn> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
import base64 | |
import json | |
import io | |
from PIL import Image | |
sbgn_path = "glycolysis.sbgn" | |
config_path = "config.json" | |
url = 'http://syblars.cs.bilkent.edu.tr/sbgnml?edges=true' | |
with open(sbgn_path, 'r') as f: | |
data_sbgn = f.read() | |
with open(config_path, 'r') as f: | |
options = f.read() | |
data = data_sbgn + options | |
with open("debug.txt", "w") as f: | |
f.write(data) | |
headers = {"Content-Type": "text/plain"} | |
res = requests.post(url, headers=headers, data=data) | |
print(res.status_code) | |
tmp = json.loads(res.text) | |
data_base64 = tmp['image'] | |
data_layout = tmp['layout'] | |
im = Image.open(io.BytesIO(base64.b64decode(data_base64.split(',')[1]))) | |
im.save("syblars.png") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
import base64 | |
import json | |
import io | |
import re | |
from PIL import Image | |
def slugify(s): | |
s = s.lower().strip() | |
s = re.sub(r'[^\w\s-]', '-', s) | |
s = re.sub(r'[\s_-]+', '-', s) | |
s = re.sub(r'^-+|-+$', '', s) | |
return s | |
# GMT file from https://www.pathwaycommons.org/archives/PC2/v12/ | |
pc_gmt_file = "PathwayCommons12.kegg.hgnc.gmt" | |
config_path = "config.json" | |
syblars_url = 'http://syblars.cs.bilkent.edu.tr/sbgnml?edges=true' | |
pc_gmt = open(pc_gmt_file, 'r') | |
lines = pc_gmt.readlines() | |
for i in range(10, 84): | |
tmp = lines[i].split('\t', 1) | |
pathway_id = tmp[0] | |
#pathway_id | |
if not pathway_id.startswith("http"): | |
continue | |
print(f'I: {str(i)}; Pathway: {pathway_id}') | |
output_file_slug = slugify(pathway_id) | |
sbgn_path = f'{output_file_slug}.sbgn' | |
png_path = f'{output_file_slug}.png' | |
#sbgn_path = "glycolysis.sbgn" | |
pc_url = f'https://www.pathwaycommons.org/pc2/get?uri={pathway_id}&format=SBGN' | |
r = requests.get(pc_url, allow_redirects=True) | |
s = r.content | |
open(sbgn_path, 'wb').write(s) | |
with open(sbgn_path, 'r') as f: | |
data_sbgn = f.read() | |
with open(config_path, 'r') as f: | |
options = f.read() | |
data = data_sbgn + options | |
with open("debug.txt", "w") as f: | |
f.write(data) | |
headers = {"Content-Type": "text/plain"} | |
res = requests.post(syblars_url, headers=headers, data=data) | |
print(res.status_code) | |
tmp = json.loads(res.text) | |
data_base64 = tmp['image'] | |
im = Image.open(io.BytesIO(base64.b64decode(data_base64.split(',')[1]))) | |
im.save(png_path) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment