From 199358976b0cd2d8d2bd3001e601d368bb22c6bf Mon Sep 17 00:00:00 2001 From: mathiasg Date: Wed, 19 Jan 2022 16:05:52 -0500 Subject: [PATCH 1/3] ENH: Add optional session filter when collecting data --- niworkflows/utils/bids.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/niworkflows/utils/bids.py b/niworkflows/utils/bids.py index f452a1aa439..5ab71a311a3 100644 --- a/niworkflows/utils/bids.py +++ b/niworkflows/utils/bids.py @@ -149,6 +149,7 @@ def collect_participants( def collect_data( bids_dir, participant_label, + session_id=False, task=None, echo=None, bids_validate=True, @@ -161,6 +162,23 @@ def collect_data( >>> data_dir_canary() + Parameters + ---------- + bids_dir : :obj:`str` or :obj:`bids.layout.BIDSLayout` + The BIDS directory + participant_label : :obj:`str` + The participant identifier + session_id : :obj:`str`, None, or ``False`` + The session identifier. If ``False``, all sessions will be used (default). + task : :obj:`str` or None + The task identifier (for BOLD queries) + echo : :obj:`int` or None + The echo identifier (for BOLD queries) + bids_validate : :obj:`bool` + Whether the `bids_dir` is validated upon initialization + bids_filters: :obj:`dict` or None + Custom filters to alter default queries + Examples -------- >>> bids_root, _ = collect_data(str(datadir / 'ds054'), '100185', @@ -217,6 +235,10 @@ def collect_data( if echo: queries["bold"]["echo"] = echo + if session_id is not False: + for acq in queries.keys(): + queries[acq]["session"] = session_id + subj_data = { dtype: sorted( layout.get( From 61a1df9b21ed571f26abaafd6f895eb7437e5a3f Mon Sep 17 00:00:00 2001 From: mathiasg Date: Tue, 25 Jan 2022 11:40:06 -0500 Subject: [PATCH 2/3] ENH: Leverage pybids functionality Co-authored-by: Chris Markiewicz --- niworkflows/utils/bids.py | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/niworkflows/utils/bids.py b/niworkflows/utils/bids.py index 5ab71a311a3..967caf4bb6b 100644 --- a/niworkflows/utils/bids.py +++ b/niworkflows/utils/bids.py @@ -26,6 +26,7 @@ import re import warnings from bids import BIDSLayout +from bids.layout import Query from packaging.version import Version @@ -149,7 +150,7 @@ def collect_participants( def collect_data( bids_dir, participant_label, - session_id=False, + session_id=Query.ANY, task=None, echo=None, bids_validate=True, @@ -168,8 +169,8 @@ def collect_data( The BIDS directory participant_label : :obj:`str` The participant identifier - session_id : :obj:`str`, None, or ``False`` - The session identifier. If ``False``, all sessions will be used (default). + session_id : :obj:`str`, None, or :obj:`bids.layout.Query` + The session identifier. By default, all sessions will be used. task : :obj:`str` or None The task identifier (for BOLD queries) echo : :obj:`int` or None @@ -235,15 +236,12 @@ def collect_data( if echo: queries["bold"]["echo"] = echo - if session_id is not False: - for acq in queries.keys(): - queries[acq]["session"] = session_id - subj_data = { dtype: sorted( layout.get( return_type="file", subject=participant_label, + session=session_id, extension=[".nii", ".nii.gz"], **query, ) From 620ce082eef019269f378422ba586d844f8acbd5 Mon Sep 17 00:00:00 2001 From: mathiasg Date: Tue, 29 Mar 2022 14:35:29 -0400 Subject: [PATCH 3/3] ENH: Use less strict new Query value --- niworkflows/utils/bids.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/niworkflows/utils/bids.py b/niworkflows/utils/bids.py index 967caf4bb6b..80209688acf 100644 --- a/niworkflows/utils/bids.py +++ b/niworkflows/utils/bids.py @@ -150,7 +150,7 @@ def collect_participants( def collect_data( bids_dir, participant_label, - session_id=Query.ANY, + session_id=Query.OPTIONAL, task=None, echo=None, bids_validate=True,