|
4 | 4 | from pydra.engine.specs import ShellSpec, ShellOutSpec, File, Directory, SpecInfo |
5 | 5 |
|
6 | 6 |
|
7 | | -def out_file_path(out_dir, filename, echo, suffix, ext): |
8 | | - # Append echo number of NIfTI echo to select is provided |
9 | | - if suffix: |
10 | | - file_suffix = "_" + suffix |
11 | | - elif echo: |
12 | | - file_suffix = f"_e{echo}" |
13 | | - else: |
14 | | - file_suffix = "" |
| 7 | +def out_file_path(out_dir, filename, suffix, ext): |
| 8 | + """Attempting to handle the different suffixes that are appended to filenames |
| 9 | + created by Dcm2niix (see https://github.com/rordenlab/dcm2niix/blob/master/FILENAMING.md) |
| 10 | + """ |
15 | 11 |
|
16 | | - fpath = Path(f"{out_dir}/{filename}{file_suffix}{ext}").absolute() |
| 12 | + fpath = Path(f"{out_dir}/{filename}{suffix}{ext}").absolute() |
17 | 13 |
|
18 | 14 | # Check to see if multiple echos exist in the DICOM dataset |
19 | 15 | if not fpath.exists(): |
20 | 16 | neighbours = [str(p) for p in fpath.parent.iterdir() if p.name.endswith(ext)] |
21 | 17 | raise ValueError( |
22 | | - f"\nDid not find expected file '{fpath}' after DICOM -> NIfTI " |
23 | | - "conversion, instead found (check provided echo and suffix):\n" |
| 18 | + f"\nDid not find expected file '{fpath}' (suffix={suffix}) " |
| 19 | + "after DICOM -> NIfTI conversion, please see " |
| 20 | + "https://github.com/rordenlab/dcm2niix/blob/master/FILENAMING.md for the " |
| 21 | + "list of suffixes that dcm2niix produces and provide an appropriate " |
| 22 | + "suffix. Found the following files with matching extensions:\n" |
24 | 23 | + "\n".join(neighbours) |
25 | 24 | ) |
26 | 25 |
|
27 | 26 | return fpath |
28 | 27 |
|
29 | 28 |
|
30 | | -def dcm2niix_out_file(out_dir, filename, echo, suffix, compress): |
| 29 | +def dcm2niix_out_file(out_dir, filename, suffix, compress): |
31 | 30 |
|
32 | 31 | ext = ".nii" |
33 | 32 | # If compressed, append the zip extension |
34 | 33 | if compress in ("y", "o", "i"): |
35 | 34 | ext += ".gz" |
36 | 35 |
|
37 | | - return out_file_path(out_dir, filename, echo, suffix, ext) |
| 36 | + return out_file_path(out_dir, filename, suffix, ext) |
38 | 37 |
|
39 | 38 |
|
40 | | -def dcm2niix_out_json(out_dir, filename, echo, suffix, bids): |
| 39 | +def dcm2niix_out_json(out_dir, filename, suffix, bids): |
41 | 40 | # Append echo number of NIfTI echo to select is provided |
42 | 41 | if bids in ("y", "o"): |
43 | | - fpath = out_file_path(out_dir, filename, echo, suffix, ".json") |
| 42 | + fpath = out_file_path(out_dir, filename, suffix, ".json") |
44 | 43 | else: |
45 | 44 | fpath = attrs.NOTHING |
46 | 45 | return fpath |
@@ -72,19 +71,6 @@ def dcm2niix_out_json(out_dir, filename, echo, suffix, bids): |
72 | 71 | "out_file", |
73 | 72 | {"argstr": "-f '{filename}'", "help_string": "The output name for the file"}, |
74 | 73 | ), |
75 | | - ( |
76 | | - "echo", |
77 | | - int, |
78 | | - { |
79 | | - "argstr": "", |
80 | | - "help_string": ( |
81 | | - "The echo number to extract from the DICOM dataset. When multiple " |
82 | | - "echoes are discovered in the dataset then dcm2niix will create " |
83 | | - "separate files for each echo with the suffix '_e<echo-number>.nii'" |
84 | | - ), |
85 | | - "xor": ["suffix"], |
86 | | - }, |
87 | | - ), |
88 | 74 | ( |
89 | 75 | "suffix", |
90 | 76 | str, |
|
0 commit comments