Skip to content

Commit 23d3e01

Browse files
committed
properly handles gzip extensions (only adding them to out_file when compress is 'y' or 'i' or 'o', and handles echo numbers via 'echo' input
1 parent 3f76f68 commit 23d3e01

File tree

2 files changed

+45
-5
lines changed

2 files changed

+45
-5
lines changed

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@ repos:
99
- id: check-yaml
1010
- id: check-added-large-files
1111
- repo: https://github.com/psf/black
12-
rev: 19.3b0
12+
rev: 22.6.0
1313
hooks:
1414
- id: black

pydra/tasks/dcm2niix/utils.py

Lines changed: 44 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,34 @@
1-
import typing as ty
1+
import os.path
22
from pydra import ShellCommandTask
33
from pydra.engine.specs import ShellSpec, ShellOutSpec, File, Directory, SpecInfo
44

55

6+
def dcm2niix_out_file(out_dir, filename, echo, compress):
7+
# Append echo number of NIfTI echo to select is provided
8+
if echo:
9+
echo_suffix = f"_e{echo}"
10+
else:
11+
echo_suffix = ""
12+
13+
out_file = f"{out_dir}/{filename}{echo_suffix}.nii"
14+
15+
# If compressed, append the zip extension
16+
if compress in ("y", "o", "i"):
17+
out_file += ".gz"
18+
19+
return os.path.abspath(out_file)
20+
21+
22+
def dcm2niix_out_json(out_dir, filename, echo):
23+
# Append echo number of NIfTI echo to select is provided
24+
if echo:
25+
echo_suffix = f"_e{echo}"
26+
else:
27+
echo_suffix = ""
28+
29+
return os.path.abspath(f"{out_dir}/{filename}{echo_suffix}.json")
30+
31+
632
input_fields = [
733
(
834
"in_dir",
@@ -16,7 +42,7 @@
1642
),
1743
(
1844
"out_dir",
19-
str,
45+
Directory,
2046
{
2147
"argstr": "-o '{out_dir}'",
2248
"help_string": "output directory",
@@ -29,6 +55,18 @@
2955
"out_file",
3056
{"argstr": "-f '{filename}'", "help_string": "The output name for the file"},
3157
),
58+
(
59+
"echo",
60+
int,
61+
{
62+
"argstr": "",
63+
"help_string": (
64+
"The echo number to extract from the DICOM dataset. When multiple "
65+
"echoes are discovered in the dataset then dcm2niix will create "
66+
"separate files for each echo with the suffix '_e<echo-number>.nii'"
67+
),
68+
},
69+
),
3270
(
3371
"compress",
3472
str,
@@ -279,15 +317,17 @@
279317
File,
280318
{
281319
"help_string": "output NIfTI image",
282-
"output_file_template": "{out_dir}/{filename}.nii.gz",
320+
"callable": dcm2niix_out_file,
321+
"mandatory": True,
283322
},
284323
),
285324
(
286325
"out_json",
287326
File,
288327
{
289328
"help_string": "output BIDS side-car JSON",
290-
"output_file_template": "{out_dir}/{filename}.json",
329+
# "requires": [("bids", 'y')], FIXME: should be either 'y' or 'o'
330+
"callable": dcm2niix_out_json,
291331
},
292332
),
293333
(

0 commit comments

Comments
 (0)