Skip to content

Commit 4c764ff

Browse files
author
mahdieh-dst
committed
Added the graph
1 parent 83d23e6 commit 4c764ff

File tree

4 files changed

+3808
-1
lines changed

4 files changed

+3808
-1
lines changed

nipype2pydra/workflow.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
import json
2+
import tempfile
3+
from pathlib import Path
4+
import subprocess as sp
25
from collections import defaultdict
36
import black
47
from nipype.interfaces.base import isdefined
@@ -82,3 +85,13 @@ def _parse_workflow_args(cls, args):
8285
)
8386
dct[name] = val
8487
return dct
88+
89+
def save_graph(self, out_path: Path, format: str = "svg", work_dir: Path = None):
90+
if work_dir is None:
91+
work_dir = tempfile.mkdtemp()
92+
work_dir = Path(work_dir)
93+
graph_dot_path = work_dir / "wf-graph.dot"
94+
self.wf.write_hierarchical_dotfile(graph_dot_path)
95+
dot_path = sp.check_output("which dot", shell=True).decode('utf-8').strip()
96+
sp.check_call(f"{dot_path} -T{format} {str(graph_dot_path)} > {str(out_path)}",
97+
shell=True)

tests/test_smriprep.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
from pathlib import Path
2+
import yaml
23
from nipype2pydra.cli import workflow
34
from nipype2pydra.utils import show_cli_trace
5+
from nipype2pydra.workflow import WorkflowConverter
46

57

6-
def test_smriprep(pkg_dir, cli_runner):
8+
def test_smriprep_conversion(pkg_dir, cli_runner):
79

810
output_dir = Path(pkg_dir) / "outputs"
911

@@ -19,3 +21,18 @@ def test_smriprep(pkg_dir, cli_runner):
1921
)
2022

2123
assert result.exit_code == 0, show_cli_trace(result)
24+
25+
26+
def test_smriprep_graph(pkg_dir, cli_runner):
27+
28+
output_dir = Path(pkg_dir) / "outputs"
29+
30+
if not output_dir.exists():
31+
output_dir.mkdir()
32+
33+
with open(f"{pkg_dir}/example-specs/smriprep.yaml") as f:
34+
spec = yaml.safe_load(f)
35+
36+
converter = WorkflowConverter(spec)
37+
38+
converter.save_graph(output_dir / "smriprep-graph.svg")

0 commit comments

Comments
 (0)