-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStep2_Vince_Script.m
More file actions
107 lines (90 loc) · 3.86 KB
/
Step2_Vince_Script.m
File metadata and controls
107 lines (90 loc) · 3.86 KB
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
%% ------------------------------------------------------------
%%used this for the main figure plotting, I used Step2_3 for calling
%%variables for the log plots
% Step 0: Setup
% ------------------------------------------------------------
cd '/Users/amrithah/Desktop/CalhounLab/Dissertation/Projects/Chapter6_Paper_5_SPECT Template/Scripts/sc-ICA'
a = spm_read_vols(spm_vol('SPECT_SZ_ICA_Output_Rest_MOO_ICAR_group_loading_coeff_.nii'));
hcind = 1:76;
szind = 77:213;
nSub = size(a,1);
nComp = size(a,2); % number of components directly from data
%% ------------------------------------------------------------
% Step 1: Build full connectivity matrices for each subject
% ------------------------------------------------------------
out_mat = zeros(nSub, nComp, nComp);
for j = 1:nSub
vec = icatb_mat2vec(a(j,:)' * a(j,:)); % vectorized connectivity
mat = icatb_vec2mat(vec); % convert to square matrix
out_mat(j,:,:) = mat; % store
end
out_clean = out_mat;
%% ------------------------------------------------------------
% Step 2 and 3: Prepare x and y axis tick labels for domains/subdomains
% ------------------------------------------------------------
tickLabels = labels; % keep if still valid; otherwise replace with your original labels
[uniqueCats, ~, idx] = unique(tickLabels, 'stable');
tickPositions = arrayfun(@(u) find(idx == u, 1, 'first'), 1:numel(uniqueCats));
%% ------------------------------------------------------------
% Step 4: Compute group means
% ------------------------------------------------------------
HC_mean = squeeze(mean(out_clean(hcind,:,:)));
SZ_mean = squeeze(mean(out_clean(szind,:,:)));
Diff_mean = HC_mean - SZ_mean;
%%
% Step 5: Reorder within domain for the 3 matrices
% labels is a 68×1 cell array of strings
% We need numeric indices 1:68
idx = 1:length(labels); % numeric indices
HC_mean_final = HC_mean(idx, idx);
SZ_mean_final = SZ_mean(idx, idx);
Diff_mean_final = Diff_mean(idx, idx);
%% ------------------------------------------------------------
% Step 5: Plot all three matrices
% --- Plot 1 ---
plotMatrix(HC_mean_final, [-.6 .6], 'Average Control CoM', tickPositions, uniqueCats);
colorbar;
set(gca, 'FontSize', 11);
save('Control_CoM_Matrix_Final.fig');
movefile('*.fig', '/Users/amrithah/Desktop/CalhounLab/Dissertation/Projects/Paper_5_SPECT Template/Figures');
%%
% --- Plot 2 ---
plotMatrix(SZ_mean_final, [-.6 .6], 'Average Patient CoM', tickPositions, uniqueCats);
colorbar;
set(gca, 'FontSize', 11);
save('Patient_CoM_Matrix_Final.fig');
movefile('*.fig', '/Users/amrithah/Desktop/CalhounLab/Dissertation/Projects/Chapter6_Paper_5_SPECT Template/Figures');
%% --- Plot 3 ---
%% GROUP DIFFERENCES WITH UPDATED FLATTENED MATRIX
figure;
imagesc(meandiff); %adapted from Step2_3_flatt script since that had a better flattening script
axis square; colormap(whitejet); caxis([-0.4 0.4]); colorbar;
title('Average SC‑ICA Difference (Control – Patients) Co-Modulation Matrix, Flattened Matrix');
set(gca, 'FontSize', 11);
xticks(tickPositions);
yticks(tickPositions);
xticklabels(uniqueCats);
yticklabels(uniqueCats);
xtickangle(90);
ax = gca;
save('GroupDiff_CoM_Matrix_Final.fig');
movefile('*.fig', '/Users/amrithah/Desktop/CalhounLab/Dissertation/Projects/Chapter6_Paper_5_SPECT Template/Figures');
%% ------------------------------------------------------------
% Nested function for plotting (updated to save .fig)
% ------------------------------------------------------------
function plotMatrix(M, clim, ttl, tickPositions, uniqueCats)
figure;
imagesc(M, clim);
colormap whitejet;
axis image;
colorbar;
title(ttl);
xticks(tickPositions);
yticks(tickPositions);
xticklabels(uniqueCats);
yticklabels(uniqueCats);
xtickangle(90);
% ---- Save figure as .fig ----
fname = [regexprep(ttl, '\s+', '_') '.fig'];
savefig(gcf, fname);
end