|
| 1 | +function concatBetaImgTmaps(funcFWHM, opt, deleteIndBeta, deleteIndTmaps) |
| 2 | + % concatBetaImgTmaps(funcFWHM, opt, deleteIndBeta, deleteIndTmaps) |
| 3 | + % |
| 4 | + % Make 4D images of beta and t-maps for the MVPA |
| 5 | + % |
| 6 | + % Inputs |
| 7 | + % funcFWHM - smoothing (FWHM) applied to the the normalized EPI |
| 8 | + % opt - options structure defined by the getOption function. If no inout is given |
| 9 | + % this function will attempt to load a opt.mat file in the same directory |
| 10 | + % to try to get some options |
| 11 | + % |
| 12 | + % deleteIndBeta, deleteIndTmaps: boolean to decide to delete |
| 13 | + % original t-maps, beta-maps or ResMaps (default = true) |
| 14 | + |
| 15 | + % if input has no opt, load the opt.mat file |
| 16 | + if nargin < 2 |
| 17 | + load('opt.mat'); |
| 18 | + fprintf('opt.mat file loaded \n\n'); |
| 19 | + end |
| 20 | + |
| 21 | + % delete individual Beta and tmaps |
| 22 | + if nargin < 3 |
| 23 | + deleteIndBeta = 1; |
| 24 | + deleteIndTmaps = 1; |
| 25 | + end |
| 26 | + |
| 27 | + % assign isMVPA to true |
| 28 | + isMVPA = 1; |
| 29 | + |
| 30 | + % load the subjects/Groups information and the task name |
| 31 | + [group, opt, ~] = getData(opt); |
| 32 | + |
| 33 | + %% Loop through the groups, subjects |
| 34 | + for iGroup = 1:length(group) |
| 35 | + |
| 36 | + for iSub = 1:group(iGroup).numSub |
| 37 | + |
| 38 | + subID = group(iGroup).subNumber{iSub}; |
| 39 | + |
| 40 | + fprintf(1, 'PREPARING: 4D maps: %s \n', subID); |
| 41 | + |
| 42 | + ffxDir = getFFXdir(subID, funcFWHM, opt, isMVPA); |
| 43 | + |
| 44 | + load(fullfile(ffxDir, 'SPM.mat')); |
| 45 | + |
| 46 | + contrasts = specifyContrasts(ffxDir, opt.taskName, opt, isMVPA); |
| 47 | + |
| 48 | + beta_maps = cell(length(contrasts), 1); |
| 49 | + t_maps = cell(length(contrasts), 1); |
| 50 | + |
| 51 | + % path to beta and t-map files. |
| 52 | + for iContrast = 1:length(beta_maps) |
| 53 | + % Note that the betas are created from the idx (Beta_idx(iBeta)) |
| 54 | + fileName = sprintf('beta_%04d.nii', find(contrasts(iContrast).C)); |
| 55 | + fileName = inputFileValidation(ffxDir, '', fileName); |
| 56 | + beta_maps{iContrast, 1} = [fileName{1}, ',1']; |
| 57 | + |
| 58 | + % while the contrastes (t-maps) are not from the index. They were created |
| 59 | + fileName = sprintf('spmT_%04d.nii', iContrast); |
| 60 | + fileName = inputFileValidation(ffxDir, '', fileName); |
| 61 | + t_maps{iContrast, 1} = [fileName{1}, ',1']; |
| 62 | + end |
| 63 | + |
| 64 | + % clear previous matlabbatch and files |
| 65 | + matlabbatch = []; |
| 66 | + |
| 67 | + % 4D beta maps |
| 68 | + matlabbatch{1}.spm.util.cat.vols = beta_maps; |
| 69 | + matlabbatch{1}.spm.util.cat.name = ['4D_beta_', num2str(funcFWHM), '.nii']; |
| 70 | + matlabbatch{1}.spm.util.cat.dtype = 4; |
| 71 | + |
| 72 | + % 4D t-maps |
| 73 | + matlabbatch{2}.spm.util.cat.vols = t_maps; |
| 74 | + matlabbatch{2}.spm.util.cat.name = ['4D_t_maps_', num2str(funcFWHM), '.nii']; |
| 75 | + matlabbatch{2}.spm.util.cat.dtype = 4; |
| 76 | + |
| 77 | + saveMatlabBatch(matlabbatch, 'concatBetaImgTmaps', opt, subID); |
| 78 | + |
| 79 | + spm_jobman('run', matlabbatch); |
| 80 | + |
| 81 | + removeBetaImgTmaps(beta_maps, t_maps, deleteIndBeta, deleteIndTmaps); |
| 82 | + |
| 83 | + end |
| 84 | + end |
| 85 | + |
| 86 | +end |
| 87 | + |
| 88 | +function removeBetaImgTmaps(beta_maps, t_maps, deleteIndBeta, deleteIndTmaps) |
| 89 | + |
| 90 | + % delete maps |
| 91 | + if deleteIndBeta |
| 92 | + |
| 93 | + % delete all individual beta maps |
| 94 | + fprintf('Deleting individual beta-maps ... '); |
| 95 | + for iBeta = 1:length(beta_maps) |
| 96 | + delete(beta_maps{iBeta}(1:end - 2)); |
| 97 | + end |
| 98 | + fprintf('Done. \n\n\n '); |
| 99 | + |
| 100 | + end |
| 101 | + |
| 102 | + if deleteIndTmaps |
| 103 | + |
| 104 | + % delete all individual con maps |
| 105 | + fprintf('Deleting individual con maps ... '); |
| 106 | + for iCon = 1:length(t_maps) |
| 107 | + delete(fullfile(ffxDir, ['con_', sprintf('%04d', iCon), '.nii'])); |
| 108 | + end |
| 109 | + fprintf('Done. \n\n\n '); |
| 110 | + |
| 111 | + % delete all individual t-maps |
| 112 | + fprintf('Deleting individual t-maps ... '); |
| 113 | + for iTmap = 1:length(t_maps) |
| 114 | + delete(t_maps{iTmap}(1:end - 2)); |
| 115 | + end |
| 116 | + fprintf('Done. \n\n\n '); |
| 117 | + end |
| 118 | + |
| 119 | + % delete mat files |
| 120 | + |
| 121 | + % This is refactorable |
| 122 | + % ex: delete(fullfile(ffxDir, ['4D_*', num2str(funcFWHM), '.mat'])); |
| 123 | + |
| 124 | + if exist(fullfile(ffxDir, ['4D_beta_', num2str(funcFWHM), '.mat']), 'file') |
| 125 | + delete(fullfile(ffxDir, ['4D_beta_', num2str(funcFWHM), '.mat'])); |
| 126 | + end |
| 127 | + if exist(fullfile(ffxDir, ['4D_t_maps_', num2str(funcFWHM), '.mat']), 'file') |
| 128 | + delete(fullfile(ffxDir, ['4D_t_maps_', num2str(funcFWHM), '.mat'])); |
| 129 | + end |
| 130 | +end |
0 commit comments