|
| 1 | +function mni = get_ROI_Coordinates |
| 2 | + % This function gets the individual subject coordniates of the highest peak |
| 3 | + % within a specified Region of interest (usually coming |
| 4 | + % from the group level univariate analysis) |
| 5 | + % |
| 6 | + % Critical t-value for each experimental condition or mask file |
| 7 | + % Critical t-value for visual condition in L-V5 and R-V5 and bilateral PT |
| 8 | + % |
| 9 | + % (C) Copyright 2021 CPP ROI developers |
| 10 | + |
| 11 | + CriticalTs = 1; |
| 12 | + |
| 13 | + %% load the data structure |
| 14 | + WD = pwd; |
| 15 | + |
| 16 | + %% group of subjects to analyze |
| 17 | + opt.groups = {'EB', 'SCa', 'SCv'}; % {'EB','SCa','SCv'}; |
| 18 | + % suject to run in each group |
| 19 | + opt.subjects = {[1:13], [1:10], [1:6]}; % {[1:13],[1:10],[1:6]}; |
| 20 | + |
| 21 | + %% |
| 22 | + smoothing = '6'; |
| 23 | + |
| 24 | + %% Regions that will be used to extract the highest t-value within that mask |
| 25 | + maskFn = { 'face_lFFA.nii' |
| 26 | + 'face_rFFA.nii' |
| 27 | + }; |
| 28 | + |
| 29 | + CriticalTs = ones(1, length(maskFn)) * CriticalTs; |
| 30 | + |
| 31 | + %% Location of the data |
| 32 | + data_path = '/Volumes/SanDisk/Oli_Data/Categs_BIDS/derivatives'; |
| 33 | + |
| 34 | + % create an mni cell with dimensions (1x number of masks) |
| 35 | + mni = cell(1, length(maskFn)); |
| 36 | + SubNames = {}; |
| 37 | + |
| 38 | + % for each mask |
| 39 | + for iMask = 1:length(maskFn) |
| 40 | + |
| 41 | + fprintf('Running Mask %.0f \n\n', iMask); |
| 42 | + CriticalT = CriticalTs(iMask); % get the critical t |
| 43 | + |
| 44 | + subCounter = 0; |
| 45 | + for iGroup = 1:length(opt.groups) |
| 46 | + for iSub = 1:length(opt.subjects{iGroup}) |
| 47 | + |
| 48 | + fprintf('Running Subject %.0f \n', iSub); |
| 49 | + |
| 50 | + SubName = ['sub-', opt.groups{iGroup}, ... |
| 51 | + sprintf('%02d', opt.subjects{iGroup}(iSub))]; |
| 52 | + |
| 53 | + fprintf('%s \n', SubName); |
| 54 | + subCounter = subCounter + 1; |
| 55 | + SubNames{subCounter, iMask} = SubName(5:end); |
| 56 | + |
| 57 | + %% the first 4 masks are for the FACE condition, the other 4 |
| 58 | + % are from the SCENE condition |
| 59 | + if iMask <= 2 |
| 60 | + result_file = [data_path, '/', ... |
| 61 | + SubName, ... |
| 62 | + '/stats/ffx_visMotion/ffx_', ... |
| 63 | + smoothing, ... |
| 64 | + '/spmT_0013.nii']; % HUMAN > BIG_ENV |
| 65 | + else |
| 66 | + result_file = [data_path, '/', ... |
| 67 | + SubName, ... |
| 68 | + '/stats/ffx_audMotion/ffx_', ... |
| 69 | + smoothing, ... |
| 70 | + '/spmT_0014.nii']; % BIG_ENV > HUMAN |
| 71 | + end |
| 72 | + |
| 73 | + %% |
| 74 | + mask_path = fullfile(WD, 'Kanwisher_ROIs', maskFn{iMask}); |
| 75 | + |
| 76 | + r = load_nii(result_file); |
| 77 | + m = load_nii(mask_path); |
| 78 | + |
| 79 | + r.img(~m.img) = nan; |
| 80 | + |
| 81 | + maxVal = max(r.img(:)); |
| 82 | + maxVals(subCounter, iMask) = maxVal; |
| 83 | + |
| 84 | + if maxVal > CriticalT %|| maxVal < CriticalT |
| 85 | + |
| 86 | + % Get the location of the higest t-value in slice space |
| 87 | + voxel_idx = find(r.img == maxVal); |
| 88 | + |
| 89 | + disp(maxVal); |
| 90 | + [x, y, z] = ind2sub(size(r.img), voxel_idx); |
| 91 | + |
| 92 | + % convert space from slice number to mni |
| 93 | + mni{1, iMask}(subCounter, :) = cor2mni([x y z], mask_path); |
| 94 | + |
| 95 | + % mni{1,iMask}(iSub,1) = mni{1,iMask}(iSub,1)* -1; |
| 96 | + % If masks created from AFNI or FSL, |
| 97 | + % the x coordinate could be flipped (multiplied x -1). |
| 98 | + % If this is the case, multiply x with -1. |
| 99 | + |
| 100 | + mni{1, iMask}(subCounter, :); |
| 101 | + |
| 102 | + else |
| 103 | + mni{1, iMask}(subCounter, 1:3) = nan; |
| 104 | + end |
| 105 | + |
| 106 | + end |
| 107 | + end |
| 108 | + end |
| 109 | + |
| 110 | + save('mni_coordinates.mat', 'mni', 'maskFn', 'opt', 'maxVals', 'SubNames'); |
| 111 | +end |
| 112 | + |
| 113 | +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 114 | +%%% cor2mni |
| 115 | +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 116 | +function mni = cor2mni(cor, nifti_image) |
| 117 | + % function mni = cor2mni(cor, T) |
| 118 | + % convert matrix coordinate to mni coordinate |
| 119 | + % |
| 120 | + % cor: an Nx3 matrix |
| 121 | + % T: (optional) rotation matrix |
| 122 | + % mni is the returned coordinate in mni space |
| 123 | + % |
| 124 | + % caution: if T is not given, the default T is |
| 125 | + % T = ... |
| 126 | + % [-4 0 0 84;... |
| 127 | + % 0 4 0 -116;... |
| 128 | + % 0 0 4 -56;... |
| 129 | + % 0 0 0 1]; |
| 130 | + % |
| 131 | + % xu cui |
| 132 | + % 2004-8-18 |
| 133 | + % last revised: 2005-04-30 |
| 134 | + |
| 135 | + % if nargin == 1 |
| 136 | + % T = ... |
| 137 | + % [-4 0 0 84;... |
| 138 | + % 0 4 0 -116;... |
| 139 | + % 0 0 4 -56;... |
| 140 | + % 0 0 0 1]; |
| 141 | + % end |
| 142 | + |
| 143 | + V = spm_vol(nifti_image); |
| 144 | + T = V.mat; |
| 145 | + |
| 146 | + cor = round(cor); |
| 147 | + mni = T * [cor(:, 1) cor(:, 2) cor(:, 3) ones(size(cor, 1), 1)]'; |
| 148 | + mni = mni'; |
| 149 | + mni(:, 4) = []; |
| 150 | +end |
0 commit comments