Skip to content

Commit 61c13dc

Browse files
authored
Changed cwlviewer.py to make node color dependent on operation class (#1655)
1 parent d8b36d5 commit 61c13dc

File tree

4 files changed

+108
-21
lines changed

4 files changed

+108
-21
lines changed

cwltool/cwlviewer.py

+26-4
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,21 @@ def _set_inner_edges(self) -> None:
4141
if inner_edge_row["source_label"] is not None
4242
else urlparse(inner_edge_row["source_step"]).fragment
4343
)
44+
# Node color and style depend on class
45+
source_color = (
46+
"#F3CEA1"
47+
if inner_edge_row["source_step_class"].endswith("Workflow")
48+
else "lightgoldenrodyellow"
49+
)
50+
source_style = (
51+
"dashed"
52+
if inner_edge_row["source_step_class"].endswith("Operation")
53+
else "filled"
54+
)
4455
n = pydot.Node(
4556
"",
46-
fillcolor="lightgoldenrodyellow",
47-
style="filled",
57+
fillcolor=source_color,
58+
style=source_style,
4859
label=source_label,
4960
shape="record",
5061
)
@@ -55,10 +66,21 @@ def _set_inner_edges(self) -> None:
5566
if inner_edge_row["target_label"] is not None
5667
else urlparse(inner_edge_row["target_step"]).fragment
5768
)
69+
70+
target_color = (
71+
"#F3CEA1"
72+
if inner_edge_row["target_step_class"].endswith("Workflow")
73+
else "lightgoldenrodyellow"
74+
)
75+
target_style = (
76+
"dashed"
77+
if inner_edge_row["target_step_class"].endswith("Operation")
78+
else "filled"
79+
)
5880
n = pydot.Node(
5981
"",
60-
fillcolor="lightgoldenrodyellow",
61-
style="filled",
82+
fillcolor=target_color,
83+
style=target_style,
6284
label=target_label,
6385
shape="record",
6486
)

cwltool/rdfqueries/get_inner_edges.sparql

+3-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
3131
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
3232

3333
# GET EDGES
34-
SELECT DISTINCT ?source_label ?target_label ?source_step ?target_step ?target_ref_input ?output_ref ?workflow
34+
SELECT DISTINCT ?source_label ?target_label ?source_step ?target_step ?target_ref_input ?output_ref ?workflow ?target_step_class ?source_step_class
3535
WHERE {
3636
?workflow Workflow:steps ?step .
3737
{
@@ -43,6 +43,8 @@ WHERE {
4343
?target_step cwl:run ?target_step_node .
4444
OPTIONAL {?source_step_node rdfs:label ?source_label} .
4545
OPTIONAL {?target_step_node rdfs:label ?target_label} .
46+
?target_step_node a ?target_step_class .
47+
?source_step_node a ?source_step_class .
4648
} .
4749
# root_graph is binded in python
4850
FILTER(?workflow = ?root_graph) .

tests/test_examples.py

+20-16
Original file line numberDiff line numberDiff line change
@@ -1008,7 +1008,7 @@ def test_var_spool_cwl_checker3() -> None:
10081008

10091009
def test_print_dot() -> None:
10101010
# print Workflow
1011-
cwl_path = get_data("tests/wf/revsort.cwl")
1011+
cwl_path = get_data("tests/wf/three_step_color.cwl")
10121012
expected_dot = pydot.graph_from_dot_data(
10131013
"""
10141014
digraph {{
@@ -1022,11 +1022,8 @@ def test_print_dot() -> None:
10221022
rank=same,
10231023
style=dashed
10241024
];
1025-
"workflow_input" [fillcolor="#94DDF4",
1026-
label=workflow_input,
1027-
style=filled];
1028-
"reverse_sort" [fillcolor="#94DDF4",
1029-
label=reverse_sort,
1025+
"file_input" [fillcolor="#94DDF4",
1026+
label=file_input,
10301027
style=filled];
10311028
}}
10321029
subgraph cluster_outputs {{
@@ -1035,20 +1032,27 @@ def test_print_dot() -> None:
10351032
rank=same,
10361033
style=dashed
10371034
];
1038-
"sorted_output" [fillcolor="#94DDF4",
1039-
label=sorted_output,
1035+
"file_output" [fillcolor="#94DDF4",
1036+
label=file_output,
1037+
style=filled];
1038+
"string_output" [fillcolor="#94DDF4",
1039+
label=string_output,
10401040
style=filled];
10411041
}}
1042-
"rev" [fillcolor=lightgoldenrodyellow,
1043-
label=rev,
1042+
"nested_workflow" [fillcolor="#F3CEA1",
1043+
label=nested_workflow,
10441044
style=filled];
1045-
"sorted" [fillcolor=lightgoldenrodyellow,
1046-
label=sorted,
1045+
"operation" [fillcolor=lightgoldenrodyellow,
1046+
label=operation,
1047+
style=dashed];
1048+
"command_line_tool" [fillcolor=lightgoldenrodyellow,
1049+
label=command_line_tool,
10471050
style=filled];
1048-
"rev" -> "sorted";
1049-
"sorted" -> "sorted_output";
1050-
"workflow_input" -> "rev";
1051-
"reverse_sort" -> "sorted";
1051+
"file_input" -> "nested_workflow";
1052+
"nested_workflow" -> "operation";
1053+
"operation" -> "command_line_tool";
1054+
"operation" -> "string_output";
1055+
"command_line_tool" -> "file_output";
10521056
}}
10531057
""".format()
10541058
)[0]

tests/wf/three_step_color.cwl

+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
#!/usr/bin/env cwl-runner
2+
3+
cwlVersion: v1.2
4+
class: Workflow
5+
6+
requirements:
7+
SubworkflowFeatureRequirement: {}
8+
9+
inputs:
10+
file_input: File
11+
12+
outputs:
13+
string_output:
14+
type: string
15+
outputSource: operation/operation_output
16+
file_output:
17+
type: File
18+
outputSource: command_line_tool/out_file
19+
20+
steps:
21+
nested_workflow:
22+
label: "workflow"
23+
run: 1st-workflow.cwl
24+
in:
25+
inp: file_input
26+
ex:
27+
default: "Hello.java"
28+
out: [ classout ]
29+
operation:
30+
label: "Operation"
31+
in:
32+
operation_input: nested_workflow/classout
33+
out:
34+
[operation_output]
35+
run:
36+
class: Operation
37+
inputs:
38+
operation_input: File
39+
outputs:
40+
operation_output: string
41+
command_line_tool:
42+
in:
43+
clt_input: operation/operation_output
44+
out: [ out_file ]
45+
run:
46+
class: CommandLineTool
47+
baseCommand: echo
48+
arguments:
49+
- $(inputs.clt_input)
50+
- ">"
51+
- "output.txt"
52+
inputs:
53+
clt_input:
54+
type: string
55+
outputs:
56+
out_file:
57+
type: File
58+
outputBinding:
59+
glob: "output.txt"

0 commit comments

Comments
 (0)