Skip to content

Commit ccc15e6

Browse files
authored
Merge pull request #2651 from effigies/fix/pybids_breakage
FIX: Various BIDSDataGrabber fixes
2 parents 04cfa7a + 799aacf commit ccc15e6

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed

nipype/interfaces/io.py

+10-3
Original file line numberDiff line numberDiff line change
@@ -2755,6 +2755,8 @@ class BIDSDataGrabberInputSpec(DynamicTraitedSpec):
27552755
desc='Generate exception if list is empty '
27562756
'for a given field')
27572757
return_type = traits.Enum('file', 'namedtuple', usedefault=True)
2758+
strict = traits.Bool(desc='Return only BIDS "proper" files (e.g., '
2759+
'ignore derivatives/, sourcedata/, etc.)')
27582760

27592761

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

28032805
if not isdefined(self.inputs.output_query):
2804-
self.inputs.output_query = {"func": {"modality": "func"},
2805-
"anat": {"modality": "anat"}}
2806+
self.inputs.output_query = {
2807+
"func": {"modality": "func", 'extensions': ['nii', '.nii.gz']},
2808+
"anat": {"modality": "anat", 'extensions': ['nii', '.nii.gz']},
2809+
}
28062810

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

28302834
def _list_outputs(self):
2831-
layout = gb.BIDSLayout(self.inputs.base_dir)
2835+
exclude = None
2836+
if self.inputs.strict:
2837+
exclude = ['derivatives/', 'code/', 'sourcedata/']
2838+
layout = gb.BIDSLayout(self.inputs.base_dir, exclude=exclude)
28322839

28332840
# If infield is not given nm input value, silently ignore
28342841
filters = {}

nipype/interfaces/tests/test_io.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -592,9 +592,9 @@ def test_bids_grabber(tmpdir):
592592
bg.inputs.base_dir = os.path.join(datadir, 'ds005')
593593
bg.inputs.subject = '01'
594594
results = bg.run()
595-
assert os.path.basename(results.outputs.anat[0]) == 'sub-01_T1w.nii.gz'
596-
assert os.path.basename(results.outputs.func[0]) == (
597-
'sub-01_task-mixedgamblestask_run-01_bold.nii.gz')
595+
assert 'sub-01_T1w.nii.gz' in map(os.path.basename, results.outputs.anat)
596+
assert 'sub-01_task-mixedgamblestask_run-01_bold.nii.gz' in \
597+
map(os.path.basename, results.outputs.func)
598598

599599

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

615615

616616
@pytest.mark.skipif(not have_pybids,

0 commit comments

Comments
 (0)