Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ENH] add model selection to CLI #1121

Merged
merged 40 commits into from
Aug 11, 2023
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
9c7deac
update submod
Remi-Gau Aug 8, 2023
d3ad58e
[DATALAD] Recorded changes
Remi-Gau Aug 8, 2023
3fe68fc
Merge remote-tracking branch 'upstream/main' into bmc
Remi-Gau Aug 8, 2023
86be519
[DATALAD] Recorded changes
Remi-Gau Aug 8, 2023
877fe1c
minor work on cli
Remi-Gau Aug 8, 2023
17eaee4
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Aug 8, 2023
eb29df5
fix some tests
Remi-Gau Aug 8, 2023
a8366bf
more fixes
Remi-Gau Aug 8, 2023
253cdc7
add folders
Remi-Gau Aug 8, 2023
86f5cc7
start implementing bms
Remi-Gau Aug 8, 2023
ff6e4e2
fix system test
Remi-Gau Aug 9, 2023
61a4751
loop over models
Remi-Gau Aug 9, 2023
7a81162
rm models
Remi-Gau Aug 9, 2023
201749b
generate models
Remi-Gau Aug 9, 2023
34a58b6
update bids matlab
Remi-Gau Aug 9, 2023
3edb174
Apply suggestions from code review
Remi-Gau Aug 9, 2023
fd2cc02
fix bug
Remi-Gau Aug 9, 2023
4e8227d
fix test
Remi-Gau Aug 9, 2023
dd4ec15
refacrtor
Remi-Gau Aug 9, 2023
da17b00
refactor
Remi-Gau Aug 9, 2023
c10d4fa
add basic error handling
Remi-Gau Aug 9, 2023
93eeef3
fix test
Remi-Gau Aug 9, 2023
2cd100c
fix and doc
Remi-Gau Aug 9, 2023
0cf78ff
fix
Remi-Gau Aug 9, 2023
9bad6bc
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Aug 9, 2023
f2d564d
move space to each action cli
Remi-Gau Aug 10, 2023
3792d28
add use_dummy_regressor arg
Remi-Gau Aug 10, 2023
71a9339
[DATALAD] Recorded changes
Remi-Gau Aug 10, 2023
5a55992
move space to each action cli
Remi-Gau Aug 10, 2023
17f0657
Merge branch 'tmp' into bmc
Remi-Gau Aug 10, 2023
6649cf0
[DATALAD] Recorded changes
Remi-Gau Aug 10, 2023
cba8f1d
update fields name, fix failing tests, add arg displaying function
Remi-Gau Aug 10, 2023
ae4418b
refactor CI
Remi-Gau Aug 10, 2023
5f7102e
FCI
Remi-Gau Aug 10, 2023
0db9412
smooth bms data
Remi-Gau Aug 10, 2023
f6098db
use the proper task
Remi-Gau Aug 10, 2023
843c032
use dummy regressor argument
Remi-Gau Aug 10, 2023
a673ccf
[DATALAD] Recorded changes
Remi-Gau Aug 10, 2023
8af559c
use proper argument
Remi-Gau Aug 10, 2023
0e2e5bb
fix passing or use fummy argument
Remi-Gau Aug 11, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions bidspm.m
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,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 Down Expand Up @@ -350,7 +353,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 @@ -15,7 +15,7 @@
clc;
close all;

download_data = true;
download_data = false;
clean = true;

