Skip to content

Commit

Permalink
adapt example
Browse files Browse the repository at this point in the history
  • Loading branch information
Remi-Gau committed Jul 25, 2024
1 parent 7f0d048 commit e79deeb
Show file tree
Hide file tree
Showing 10 changed files with 84 additions and 50 deletions.
1 change: 1 addition & 0 deletions .flake8
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ exclude =
tests/*
_version.py
demos/*
WIP/*
count = True
show-source = True
statistics = True
43 changes: 43 additions & 0 deletions WIP/find_data_set_with_3_groups.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
from pathlib import Path

import pandas as pd
from pandas.errors import ParserError

openneuro = Path("/home/remi/datalad/datasets.datalad.org/openneuro")

for ds in openneuro.iterdir():
file = ds / "participants.tsv"

if file.exists():

try:
df = pd.read_csv(file, sep="\t")
except ParserError:
...

if len(df) < 10:
continue
if "group" in df.columns:
col = "group"
elif "Group" in df.columns:
col = "Group"
else:
continue
if len(df[col].value_counts()) < 3:
continue
if "age" in df.columns and df["age"].mean() < 18:
continue
bold_files = list(ds.glob("**/*bold*"))

has_func = len(bold_files) > 0
if not has_func:
continue

tasks = {x.name.split("task-")[1].split("_")[0] for x in bold_files}
if len(tasks) == 1 and "rest" in tasks:
continue

print()
print(file)
print(df[col].value_counts())
print(tasks)
21 changes: 19 additions & 2 deletions demos/openneuro/ds003397_run.m
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,23 @@
'models', ...
'model-ds003397_smdl.json');

