From 7ae2ed6353c22428ca20e780d3c53c9e055fdec5 Mon Sep 17 00:00:00 2001 From: WillForan Date: Sat, 28 Oct 2023 20:13:55 -0400 Subject: [PATCH 01/12] [BUG] only one el in BIDS.participants.meta --- spm_BIDS_App.m | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/spm_BIDS_App.m b/spm_BIDS_App.m index f5af1bc..6665588 100644 --- a/spm_BIDS_App.m +++ b/spm_BIDS_App.m @@ -260,7 +260,13 @@ if ~isempty(BIDS.participants) idx = ismember(BIDS.participants.participant_id,BIDS_App.participants); for fn=fieldnames(BIDS.participants)' - BIDS.participants.(char(fn)) = BIDS.participants.(char(fn))(idx); + replace = BIDS.participants.(char(fn)); + % BIDS.participants.meta is 1x1. other fields are 1xN + if(length(replace) < length(idx)) + warning('%s: idx len %d > number of values %d; ignored', char(fn), length(idx), length(replace)) + continue + end + BIDS.participants.(char(fn)) = replace(idx); end end From cabf8a03b91ac7901ea7f9f5bc7010e1fbd8861d Mon Sep 17 00:00:00 2001 From: WillForan Date: Sat, 28 Oct 2023 21:44:58 -0400 Subject: [PATCH 02/12] [WIP] narrow_participants.m and test, run before copy --- narrow_participants.m | 25 +++++++++++++++++++++++++ spm_BIDS_App.m | 20 +++----------------- test_narrow_participants.m | 30 ++++++++++++++++++++++++++++++ 3 files changed, 58 insertions(+), 17 deletions(-) create mode 100644 narrow_participants.m create mode 100644 test_narrow_participants.m diff --git a/narrow_participants.m b/narrow_participants.m new file mode 100644 index 0000000..01f9bcd --- /dev/null +++ b/narrow_participants.m @@ -0,0 +1,25 @@ +function BIDS = narrow_participants(BIDS, labels) +% NARROW_PARTICIPANTS - restrict BIDS struct to only requested labels +% + +% nothing to do if no labels to change? +if isempty(labels) + return +end + +idx = ismember({BIDS.subjects.name},labels); +BIDS.subjects = BIDS.subjects(idx); + +idx = ismember(BIDS.participants.participant_id,labels); +for fn=fieldnames(BIDS.participants)' + replace = BIDS.participants.(char(fn)); + % BIDS.participants.meta is 1x1. other fields are 1xN + if(length(replace) < length(idx)) + warning('BIDS participants field "%s" too short: ID idx len %d > number of field values %d; ignored', ... + char(fn), length(idx), length(replace)) + continue + end + BIDS.participants.(char(fn)) = replace(idx); +end + +end diff --git a/spm_BIDS_App.m b/spm_BIDS_App.m index 6665588..d83f038 100644 --- a/spm_BIDS_App.m +++ b/spm_BIDS_App.m @@ -201,6 +201,9 @@ spm('defaults','fmri'); spm_jobman('initcfg'); +% if we used --participant_label PARTICIPANT_LABEL [PARTICIPANT_LABEL ...] +BIDS = narrow_participants(BIDS, BIDS_App.participants); + %========================================================================== %-(Temporary) Copy of input data and uncompress image files %========================================================================== @@ -253,23 +256,6 @@ BIDS = spm_changepath(BIDS,'.nii.gz','.nii',false); end -%-Simplify BIDS structure to only contain participants under study -%-------------------------------------------------------------------------- -idx = ismember({BIDS.subjects.name},BIDS_App.participants); -BIDS.subjects = BIDS.subjects(idx); -if ~isempty(BIDS.participants) - idx = ismember(BIDS.participants.participant_id,BIDS_App.participants); - for fn=fieldnames(BIDS.participants)' - replace = BIDS.participants.(char(fn)); - % BIDS.participants.meta is 1x1. other fields are 1xN - if(length(replace) < length(idx)) - warning('%s: idx len %d > number of values %d; ignored', char(fn), length(idx), length(replace)) - continue - end - BIDS.participants.(char(fn)) = replace(idx); - end -end - %========================================================================== %-Analysis level: participant* %========================================================================== diff --git a/test_narrow_participants.m b/test_narrow_participants.m new file mode 100644 index 0000000..58049f6 --- /dev/null +++ b/test_narrow_participants.m @@ -0,0 +1,30 @@ +% +% script based testing for narrow_participants +% participants.json adds a 'meta' field that can be avoided when selecting only some participants +% + +bids_dir = [tempname '_bids_test']; +try + % build minimal BIDS filesystem: participants.json and 1 anat file pair + system(['mkdir -p ' bids_dir '/sub-{a,b}/ses-{1,2}/anat/']); + system([ 'touch ' bids_dir '/sub-{a,b}/ses-{1,2}/anat/T1.{json,nii.gz}']); + system(['echo -e ''participant_id\nsub-a\nsub-a\nsub-b\nsub-b'' > ' bids_dir '/participants.tsv']); + system(['echo ''{ "Name": "test", "BIDSVersion": "1.4.1"}'' > ' bids_dir '/dataset_description.json']); + system(['echo ''{ "age": { "Description": "xyz" } }'' > ' bids_dir '/participants.json']); + + % get what we built -- matches expectations + BIDS = spm_BIDS(bids_dir); + assert(length(BIDS.participants.participant_id) == 4) + + % narrowing works + BIDS_narrow = narrow_participants(BIDS, {'sub-a'}) + assert(length(BIDS_narrow.participants.participant_id) == 2) + + % no change on empty + BIDS_nochange = narrow_participants(BIDS, {}); % TODO: {{}}? + assert(length(BIDS_nochange.participants.participant_id) == 4) + +catch me + rmdir(bids_dir,'s') + rethrow(me) +end From a73da7c11f7a3a19d1fee636b8085d52524a5735 Mon Sep 17 00:00:00 2001 From: Remi Gau Date: Wed, 8 Nov 2023 13:39:06 +0100 Subject: [PATCH 03/12] Update narrow_participants.m --- narrow_participants.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/narrow_participants.m b/narrow_participants.m index 01f9bcd..d952e99 100644 --- a/narrow_participants.m +++ b/narrow_participants.m @@ -1,6 +1,6 @@ function BIDS = narrow_participants(BIDS, labels) % NARROW_PARTICIPANTS - restrict BIDS struct to only requested labels -% +% % nothing to do if no labels to change? if isempty(labels) From a79effcec0f23c3bd601782223b94ed63fd09bd9 Mon Sep 17 00:00:00 2001 From: WillForan Date: Mon, 2 Feb 2026 17:22:31 -0500 Subject: [PATCH 04/12] fix(narrow): skip participant field if empty --- Dockerfile | 2 +- narrow_participants.m | 27 +++++++++++++++++---------- 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/Dockerfile b/Dockerfile index 802be5d..31ad3a9 100644 --- a/Dockerfile +++ b/Dockerfile @@ -38,7 +38,7 @@ RUN wget --progress=dot:giga -P /opt https://www.fil.ion.ucl.ac.uk/spm/download/ ${SPM_EXEC} function exit # Configure SPM BIDS App entry point -COPY run.sh spm_BIDS_App.m pipeline_participant.m pipeline_group.m /opt/spm${SPM_VERSION}/ +COPY run.sh spm_BIDS_App.m pipeline_participant.m narrow_participants.m pipeline_group.m /opt/spm${SPM_VERSION}/ RUN chmod +x /opt/spm${SPM_VERSION}/run.sh && \ chmod +x /opt/spm${SPM_VERSION}/spm${SPM_VERSION} && \ chmod +x /opt/spm${SPM_VERSION}/run_spm12.sh diff --git a/narrow_participants.m b/narrow_participants.m index d952e99..99f6175 100644 --- a/narrow_participants.m +++ b/narrow_participants.m @@ -10,16 +10,23 @@ idx = ismember({BIDS.subjects.name},labels); BIDS.subjects = BIDS.subjects(idx); -idx = ismember(BIDS.participants.participant_id,labels); -for fn=fieldnames(BIDS.participants)' - replace = BIDS.participants.(char(fn)); - % BIDS.participants.meta is 1x1. other fields are 1xN - if(length(replace) < length(idx)) - warning('BIDS participants field "%s" too short: ID idx len %d > number of field values %d; ignored', ... - char(fn), length(idx), length(replace)) - continue - end - BIDS.participants.(char(fn)) = replace(idx); +if isempty(BIDS.participants) + warning('no participants information. missing participants.csv?') +else + if ~ismember(fieldnames(BIDS.participants), 'participant_id') + error('participants.tsv does not contain a participant_id column') + end + idx = ismember(BIDS.participants.participant_id, labels); + for fn=fieldnames(BIDS.participants)' + replace = BIDS.participants.(char(fn)); + % BIDS.participants.meta is 1x1. other fields are 1xN + if(length(replace) < length(idx)) + warning('BIDS participants field "%s" too short: ID idx len %d > number of field values %d; ignored', ... + char(fn), length(idx), length(replace)) + continue + end + BIDS.participants.(char(fn)) = replace(idx); + end end end From 0405e6cfc58068ef1f88fd8d5409a0f007262d78 Mon Sep 17 00:00:00 2001 From: WillForan Date: Mon, 2 Feb 2026 17:24:41 -0500 Subject: [PATCH 05/12] fix(Dockerfile): track narrow_participants.m --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 31ad3a9..cfd38d1 100644 --- a/Dockerfile +++ b/Dockerfile @@ -38,7 +38,7 @@ RUN wget --progress=dot:giga -P /opt https://www.fil.ion.ucl.ac.uk/spm/download/ ${SPM_EXEC} function exit # Configure SPM BIDS App entry point -COPY run.sh spm_BIDS_App.m pipeline_participant.m narrow_participants.m pipeline_group.m /opt/spm${SPM_VERSION}/ +COPY run.sh spm_BIDS_App.m narrow_participants.m pipeline_participant.m pipeline_group.m /opt/spm${SPM_VERSION}/ RUN chmod +x /opt/spm${SPM_VERSION}/run.sh && \ chmod +x /opt/spm${SPM_VERSION}/spm${SPM_VERSION} && \ chmod +x /opt/spm${SPM_VERSION}/run_spm12.sh From 0e7b4df929f81641212cc338ea6a867c2e74c7a0 Mon Sep 17 00:00:00 2001 From: WillForan Date: Mon, 2 Feb 2026 17:25:31 -0500 Subject: [PATCH 06/12] wip: global BIDS on pipeline --- pipeline_participant.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pipeline_participant.m b/pipeline_participant.m index 48868dd..01ce768 100644 --- a/pipeline_participant.m +++ b/pipeline_participant.m @@ -3,7 +3,7 @@ %========================================================================== % Available variables: BIDS and BIDS_App - +global BIDS; %========================================================================== %-fMRI Preprocessing %========================================================================== From 13c7b861b404cb6bf58e6b6bbbcc934d1fd27e49 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 2 Feb 2026 22:25:48 +0000 Subject: [PATCH 07/12] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- narrow_participants.m | 2 +- test_narrow_participants.m | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/narrow_participants.m b/narrow_participants.m index 99f6175..ddd48d6 100644 --- a/narrow_participants.m +++ b/narrow_participants.m @@ -1,6 +1,6 @@ function BIDS = narrow_participants(BIDS, labels) % NARROW_PARTICIPANTS - restrict BIDS struct to only requested labels -% +% % nothing to do if no labels to change? if isempty(labels) diff --git a/test_narrow_participants.m b/test_narrow_participants.m index 58049f6..1522768 100644 --- a/test_narrow_participants.m +++ b/test_narrow_participants.m @@ -19,7 +19,7 @@ % narrowing works BIDS_narrow = narrow_participants(BIDS, {'sub-a'}) assert(length(BIDS_narrow.participants.participant_id) == 2) - + % no change on empty BIDS_nochange = narrow_participants(BIDS, {}); % TODO: {{}}? assert(length(BIDS_nochange.participants.participant_id) == 4) From c2c4b5e9083097232b33953313fafb82691897a4 Mon Sep 17 00:00:00 2001 From: Remi Gau Date: Tue, 14 Nov 2023 11:12:53 +0100 Subject: [PATCH 08/12] 'precommit_update' --- .pre-commit-config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index fd3e29e..9f5bd82 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -4,7 +4,7 @@ repos: - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.4.0 + rev: v4.5.0 hooks: - id: trailing-whitespace - id: end-of-file-fixer From ff36d8c06fbda1a67ccb0cb0d4c5454d2c899ad4 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 8 Apr 2024 21:18:24 +0000 Subject: [PATCH 09/12] [pre-commit.ci] pre-commit autoupdate MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit updates: - [github.com/pre-commit/pre-commit-hooks: v4.5.0 → v4.6.0](https://github.com/pre-commit/pre-commit-hooks/compare/v4.5.0...v4.6.0) --- .pre-commit-config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 9f5bd82..d50735d 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -4,7 +4,7 @@ repos: - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.5.0 + rev: v4.6.0 hooks: - id: trailing-whitespace - id: end-of-file-fixer From 9b51ea612d501b001cdd1ce24f771f11c53bc579 Mon Sep 17 00:00:00 2001 From: Remi Gau Date: Tue, 30 Apr 2024 11:37:20 +0200 Subject: [PATCH 10/12] autoupdate_precommit --- .pre-commit-config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index d50735d..7b424f4 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -23,7 +23,7 @@ repos: - repo: https://github.com/hadolint/hadolint - rev: v2.12.1-beta + rev: v2.13.0-beta hooks: - id: hadolint-docker name: Lint Dockerfiles From 1277dab6103a2dd52415bfea3fab54cc1f9899ee Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 7 Oct 2024 22:51:42 +0000 Subject: [PATCH 11/12] [pre-commit.ci] pre-commit autoupdate MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit updates: - [github.com/pre-commit/pre-commit-hooks: v4.6.0 → v5.0.0](https://github.com/pre-commit/pre-commit-hooks/compare/v4.6.0...v5.0.0) - [github.com/hadolint/hadolint: v2.13.0-beta → v2.13.1-beta](https://github.com/hadolint/hadolint/compare/v2.13.0-beta...v2.13.1-beta) --- .pre-commit-config.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 7b424f4..4b8b8df 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -4,7 +4,7 @@ repos: - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.6.0 + rev: v5.0.0 hooks: - id: trailing-whitespace - id: end-of-file-fixer @@ -23,7 +23,7 @@ repos: - repo: https://github.com/hadolint/hadolint - rev: v2.13.0-beta + rev: v2.13.1-beta hooks: - id: hadolint-docker name: Lint Dockerfiles From f72e7c1f6d61dfe241c0627f25859ae5f2462fe0 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 22 Sep 2025 20:01:44 +0000 Subject: [PATCH 12/12] [pre-commit.ci] pre-commit autoupdate MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit updates: - [github.com/pre-commit/pre-commit-hooks: v5.0.0 → v6.0.0](https://github.com/pre-commit/pre-commit-hooks/compare/v5.0.0...v6.0.0) - [github.com/hadolint/hadolint: v2.13.1-beta → v2.14.0](https://github.com/hadolint/hadolint/compare/v2.13.1-beta...v2.14.0) --- .pre-commit-config.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 4b8b8df..6a08a3b 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -4,7 +4,7 @@ repos: - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v5.0.0 + rev: v6.0.0 hooks: - id: trailing-whitespace - id: end-of-file-fixer @@ -23,7 +23,7 @@ repos: - repo: https://github.com/hadolint/hadolint - rev: v2.13.1-beta + rev: v2.14.0 hooks: - id: hadolint-docker name: Lint Dockerfiles