-
Notifications
You must be signed in to change notification settings - Fork 0
/
aparc12_FA_analysis.m
463 lines (377 loc) · 15.4 KB
/
aparc12_FA_analysis.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
function aparc12_FA_analysis(meas, xmm, dtiPrepMode, varargin)
sIDs.PWS = {'S01', 'S04', 'S06', 'S07', 'S08', 'S09', 'S10', 'S12', 'S15', ...
'S16', 'S17', 'S20', 'S21', 'S26', 'S28', 'S29', 'S33', 'S34', ...
'S36', 'S37'};
% Included S16 (But S16 should probably be kept in the group FA comparison)
% What's wrong with S21? Why was he excluded before, in
% aparcSL_FA_analysis?
% Left out S04: due to registration problems, and B0
% distortions.
sIDs.PFS = {'S02', 'S03', 'S05', 'S11', 'S13', 'S14', 'S18', 'S19', 'S22', ...
'S23', 'S25', 'S27', 'S30', 'S31', 'S32', 'S35', ...
'S39'};
% Left out S24 (gross structural brain abnormality)
% xmm = 3;
% ROI = 'lh_dIFo';
DATA_DIR = '/users/cais/STUT/DATA';
if isequal(dtiPrepMode, 'none')
DAT_FN_WC = 'aparc12_%s_wm%dmm.mat';
elseif isequal(dtiPrepMode, 'dtiprep')
DAT_FN_WC = 'aparc12_dtiprep_%s_wm%dmm.mat';
elseif isequal(dtiPrepMode, 'dtiprep2')
DAT_FN_WC = 'aparc12_dtiprep2_%s_wm%dmm.mat';
else
error('Unrecognized dtiPrepMode');
end
TTEST_P_THRESH_UC = 0.05;
LINCORR_P_THRESH_UC = 0.05;
%%
% ROIS_BEHAVCORR = {'lh_vIFo', 'rh_vIFo', ...
% 'lh_dIFo', 'rh_dIFo', ...
% 'lh_vPMC', 'rh_vPMC', ...
% 'lh_SMA', 'rh_SMA', ...
% 'lh_preSMA', 'rh_preSMA', ...
% 'lh_vMC', 'rh_vMC', ...
% 'lh_vSC', 'rh_vSC', ...
% 'lh_aCO', 'rh_aCO', ...
% 'lh_pCO', 'rh_pCO', ...
% 'lh_H', 'rh_H', ...
% 'lh_pSTg', 'rh_pSTg', ...
% 'lh_PT', 'rh_PT'};
% ROIS_BEHAVCORR = {};
hemis = {'lh', 'rh'};
% t_rois = get_aparc12_cortical_rois('speech');
% for i1 = 1 : numel(hemis)
% hemi = hemis{i1};
%
% for i2 = 1 : numel(t_rois)
% ROIS_BEHAVCORR{end + 1} = sprintf('%s_%s', hemi, t_rois{i2});
% end
% end
% ROIS_sel = {'lh.iFo', 'lh.vPMC', 'lh.vMC', 'lh.aCO', 'lh.vSSC', ...
% 'lh.H', 'lh.PT'};
ROIS_sel = {'lh_vIFo', 'lh_vPMC', 'lh_vMC', 'lh_aCO', 'lh_vSC', ...
'lh_H', 'lh_PT'};
% ROIS_sel = {'lh_aIFs', 'lh_vIFo', 'lh_vPMC', 'lh_vMC', 'lh_aCO', 'lh_vSC', ...
% 'lh_H', 'lh_PT'};
%% Config: visualization
colors.PWS = 'r';
colors.PFS = 'k';
defaultFigClr = 'w';
figSaveDir = '/users/cais/STUT/figures';
for i0 = 1 : numel(hemis)
hemi = hemis{i0};
roiFigs.(hemi) = ...
sprintf('/users/cais/STUT/figures/rois_%s_flat_SLaparc_noText.tif', hemi);
roiFigsDiv.(hemi) = ...
sprintf('/users/cais/STUT/figures/rois_%s_flat_SLaparc_noText_div.tif', hemi);
roiFigsText.(hemi) = ...
sprintf('/users/cais/STUT/figures/rois_%s_flat_SLaparc.tif', hemi);
check_file(roiFigs.(hemi));
check_file(roiFigsDiv.(hemi));
check_file(roiFigsText.(hemi));
end
hiliteROIClr = [0.5, 1, 0];
drawBndClr = [0, 1.0, 0];
%% Config: alternative ROI names, for dealing with ROI name changes
altROINames = {'Ag', 'AG'; ...
'Hg', 'H'; ...
'aCGg', 'aCG'; ...
'midCGg', 'midCG'; ...
'pCGg', 'pCG'; ...
'ITOg', 'ITO'; ...
'MTOg', 'MTO'; ...
'Lg', 'LG'};
%% Get aparc12 ROI names
%if nargin == 0
roi_names_0 = get_aparc12_cortical_rois;
if length(roi_names_0{1}) > 3 ...
&& (isequal(roi_names_0{1}(1 : 3), 'lh_') ...
|| isequal(roi_names_0{1}(1 : 3), 'rh_'))
roi_names = roi_names_0;
else
roi_names = {};
for hemi = {'lh', 'rh'};
for i1 = 1 : numel(roi_names_0)
% if ~(length(roi_names_0{i1}) > 3 ...
% && (isequal(roi_names_0{i1}(1 : 3), 'lh_') ...
% || isequal(roi_names_0{i1}(1 : 3), 'rh_')))
roi_names{end + 1} = [hemi{1}, '_', roi_names_0{i1}];
% else
% roi_names{end + 1} = roi_names_0{i1};
% end
end
end
end
ROIS_BEHAVCORR = roi_names;
%end
%% Get behavioral measures
grps = fields(sIDs);
SSI4 = struct;
for i1 = 1 : numel(grps)
grp = grps{i1};
auSTI.(grp) = get_qdec_measure(sIDs.(grp), 'auSTI');
auSTI_n.(grp) = get_qdec_measure(sIDs.(grp), 'auSTI_n');
auSTI_dsd.(grp) = get_qdec_measure(sIDs.(grp), 'auSTI_dsd');
auSTI_dsd2.(grp) = get_qdec_measure(sIDs.(grp), 'auSTI_dsd2');
hnSV.(grp) = get_qdec_measure(sIDs.(grp), 'hnSV');
rnSV.(grp) = get_qdec_measure(sIDs.(grp), 'rnSV');
nnSV.(grp) = get_qdec_measure(sIDs.(grp), 'nnSV');
EHc.(grp) = get_qdec_measure(sIDs.(grp), 'EH_comp_300');
tempResp.(grp) = get_qdec_measure(sIDs.(grp), 'tempResp');
if isequal(grp, 'PWS')
if isempty(fsic(varargin, 'SSI_freq'))
SSI4.(grp) = get_qdec_measure(sIDs.(grp), 'SSI');
else
SSI4.(grp) = get_qdec_measure(sIDs.(grp), 'SSI_freq');
end
end
end
%%
nROIs = length(roi_names);
measDat.PWS = nan(nROIs, numel(sIDs.PWS));
measDat.PFS = nan(nROIs, numel(sIDs.PFS));
for h1 = 1 : nROIs
t_roi = roi_names{h1};
grps = fields(sIDs);
for i1 = 1 : numel(grps)
grp = grps{i1};
for i2 = 1 : numel(sIDs.(grp))
sID = sIDs.(grp){i2};
matfn = fullfile(DATA_DIR, sID, sprintf(DAT_FN_WC, meas, xmm));
if ~isfile(matfn)
error('Cannot find mat file: %s', matfn)
end
load(matfn); % gives rois, meanfa (or meanMD, meanRD, meanL1)
iroi = strmatch(t_roi, rois, 'exact');
% --- Deal with ROI name changes --- %
% if isequal(t_roi(end - 1 : end), 'Hg')
% iroi = [iroi, strmatch(strrep(t_roi, 'Hg', 'H'), rois, 'exact')];
% end
t_roi_0 = strrep(strrep(t_roi, 'lh_', ''), 'rh_', '');
if ~isempty(fsic(altROINames(:, 1), t_roi_0))
irow = fsic(altROINames(:, 1), t_roi_0);
for k1 = 2 : size(altROINames, 2)
t_roi_alt = strrep(t_roi, altROINames{irow, 1}, ...
altROINames{irow, k1});
iroi = [iroi, strmatch(t_roi_alt, rois, 'exact')];
end
end
if isempty(iroi)
fprintf('WARNING: Failed to find the ROI %s in the %d-mm data of subject %s\n', ...
t_roi, xmm, sID);
continue;
elseif length(iroi) > 1
fprintf('WARNING: More than one entries for ROI %s found in the %d-mm data of subject %s. Will use the first one.\n', ...
t_roi, xmm, sID);
iroi = iroi(1);
end
if isequal(meas, 'FA')
measDat.(grp)(h1, i2) = meanfa(iroi);
elseif isequal(meas, 'L1')
measDat.(grp)(h1, i2) = meanL1(iroi);
elseif isequal(meas, 'RD')
measDat.(grp)(h1, i2) = meanRD(iroi);
elseif isequal(meas, 'MD')
measDat.(grp)(h1, i2) = meanMD(iroi);
else
error('Unrecognized measure type: %s', meas);
end
end
end
end
%% ROI-by-ROI comparisons
p_vals_byROI = nan(nROIs, 1);
t_vals_byROI = nan(nROIs, 1);
sig_vals_byROI = nan(nROIs, 1);
for i1 = 1 : nROIs
xs_PWS = measDat.PWS(i1, :);
xs_PFS = measDat.PFS(i1, :);
[h, p, ci, stats] = ttest2(xs_PWS, xs_PFS);
p_vals_byROI(i1) = p;
t_vals_byROI(i1) = stats.tstat;
sig_vals_byROI(i1) = -log10(p) * sign(t_vals_byROI(i1));
end
%% Print the significant differences
idx_sig = find(p_vals_byROI < TTEST_P_THRESH_UC);
for i1 = 1 : numel(idx_sig)
fprintf('%s: p = %f; t = %f ', ...
roi_names{idx_sig(i1)}, ...
p_vals_byROI(idx_sig(i1)), ...
t_vals_byROI(idx_sig(i1)))
if t_vals_byROI(idx_sig(i1)) < 0
fprintf('(PWS < PFS)\n');
else
fprintf('(PWS > PFS)\n');
end
end
%% Prepare for behavioral correlation
roi_mean_fa = struct;
for i1 = 1 : numel(grps)
grp = grps{i1};
roi_mean_fa.(grp) = nan(numel(sIDs.(grp)), numel(ROIS_BEHAVCORR));
for i2 = 1 : numel(ROIS_BEHAVCORR)
t_roi = ROIS_BEHAVCORR{i2};
i_roi = strmatch(t_roi, roi_names, 'exact');
i_roi = fsic(roi_names, t_roi);
if length(i_roi) == 1
roi_mean_fa.(grp)(:, i2) = measDat.(grp)(i_roi, :)';
else
fprintf(2, 'WARNING: Cannot find data for ROI %s for behavioral correlation.\n', ...
t_roi);
end
end
end
roi_mean_fa_2g = [roi_mean_fa.PWS; roi_mean_fa.PFS];
%% Correlation between the measure and SSI4
[p_SSI4_corr_PWS, r_SSI4_corr_PWS] = corr_rois(roi_mean_fa.PWS, SSI4.PWS);
hashROIs.lh = {};
hashROIs.rh = {};
hashROISigns.lh = [];
hashROISigns.rh = [];
fprintf(1, '=== Significant correlations between ROI-mean %s and SSI4 ===\n', ...
meas);
for i1 = 1 : numel(ROIS_BEHAVCORR)
if (p_SSI4_corr_PWS(i1) < LINCORR_P_THRESH_UC)
fprintf(1, '%s: p = %.4f; r = %.3f\n', ...
ROIS_BEHAVCORR{i1}, p_SSI4_corr_PWS(i1), r_SSI4_corr_PWS(i1));
t_hemi = ROIS_BEHAVCORR{i1}(1 : 2);
hashROIs.(t_hemi){end + 1} = ROIS_BEHAVCORR{i1}(4 : end);
hashROISigns.(t_hemi)(end + 1) = ...
(r_SSI4_corr_PWS(i1) > 0) * 2 - 1;
end
end
%% Draw the aparc12 (SLaparc) ROI figures
% Create green-red colormap
cm0 = create_green_red_colormap();
cm = nan(size(cm0, 1) + 1, size(cm0, 2));
for i1 = 1 : size(cm, 2)
cm(:, i1) = interp1(1 : size(cm0, 1), cm0(:, i1), ...
linspace(1, size(cm0, 1), size(cm, 1)));
end
for i1 = 1 : numel(hemis)
hemi = hemis{i1};
t_fillROIs = {};
t_sigVals = [];
for i2 = 1 : numel(roi_names)
if isequal(roi_names{i2}(1 : 2), hemi)
t_fillROIs{end + 1} = roi_names{i2}(4 : end);
t_sigVals(end + 1) = sig_vals_byROI(i2);
end
end
% -- Figure out the mapping between sig values and color values -- %
max_abs_sig = max(abs(t_sigVals));
t_fillClrs = cell(size(t_fillROIs));
for i2 = 1 : numel(t_fillROIs)
tpos = (t_sigVals(i2) + max_abs_sig) / 2 / max_abs_sig;
tpos = round(1 + tpos * (size(cm, 1) - 1));
t_fillClrs{i2} = cm(tpos, :);
end
% -- Determine which ROI names to highlight -- %
hiliteROIs = t_fillROIs(find(abs(t_sigVals) > -log10(0.05)));
hiliteROIClrs = repmat({hiliteROIClr}, 1, length(hiliteROIs));
drawBndClrs = repmat({drawBndClr}, 1, length(hiliteROIs));
% -- Carry out the drawing -- %
imBase = imread(roiFigs.(hemi));
imDiv = imread(roiFigsDiv.(hemi));
imText = imread(roiFigsText.(hemi));
imSigMap.(hemi) = ...
fill_aparc12_roi_fig(imBase, imDiv, imText, hemi, ...
t_fillROIs, 'fillClrs', t_fillClrs, ...
'clrNameROIs', hiliteROIs, hiliteROIClrs, ...
'drawBndROIs', hiliteROIs, drawBndClrs, ...
'hashROIs', hashROIs.(hemi), hashROISigns.(hemi))
% -- Draw the color bar with ticks -- %
tickSigVals = 0 : 0.5 : max_abs_sig;
tickSigVals = [-fliplr(tickSigVals(2 : end)), tickSigVals];
tickSigIdx = (tickSigVals + max_abs_sig) / 2 / max_abs_sig;
tickSigIdx = round(1 + tickSigIdx * (size(cm, 1) - 1));
clrBarX = 400;
clrBarY = 560;
clrBarLenFact = 3;
clrBarWidth = 20;
imSigMap.(hemi) = draw_colorbar(imSigMap.(hemi), cm, ...
[clrBarX, clrBarY], clrBarLenFact, clrBarWidth, ...
'tickIdx', tickSigIdx);
% -- Visualize -- %
hf_faSigMap.(hemi) = figure('Name', sprintf('%s sig value map: %s', meas, hemi), ...
'Color', defaultFigClr);
imshow(imSigMap.(hemi));
hold on;
% for j1 = 1 : length(tickSigIdx)
% text(clrBarX + clrBarWidth + 10, ...
% clrBarY + tickSigIdx(j1) * (clrBarLenFact + 1) / 2, ...
% 'a');
% end
% -- Save to image file -- %
figFN = fullfile(figSaveDir, ...
sprintf('aparc12_%s.%dmm.%s.tif', meas, xmm, hemi));
saveas(hf_faSigMap.(hemi) , figFN, 'tif');
check_file(figFN);
fprintf(1, 'Saved %s data to image file: %s\n', meas, figFN);
end
%% Perform correlations with behavioral measures
[p_rnSV_corr, r_rnSV_corr] = corr_rois(roi_mean_fa_2g, rnSV);
[p_rnSV_corr_PWS, r_rnSV_corr_PWS] = corr_rois(roi_mean_fa.PWS, rnSV.PWS);
[p_rnSV_corr_PFS, r_rnSV_corr_PFS] = corr_rois(roi_mean_fa.PFS, rnSV.PFS);
[p_hnSV_corr, r_hnSV_corr] = corr_rois(roi_mean_fa_2g, hnSV);
[p_hnSV_corr_PWS, r_hnSV_corr_PWS] = corr_rois(roi_mean_fa.PWS, hnSV.PWS);
[p_hnSV_corr_PFS, r_hnSV_corr_PFS] = corr_rois(roi_mean_fa.PFS, hnSV.PFS);
plot_corr(p_rnSV_corr, r_rnSV_corr, ...
p_rnSV_corr_PWS, r_rnSV_corr_PWS, ...
p_rnSV_corr_PFS, r_rnSV_corr_PFS, ...
ROIS_BEHAVCORR, 'rnSV corr.', ...
roi_mean_fa_2g, rnSV);
plot_corr(p_hnSV_corr, r_hnSV_corr, ...
p_hnSV_corr_PWS, r_hnSV_corr_PWS, ...
p_hnSV_corr_PFS, r_hnSV_corr_PFS, ...
ROIS_BEHAVCORR, 'hnSV corr.', ...
roi_mean_fa_2g, hnSV);
%% Comparison wih SfN 2011 poster
figure('Position', [50, 100, 800, 300], 'Color', 'w');
yLim = [0.25, 0.4];
fontSize = 15;
barW = 0.4;
set(gca, 'FontSize', fontSize, 'LineWidth', 1);
xTickLabel = {};
p_uc = nan(1, numel(ROIS_sel)); % Uncorrected p-value
for i1 = 1 : numel(ROIS_sel)
t_ROI = ROIS_sel{i1};
idx_roi = fsic(roi_names, t_ROI);
t_meas_PWS = measDat.PWS(idx_roi, :);
t_meas_PFS = measDat.PFS(idx_roi, :);
bar(i1 - barW / 2, mean(t_meas_PFS), barW, 'FaceColor', 'none', ...
'EdgeColor', colors.PFS, 'LineWidth', 1);
hold on;
plot(repmat(i1 - barW / 2, 1, 2), mean(t_meas_PFS) + [-1, 1] * ste(t_meas_PFS), ...
'Color', colors.PFS, 'LineWidth', 1);
bar(i1 + barW / 2, mean(t_meas_PWS), barW, 'FaceColor', 'none', ...
'EdgeColor', colors.PWS, 'LineWidth', 1);
plot(repmat(i1 + barW / 2, 1, 2), mean(t_meas_PWS) + [-1, 1] * ste(t_meas_PWS), ...
'Color', colors.PWS, 'LineWidth', 1);
xTickLabel{end + 1} = strrep(strrep(t_ROI, 'lh.', ''), 'rh.', '');
[h_t, p_t] = ttest2(t_meas_PFS, t_meas_PWS);
if p_t < 0.05
plot(i1 + [-0.5, 0.5] * barW, repmat(yLim(2) - 0.075 * range(yLim), 1, 2), ...
'b-', 'LineWidth', 1);
plot(repmat(i1 - 0.5 * barW, 1, 2), yLim(2) - [0.1, 0.075] * range(yLim), ...
'b-', 'LineWidth', 1);
plot(repmat(i1 + 0.5 * barW, 1, 2), yLim(2) - [0.1, 0.075] * range(yLim), ...
'b-', 'LineWidth', 1);
plot(i1, yLim(2) - 0.025 * range(yLim), 'b*', 'MarkerSize', 10);
end
p_uc(i1) = p_t; % Uncorrected p-value
if i1 == 1
text(i1 - barW, yLim(1) + 0.02 * range(yLim), 'PFS', ...
'FontSize', fontSize, 'Color', colors.PFS);
text(i1 + barW, yLim(1) + 0.02 * range(yLim), 'PWS', ...
'FontSize', fontSize, 'Color', colors.PWS);
end
end
set(gca, 'XLim', [0.25, numel(ROIS_sel) + 0.75]);
set(gca, 'XTick', 1 : numel(ROIS_sel), 'XTickLabel', xTickLabel);
set(gca, 'YLim', yLim);
ylabel(sprintf('ROI %s (mean\pm1 SE)', meas), 'FontSize', fontSize);
%% Analysis and visualization
% meta_comp2(measDat, sprintf('Mean FA'));
return