-
Notifications
You must be signed in to change notification settings - Fork 15
/
demo_ExampleSurfacePlotFunction.m
182 lines (111 loc) · 4.5 KB
/
demo_ExampleSurfacePlotFunction.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
% This script just gives some examples of how the code can be used
load('surface_data.mat')
load('example_data.mat')
%% Accentuate plotted data
surface.vertices = lh_inflated_verts;
surface.faces = lh_faces;
vertex_id = lh_HCPMMP1;
data = zscore(lh_HCPMMP1_gene_pc1);
cmap = turbo(256);
data_label = 'Gene PC1';
ExampleSurfacePlotFunction(surface,vertex_id,data,cmap,data_label);
%print('./figures/Example1.png','-dpng','-r300')
%% Plot parcellation over continuous data
surface.vertices = lh_verts;
surface.faces = lh_faces;
vertex_id = lh_rand200;
data = lh_sulc;
cmap = parula(256);
data_label = 'Sulcal depth';
ExampleSurfacePlotFunction(surface,vertex_id,data,cmap,data_label);
%print('./figures/Example2.png','-dpng','-r300')
%% Plot parcellation over another parcellation
surface.vertices = lh_inflated_verts;
surface.faces = lh_faces;
vertex_id = lh_rand500;
data = lh_Yeo_7net;
data(data==0) = NaN;
cmap = Yeo_7net_cmap;
data_label = 'Yeo network';
[~,~,c] = ExampleSurfacePlotFunction(surface,vertex_id,data,cmap,data_label);
% Make the colorbar look less weird
caxis([nanmin(data)-.5 nanmax(data)+.5])
c.Ticks = 1:7;
%print('./figures/Example3.png','-dpng','-r300')
%% Plot data that has been thresholded
surface.vertices = lh_inflated_verts;
surface.faces = lh_faces;
vertex_id = lh_rand500;
data = lh_func_grad1;
% Threshold to only display data 1 SD above the mean
data(data<(mean(data) +std(data))) = NaN;
% Any data which has a NaN value will not be assigned a colour from the
% colour map. Instead by default it will be displayed as grey.
cmap = turbo(256);
data_label = 'Functional gradient';
ExampleSurfacePlotFunction(surface,vertex_id,data,cmap,data_label);
%print('./figures/Example4.png','-dpng','-r300')
%% Threshold data on a per region basis
surface.vertices = lh_inflated_verts;
surface.faces = lh_faces;
vertex_id = lh_rand500;
data = zeros(length(unique(vertex_id))-1,1);
for i = 1:length(data)
data(i) = mean(lh_func_grad1(vertex_id==i));
end
% Threshold to only display data 1 SD above the mean
data(data<(mean(data) +std(data))) = NaN;
% Any data which has a NaN value will not be assigned a colour from the
% colour map. Instead by default it will be displayed as grey.
cmap = turbo(256);
data_label = 'Functional gradient';
ExampleSurfacePlotFunction(surface,vertex_id,data,cmap,data_label);
%print('./figures/Example5.png','-dpng','-r300')
%% Threshold data and borders
% This will only work if 'data' is plotted continuously on the surface
% Why you would want to do this, I have no idea but here you go anyway!
surface.vertices = lh_inflated_verts;
surface.faces = lh_faces;
vertex_id = lh_rand500;
data_temp = zeros(length(unique(vertex_id))-1,1);
for i = 1:length(data_temp)
data_temp(i) = mean(lh_func_grad1(vertex_id==i));
end
% Threshold to only display data 1 SD above the mean
data_temp(data_temp<(mean(data_temp) +std(data_temp))) = NaN;
% Plot the data back to the surface
data = nan(size(vertex_id));
for i = 1:length(data_temp)
data(vertex_id==i) = data_temp(i);
end
vertex_id(ismember(vertex_id,find(isnan(data_temp)))) = 0;
% If you set a regions vertex_id to 0, then it won't appear to be plotted
% (technically is still is plotted but as an unknown region)
cmap = turbo(256);
data_label = 'Functional gradient';
ExampleSurfacePlotFunction(surface,vertex_id,data,cmap,data_label);
%print('./figures/Example6.png','-dpng','-r300')
%% Plot data where ROI ids are not sequential
% Read the .annot file for the HCPMMP1 parcellation
[vertices, label, colortable] = read_annotation('lh.HCPMMP1.annot');
surface.vertices = lh_inflated_verts;
surface.faces = lh_faces;
vertex_id = label;
% Get the IDs of the ROIs. Note this values are not sequential
ROI_ids = colortable.table(:,5);
% For some reason in this .annot file, the ID for the medial wall in
% 'label' and 'ROI_ids' do not match. Can be easily fixed by substituting
% the value for the medial wall in 'label' to 'ROI_ids' (it will be the
% only value not present in both).
HCPMMP1_medialwall = setdiff(unique(label),ROI_ids);
data = [(1:size(ROI_ids,1))' ROI_ids];
data(1,2) = HCPMMP1_medialwall;
% Pull out the colormap from the .annot file
cmap = colortable.table(:,1:3)./255;
% Replace the colour for the medial wall with grey
cmap(1,:) = [.5 .5 .5];
% Alternative way to displaying the medial wall as grey:
% vertex_id(vertex_id==HCPMMP1_medialwall) = 0;
data_label = 'HCPMMP1 ROI ID';
ExampleSurfacePlotFunction(surface,vertex_id,data,cmap,data_label);
%print('./figures/Example7.png','-dpng','-r300')