bidspm(bids_dir, output_dir, 'subject', ...
opt.results(1) = defaultResultsStructure();
opt.results(1).nodeName = 'subject_level';
opt.results(1).name = 'flashing checkerboard';

% bidspm(bids_dir, output_dir, 'subject', ...
% 'participant_label', participant_label, ...
% 'action', 'results', ...
% 'preproc_dir', preproc_dir, ...
% 'model_file', model_file, ...
% 'roi_atlas', 'hcpex', ...
% 'space', space, ...
% 'fwhm', 0, ...
% 'skip_validation', true, ...
% 'verbosity', 3, ...
% 'opt', opt);

bidspm(bids_dir, output_dir, 'dataset', ...
'participant_label', participant_label, ...
'action', 'stats', ...
'preproc_dir', preproc_dir, ...
Expand All @@ -44,4 +60,5 @@
'space', space, ...
'fwhm', 0, ...
'skip_validation', true, ...
'verbosity', 3);
'verbosity', 3, ...
'opt', opt);
23 changes: 1 addition & 22 deletions demos/openneuro/models/model-ds003397_smdl.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,23 +61,6 @@
"Test": "t"
}
},
{
"Level": "Dataset",
"Name": "dataset_level",
"GroupBy": [
"contrast",
"group"
],
"Model": {
"Type": "glm",
"X": [
1
]
},
"DummyContrasts": {
"Test": "t"
}
},
{
"Level": "Dataset",
"Name": "between_groups",
Expand All @@ -94,7 +77,7 @@
},
"Contrasts": [
{
"Name": "VisMot_gt_VisStat",
"Name": "flashing checkerboard",
"ConditionList": [
"group.B",
"group.I",
Expand All @@ -115,10 +98,6 @@
"Source": "run_level",
"Destination": "subject_level"
},
{
"Source": "subject_level",
"Destination": "dataset_level"
},
{
"Source": "subject_level",
"Destination": "between_groups",
Expand Down
2 changes: 1 addition & 1 deletion lib/bids-matlab
Submodule bids-matlab updated 2 files
+3 −0 +bids/layout.m
+1 −1 schema.json
5 changes: 5 additions & 0 deletions src/batches/stats/setBatchFactorialDesign.m
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@

availableGroups = unique(BIDS.raw.participants.content.(groupColumnHdr));

label = '1WayANOVA';

rfxDir = getRFXdir(opt, nodeName, contrasts{1}, '1WayANOVA');
overwriteDir(rfxDir, opt);

Expand Down Expand Up @@ -126,6 +128,9 @@

end

groups = {label};
contrastsList = {contrastsList{1}};

end
end

Expand Down
6 changes: 3 additions & 3 deletions src/stats/subject_level/specifyDummyContrasts.m
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@
return
end

if ismember(node.Level, {'session'}) && ~checkGroupBy(node)
if ismember(node.Level, {'Session'}) && ~checkGroupBy(node)
return
end
if strcmp(node.Level, 'subject') && ~checkGroupBy(node)
if strcmp(node.Level, 'Subject') && ~checkGroupBy(node)
return
end
if ismember(node.Level, {'dataset'})
if ismember(node.Level, {'Dataset'})
% see setBatchGroupLevelContrasts
return
end
Expand Down
3 changes: 1 addition & 2 deletions src/workflows/stats/bidsRFX.m
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@

% TODO refactor
% - extract function for anat and mask computation
% - merge rfx and ffx into a single "stats" workflow

if ismember(lower(action), {'meananatandmask', 'rfx', 'contrasts'})
opt.dir.output = fullfile(opt.dir.stats, 'derivatives', 'bidspm-groupStats');
Expand Down Expand Up @@ -102,7 +101,7 @@

switch groupLevelGlmType(opt, nodeName, participants)

case 'one_sample_t_test'
case {'one_sample_t_test', 'one_way_anova'}
[matlabbatch, contrastsList, groups] = setBatchFactorialDesign(matlabbatch, ...
opt, ...
datasetNodes{i}.Name);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ function test_setBatchFactorialDesign_between_3_groups()
opt.verbosity = 3;

matlabbatch = {};
[matlabbatch, contrastsList, groups] = setBatchFactorialDesign(matlabbatch, ...
opt, ...
'between_groups');
[matlabbatch, ~, ~] = setBatchFactorialDesign(matlabbatch, ...
opt, ...
'between_groups');
matlabbatch;

end
24 changes: 7 additions & 17 deletions tests/tests_slow/tests_workflows/stats/test_bidsRFX_3_groups.m
Original file line number Diff line number Diff line change
Expand Up @@ -12,29 +12,19 @@ function test_bidsRFX_two_sample_ttest()

markTestAs('slow');

opt = setOptions('vislocalizer', '', 'pipelineType', 'stats');
opt.model.file = spm_file(opt.model.file, ...
'basename', ...
'model-vislocalizer2sampleTTest_smdl');
opt = setOptions('3_groups', '', 'pipelineType', 'stats');

opt.model.bm = BidsModel('file', opt.model.file);
opt.verbosity = 3;

matlabbatch = bidsRFX('RFX', opt);

summary = batchSummary(matlabbatch);

% creates 1 batch for (specify, figure, estimate, review, figure)
batchOrder = {'stats', 'factorial_design'; ...
'util', 'print'};
batchOrder = extendBatchOrder(batchOrder);
assertEqual(summary, batchOrder);
matlabbatch = bidsRFX('RFX', opt, 'nodeName', 'between_groups');

assertEqual(matlabbatch{1}.spm.stats.factorial_design.dir{1}, ...
fileparts(matlabbatch{3}.spm.stats.fmri_est.spmmat{1}));
fileparts(matlabbatch{2}.spm.stats.fmri_est.spmmat{1}));
assertEqual(matlabbatch{1}.spm.stats.factorial_design.dir{1}, ...
matlabbatch{3}.spm.tools.MACS.MA_model_space.dir{1});

% 2 blind and 1 ctrl
assertEqual(numel(matlabbatch{1}.spm.stats.factorial_design.des.t2.scans1), 2);
assertEqual(numel(matlabbatch{1}.spm.stats.factorial_design.des.t2.scans2), 1);
summary = batchSummary(matlabbatch);

end

Expand Down

0 comments on commit e79deeb

Please sign in to comment.