Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX] Add cropped files to dcm2niix output #3609

Merged
merged 8 commits into from
Mar 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .zenodo.json
Original file line number Diff line number Diff line change
Expand Up @@ -910,6 +910,11 @@
"name": "Anijärv, Toomas Erik",
"orcid": "0000-0002-3650-4230"
},
{
"affiliation": "Azienda Ospedaliero-Universitaria di Modena",
"name": "Genovese, Maurilio",
"orcid": "0000-0002-8154-8224"
},
{
"affiliation": "Department of Psychology, Stanford University",
"name": "Gorgolewski, Krzysztof J.",
Expand Down
14 changes: 11 additions & 3 deletions nipype/interfaces/dcm2nii.py
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,7 @@ def _parse_files(self, filenames):

for filename in filenames:
# search for relevant files, and sort accordingly
for fl in search_files(filename, outtypes):
for fl in search_files(filename, outtypes, self.inputs.crop):
if (
fl.endswith(".nii")
or fl.endswith(".gz")
Expand Down Expand Up @@ -508,7 +508,15 @@ def _list_outputs(self):


# https://stackoverflow.com/a/4829130
def search_files(prefix, outtypes):
return it.chain.from_iterable(
def search_files(prefix, outtypes, search_crop):
effigies marked this conversation as resolved.
Show resolved Hide resolved
found = it.chain.from_iterable(
iglob(glob.escape(prefix + outtype)) for outtype in outtypes
)
if search_crop:
found = it.chain(
it.chain.from_iterable(
iglob(glob.escape(prefix) + "_Crop_*" + outtype) for outtype in outtypes
),
found,
)
return found
25 changes: 18 additions & 7 deletions nipype/interfaces/tests/test_dcm2nii.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,28 @@


@pytest.mark.parametrize(
"fname, extension",
"fname, extension, search_crop",
[
("output_1", ".txt"),
("output_w_[]_meta_1", ".json"),
("output_w_**^$?_meta_2", ".txt"),
("output_1", ".txt", False),
("output_w_[]_meta_1", ".json", False),
("output_w_**^$?_meta_2", ".txt", False),
("output_cropped", ".txt", True),
],
)
def test_search_files(tmp_path, fname, extension):
def test_search_files(tmp_path, fname, extension, search_crop):
tmp_fname = fname + extension
test_file = tmp_path / tmp_fname
test_file.touch()
actual_files_list = dcm2nii.search_files(str(tmp_path / fname), [extension])
if search_crop:
tmp_cropped_fname = fname + "_Crop_1" + extension
test_cropped_file = tmp_path / tmp_cropped_fname
test_cropped_file.touch()

actual_files_list = dcm2nii.search_files(
str(tmp_path / fname), [extension], search_crop
)
for f in actual_files_list:
assert str(test_file) == f
if search_crop:
assert f in (str(test_cropped_file), str(test_file))
else:
assert str(test_file) == f