-
Notifications
You must be signed in to change notification settings - Fork 0
/
main_DIAN_centrality_anal_signed_final.m
executable file
·116 lines (95 loc) · 4.03 KB
/
main_DIAN_centrality_anal_signed_final.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
%% main_DIAN_centrality_anal_signed
% data available upon request from Dominantly Inherited Alzhiemer Network
% Consortium
% savedir = './postcovbat_individual_signed_mst_0.10_Z_';
% function main_DIAN_centrality_anal_signed_final(savedir)
clear;close all;
here = pwd;
addpath(here)
cd '/data/wheelock/data1/people/Cindy/DIAN'
%% Load data and correct for data amount
allROI = readtable('DIAN_Seitzman_246.xlsx');
exclusion_id = [72,145];% the two subjects that are the only ones for their sites
load('IM_13nets_246_newcolor_MNI.mat'); % load parcellation based on Seitzman 2020 300 ROI
subjectdata = readtable('/data/wheelock/data1/people/Cindy/DIAN/MRI_subjectlist_N207_240105.xlsx');
subjectdata(exclusion_id,:)=[];
load('./Data/ROIv_207.mat')
ROIv(:,exclusion_id) = [];
ROIv = ROIv';
% savedir = './postcovbat_individual_signed_complete_Z_';
savedir = './postcovbat_individual_signed_mst_0.05_Z_';
% savedir = './individual_signed_mst_0.05_Z_';
% savedir = './postcovbat_truncated_individual_signed_mst_0.05_Z_excludist0mm';
Centrality = load(fullfile(savedir,'Centrality.mat'));
Centrality = Util.excludesubjects(Centrality,exclusion_id);
fs = fields(Centrality);
for i = 1:length(fs)
eval([fs{i},'=','Centrality.',fs{i},';'])
end
bindata = load('Mutation_CDR_bins_NCmatched.mat');
bindata = Util.excludesubjects(bindata,exclusion_id);
fs = fields(bindata);
for i = 1:length(fs)
eval([fs{i},'=','bindata.',fs{i},';'])
end
grouplabel{3} = strrep(grouplabel{3},'>=','\geq')
load(fullfile(savedir,'RealNets.mat'));
rmatGroupMean(:,:,exclusion_id)=[];
Nroi = size(S,2);
NPE=Nroi*(Nroi-1)/2; % number of possible edges
UDidx=find(triu(ones(Nroi),1)==1); % indices of unique conns
Nsubj = size(S,1);
try
normcoef = (Sneg./(Spos+Sneg));
normcoef(isnan(normcoef)) = 0;
catch
normcoef = 0;
end
% Correcting for num of minutes - N.B.the zscores of S and Scorr are the same
% X = repmat(subjectdata.totalMinutes,1,Nroi);
% model = fitlm(X(:),S(:));
% Scorr = model.Residuals.raw+model.Coefficients.Estimate(1);
% Scorr = reshape(Scorr,size(S));
%
% model = fitlm(X(:),Pc(:));
% Pccorr = model.Residuals.raw+model.Coefficients.Estimate(1);
% Pccorr = reshape(Pccorr,size(Pc));
% warning('Pc not corrected yet');
% Correcting for num of minutes and ROI volume- N.B.the zscores of S and Scorr are the same
X = repmat(subjectdata.totalMinutes,1,Nroi);
model = fitlm([X(:),ROIv(:)],S(:));
Scorr = model.Residuals.raw+model.Coefficients.Estimate(1);
Scorr = reshape(Scorr,size(S));
X = repmat(subjectdata.totalMinutes,1,Nroi);
model = fitlm([X(:),ROIv(:)],Pc(:));
Pccorr = model.Residuals.raw+model.Coefficients.Estimate(1);
Pccorr = reshape(Pccorr,size(Pc));
warning('Pc not corrected yet');
%% Intermodule and intramodule strength
M = double(IM.key(:,2)==IM.key(:,2)');
[withinS,betweenS,withinS_raw,betweenS_raw,Z] = deal(NaN(size(S)));
rmat0 = rmatGroupMean;
for isubj = 1:size(rmat0,3)
tmp = rmat0(:,:,isubj);
tmppos = tmp.*(M==1&tmp>0);
tmpneg = -tmp.*(M==1&tmp<0);
correctnanpos = sum(tmppos);correctnanpos(isnan(correctnanpos)) = 0;
correctnanneg = (sum(tmpneg));correctnanneg(isnan(correctnanneg)) = 0;
withinS_raw(isubj,:) = correctnanpos-normcoef(isubj,:).*correctnanneg;
withinS(isubj,:) = withinS_raw(isubj,:)./(sum(M==1)-1);%sum(M==1&tmp>0);
correctnanpos = BCT.module_degree_zscore(tmp.*(tmp>0),IM.key(:,2))';correctnanpos(isnan(correctnanpos)) = 0; % I think technically they got the same result because it is using within K only
correctnanneg =BCT.module_degree_zscore(-tmp.*(tmp<0),IM.key(:,2))';correctnanneg(isnan(correctnanpos)) = 0;
Z(isubj,:) = correctnanpos-normcoef(isubj,:).*correctnanneg;
end
withinS(isnan(withinS))=0;
% correcting for ROI volume- N.B.the zscores of S and Scorr are the same
model = fitlm(ROIv(:),Z(:));
Zcorr = model.Residuals.raw+model.Coefficients.Estimate(1);
Zcorr = reshape(Zcorr,size(Z));
model = fitlm(ROIv(:),withinS(:));
withinScorr = model.Residuals.raw+model.Coefficients.Estimate(1);
withinScorr = reshape(withinScorr,size(withinS));
cd(here)
%% plot figures
return
% end