diff --git a/src/workflows/bidsConcatBetaTmaps.m b/src/workflows/bidsConcatBetaTmaps.m index 4b922a309..1f7ef441c 100644 --- a/src/workflows/bidsConcatBetaTmaps.m +++ b/src/workflows/bidsConcatBetaTmaps.m @@ -9,9 +9,9 @@ function bidsConcatBetaTmaps(opt, funcFWHM, deleteIndBeta, deleteIndTmaps) % :param funcFWHM: smoothing (FWHM) applied to the the normalized EPI % :type funcFWHM: (scalar) % :param deleteIndBeta: decide to delete beta-maps - % :type funcFWHM: (boolean) + % :type deleteIndBeta: (boolean) % :param deleteIndTmaps: decide to delete t-maps - % :type funcFWHM: (boolean) + % :type deleteIndTmaps: (boolean) % % When concatenating betamaps: % @@ -22,12 +22,21 @@ function bidsConcatBetaTmaps(opt, funcFWHM, deleteIndBeta, deleteIndTmaps) % % (C) Copyright 2019 CPP_SPM developers - if nargin < 3 - deleteIndBeta = 1; - deleteIndTmaps = 1; + [~, opt] = setUpWorkflow(opt, 'merge beta images and t-maps'); + + % TODO temporary check: will be removed on the dev branch + if ~isfield(opt, 'dryRun') + opt.dryRun = false; end - [~, opt] = setUpWorkflow(opt, 'merge beta images and t-maps'); + if nargin < 3 + deleteIndBeta = true; + deleteIndTmaps = true; + end + if opt.dryRun + deleteIndBeta = false; + deleteIndTmaps = false; + end RT = 0; @@ -41,21 +50,25 @@ function bidsConcatBetaTmaps(opt, funcFWHM, deleteIndBeta, deleteIndTmaps) load(fullfile(ffxDir, 'SPM.mat')); - contrasts = specifyContrasts(ffxDir, opt.taskName, opt); + model = spm_jsonread(opt.model.file); + + contrasts = specifyContrasts(SPM, opt.taskName, model); beta_maps = cell(length(contrasts), 1); t_maps = cell(length(contrasts), 1); % path to beta and t-map files. + fprintf(1, '\nConcatenating the following contrasts:'); for iContrast = 1:length(beta_maps) + fprintf(1, '\n\t%s', contrasts(iContrast).name); betasIndices = find(contrasts(iContrast).C); if numel(betasIndices) > 1 error('Supposed to concatenate one beta image per contrast.'); end - % for this beta iamge we identify + % for this beta image we identify % - which run it came from % - the exact condition name stored in the SPM.mat % so they can be saved in a tsv for for "label" and "fold" for MVPA @@ -70,7 +83,6 @@ function bidsConcatBetaTmaps(opt, funcFWHM, deleteIndBeta, deleteIndTmaps) fileName = validationInputFile(ffxDir, fileName); beta_maps{iContrast, 1} = [fileName, ',1']; - % while the contrastes (t-maps) are not from the index. They were created fileName = sprintf('spmT_%04d.nii', iContrast); fileName = validationInputFile(ffxDir, fileName); t_maps{iContrast, 1} = [fileName, ',1']; @@ -81,15 +93,17 @@ function bidsConcatBetaTmaps(opt, funcFWHM, deleteIndBeta, deleteIndTmaps) nameStructure = struct( ... 'ext', '.tsv', ... 'suffix', 'labelfold', ... - 'entities' struct('sub', subLabel, ... - 'task', opt.taskName, ... - 'space', opt.space)); + 'entities', struct('sub', subLabel, ... + 'task', opt.taskName, ... + 'space', opt.space)); + nameStructure.use_schema = false; tsvName = bids.create_filename(nameStructure); tsvContent = struct('folds', runs, 'labels', {conditions}); spm_save(fullfile(ffxDir, tsvName), tsvContent); + % TODO in the dev branch make those output filenames "BIDS derivatives" compliant % beta maps outputName = ['4D_beta_', num2str(funcFWHM), '.nii']; @@ -101,7 +115,10 @@ function bidsConcatBetaTmaps(opt, funcFWHM, deleteIndBeta, deleteIndTmaps) matlabbatch = setBatch3Dto4D(matlabbatch, t_maps, RT, outputName); - saveAndRunWorkflow(matlabbatch, 'concat_betaImg_tMaps', opt, subLabel); + % TODO temporary: remove on dev branch + if ~opt.dryRun + saveAndRunWorkflow(matlabbatch, 'concat_betaImg_tMaps', opt, subLabel); + end removeBetaImgTmaps(t_maps, deleteIndBeta, deleteIndTmaps, ffxDir); @@ -136,6 +153,7 @@ function removeBetaImgTmaps(t_maps, deleteIndBeta, deleteIndTmaps, ffxDir) delete(t_maps{iTmap}(1:end - 2)); end fprintf('Done. \n\n\n '); + end end diff --git a/tests/createDummyDataSet.sh b/tests/createDummyDataSet.sh index 85bc6dce6..3c9facce9 100755 --- a/tests/createDummyDataSet.sh +++ b/tests/createDummyDataSet.sh @@ -110,7 +110,14 @@ do touch $ThisDir/mask.nii touch $ThisDir/spmT_0001.nii - touch $ThisDir/spmT_0002.nii + touch $ThisDir/spmT_0002.nii + touch $ThisDir/spmT_0003.nii + touch $ThisDir/spmT_0004.nii + + touch $ThisDir/beta_0001.nii + touch $ThisDir/beta_0002.nii + touch $ThisDir/beta_0003.nii + touch $ThisDir/beta_0004.nii touch $ThisDir/con_0001.nii touch $ThisDir/con_0002.nii diff --git a/tests/dummyData/models/model-vismotionMVPA_smdl.json b/tests/dummyData/models/model-vismotionMVPA_smdl.json new file mode 100644 index 000000000..6e776805c --- /dev/null +++ b/tests/dummyData/models/model-vismotionMVPA_smdl.json @@ -0,0 +1,16 @@ +{ + "Name": "vismotion", + "Description": "This model only has simple contrasts for MVPA", + "Input": { + "task": "vismotion" + }, + "Steps": [ + { + "Level": "subject", + "AutoContrasts": [ + "trial_type.VisMot", + "trial_type.VisStat" + ] + } + ] +} \ No newline at end of file diff --git a/tests/test_bidsConcatBetaTmaps.m b/tests/test_bidsConcatBetaTmaps.m new file mode 100644 index 000000000..1326e61b2 --- /dev/null +++ b/tests/test_bidsConcatBetaTmaps.m @@ -0,0 +1,33 @@ +function test_suite = test_bidsConcatBetaTmaps %#ok<*STOUT> + % + % (C) Copyright 2019 CPP_SPM developers + try % assignment of 'localfunctions' is necessary in Matlab >= 2016 + test_functions = localfunctions(); %#ok<*NASGU> + catch % no problem; early Matlab versions can use initTestSuite fine + end + initTestSuite; +end + +function test_bidsConcatBetaTmapsBasic() + + subLabel = '01'; + funcFWHM = 6; + + opt = setOptions('vismotion', subLabel); + opt.dryRun = true; + + opt.model.file = spm_file(opt.model.file, 'filename', 'model-vismotionMVPA_smdl.json'); + + bidsConcatBetaTmaps(opt, funcFWHM); + + ffxDir = getFFXdir(subLabel, funcFWHM, opt); + content = bids.util.tsvread(fullfile(ffxDir, ... + 'sub-01_task-vismotion_space-MNI_labelfold.tsv')); + + expectedContent = struct('labels', {{'VisMot*bf(1)'; 'VisStat*bf(1)'}}, 'folds', [1; 1]); + + assertEqual(content, expectedContent); + + delete(fullfile(ffxDir, 'sub-01_task-vismotion_space-MNI_labelfold.tsv')); + +end diff --git a/version.txt b/version.txt index efdb8b180..32e7334eb 100644 --- a/version.txt +++ b/version.txt @@ -1 +1 @@ -v1.1.2 \ No newline at end of file +v1.1.3 \ No newline at end of file