WD = fileparts(mfilename('fullpath'));
Expand All @@ -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 @@ -57,7 +57,7 @@
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/*linebisection*MNI152NLin2009cAsym*_mask.nii.gz -J 12
cd inputs/ds000114-fmriprep && datalad get sub-*/ses-*/func/*linebisection*MNI152NLin2009cAsym*desc-preproc*bold.nii.gz -J 12
110 changes: 110 additions & 0 deletions demos/bayes/ds000114_run.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
% (C) Copyright 2023 bidspm developers

clear;
clc;

addpath(fullfile(pwd, '..', '..'));
bidspm();

% set to false to not re run the smoothing
SMOOTH = false;

% set to false to not re run the model specification
FIRST_LEVEL = true;

VERBOSITY = 1;

FWHM = 8;

% to run on fewer subjects
TESTING = false;

% The directory where the data are located
root_dir = fileparts(mfilename('fullpath'));
bids_dir = fullfile(root_dir, 'inputs', 'ds000114');
fmriprep_dir = fullfile(root_dir, 'inputs', 'ds000114-fmriprep');
output_dir = fullfile(root_dir, 'outputs', 'ds000114', 'derivatives');

models_dir = fullfile(root_dir, 'models');

participant_label = {'[0-9]*'};
if TESTING
participant_label = {'^0[12]$'};
end

%% Smooth
if SMOOTH
bidspm(fmriprep_dir, output_dir, 'subject', ...
'action', 'smooth', ...
'participant_label', participant_label, ...
'task', {'overtverbgeneration'}, ...
'space', {'MNI152NLin2009cAsym'}, ...
'fwhm', FWHM, ...
'verbosity', VERBOSITY); %#ok<*UNRCH>
end

%% create models from a default one

default_model_file = fullfile(models_dir, 'default_model.json');
% FIXME: crashes with 0 real param
nb_realignment_param = [6, 24];
scrubbing = [0, 1];

for i = 1:numel(nb_realignment_param)
for j = 1:numel(scrubbing)

model = bids.util.jsondecode(default_model_file);

name = sprintf('rp-%i_srub-%i', ...
nb_realignment_param(i), ...
scrubbing(j));
model.Name = name;
model.Nodes.Name = name;

design_matrix = model.Nodes.Model.X;
if scrubbing(j) == 1
design_matrix{end + 1} = '*outlier*'; %#ok<*SAGROW>
end
switch nb_realignment_param(i)
case 0
case 6
design_matrix{end + 1} = 'rot_?';
design_matrix{end + 1} = 'trans_?';
case 24
design_matrix{end + 1} = 'rot_*';
design_matrix{end + 1} = 'trans_*';
end
model.Nodes.Model.X = design_matrix;

output_file = fullfile(models_dir, ['model_' name '_smdl.json']);
bids.util.jsonencode(output_file, model);
end
end

%% Statistics
preproc_dir = fullfile(output_dir, 'bidspm-preproc');

%% Subject level analysis
if FIRST_LEVEL

opt.glm.useDummyRegressor = true;

bidspm(bids_dir, output_dir, 'subject', ...
'participant_label', participant_label, ...
'action', 'specify_only', ...
'preproc_dir', preproc_dir, ...
'model_file', models_dir, ...
'fwhm', FWHM, ...
'skip_validation', true, ...
'verbosity', VERBOSITY, ...
'options', opt);

end

bidspm(bids_dir, output_dir, 'subject', ...
'action', 'bms', ...
'participant_label', participant_label, ...
'models_dir', models_dir, ...
'fwhm', FWHM, ...
'skip_validation', true, ...
'verbosity', VERBOSITY);
Empty file added demos/bayes/inputs/.gitkeep
Empty file.
2 changes: 2 additions & 0 deletions demos/bayes/miss_hit.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
exclude_dir: "inputs"
exclude_dir: "outputs"
1 change: 1 addition & 0 deletions demos/bayes/models/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*smdl.json
54 changes: 54 additions & 0 deletions demos/bayes/models/default_model.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
{
"Name": "default model",
"BIDSModelVersion": "1.0.0",
"Description": "FIXME",
"Input": {
"task": [
"overtverbgeneration"
],
"space": [
"MNI152NLin2009cAsym"
]
},
"Nodes": [
{
"Level": "Run",
"Name": "FIXME",
"GroupBy": [
"run",
"session",
"subject"
],
"Model": {
"X": [
"trial_type.Task",
1
],
"Type": "glm",
"HRF": {
"Variables": [
"trial_type.Task"
],
"Model": "spm"
},
"Options": {
"HighPassFilterCutoffHz": 0.008,
"Mask": {
"desc": [
"brain"
],
"suffix": [
"mask"
]
}
},
"Software": {
"SPM": {
"SerialCorrelation": "FAST",
"InclusiveMaskingThreshold": 0.8
}
}
}
}
]
}
Empty file added demos/bayes/outputs/.gitkeep
Empty file.
7 changes: 7 additions & 0 deletions demos/bayes/spm_my_defaults.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
function spm_my_defaults
% (C) Copyright 2023 bidspm developers
global defaults

defaults.cmdline = true;

end
2 changes: 1 addition & 1 deletion demos/face_repetition/face_rep_01_bids_app.m
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,6 @@
bidspm(bids_dir, output_dir, 'subject', ...
'participant_label', {subject_label}, ...
'action', 'preprocess', ...
'task', {'facerepetition'}, ...
'task', 'facerepetition', ...
'space', {'individual', 'IXI549Space'}, ...
'skip_validation', skip_validation);
2 changes: 1 addition & 1 deletion demos/face_repetition/test_face_rep.m
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
bidspm(bids_dir, output_dir, 'subject', ...
'participant_label', {'01'}, ...
'action', 'preprocess', ...
'task', {'facerepetition'}, ...
'task', 'facerepetition', ...
'space', {'IXI549Space'}, ...
'ignore', ignore, ...
'options', opt, ...
Expand Down
1 change: 0 additions & 1 deletion demos/openneuro/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ data_ds001734:
cd inputs/ds001734-fmriprep && datalad get sub-00[1]/func/*json -J 12
cd inputs/ds001734-fmriprep && datalad get sub-00[1]/func/*MNI152NLin2009cAsym*desc-preproc*bold.nii.gz -J 12


data_ds002799:
mkdir -p inputs
cd inputs && datalad install ///openneuro/ds002799
Expand Down
2 changes: 1 addition & 1 deletion demos/openneuro/ds000001_run.m
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
bidspm(bids_dir, output_dir, 'subject', ...
'participant_label', participant_label(i_participant), ...
'action', 'preprocess', ...
'task', {'balloonanalogrisktask'}, ...
'task', 'balloonanalogrisktask', ...
'space', {'IXI549Space'});
end

Expand Down
2 changes: 1 addition & 1 deletion demos/openneuro/ds001168_run.m
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
bidspm(bids_dir, output_dir, 'subject', ...
'participant_label', {'01'}, ...
'action', 'preprocess', ...
'task', {'rest'}, ...
'task', 'rest', ...
'space', {'IXI549Space'}, ...
'ignore', {'slicetiming'}, ...
'options', opt);
Expand Down
Loading
Loading