Skip to content

Commit 18468d1

Browse files
authored
Merge pull request #1585 from ashgillman/allow_arbitrary_depth_graphing
Fix #1584 color graphing to loop through blue, red, green.
2 parents 877e223 + 7ee83ba commit 18468d1

File tree

3 files changed

+76
-6
lines changed

3 files changed

+76
-6
lines changed

.travis.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@ before_install:
1919
if $INSTALL_DEB_DEPENDECIES; then sudo ln -s /run/shm /dev/shm; fi &&
2020
bash <(wget -q -O- http://neuro.debian.net/_files/neurodebian-travis.sh) &&
2121
sudo apt-get -y update &&
22-
sudo apt-get -y install xvfb fusefat &&
22+
sudo apt-get -y install xvfb fusefat graphviz &&
2323
if $INSTALL_DEB_DEPENDECIES; then travis_retry sudo apt-get install -y -qq
2424
fsl afni elastix fsl-atlases; fi &&
2525
if $INSTALL_DEB_DEPENDECIES; then
2626
source /etc/fsl/fsl.sh;
27-
source /etc/afni/afni.sh;
27+
source /etc/afni/afni.sh;
2828
export FSLOUTPUTTYPE=NIFTI_GZ; fi }
2929
- travis_retry bef_inst
3030
install:

nipype/pipeline/engine/tests/test_engine.py

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -750,3 +750,70 @@ def func1(in1):
750750

751751
os.chdir(cwd)
752752
rmtree(wd)
753+
754+
755+
def test_write_graph_runs():
756+
cwd = os.getcwd()
757+
wd = mkdtemp()
758+
os.chdir(wd)
759+
760+
for graph in ('orig', 'flat', 'exec', 'hierarchical', 'colored'):
761+
for simple in (True, False):
762+
pipe = pe.Workflow(name='pipe')
763+
mod1 = pe.Node(interface=TestInterface(), name='mod1')
764+
mod2 = pe.Node(interface=TestInterface(), name='mod2')
765+
pipe.connect([(mod1, mod2, [('output1', 'input1')])])
766+
try:
767+
pipe.write_graph(graph2use=graph, simple_form=simple)
768+
except Exception:
769+
yield assert_true, False, \
770+
'Failed to plot {} {} graph'.format(
771+
'simple' if simple else 'detailed', graph)
772+
773+
yield assert_true, os.path.exists('graph.dot') or os.path.exists('graph_detailed.dot')
774+
try:
775+
os.remove('graph.dot')
776+
except OSError:
777+
pass
778+
try:
779+
os.remove('graph_detailed.dot')
780+
except OSError:
781+
pass
782+
783+
os.chdir(cwd)
784+
rmtree(wd)
785+
786+
def test_deep_nested_write_graph_runs():
787+
cwd = os.getcwd()
788+
wd = mkdtemp()
789+
os.chdir(wd)
790+
791+
for graph in ('orig', 'flat', 'exec', 'hierarchical', 'colored'):
792+
for simple in (True, False):
793+
pipe = pe.Workflow(name='pipe')
794+
parent = pipe
795+
for depth in range(10):
796+
sub = pe.Workflow(name='pipe_nest_{}'.format(depth))
797+
parent.add_nodes([sub])
798+
parent = sub
799+
mod1 = pe.Node(interface=TestInterface(), name='mod1')
800+
parent.add_nodes([mod1])
801+
try:
802+
pipe.write_graph(graph2use=graph, simple_form=simple)
803+
except Exception as e:
804+
yield assert_true, False, \
805+
'Failed to plot {} {} deep graph: {!s}'.format(
806+
'simple' if simple else 'detailed', graph, e)
807+
808+
yield assert_true, os.path.exists('graph.dot') or os.path.exists('graph_detailed.dot')
809+
try:
810+
os.remove('graph.dot')
811+
except OSError:
812+
pass
813+
try:
814+
os.remove('graph_detailed.dot')
815+
except OSError:
816+
pass
817+
818+
os.chdir(cwd)
819+
rmtree(wd)

nipype/pipeline/engine/workflows.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -902,8 +902,13 @@ def _get_dot(self, prefix=None, hierarchy=None, colored=False,
902902
prefix = ' '
903903
if hierarchy is None:
904904
hierarchy = []
905-
colorset = ['#FFFFC8', '#0000FF', '#B4B4FF', '#E6E6FF', '#FF0000',
906-
'#FFB4B4', '#FFE6E6', '#00A300', '#B4FFB4', '#E6FFE6']
905+
colorset = ['#FFFFC8', # Y
906+
'#0000FF', '#B4B4FF', '#E6E6FF', # B
907+
'#FF0000', '#FFB4B4', '#FFE6E6', # R
908+
'#00A300', '#B4FFB4', '#E6FFE6', # G
909+
'#0000FF', '#B4B4FF'] # loop B
910+
if level > len(colorset) - 2:
911+
level = 3 # Loop back to blue
907912

908913
dotlist = ['%slabel="%s";' % (prefix, self.name)]
909914
for node in nx.topological_sort(self._graph):
@@ -942,8 +947,6 @@ def _get_dot(self, prefix=None, hierarchy=None, colored=False,
942947
colored=colored,
943948
simple_form=simple_form, level=level + 3))
944949
dotlist.append('}')
945-
if level == 6:
946-
level = 2
947950
else:
948951
for subnode in self._graph.successors_iter(node):
949952
if node._hierarchy != subnode._hierarchy:

0 commit comments

Comments
 (0)