-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathpretty_qpgraph.py
53 lines (40 loc) · 1.33 KB
/
pretty_qpgraph.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
43
44
45
46
47
48
49
50
51
52
53
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import graphviz
import re
# import the custom modules
from pipeline_utils import *
# import csv
# import colors from project
# with open('pop_names.csv', 'rU') as fin:
# colors = dict((line[0], line[3]) for line in csv.reader(fin))
# the base name of the dot file
basename = "permute/_final/0f3755a"
# extract the body contents from the dot file
with open(basename + '.dot', 'rU') as fin:
body = re.search("{(.+)}", fin.read(), re.DOTALL).group(1).strip().split("\n")
# make a new direct graph
dot = graphviz.Digraph(body=body)
# remove the messy graph label
dot.attr('graph', label='')
# set Node defaults
dot.node_attr['shape'] = 'point'
dot.node_attr['fontname'] = 'arial'
dot.node_attr['fontsize'] = '11'
# set Edge defaults
dot.edge_attr['arrowhead'] = 'vee'
dot.edge_attr['fontcolor'] = '#838b8b' # grey
dot.edge_attr['fontname'] = 'arial'
dot.edge_attr['fontsize'] = '11'
nodes = []
for line in dot:
# extract the leaf nodes from the body of the graph
match = re.search("^ +([a-z]+) +\[", line, re.IGNORECASE)
if match:
nodes.append(match.group(1))
# set leaf node attributes
for node in nodes:
colour = COLOURS.get(POPULATIONS.get(node), DEFAULT_COLOUR)
dot.node(node, shape='ellipse', color=colour, fontcolor=colour)
# render the graph
dot.render(basename)