Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Remi-Gau committed Jul 30, 2024
1 parent 4f103ed commit b3722d5
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 79 deletions.
10 changes: 5 additions & 5 deletions src/batches/stats/setBatchFactorialDesign.m
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@

contrastName = contrastsList{iCon};

rfxDir = getRFXdir(opt, nodeName, contrastName, '1WayANOVA');
rfxDir = getRFXdir(opt, nodeName, contrastName, label);
overwriteDir(rfxDir, opt);

assert(~checkSpmMat(rfxDir, opt));
Expand Down Expand Up @@ -283,7 +283,7 @@
thisGroup = 'GROUP';
end

factorialDesign = commonFaxtorialDesignBatch(directory);
factorialDesign = commonFactorialDesignBatch(directory);

factorialDesign.des.fd.icell = icell;

Expand All @@ -296,7 +296,7 @@
end

function factorialDesign = returnTwoSampleTTestBatch(directory)
factorialDesign = commonFaxtorialDesignBatch(directory);
factorialDesign = commonFactorialDesignBatch(directory);

factorialDesign.cov = struct('c', {}, 'cname', {}, 'iCFI', {}, 'iCC', {});
factorialDesign.multi_cov = struct('files', {}, 'iCFI', {}, 'iCC', {});
Expand All @@ -308,7 +308,7 @@
end

function factorialDesign = returnOneWayAnovaBatch(directory)
factorialDesign = commonFaxtorialDesignBatch(directory);
factorialDesign = commonFactorialDesignBatch(directory);

factorialDesign.cov = struct('c', {}, 'cname', {}, 'iCFI', {}, 'iCC', {});
factorialDesign.multi_cov = struct('files', {}, 'iCFI', {}, 'iCC', {});
Expand All @@ -318,7 +318,7 @@
factorialDesign.des.anova.icell(1).scans = {};
end

function factorialDesign = commonFaxtorialDesignBatch(directory)
function factorialDesign = commonFactorialDesignBatch(directory)
factorialDesign.dir = {directory};
factorialDesign = setBatchFactorialDesignImplicitMasking(factorialDesign);
factorialDesign = setBatchFactorialDesignGlobalCalcAndNorm(factorialDesign);
Expand Down
8 changes: 2 additions & 6 deletions src/stats/group_level/getRFXdir.m
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,8 @@
end

sub = 'ALL';
if ~isempty(contrastName)
participants = bids.util.tsvread(fullfile(opt.dir.raw, 'participants.tsv'));
groupColumnHdr = opt.model.bm.getGroupColumnHdrFromGroupBy(nodeName, participants);
if ~isempty(groupColumnHdr) && ~isempty(thisGroup)
sub = thisGroup;
end
if ~isempty(contrastName) && ~isempty(thisGroup)
sub = thisGroup;
end

