From 1efa6cdc99dd7e754bc82a01779692f53f6767e8 Mon Sep 17 00:00:00 2001 From: "Christopher J. Markiewicz" Date: Wed, 25 Jul 2018 11:22:39 -0400 Subject: [PATCH 1/5] ENH: Exclude non-"proper" BIDS subdirectories --- nipype/interfaces/io.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/nipype/interfaces/io.py b/nipype/interfaces/io.py index 274fddcccb..b4782231cb 100644 --- a/nipype/interfaces/io.py +++ b/nipype/interfaces/io.py @@ -2828,7 +2828,8 @@ def _run_interface(self, runtime): return runtime def _list_outputs(self): - layout = gb.BIDSLayout(self.inputs.base_dir) + layout = gb.BIDSLayout(self.inputs.base_dir, + exclude=['derivatives/', 'code/', 'sourcedata/']) # If infield is not given nm input value, silently ignore filters = {} From db3b0ed8904e0b681cd395d13dd310a342d0fc8b Mon Sep 17 00:00:00 2001 From: "Christopher J. Markiewicz" Date: Wed, 25 Jul 2018 13:23:21 -0400 Subject: [PATCH 2/5] ENH: Add strict mode to BIDSDataGrabber --- nipype/interfaces/io.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/nipype/interfaces/io.py b/nipype/interfaces/io.py index b4782231cb..31828ec2cc 100644 --- a/nipype/interfaces/io.py +++ b/nipype/interfaces/io.py @@ -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): @@ -2828,8 +2830,10 @@ def _run_interface(self, runtime): return runtime def _list_outputs(self): - layout = gb.BIDSLayout(self.inputs.base_dir, - exclude=['derivatives/', 'code/', 'sourcedata/']) + 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 = {} From 4ab3437a8b0215731fa5deb238bfd5fc09d9de6a Mon Sep 17 00:00:00 2001 From: "Christopher J. Markiewicz" Date: Wed, 25 Jul 2018 13:23:50 -0400 Subject: [PATCH 3/5] FIX: BIDSDataGrabber indexing non-images --- nipype/interfaces/io.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/nipype/interfaces/io.py b/nipype/interfaces/io.py index 31828ec2cc..be3b7e36e5 100644 --- a/nipype/interfaces/io.py +++ b/nipype/interfaces/io.py @@ -2803,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: From b0b6670b1093b61767133b65ed6b481b14d35e7d Mon Sep 17 00:00:00 2001 From: "Christopher J. Markiewicz" Date: Wed, 25 Jul 2018 13:24:01 -0400 Subject: [PATCH 4/5] TEST: More resilient tests --- nipype/interfaces/tests/test_io.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/nipype/interfaces/tests/test_io.py b/nipype/interfaces/tests/test_io.py index 1eea2b31f3..abff491f36 100644 --- a/nipype/interfaces/tests/test_io.py +++ b/nipype/interfaces/tests/test_io.py @@ -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, @@ -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, From 799aacf7c86bd9ffd970728d8702f6497252a7e4 Mon Sep 17 00:00:00 2001 From: "Christopher J. Markiewicz" Date: Wed, 25 Jul 2018 16:01:52 -0400 Subject: [PATCH 5/5] FIX: Dict syntax --- nipype/interfaces/io.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/nipype/interfaces/io.py b/nipype/interfaces/io.py index be3b7e36e5..7a89675e8d 100644 --- a/nipype/interfaces/io.py +++ b/nipype/interfaces/io.py @@ -2804,8 +2804,8 @@ def __init__(self, infields=None, **kwargs): if not isdefined(self.inputs.output_query): self.inputs.output_query = { - "func": {"modality": "func", extensions=['nii', '.nii.gz']}, - "anat": {"modality": "anat", extensions=['nii', '.nii.gz']}, + "func": {"modality": "func", 'extensions': ['nii', '.nii.gz']}, + "anat": {"modality": "anat", 'extensions': ['nii', '.nii.gz']}, } # If infields is empty, use all BIDS entities