Skip to content

Commit

Permalink
[ENH] add model selection to CLI (#1121)
Browse files Browse the repository at this point in the history
* update submod

* [DATALAD] Recorded changes

* [DATALAD] Recorded changes

* minor work on cli

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* fix some tests

* more fixes

* add folders

* start implementing bms

* fix system test

* loop over models

* rm models

* generate models

* update bids matlab

* Apply suggestions from code review

* fix bug

* fix test

* refacrtor

* refactor

* add basic error handling

* fix test

* fix and doc

* fix

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* move space to each action cli

* add use_dummy_regressor arg

* [DATALAD] Recorded changes

* move space to each action cli

* [DATALAD] Recorded changes

* update fields name, fix failing tests, add arg displaying function

* refactor CI

* FCI

* smooth bms data

* use the proper task

* use dummy regressor argument

* [DATALAD] Recorded changes

* use proper argument

* fix passing or use fummy argument

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
Remi-Gau and pre-commit-ci[bot] authored Aug 11, 2023
1 parent 0d1ecae commit b7ebdc9
Show file tree
Hide file tree
Showing 75 changed files with 1,038 additions and 373 deletions.
12 changes: 12 additions & 0 deletions .github/workflows/system_tests_bms.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
%
% (C) Copyright 2023 bidspm developers

root_dir = getenv('GITHUB_WORKSPACE');

fprintf('\nroot dir is %s\n', root_dir);

addpath(fullfile(root_dir, 'spm12'));

cd(fullfile(root_dir, 'demos', 'bayes'));

run ds000114_run;
23 changes: 16 additions & 7 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ jobs:
os: [ubuntu-latest, macos-latest]
matlab: [R2022b]
include:
- test_type: system
script: bms
os: ubuntu-latest
matlab: R2022b
- test_type: unit
os: ubuntu-latest
matlab: R2022b
Expand All @@ -59,12 +63,6 @@ jobs:
if: matrix.test_type == 'system'
run: echo ${{ matrix.test_type }} test ${{ matrix.script }}

- name: Install dependencies
if: matrix.os == 'ubuntu-latest'
run: |
sudo apt-get -y -qq update
sudo apt-get -y install unzip wget
- name: Install Node
uses: actions/setup-node@v3
with:
Expand All @@ -75,6 +73,14 @@ jobs:
with:
python-version: '3.11'

- name: Install dependencies
if: matrix.os == 'ubuntu-latest'
run: |
sudo apt-get -y -qq update
sudo apt-get -y install unzip wget git-annex
python -m pip install --upgrade pip setuptools
pip install datalad
- name: Clone bidspm
uses: actions/checkout@v3
with:
Expand Down Expand Up @@ -104,6 +110,10 @@ jobs:
cd tests
make data
- name: Get data for BMS
if: matrix.script == 'bms'
run: make -C demos/bayes data_ds000114

- name: Install Moxunit and MOcov
run: |
git clone https://github.com/MOxUnit/MOxUnit.git --depth 1
Expand All @@ -130,7 +140,6 @@ jobs:
fail_ci_if_error: false
# token: ${{ secrets.CODECOV_TOKEN }} # not required but might help API rate limits


- name: Run system tests MATLAB ${{ matrix.script }}
if: matrix.test_type == 'system'
uses: matlab-actions/run-command@v1.2.1
Expand Down
61 changes: 40 additions & 21 deletions bidspm.m
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@
% (C) Copyright 2022 bidspm developers

args = defaultInputParser();
parse(args, varargin{:});
try
parse(args, varargin{:});
catch ME
displayArguments(varargin{:});
rethrow(ME);
end

action = args.Results.action;

Expand Down Expand Up @@ -45,7 +50,7 @@

case 'help'
system('bidspm --help');
help(fullfile(fileparts(mfilename('fullpath')), 'src', 'messages', 'bidspmHelp.m'));
help(fullfile(rootDir(), 'src', 'messages', 'bidspmHelp.m'));

case 'version'
versionBidspm();
Expand Down Expand Up @@ -77,9 +82,12 @@
case 'default_model'
cliDefaultModel(varargin{2:end});

case {'stats', 'contrasts', 'results'}
case {'stats', 'contrasts', 'results', 'specify_only'}
cliStats(varargin{2:end});

case {'bms'}
cliBayesModel(varargin{2:end});

case 'meaning_of_life'
fprintf('\n42\n\n');

Expand All @@ -94,12 +102,25 @@

end

function displayArguments(varargin)
disp('arguments passed were :');
for i = 1:numel(varargin)
fprintf('- ');
disp(varargin{i});
end
fprintf(1, '\n');
end

function value = rootDir()
value = fullfile(fileparts(mfilename('fullpath')));
end

%% low level actions
function versionBidspm()
try
versionNumber = getVersion();
catch
versionNumber = fileread(fullfile(fileparts(mfilename('fullpath')), 'version.txt'));
versionNumber = fileread(rootDir(), 'version.txt');
versionNumber = versionNumber(1:end - 1);
end
fprintf(1, '%s\n', versionNumber);
Expand Down Expand Up @@ -130,8 +151,6 @@ function initBidspm(dev)
% octave packages
installlist = {'io', 'statistics', 'image'};

thisDirectory = fileparts(mfilename('fullpath'));

global BIDSPM_INITIALIZED
global BIDSPM_PATHS

Expand All @@ -143,27 +162,27 @@ function initBidspm(dev)
end

% add bidspm source code
BIDSPM_PATHS = fullfile(thisDirectory);
BIDSPM_PATHS = fullfile(rootDir());
BIDSPM_PATHS = cat(2, BIDSPM_PATHS, ...
pathSep, ...
genpath(fullfile(thisDirectory, 'src')));
genpath(fullfile(rootDir(), 'src')));
if dev
BIDSPM_PATHS = cat(2, BIDSPM_PATHS, pathSep, ...
fullfile(thisDirectory, 'tests', 'utils'));
fullfile(rootDir(), 'tests', 'utils'));
end

