Skip to content

Commit

Permalink
Merge pull request #833 from nipreps/fix/bids-collect-data-dwi
Browse files Browse the repository at this point in the history
FIX: Add DWI to the default queries of BIDS querying
  • Loading branch information
oesteban authored Nov 15, 2023
2 parents 16ccaa9 + 7ddadd5 commit 81bf8f5
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 13 deletions.
1 change: 1 addition & 0 deletions niworkflows/interfaces/bids.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@ class _BIDSDataGrabberOutputSpec(TraitedSpec):
t2w = OutputMultiObject(desc="output T2w images")
flair = OutputMultiObject(desc="output FLAIR images")
pet = OutputMultiObject(desc="output PET images")
dwi = OutputMultiObject(desc="output DWI images")


class BIDSDataGrabber(SimpleInterface):
Expand Down
36 changes: 23 additions & 13 deletions niworkflows/utils/bids.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,19 @@
from packaging.version import Version


DEFAULT_BIDS_QUERIES = {
"bold": {"datatype": "func", "suffix": "bold", "part": ["mag", None]},
"dwi": {"suffix": "dwi"},
"flair": {"datatype": "anat", "suffix": "FLAIR", "part": ["mag", None]},
"fmap": {"datatype": "fmap"},
"pet": {"suffix": "pet"},
"roi": {"datatype": "anat", "suffix": "roi"},
"sbref": {"datatype": "func", "suffix": "sbref", "part": ["mag", None]},
"t1w": {"datatype": "anat", "suffix": "T1w", "part": ["mag", None]},
"t2w": {"datatype": "anat", "suffix": "T2w", "part": ["mag", None]},
}


class BIDSError(ValueError):
def __init__(self, message, bids_root):
indent = 10
Expand Down Expand Up @@ -151,11 +164,13 @@ def collect_participants(
def collect_data(
bids_dir,
participant_label,
session_id=Query.OPTIONAL,
session_id=None,
task=None,
echo=None,
group_echos=True,
bids_validate=True,
bids_filters=None,
queries=None,
):
"""
Uses pybids to retrieve the input data for a given participant
Expand Down Expand Up @@ -223,19 +238,10 @@ def collect_data(
'return_type': 'file',
'subject': participant_label,
'extension': ['.nii', '.nii.gz'],
'session': session_id,
'session': session_id or Query.OPTIONAL,
}

queries = {
"fmap": {"datatype": "fmap"},
"bold": {"datatype": "func", "suffix": "bold", "part": ["mag", None]},
"sbref": {"datatype": "func", "suffix": "sbref", "part": ["mag", None]},
"flair": {"datatype": "anat", "suffix": "FLAIR", "part": ["mag", None]},
"t2w": {"datatype": "anat", "suffix": "T2w", "part": ["mag", None]},
"t1w": {"datatype": "anat", "suffix": "T1w", "part": ["mag", None]},
"roi": {"datatype": "anat", "suffix": "roi"},
"pet": {"suffix": "pet"}
}
queries = queries or DEFAULT_BIDS_QUERIES
bids_filters = bids_filters or {}
for acq, entities in bids_filters.items():
queries[acq].update(entities)
Expand All @@ -256,7 +262,11 @@ def collect_data(
}

# Special case: multi-echo BOLD, grouping echos
if any(["_echo-" in bold for bold in subj_data["bold"]]):
if (
group_echos
and "bold" in subj_data
and any(["_echo-" in bold for bold in subj_data["bold"]])
):
subj_data["bold"] = group_multiecho(subj_data["bold"])

return subj_data, layout
Expand Down

0 comments on commit 81bf8f5

Please sign in to comment.