-
Notifications
You must be signed in to change notification settings - Fork 53
Description
If a dataset contains a compressed and uncompressed version of a file that will be operated on, the behavior or downstream tools may change. sMRIPrep will align and average a compressed and uncompressed T1w image, wasting time and possibly producing slightly confusing reports. In fMRIPrep, each BOLD series will get a workflow, and Nipype will crash due to duplication, as extension does not enter into the node name.
The best place to resolve this is in collect_data
:
niworkflows/niworkflows/utils/bids.py
Lines 126 to 209 in 616d2bc
def collect_data( | |
bids_dir, | |
participant_label, | |
task=None, | |
echo=None, | |
bids_validate=True, | |
bids_filters=None, | |
): | |
""" | |
Uses pybids to retrieve the input data for a given participant | |
Examples | |
-------- | |
>>> bids_root, _ = collect_data(str(datadir / 'ds054'), '100185', | |
... bids_validate=False) | |
>>> bids_root['fmap'] # doctest: +ELLIPSIS | |
['.../ds054/sub-100185/fmap/sub-100185_magnitude1.nii.gz', \ | |
'.../ds054/sub-100185/fmap/sub-100185_magnitude2.nii.gz', \ | |
'.../ds054/sub-100185/fmap/sub-100185_phasediff.nii.gz'] | |
>>> bids_root['bold'] # doctest: +ELLIPSIS | |
['.../ds054/sub-100185/func/sub-100185_task-machinegame_run-01_bold.nii.gz', \ | |
'.../ds054/sub-100185/func/sub-100185_task-machinegame_run-02_bold.nii.gz', \ | |
'.../ds054/sub-100185/func/sub-100185_task-machinegame_run-03_bold.nii.gz', \ | |
'.../ds054/sub-100185/func/sub-100185_task-machinegame_run-04_bold.nii.gz', \ | |
'.../ds054/sub-100185/func/sub-100185_task-machinegame_run-05_bold.nii.gz', \ | |
'.../ds054/sub-100185/func/sub-100185_task-machinegame_run-06_bold.nii.gz'] | |
>>> bids_root['sbref'] # doctest: +ELLIPSIS | |
['.../ds054/sub-100185/func/sub-100185_task-machinegame_run-01_sbref.nii.gz', \ | |
'.../ds054/sub-100185/func/sub-100185_task-machinegame_run-02_sbref.nii.gz', \ | |
'.../ds054/sub-100185/func/sub-100185_task-machinegame_run-03_sbref.nii.gz', \ | |
'.../ds054/sub-100185/func/sub-100185_task-machinegame_run-04_sbref.nii.gz', \ | |
'.../ds054/sub-100185/func/sub-100185_task-machinegame_run-05_sbref.nii.gz', \ | |
'.../ds054/sub-100185/func/sub-100185_task-machinegame_run-06_sbref.nii.gz'] | |
>>> bids_root['t1w'] # doctest: +ELLIPSIS | |
['.../ds054/sub-100185/anat/sub-100185_T1w.nii.gz'] | |
>>> bids_root['t2w'] # doctest: +ELLIPSIS | |
[] | |
>>> bids_root, _ = collect_data(str(datadir / 'ds051'), '01', | |
... bids_validate=False, bids_filters={'t1w':{'run': 1}}) | |
>>> bids_root['t1w'] # doctest: +ELLIPSIS | |
['.../ds051/sub-01/anat/sub-01_run-01_T1w.nii.gz'] | |
""" | |
if isinstance(bids_dir, BIDSLayout): | |
layout = bids_dir | |
else: | |
layout = BIDSLayout(str(bids_dir), validate=bids_validate) | |
queries = { | |
"fmap": {"datatype": "fmap"}, | |
"bold": {"datatype": "func", "suffix": "bold"}, | |
"sbref": {"datatype": "func", "suffix": "sbref"}, | |
"flair": {"datatype": "anat", "suffix": "FLAIR"}, | |
"t2w": {"datatype": "anat", "suffix": "T2w"}, | |
"t1w": {"datatype": "anat", "suffix": "T1w"}, | |
"roi": {"datatype": "anat", "suffix": "roi"}, | |
} | |
bids_filters = bids_filters or {} | |
for acq, entities in bids_filters.items(): | |
queries[acq].update(entities) | |
if task: | |
queries["bold"]["task"] = task | |
if echo: | |
queries["bold"]["echo"] = echo | |
subj_data = { | |
dtype: sorted( | |
layout.get( | |
return_type="file", | |
subject=participant_label, | |
extension=["nii", "nii.gz"], | |
**query, | |
) | |
) | |
for dtype, query in queries.items() | |
} | |
# Special case: multi-echo BOLD, grouping echos | |
if any(["_echo-" in bold for bold in subj_data["bold"]]): | |
subj_data["bold"] = group_multiecho(subj_data["bold"]) | |
return subj_data, layout |
When the same file is present in compressed and uncompressed form, we should raise an error rather than return both, so that each downstream tool does not have to decide how best to deal with these.
Issue discovered in nipreps/fmriprep#2396.
Activity