forked from iricchi/Brain_GLMM
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbrainvis.m
executable file
·95 lines (70 loc) · 2.1 KB
/
brainvis.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
clc
% Make sure to load the proper Ls and mus
% e.g. load RS_k6_Ls load RS_k6_mus
% Num of nodes according to atlas used
N = size(mus,1); % 90 (AAL)
%% Read Node file for BrainNet
if (N == 90)
fid = fopen('Node_AAL90.node');
line1 = textscan(fid, '%f%f%f%f%f%s %*[^\n]','HeaderLines',1);
fclose(fid);
elseif(N==360)
line1 = cell(1,6);
end
%% Laplacian -> Adjacency
% given the Ls from the Algorithm take the W and plot them
prompt = 'Mean mu to visualize: ';
ind = input(prompt); % which mean to visualize
%L = L_final(:,:,ind);
L = Ls(:,:,ind);
W = diag(diag(L)) - L;
W(W<1e-4) = 0;
L = diag(sum(W)) - W;
% Thresholding W to reduce not relevant weigths
nozeros = W(W~=0);
th = prctile(nozeros, [10,50]);
W(W<th(2)) = 0;
% Thresholding W to avoid correlation between non-active nodes
indexes = mus(:,ind)> -0.01 ;
W(~indexes,~indexes) = 0;
%% Write edges
dlmwrite('W.edge', W, 'delimiter', ' ');
%% Create nodes file for mus
D = sum(W,2); % degrees
if (N == 360)
codeBook = load('CodeBook_GLasser_360regions.mat');
x = zeros(N,1);
y = zeros(N,1);
z = zeros(N,1);
for i = 1:N
x(i) = codeBook.codeBook.center{i}(1);
y(i) = codeBook.codeBook.center{i}(2);
z(i) = codeBook.codeBook.center{i}(3);
end
% set coordinates of nodes
line1{1}(:,1) = x;
line1{2}(:,1) = y;
line1{3}(:,1) = z;
line1{6} = num2str(zeros(N,1));
line1{6}(:) = '-';
end
line1{4} = mus(:,ind); % COLORS
line1{5} = mus(:,ind); %D; %% nodes size
data = [num2str(line1{1}), num2str(line1{2}),num2str(line1{3}), num2str(line1{4}), num2str(line1{5}), string(line1{6})];
fid = fopen('/Users/iricchi/Documents/MIP_LabImmersion/Nodes_output.node', 'wt');
for i = 1:N
line = [data(i,1:3),' ',data(i,4:5),' ', data(i,6)];
fprintf(fid,'%s%s%s%s%s%s%s%s\n',line);
end
fclose(fid);
%%
% Range : abs value of percentile +-
prc = prctile(line1{4}, [10,90]);
lim = max(abs(prc));
%%
load('conf.mat');
EC.nod.color_map_low = -lim;
EC.nod.color_map_high = lim;
save('EC','EC')
BrainNet_MapCfg('BrainMesh_ICBM152_smoothed.nv','Nodes_output.node','W.edge', 'EC.mat');
% savefig()