Skip to content

Commit

Permalink
Merge pull request #788 from nipreps/fix/786-read-bids-meta
Browse files Browse the repository at this point in the history
ENH: Allow passing a ``database_path`` to create a ``BIDSLayout``
  • Loading branch information
effigies authored Mar 11, 2023
2 parents 647c895 + 996693b commit c2b8e0f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
9 changes: 8 additions & 1 deletion niworkflows/interfaces/bids.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ class _BIDSBaseInputSpec(BaseInterfaceInputSpec):
(None, Directory(exists=True)), usedefault=True, desc="optional bids directory"
)
bids_validate = traits.Bool(True, usedefault=True, desc="enable BIDS validator")
index_db = Directory(exists=True, desc="a PyBIDS layout cache directory")


class _BIDSInfoInputSpec(_BIDSBaseInputSpec):
Expand Down Expand Up @@ -832,7 +833,13 @@ def _outputs(self):
def _run_interface(self, runtime):
self.layout = self.inputs.bids_dir or self.layout
self.layout = _init_layout(
self.inputs.in_file, self.layout, self.inputs.bids_validate
self.inputs.in_file,
self.layout,
self.inputs.bids_validate,
database_path=(
self.inputs.index_db if isdefined(self.inputs.index_db)
else None
)
)

# Fill in BIDS entities of the output ("*_id")
Expand Down
8 changes: 6 additions & 2 deletions niworkflows/utils/bids.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ def get_metadata_for_nifti(in_file, bids_dir=None, validate=True):
return _init_layout(in_file, bids_dir, validate).get_metadata(str(in_file))


def _init_layout(in_file=None, bids_dir=None, validate=True):
def _init_layout(in_file=None, bids_dir=None, validate=True, database_path=None):
if isinstance(bids_dir, BIDSLayout):
return bids_dir

Expand All @@ -294,7 +294,11 @@ def _init_layout(in_file=None, bids_dir=None, validate=True):
if bids_dir is None:
raise RuntimeError("Could not infer BIDS root")

layout = BIDSLayout(str(bids_dir), validate=validate)
layout = BIDSLayout(
str(bids_dir),
validate=validate,
database_path=database_path,
)
return layout


Expand Down

0 comments on commit c2b8e0f

Please sign in to comment.