1
- import os . path
1
+ from pathlib import Path
2
2
from pydra import ShellCommandTask
3
3
from pydra .engine .specs import ShellSpec , ShellOutSpec , File , Directory , SpecInfo
4
4
5
5
6
- def dcm2niix_out_file (out_dir , filename , echo , compress ):
6
+ def dcm2niix_out_file (out_dir , filename , echo , suffix , compress ):
7
7
# Append echo number of NIfTI echo to select is provided
8
- if echo :
9
- echo_suffix = f"_e{ echo } "
8
+ if suffix :
9
+ file_suffix = "_" + suffix
10
+ elif echo :
11
+ file_suffix = f"_e{ echo } "
10
12
else :
11
- echo_suffix = ""
13
+ file_suffix = ""
12
14
13
- out_file = f"{ out_dir } /{ filename } { echo_suffix } .nii"
15
+ out_file = f"{ out_dir } /{ filename } { file_suffix } .nii"
14
16
15
17
# If compressed, append the zip extension
16
18
if compress in ("y" , "o" , "i" ):
17
19
out_file += ".gz"
18
20
19
- return os .path .abspath (out_file )
21
+ out_file = Path (out_file ).absolute ()
22
+
23
+ # Check to see if multiple echos exist in the DICOM dataset
24
+ if not out_file .exists ():
25
+ echoes = [
26
+ str (p )
27
+ for p in out_file .parent .iterdir ()
28
+ if p .stem .startswith (filename + "_e" )
29
+ ]
30
+ if echoes :
31
+ raise ValueError (
32
+ "DICOM dataset contains multiple echos, please specify which "
33
+ "echo you want via the 'echo' input:\n "
34
+ "\n " .join (echoes )
35
+ )
36
+
37
+ return out_file
20
38
21
39
22
40
def dcm2niix_out_json (out_dir , filename , echo ):
@@ -26,7 +44,7 @@ def dcm2niix_out_json(out_dir, filename, echo):
26
44
else :
27
45
echo_suffix = ""
28
46
29
- return os . path . abspath (f"{ out_dir } /{ filename } { echo_suffix } .json" )
47
+ return Path (f"{ out_dir } /{ filename } { echo_suffix } .json" ). absolute ( )
30
48
31
49
32
50
input_fields = [
@@ -65,6 +83,22 @@ def dcm2niix_out_json(out_dir, filename, echo):
65
83
"echoes are discovered in the dataset then dcm2niix will create "
66
84
"separate files for each echo with the suffix '_e<echo-number>.nii'"
67
85
),
86
+ "xor" : ["suffix" ],
87
+ },
88
+ ),
89
+ (
90
+ "suffix" ,
91
+ str ,
92
+ {
93
+ "argstr" : "" ,
94
+ "help_string" : (
95
+ "A suffix to append to the out_file, used to select which "
96
+ "of the disambiguated outputs to return (see https://github.com/"
97
+ "rordenlab/dcm2niix/blob/master/FILENAMING.md"
98
+ "#file-name-post-fixes-image-disambiguation) "
99
+ ),
100
+ "xor" : ["echo" ],
101
+ "allowed_values" : ["Eq" , "ph" , "imaginary" , "MoCo" , "real" , "phMag" ],
68
102
},
69
103
),
70
104
(
0 commit comments