Skip to content

Commit

Permalink
Merge pull request #7 from tclose/arbitrary-suffixes
Browse files Browse the repository at this point in the history
I'm going to merge this for now, as I need to make a release with these changes. We could come back and revisit whether this is the best way to handle this later perhaps
  • Loading branch information
tclose authored Aug 2, 2022
2 parents dcab68b + 61aee20 commit c5b6621
Showing 1 changed file with 42 additions and 8 deletions.
50 changes: 42 additions & 8 deletions pydra/tasks/dcm2niix/utils.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,40 @@
import os.path
from pathlib import Path
from pydra import ShellCommandTask
from pydra.engine.specs import ShellSpec, ShellOutSpec, File, Directory, SpecInfo


def dcm2niix_out_file(out_dir, filename, echo, compress):
def dcm2niix_out_file(out_dir, filename, echo, suffix, compress):
# Append echo number of NIfTI echo to select is provided
if echo:
echo_suffix = f"_e{echo}"
if suffix:
file_suffix = "_" + suffix
elif echo:
file_suffix = f"_e{echo}"
else:
echo_suffix = ""
file_suffix = ""

out_file = f"{out_dir}/{filename}{echo_suffix}.nii"
out_file = f"{out_dir}/{filename}{file_suffix}.nii"

# If compressed, append the zip extension
if compress in ("y", "o", "i"):
out_file += ".gz"

return os.path.abspath(out_file)
out_file = Path(out_file).absolute()

# Check to see if multiple echos exist in the DICOM dataset
if not out_file.exists():
echoes = [
str(p)
for p in out_file.parent.iterdir()
if p.stem.startswith(filename + "_e")
]
if echoes:
raise ValueError(
"DICOM dataset contains multiple echos, please specify which "
"echo you want via the 'echo' input:\n"
"\n".join(echoes)
)

return out_file


def dcm2niix_out_json(out_dir, filename, echo):
Expand All @@ -26,7 +44,7 @@ def dcm2niix_out_json(out_dir, filename, echo):
else:
echo_suffix = ""

return os.path.abspath(f"{out_dir}/{filename}{echo_suffix}.json")
return Path(f"{out_dir}/{filename}{echo_suffix}.json").absolute()


input_fields = [
Expand Down Expand Up @@ -65,6 +83,22 @@ def dcm2niix_out_json(out_dir, filename, echo):
"echoes are discovered in the dataset then dcm2niix will create "
"separate files for each echo with the suffix '_e<echo-number>.nii'"
),
"xor": ["suffix"],
},
),
(
"suffix",
str,
{
"argstr": "",
"help_string": (
"A suffix to append to the out_file, used to select which "
"of the disambiguated outputs to return (see https://github.com/"
"rordenlab/dcm2niix/blob/master/FILENAMING.md"
"#file-name-post-fixes-image-disambiguation) "
),
"xor": ["echo"],
"allowed_values": ["Eq", "ph", "imaginary", "MoCo", "real", "phMag"],
},
),
(
Expand Down

0 comments on commit c5b6621

Please sign in to comment.