glmDirName = ['sub-', sub, '_', glmDirName];
Expand Down
12 changes: 10 additions & 2 deletions tests/data/models/model-vismotionNoOverWrite_smdl.json
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@
{
"Level": "Dataset",
"Name": "between_groups",
"Description": "2 sample t-test of the all_olf condition",
"Description": "2 sample t-test",
"GroupBy": [
"contrast"
],
Expand Down Expand Up @@ -247,7 +247,15 @@
},
{
"Source": "subject_level",
"Destination": "between_groups"
"Destination": "between_groups",
"Filter": {
"contrast": [
"VisMot",
"VisStat",
"VisMot_gt_VisStat",
"VisStat_gt_VisMot"
]
}
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,37 +8,6 @@
initTestSuite;
end

function test_setBatchFactorialDesign_complex_alone()

markTestAs('slow');

opt = setOptions('vismotion', {'^01'}, 'pipelineType', 'stats');

[~, opt] = getData(opt, opt.dir.preproc);

opt.model.file = spm_file(opt.model.file, ...
'basename', ...
'model-vismotionSeveralDatasetLevel_smdl');

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

datasetNode = opt.model.bm.get_nodes('Name', 'complex contrast');

matlabbatch = {};
matlabbatch = setBatchFactorialDesign(matlabbatch, opt, datasetNode.Name);

% (1 contrasts) specified at the dataset level * 2
% batches (design specification + figure design matrix)
assertEqual(numel(matlabbatch), 2);

% check that directory name contains:
% desc-Node(dataset).name_contrast_contrastName
[~, dir] = fileparts(matlabbatch{1}.spm.stats.factorial_design.dir{1});
assertEqual(dir, ...
[basedirName 'node-complexContrast_contrast-VisMotGtVisStat']);

end

function test_setBatchFactorialDesign_within_group()

markTestAs('slow');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ function test_bidsRFX_within_group_ttest()
summary = batchSummary(matlabbatch);
assertEqual(summary, batchOrder);

[~, folder] = fileparts(matlabbatch{1}.spm.stats.factorial_design.dir{1});
assert(bids.internal.starts_with(folder, 'sub-blind'));

[~, folder] = fileparts(matlabbatch{3}.spm.stats.factorial_design.dir{1});
assert(bids.internal.starts_with(folder, 'sub-ctrl'));

assertEqual(matlabbatch{1}.spm.stats.factorial_design.dir{1}, ...
fileparts(matlabbatch{5}.spm.stats.fmri_est.spmmat{1}));
if bids.internal.is_octave()
Expand Down Expand Up @@ -77,6 +83,9 @@ function test_bidsRFX_two_sample_ttest()
batchOrder = extendBatchOrder(batchOrder);
assertEqual(summary, batchOrder);

[~, folder] = fileparts(matlabbatch{1}.spm.stats.factorial_design.dir{1});
assert(bids.internal.starts_with(folder, 'sub-2samplesTTest'));

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,13 @@ function test_bidsRFX_one_way_anova()

nodeName = 'between_groups';
contrastName = 'VisMot_gt_VisStat';

[~, folder] = fileparts(matlabbatch{1}.spm.stats.factorial_design.dir{1});
assert(bids.internal.starts_with(folder, 'sub-1WayANOVA'));

rfxDir = getRFXdir(opt, nodeName, contrastName, '1WayANOVA');
assertEqual(matlabbatch{1}.spm.stats.factorial_design.dir{1}, rfxDir);

assertEqual(numel(matlabbatch{1}.spm.stats.factorial_design.des.anova.icell), 3);
assertEqual(numel(matlabbatch{1}.spm.stats.factorial_design.des.anova.icell(1).scans), 2);
assertEqual(fileparts(matlabbatch{5}.spm.stats.fmri_est.spmmat{1}), rfxDir);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,29 @@ function test_bidsRFX_no_overwrite()
'model-vismotionNoOverWrite_smdl');
opt.model.bm = BidsModel('file', opt.model.file);

opt.ignore = {'qa'};

matlabbatch = bidsRFX('RFX', opt);

expectedNbBatch = 79;
if bids.internal.is_octave()
expectedNbBatch = 5;
end
assertEqual(numel(matlabbatch), expectedNbBatch);
% 2 simple dummy contrasts
% 1 complex
% 8 within group: 4 contrast from run level * 2 groups
% 4 between group: 4 contrast from run level * 1 group comparison
expected_nb_dsigns = 2 + 1 + 8 + 4;
summary = batchSummary(matlabbatch);
nb_designs = sum(sum(cellfun(@(x) strcmp(x, 'factorial_design'), summary)));
assertEqual(nb_designs, expected_nb_dsigns);

% folders = {};
% for i = 1:numel(matlabbatch)
% if isfield(matlabbatch{i}.spm, 'stats') && ...
% isfield(matlabbatch{i}.spm.stats, 'factorial_design')
% [~, tmp] = fileparts(matlabbatch{i}.spm.stats.factorial_design.dir{1});
% folders{end+1, 1} = tmp;
%
% end
% end
% folders

end

Expand All @@ -41,36 +57,9 @@ function test_bidsRFX_several_datasets_level()
matlabbatch = bidsRFX('RFX', opt);

summary = batchSummary(matlabbatch);

% only the batches from the last node is returned
% creates 1 batch for (specify, figure, estimate, review, figure)
batchOrder = {'stats', 'factorial_design'; ...
'util', 'print'};
batchOrder = extendBatchOrder(batchOrder);
assertEqual(summary, batchOrder);

nbGroupLevelModelsReturned = 1;
nbBatchPerModel = 7;
if bids.internal.is_octave()
nbBatchPerModel = 5;
end
assertEqual(numel(matlabbatch), nbGroupLevelModelsReturned * nbBatchPerModel);

end

function batchOrder = extendBatchOrder(batchOrder)
if nargin < 1
batchOrder = {};
end
extension = {'stats', 'fmri_est'; ...
'tools', 'MACS'; ...
'tools', 'MACS'; ...
'stats', 'review'; ...
'util', 'print'};
if bids.internal.is_octave()
extension(2:3, :) = [];
end
batchOrder = cat(1, batchOrder, extension);
nb_designs = sum(sum(cellfun(@(x) strcmp(x, 'factorial_design'), summary)));
% 2 simple dummy contrasts and one complex
assertEqual(nb_designs, 3);
end

function value = batchSummary(matlabbatch)
Expand Down

0 comments on commit b3722d5

Please sign in to comment.