From 5c8fec5d404ad0c093adf08008b8fbd440c6acba Mon Sep 17 00:00:00 2001 From: Remi Gau Date: Thu, 4 Apr 2024 12:00:34 +0200 Subject: [PATCH] [FIX] install MACS toobox during initialisation (#1203) * copy macs tooolbox during init * update changelog * fix and refactor --- .github/workflows/run_tests_notebooks.yml | 3 --- .github/workflows/tests.yml | 3 --- .github/workflows/tests_octave.yml | 3 --- .github/workflows/tests_windows.yml | 3 --- CHANGELOG.md | 1 + bidspm.m | 19 +++++++++++++++++ src/infra/checkToolbox.m | 25 ++++++++++++++++------- 7 files changed, 38 insertions(+), 19 deletions(-) diff --git a/.github/workflows/run_tests_notebooks.yml b/.github/workflows/run_tests_notebooks.yml index e1295b19c..8219d8c3a 100644 --- a/.github/workflows/run_tests_notebooks.yml +++ b/.github/workflows/run_tests_notebooks.yml @@ -45,9 +45,6 @@ jobs: run: | git clone https://github.com/spm/spm12.git --depth 1 - - name: Copy Macs toolbox to SPM inputs_folder - run: cp -rv lib/MACS spm12/toolbox/MACS - - name: Test notebooks uses: matlab-actions/run-command@v2.1.0 with: diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 7349a3e40..43bc98f97 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -105,9 +105,6 @@ jobs: run: | git clone https://github.com/spm/spm12.git --depth 1 - - name: Copy Macs toolbox to SPM inputs_folder - run: cp -rv lib/MACS spm12/toolbox/MACS - - name: Get moae fmriprep data from OSF run: | mkdir -p demos/MoAE/inputs/ diff --git a/.github/workflows/tests_octave.yml b/.github/workflows/tests_octave.yml index 26f029d2d..d918e3169 100644 --- a/.github/workflows/tests_octave.yml +++ b/.github/workflows/tests_octave.yml @@ -86,9 +86,6 @@ jobs: run: | git clone https://github.com/spm/spm12.git --depth 1 - - name: Copy Macs toolbox to SPM inputs_folder - run: cp -rv lib/MACS spm12/toolbox/MACS - - name: Get moae fmriprep data from OSF run: | mkdir -p demos/MoAE/inputs/ diff --git a/.github/workflows/tests_windows.yml b/.github/workflows/tests_windows.yml index ba731d0c7..1d6affe54 100644 --- a/.github/workflows/tests_windows.yml +++ b/.github/workflows/tests_windows.yml @@ -84,9 +84,6 @@ jobs: run: | git clone https://github.com/spm/spm12.git --depth 1 - - name: Copy Macs toolbox to SPM inputs_folder - run: Copy-Item -Recurse -Verbose -Path ".\lib\MACS" -Destination ".\spm12\toolbox\MACS" - - name: Get moae fmriprep data from OSF run: | New-Item -ItemType Directory -Path ".\demos\MoAE\inputs\" -Force diff --git a/CHANGELOG.md b/CHANGELOG.md index 697489ffb..5067496c7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -50,6 +50,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed +* [FIX] copy the MACS toolbox to the SPM toolbox folder during the initialisation #1203 by @Remi-Gau * [FIX] save onsets.mat directly in subject stats folder #1187 by @Remi-Gau * [FIX] do not compute subject level contrast when running dataset level #1102 by @Remi-Gau * [FIX] copy `RepetitionTime` in sidecar JSON after running smoothing in #1099 by @Remi-Gau diff --git a/bidspm.m b/bidspm.m index 35c108f51..578dd5363 100644 --- a/bidspm.m +++ b/bidspm.m @@ -171,6 +171,9 @@ function initBidspm(dev) fullfile(rootDir(), 'tests', 'utils')); end + % Make sure MACS toolbox used by SPM is the one from bidspm + installMacstoolbox(); + % for some reasons this folder was otherwise not added to the path in Octave BIDSPM_PATHS = cat(2, BIDSPM_PATHS, ... pathSep, ... @@ -256,6 +259,22 @@ function initBidspm(dev) end +function installMacstoolbox() + + SPM_DIR = spm('dir'); + target_dir = fullfile(SPM_DIR, 'toolbox', 'MACS'); + MACS_TOOLBOX_DIR = fullfile(rootDir(), 'lib', 'MACS'); + + msg = sprintf('installing MACS toolbox in:\n%s.\n\n', target_dir); + fprintf(1, msg); + + if exist(target_dir, 'dir') == 7 + rmdir(target_dir, 's'); + end + mkdir(target_dir); + copyfile(MACS_TOOLBOX_DIR, target_dir); +end + function uninitBidspm() % % Removes the added folders from the path for a given session. diff --git a/src/infra/checkToolbox.m b/src/infra/checkToolbox.m index f54771c72..f513c265a 100644 --- a/src/infra/checkToolbox.m +++ b/src/infra/checkToolbox.m @@ -65,13 +65,7 @@ if ~status && install - msg = sprintf('installing MACS toolbox in:\n%s.\n\n', ... - fullfile(spm('dir'), 'toolbox', 'MACS')); - id = 'installingMacsToolbox'; - logger('WARNING', msg, 'id', id, 'filename', mfilename(), 'options', opt); - - copyfile(fullfile(returnRootDir(), 'lib', 'MACS'), ... - fullfile(spm('dir'), 'toolbox', 'MACS')); + installMacstoolbox(opt); status = checkToolbox(toolboxName); @@ -94,3 +88,20 @@ end end + +function installMacstoolbox(opt) + SPM_DIR = spm('dir'); + MACS_TOOLBOX_DIR = fullfile(returnRootDir(), 'lib', 'MACS'); + + target_dir = fullfile(SPM_DIR, 'toolbox', 'MACS'); + + msg = sprintf('installing MACS toolbox in:\n%s.\n\n', target_dir); + id = 'installingMacsToolbox'; + logger('WARNING', msg, 'id', id, 'filename', mfilename(), 'options', opt); + + if exist(target_dir, 'dir') == 7 + rmdir(target_dir, 's'); + end + mkdir(target_dir); + copyfile(MACS_TOOLBOX_DIR, target_dir); +end