Skip to content

Commit dd8626a

Browse files
committed
Merge branch 'pr/854'
Conflicts: CHANGES
2 parents 419494d + 4dd703f commit dd8626a

File tree

2 files changed

+31
-17
lines changed

2 files changed

+31
-17
lines changed

CHANGES

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ Next Release
55
* ENH: New ANTs interface: ApplyTransformsToPoints
66
* ENH: New FreeSurfer workflow: create_skullstripped_recon_flow()
77
* ENH: New data grabbing interface that works over SSH connections, SSHDataGrabber
8+
* ENH: New color mode for write_graph
89
* FIX: MRTrix tracking algorithms were ignoring mask parameters.
910

1011
Release 0.9.2 (January 31, 2014)

nipype/pipeline/engine.py

Lines changed: 30 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -505,10 +505,14 @@ def write_graph(self, dotfilename='graph.dot', graph2use='hierarchical',
505505
Parameters
506506
----------
507507
508-
graph2use: 'orig', 'hierarchical' (default), 'flat', 'exec'
508+
graph2use: 'orig', 'hierarchical' (default), 'flat', 'exec', 'colored'
509509
orig - creates a top level graph without expanding internal
510510
workflow nodes;
511511
flat - expands workflow nodes recursively;
512+
hierarchical - expands workflow nodes recursively with a
513+
notion on hierarchy;
514+
colored - expands workflow nodes recursively with a
515+
notion on hierarchy in color;
512516
exec - expands workflows to depict iterables
513517
514518
format: 'png', 'svg'
@@ -519,7 +523,7 @@ def write_graph(self, dotfilename='graph.dot', graph2use='hierarchical',
519523
False.
520524
521525
"""
522-
graphtypes = ['orig', 'flat', 'hierarchical', 'exec']
526+
graphtypes = ['orig', 'flat', 'hierarchical', 'exec', 'colored']
523527
if graph2use not in graphtypes:
524528
raise ValueError('Unknown graph2use keyword. Must be one of: ' +
525529
str(graphtypes))
@@ -532,10 +536,10 @@ def write_graph(self, dotfilename='graph.dot', graph2use='hierarchical',
532536
else:
533537
base_dir = os.getcwd()
534538
base_dir = make_output_dir(base_dir)
535-
if graph2use == 'hierarchical':
539+
if graph2use in ['hierarchical', 'colored']:
536540
dotfilename = os.path.join(base_dir, dotfilename)
537541
self.write_hierarchical_dotfile(dotfilename=dotfilename,
538-
colored=False,
542+
colored=graph2use == "colored",
539543
simple_form=simple_form)
540544
format_dot(dotfilename, format=format)
541545
else:
@@ -547,11 +551,9 @@ def write_graph(self, dotfilename='graph.dot', graph2use='hierarchical',
547551
export_graph(graph, base_dir, dotfilename=dotfilename,
548552
format=format, simple_form=simple_form)
549553

550-
def write_hierarchical_dotfile(self, dotfilename=None, colored=True,
554+
def write_hierarchical_dotfile(self, dotfilename=None, colored=False,
551555
simple_form=True):
552556
dotlist = ['digraph %s{' % self.name]
553-
if colored:
554-
dotlist.append(' ' + 'colorscheme=pastel28;')
555557
dotlist.append(self._get_dot(prefix=' ', colored=colored,
556558
simple_form=simple_form))
557559
dotlist.append('}')
@@ -1007,18 +1009,18 @@ def _generate_flatgraph(self):
10071009
self._graph.remove_nodes_from(nodes2remove)
10081010
logger.debug('finished expanding workflow: %s', self)
10091011

1010-
def _get_dot(self, prefix=None, hierarchy=None, colored=True,
1011-
simple_form=True):
1012+
def _get_dot(self, prefix=None, hierarchy=None, colored=False,
1013+
simple_form=True, level=0):
10121014
"""Create a dot file with connection info
10131015
"""
10141016
if prefix is None:
10151017
prefix = ' '
10161018
if hierarchy is None:
10171019
hierarchy = []
1018-
level = (len(prefix) / 2) + 1
1020+
colorset = ['#FFFFC8','#0000FF','#B4B4FF','#E6E6FF','#FF0000',
1021+
'#FFB4B4','#FFE6E6','#00A300','#B4FFB4','#E6FFE6']
1022+
10191023
dotlist = ['%slabel="%s";' % (prefix, self.name)]
1020-
if colored:
1021-
dotlist.append('%scolor=%d;' % (prefix, level))
10221024
for node in nx.topological_sort(self._graph):
10231025
fullname = '.'.join(hierarchy + [node.fullname])
10241026
nodename = fullname.replace('.', '_')
@@ -1027,24 +1029,35 @@ def _get_dot(self, prefix=None, hierarchy=None, colored=True,
10271029
if not simple_form:
10281030
node_class_name = '.'.join(node_class_name.split('.')[1:])
10291031
if hasattr(node, 'iterables') and node.iterables:
1030-
dotlist.append(('%s[label="%s", style=filled, colorscheme'
1031-
'=greys7 color=2];') % (nodename,
1032+
dotlist.append(('%s[label="%s", shape=box3d,'
1033+
'style=filled, color=black, colorscheme'
1034+
'=greys7 fillcolor=2];') % (nodename,
10321035
node_class_name))
10331036
else:
1034-
dotlist.append('%s[label="%s"];' % (nodename,
1035-
node_class_name))
1037+
if colored:
1038+
dotlist.append(('%s[label="%s", style=filled,'
1039+
' fillcolor="%s"];')
1040+
% (nodename,node_class_name,
1041+
colorset[level]))
1042+
else:
1043+
dotlist.append(('%s[label="%s"];')
1044+
% (nodename,node_class_name))
1045+
10361046
for node in nx.topological_sort(self._graph):
10371047
if isinstance(node, Workflow):
10381048
fullname = '.'.join(hierarchy + [node.fullname])
10391049
nodename = fullname.replace('.', '_')
10401050
dotlist.append('subgraph cluster_%s {' % nodename)
10411051
if colored:
1052+
dotlist.append(prefix + prefix + 'edge [color="%s"];' % (colorset[level+1]))
10421053
dotlist.append(prefix + prefix + 'style=filled;')
1054+
dotlist.append(prefix + prefix + 'fillcolor="%s";' % (colorset[level+2]))
10431055
dotlist.append(node._get_dot(prefix=prefix + prefix,
10441056
hierarchy=hierarchy + [self.name],
10451057
colored=colored,
1046-
simple_form=simple_form))
1058+
simple_form=simple_form, level=level+3))
10471059
dotlist.append('}')
1060+
if level==6:level=2
10481061
else:
10491062
for subnode in self._graph.successors_iter(node):
10501063
if node._hierarchy != subnode._hierarchy:

0 commit comments

Comments
 (0)