% for some reasons this folder was otherwise not added to the path in Octave
BIDSPM_PATHS = cat(2, BIDSPM_PATHS, ...
pathSep, ...
genpath(fullfile(thisDirectory, 'src', 'workflows', 'stats')));
genpath(fullfile(rootDir(), 'src', 'workflows', 'stats')));

% add library that do not have an set up script
libList = {'spmup'};

for i = 1:numel(libList)
BIDSPM_PATHS = cat(2, BIDSPM_PATHS, ...
pathSep, ...
genpath(fullfile(thisDirectory, 'lib', libList{i})));
genpath(fullfile(rootDir(), 'lib', libList{i})));
end

libList = {'mancoreg', ...
Expand All @@ -173,23 +192,23 @@ function initBidspm(dev)
'utils'};
for i = 1:numel(libList)
BIDSPM_PATHS = cat(2, BIDSPM_PATHS, pathSep, ...
fullfile(thisDirectory, 'lib', libList{i}));
fullfile(rootDir(), 'lib', libList{i}));
end

BIDSPM_PATHS = cat(2, BIDSPM_PATHS, pathSep, ...
fullfile(thisDirectory, 'lib', 'brain_colours', 'code'));
fullfile(rootDir(), 'lib', 'brain_colours', 'code'));

BIDSPM_PATHS = cat(2, BIDSPM_PATHS, pathSep, ...
fullfile(thisDirectory, 'lib', 'riksneurotools', 'GLM'));
fullfile(rootDir(), 'lib', 'riksneurotools', 'GLM'));

addpath(BIDSPM_PATHS, '-begin');

silenceOctaveWarning();

% add library that have a set up script
run(fullfile(thisDirectory, 'lib', 'CPP_ROI', 'initCppRoi'));
run(fullfile(thisDirectory, 'lib', 'spm_2_bids', 'init_spm_2_bids'));
run(fullfile(thisDirectory, 'lib', 'octache', 'setup'));
run(fullfile(rootDir(), 'lib', 'CPP_ROI', 'initCppRoi'));
run(fullfile(rootDir(), 'lib', 'spm_2_bids', 'init_spm_2_bids'));
run(fullfile(rootDir(), 'lib', 'octache', 'setup'));

checkDependencies(opt);
printCredits(opt);
Expand Down Expand Up @@ -248,8 +267,6 @@ function uninitBidspm()

% (C) Copyright 2021 bidspm developers

thisDirectory = fileparts(mfilename('fullpath'));

global BIDSPM_INITIALIZED
global BIDSPM_PATHS

Expand All @@ -258,7 +275,7 @@ function uninitBidspm()
return

else
run(fullfile(thisDirectory, 'lib', 'CPP_ROI', 'uninitCppRoi'));
run(fullfile(rootDir(), 'lib', 'CPP_ROI', 'uninitCppRoi'));
rmpath(BIDSPM_PATHS);
spm('Clean');
spm('Quit');
Expand Down Expand Up @@ -350,7 +367,9 @@ function update()
'default_model'; ...
'stats'; ...
'contrasts'; ...
'results'};
'results'; ...
'specify_only', ...
'bms'};

end

Expand Down
2 changes: 1 addition & 1 deletion demos/MoAE/moae_01_bids_app.m
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@
bidspm(bids_dir, output_dir, 'subject', ...
'participant_label', {subject_label}, ...
'action', 'preprocess', ...
'task', {'auditory'}, ...
'task', 'auditory', ...
'ignore', {'unwarp', 'slicetiming'}, ...
'space', {'IXI549Space'}, ...
'fwhm', 6, ...
Expand Down
6 changes: 3 additions & 3 deletions demos/MoAE/test_moae.m
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

bidspm();
if download_data
download_moae_ds(download_data, clean);
download_moae_ds(download_data, clean); %#ok<*UNRCH>
end

warning('off', 'SPM:noDisplay');
Expand Down Expand Up @@ -52,12 +52,12 @@
%% preproc
bids_dir = fullfile(WD, 'inputs', 'raw');
output_dir = fullfile(tempname, 'outputs', 'derivatives');
mkdir(output_dir);
spm_mkdir(output_dir);

bidspm(bids_dir, output_dir, 'subject', ...
'participant_label', {'01'}, ...
'action', 'preprocess', ...
'task', {'auditory'}, ...
'task', 'auditory', ...
'ignore', ignore{iOption}, ...
'space', space(iOption), ...
'options', optionsFile);
Expand Down
11 changes: 11 additions & 0 deletions demos/bayes/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
.PHONY: clean data data_ds000001

data_ds000114:
mkdir -p inputs
cd inputs && datalad install ///openneuro/ds000114
cd inputs && datalad install ///openneuro-derivatives/ds000114-fmriprep
cd inputs/ds000114-fmriprep && datalad get sub-*/anat/*MNI152NLin2009cAsym*desc-preproc*.nii.gz -J 12
cd inputs/ds000114-fmriprep && datalad get sub-*/ses-*/func/*tsv -J 12
cd inputs/ds000114-fmriprep && datalad get sub-*/ses-*/func/*json -J 12
cd inputs/ds000114-fmriprep && datalad get sub-*/ses-*/func/*overtverbgeneration*MNI152NLin2009cAsym*_mask.nii.gz -J 12
cd inputs/ds000114-fmriprep && datalad get sub-*/ses-*/func/*overtverbgeneration*MNI152NLin2009cAsym*desc-preproc*bold.nii.gz -J 12
Loading

0 comments on commit b7ebdc9

Please sign in to comment.