From b3722d513a7810dd54e57e095034d84cbe066236 Mon Sep 17 00:00:00 2001 From: Remi Gau Date: Tue, 30 Jul 2024 12:36:08 +0200 Subject: [PATCH] fixes --- src/batches/stats/setBatchFactorialDesign.m | 10 ++-- src/stats/group_level/getRFXdir.m | 8 +-- .../model-vismotionNoOverWrite_smdl.json | 12 +++- .../stats/test_setBatchFactorialDesign.m | 31 ---------- .../stats/test_bidsRFX_2_groups.m | 9 +++ .../stats/test_bidsRFX_3_groups.m | 5 ++ .../stats/test_bidsRFX_chain_several_nodes.m | 59 ++++++++----------- 7 files changed, 55 insertions(+), 79 deletions(-) diff --git a/src/batches/stats/setBatchFactorialDesign.m b/src/batches/stats/setBatchFactorialDesign.m index 0f5534af..3196e47b 100644 --- a/src/batches/stats/setBatchFactorialDesign.m +++ b/src/batches/stats/setBatchFactorialDesign.m @@ -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)); @@ -283,7 +283,7 @@ thisGroup = 'GROUP'; end - factorialDesign = commonFaxtorialDesignBatch(directory); + factorialDesign = commonFactorialDesignBatch(directory); factorialDesign.des.fd.icell = icell; @@ -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', {}); @@ -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', {}); @@ -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); diff --git a/src/stats/group_level/getRFXdir.m b/src/stats/group_level/getRFXdir.m index 601ecf4a..a64e3d15 100644 --- a/src/stats/group_level/getRFXdir.m +++ b/src/stats/group_level/getRFXdir.m @@ -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]; diff --git a/tests/data/models/model-vismotionNoOverWrite_smdl.json b/tests/data/models/model-vismotionNoOverWrite_smdl.json index 1d4d6fbc..0c66cdf6 100644 --- a/tests/data/models/model-vismotionNoOverWrite_smdl.json +++ b/tests/data/models/model-vismotionNoOverWrite_smdl.json @@ -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" ], @@ -247,7 +247,15 @@ }, { "Source": "subject_level", - "Destination": "between_groups" + "Destination": "between_groups", + "Filter": { + "contrast": [ + "VisMot", + "VisStat", + "VisMot_gt_VisStat", + "VisStat_gt_VisMot" + ] + } } ] } diff --git a/tests/tests_slow/tests_batches/stats/test_setBatchFactorialDesign.m b/tests/tests_slow/tests_batches/stats/test_setBatchFactorialDesign.m index 74036151..e73fe54b 100644 --- a/tests/tests_slow/tests_batches/stats/test_setBatchFactorialDesign.m +++ b/tests/tests_slow/tests_batches/stats/test_setBatchFactorialDesign.m @@ -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'); diff --git a/tests/tests_slow/tests_workflows/stats/test_bidsRFX_2_groups.m b/tests/tests_slow/tests_workflows/stats/test_bidsRFX_2_groups.m index 3abf07e4..f6415c38 100644 --- a/tests/tests_slow/tests_workflows/stats/test_bidsRFX_2_groups.m +++ b/tests/tests_slow/tests_workflows/stats/test_bidsRFX_2_groups.m @@ -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() @@ -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})); diff --git a/tests/tests_slow/tests_workflows/stats/test_bidsRFX_3_groups.m b/tests/tests_slow/tests_workflows/stats/test_bidsRFX_3_groups.m index ddea572d..33ea9bcc 100644 --- a/tests/tests_slow/tests_workflows/stats/test_bidsRFX_3_groups.m +++ b/tests/tests_slow/tests_workflows/stats/test_bidsRFX_3_groups.m @@ -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); diff --git a/tests/tests_slow/tests_workflows/stats/test_bidsRFX_chain_several_nodes.m b/tests/tests_slow/tests_workflows/stats/test_bidsRFX_chain_several_nodes.m index 97a2984b..00674a53 100644 --- a/tests/tests_slow/tests_workflows/stats/test_bidsRFX_chain_several_nodes.m +++ b/tests/tests_slow/tests_workflows/stats/test_bidsRFX_chain_several_nodes.m @@ -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 @@ -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)