Skip to content

FIX: Various BIDSDataGrabber fixes #2651

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

Merged
merged 5 commits into from
Jul 25, 2018
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
13 changes: 10 additions & 3 deletions nipype/interfaces/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -2755,6 +2755,8 @@ class BIDSDataGrabberInputSpec(DynamicTraitedSpec):
desc='Generate exception if list is empty '
'for a given field')
return_type = traits.Enum('file', 'namedtuple', usedefault=True)
strict = traits.Bool(desc='Return only BIDS "proper" files (e.g., '
'ignore derivatives/, sourcedata/, etc.)')


class BIDSDataGrabber(IOBase):
Expand Down Expand Up @@ -2801,8 +2803,10 @@ def __init__(self, infields=None, **kwargs):
super(BIDSDataGrabber, self).__init__(**kwargs)

if not isdefined(self.inputs.output_query):
self.inputs.output_query = {"func": {"modality": "func"},
"anat": {"modality": "anat"}}
self.inputs.output_query = {
"func": {"modality": "func", 'extensions': ['nii', '.nii.gz']},
"anat": {"modality": "anat", 'extensions': ['nii', '.nii.gz']},
}

# If infields is empty, use all BIDS entities
if infields is None and have_pybids:
Expand All @@ -2828,7 +2832,10 @@ def _run_interface(self, runtime):
return runtime

def _list_outputs(self):
layout = gb.BIDSLayout(self.inputs.base_dir)
exclude = None
if self.inputs.strict:
exclude = ['derivatives/', 'code/', 'sourcedata/']
layout = gb.BIDSLayout(self.inputs.base_dir, exclude=exclude)

# If infield is not given nm input value, silently ignore
filters = {}
Expand Down
8 changes: 4 additions & 4 deletions nipype/interfaces/tests/test_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -592,9 +592,9 @@ def test_bids_grabber(tmpdir):
bg.inputs.base_dir = os.path.join(datadir, 'ds005')
bg.inputs.subject = '01'
results = bg.run()
assert os.path.basename(results.outputs.anat[0]) == 'sub-01_T1w.nii.gz'
assert os.path.basename(results.outputs.func[0]) == (
'sub-01_task-mixedgamblestask_run-01_bold.nii.gz')
assert 'sub-01_T1w.nii.gz' in map(os.path.basename, results.outputs.anat)
assert 'sub-01_task-mixedgamblestask_run-01_bold.nii.gz' in \
map(os.path.basename, results.outputs.func)


@pytest.mark.skipif(not have_pybids,
Expand All @@ -610,7 +610,7 @@ def test_bids_fields(tmpdir):
bg.inputs.subject = '01'
bg.inputs.output_query['dwi'] = dict(modality='dwi')
results = bg.run()
assert os.path.basename(results.outputs.dwi[0]) == 'sub-01_dwi.nii.gz'
assert 'sub-01_dwi.nii.gz' in map(os.path.basename, results.outputs.dwi)


@pytest.mark.skipif(not have_pybids,
Expand Down