forked from rwest/RMG-Visualizer
-
Notifications
You must be signed in to change notification settings - Fork 1
/
prettyDot.py
42 lines (31 loc) · 1.25 KB
/
prettyDot.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# this version updated by RHW in November 2008
"""
make the dot file prettier
"""
import os, sys, re
StripLineLabels=True
if StripLineLabels:
print "stripping edge (line) labels"
infile=file('rxnpath.dot')
outfile=file('rxnpath2.dot','w')
# replace this:
# s10 [ fontname="Helvetica", label="C11H23J"];
# with this:
# s10 [ shapefile="mols/C11H23J.png" label="" width="1" height="1" imagescale=true fixedsize=true color="white" ];
reSize=re.compile('size=\"5,6\"\;page=\"5,6\"')
reNode=re.compile('(?P<node>s\d+)\ \[\ fontname=\"Helvetica\",\ label=\"(?P<label>[^\"]*)\"\]\;')
for line in infile:
(line,changedSize)=reSize.subn('size="12,12";page="12,12"',line)
match=reNode.search(line)
if match:
if os.path.isfile("pics/%s.png"%match.group('label')):
line='%s [ image="pics/%s.png" label="" width="0.5" height="0.5" imagescale=false fixedsize=false color="none" ];\n'%(match.group('node'),match.group('label'))
# rankdir="LR" to make graph go left>right instead of top>bottom
if StripLineLabels:
line=re.sub('label\s*=\s*\"\s*[\d.]+\"','label=""',line)
# change colours
line=re.sub('color="0.7,\ (.*?),\ 0.9"',r'color="1.0, \1, 0.7*\1"',line)
outfile.write(line)
outfile.close()
infile.close()
print "now try:\n dot -O -Tpdf rxnpath2.dot"