Skip to content

[ENH] add option to include derivatives in BIDSDataGrabber #2815

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

Closed
wants to merge 4 commits into from
Closed
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
24 changes: 23 additions & 1 deletion nipype/interfaces/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import tempfile
from os.path import join, dirname
from warnings import warn
from packaging import version

from .. import config, logging
from ..utils.filemanip import (
Expand Down Expand Up @@ -2733,6 +2734,10 @@ class BIDSDataGrabberInputSpec(DynamicTraitedSpec):
return_type = traits.Enum('file', 'namedtuple', usedefault=True)
strict = traits.Bool(desc='Return only BIDS "proper" files (e.g., '
'ignore derivatives/, sourcedata/, etc.)')
domains = traits.Either(None, traits.List(),
usedefault=True,
desc='(Optional): Pass list of domains '
'(e.g. ["bids", "derivatives"]) for file searching.')


class BIDSDataGrabber(LibraryBaseInterface, IOBase):
Expand Down Expand Up @@ -2808,14 +2813,31 @@ def __init__(self, infields=None, **kwargs):

def _list_outputs(self):
# Version resilience
import bids
from packaging import version
try:
from bids import BIDSLayout
except ImportError:
from bids.grabbids import BIDSLayout

pybids_ver = version.parse(bids.__version__)
exclude = None
if self.inputs.strict:
exclude = ['derivatives/', 'code/', 'sourcedata/']
layout = BIDSLayout(self.inputs.base_dir, exclude=exclude)

if pybids_ver < version.parse('0.5'):
Copy link
Contributor

@adelavega adelavega Dec 14, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe you can include something like this in my PR? My PR is more general update to 0.7, and includes some extra functionality / updates, in addition to allowing for derivatives. I just hadn't merged because I'm waiting for pybids 0.7 release.

Copy link
Contributor

@adelavega adelavega Dec 14, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Although now that I think about it, I wouldn't worry too much about backwards compatibility. I would make 0.7 the hard requirement. The default behavior of my PR is to only look in the core BIDS folder, but you can optionally ask it to look in /derivatives or add extra paths.

raise ImportError("pybids must be >= 0.5, "
"installed version: {ver}".format(ver=pybids_ver))
elif pybids_ver >= version.parse('0.5') and pybids_ver < version.parse('0.6'):
layout = BIDSLayout(self.inputs.base_dir,
config=self.inputs.domains,
exclude=exclude)
else:
# pybids >= 0.6.0
if self.inputs.domains is None:
self.inputs.domains = ['bids']
layout = BIDSLayout((self.inputs.base_dir, self.inputs.domains),
exclude=exclude)

# If infield is not given nm input value, silently ignore
filters = {}
Expand Down
1 change: 1 addition & 0 deletions nipype/interfaces/tests/test_auto_BIDSDataGrabber.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
def test_BIDSDataGrabber_inputs():
input_map = dict(
base_dir=dict(mandatory=True, ),
domains=dict(usedefault=True, ),
output_query=dict(),
raise_on_empty=dict(usedefault=True, ),
return_type=dict(usedefault=True, ),
Expand Down