-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreate_cerflatmaps.m
383 lines (305 loc) · 12.5 KB
/
create_cerflatmaps.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
%% Introduction
% This matlab script uses the SUIT Toolbox (http://www.diedrichsenlab.org/imaging/suit.htm) in SPM12
% to create flatmap representations of the cerebellar retinotopy data.
% created by: Daan van Es ([email protected])
%% base setup
% this dir should point to where the masked niftis are stored:
data_dir = '/Users/daanvanes/disks/Aeneas_Shared/2018/visual/hcp_cerebellum/';
mask_dir = strcat(data_dir,'masked_niftis/');
% for the tsnr maps
tsnr_dir = strcat(data_dir,'timeseries/');
% this dir should point to where you want the flatmaps saved
flatmap_dir = '/Users/daanvanes/Documents/Documenten/Research/data/hcp_retinotopy/hcp_data/suit_flatmaps/';
if exist(flatmap_dir,'dir') ~= 7
mkdir(flatmap_dir)
end
% this is where the flattened data is stored
flat_dir = strcat(data_dir,'flat_data/');
if exist(flat_dir,'dir') ~= 7
mkdir(flat_dir)
end
% this should be your spm / suit install:
addpath('/Applications/spm12')
addpath('/Applications/spm12/toolbox/suit')
% fsl colormap dir
fsl_cmap_dir = '/Applications/FSLeyes.app/Contents/Resources/assets/colourmaps/';
% this is the git repo (www.github.com/daanvanes/hcp_cerebellum):
resource_dir = '/Users/daanvanes/disks/Aeneas_Home/git/hcp_cerebellum/resources/';
mat_functions = strcat(resource_dir,'mscripts');
addpath(mat_functions)
%% create flattened representation of cerebellar retinotopic masks
fn = strcat(resource_dir,'volume_masks/','cerebellum_retmaps.nii');
Data = int32(suit_map2surf(fn,'depths',0:0.1:1));
% random colors
cm = [
120 ,18 ,134;
255, 0, 0;
70, 130, 180;
42, 204, 164;
74, 155, 60 ;
0, 118, 14;
196, 58, 250;
255, 152, 213;
200, 248, 164;
122, 135, 50;]/255;
% save data matrix
fn = strcat(flat_dir,'retmaps_flat.csv');
csvwrite(fn,Data)
% plot flatmap
suit_plotflatmap(Data,'type','label','cmap',cm)
hAxes = gca;
hAxes.XRuler.Axle.LineStyle = 'none';
axis off
set(gcf,'paperunits','inches','papersize',[3,3],'paperposition',[-1.1,-1.1,5,5])
fn = strcat(flatmap_dir,'retmaps.pdf');
print(gcf,fn,'-dpdf','-r300');
close()
%% now create the actual flatmaps
close('all')
for s = [0:180]%[181,182,183]%,0:4,88:92,176:180,183] % ! sj here refers to subject rank, not original subject id (except for 183, which still refers to avg subject)
for h = [0,1,2]
if ((s == 183) * (h == 0))
masks = ["r2","r2_spill","r2_spill_fix"];
vars = ["ang","ecc","rfsize","r2"];
sj = num2str(s);
elseif s > 180
masks = ["r2_spill_fix"];
vars = ["ang","ecc","rfsize","r2"];%"ang","ecc"];
if h > 0
sj = strcat(num2str(s),'_',num2str(h));
else
sj = num2str(s);
end
else
masks = ["r2_fix_roi"];
vars = ["ecc"];
sj = num2str(s);
end
for mask = masks
for var = vars
threshold=0;
% the standard function to perform across layers:
func=@nanmean;
if strcmp(var,'ang')
% create a colormap that is more focused on the lower
% visual fied:
blue = [45,52,135];
red = [153,27,68];
yellow = [250,195,83];
green = [0,153,74];
magenta = [223,112,172];
cyan = [110,207,246];
rgbs = [yellow;green;green;green;cyan;blue;magenta;red;yellow]/255;
cm = interpolate_cvals_rgbspace(rgbs);
% save cmap as .cmap that can be read by FSLeyes
fn = strcat(fsl_cmap_dir,'angcmap.cmap');
fileID = fopen(fn,'w');
formatSpec = '%1.6f %1.6f %1.6f \n';
[nrows,ncols] = size(cm);
for row = 1:nrows
fprintf(fileID,formatSpec,cm(row,:));
end
fclose(fileID);
% use circular mean
func = @circ_mean_adapted; % adapted such that it is appropriately used in suit toolbox
sc = [0,pi*2];
elseif strcmp(var,'ecc')
cm = colorcet('R2');
sc = [0,6];
% save cmap as .cmap that can be read by FSLeyes
fn = strcat(fsl_cmap_dir,'ecccmap.cmap');
fileID = fopen(fn,'w');
formatSpec = '%1.6f %1.6f %1.6f \n';
[nrows,ncols] = size(cm);
for row = 1:nrows
fprintf(fileID,formatSpec,cm(row,:));
end
fclose(fileID);
elseif strcmp(var,'r2')
cm = colorcet('L8');
sc = [9.8,40];
elseif strcmp(var,'rfsize')
cm = colorcet('L5');
sc = [0,6];
end
% load data:
dir = char(strcat(mask_dir,mask,'/','prfresults_subject_rank_',sj,'_',var,'.nii'));
Data = suit_map2surf(dir,'space','FSL','stats',func,'depths',0:0.1:1);
% save data matrix (for later plots along a certain direction
% on the flatmap)
write_data=false;
if (var == "ang") + (var == "ecc") + (var == "r2")
if ((s == 183) * (h == 0))
if mask == "r2_spill_fix"
write_data = true;
end
elseif s < 183
write_data = true;
end
end
if write_data
fn = strcat(flat_dir,var,'_flatdata_',sj,'.csv');
csvwrite(fn,Data)
end
% plot flatmap
suit_plotflatmap(Data,'cmap',cm,'cscale',sc,'threshold',threshold);
hAxes = gca;
hAxes.XRuler.Axle.LineStyle = 'none';
axis off
set(gcf,'paperunits','inches','papersize',[3,3],'paperposition',[-1.1,-1.1,5,5])
fn = strcat(flatmap_dir,var,'_',num2str(sj),'flatmap','_',mask,'.pdf');
print(gcf,fn,'-dpdf','-r300');
close()
end
end
end
end
close('all')
%% create tsnr maps
close('all')
for s = [184,185,186]%[0:4,88:92,176:180]%,181:183]%:180]
% load data:
dir = char(strcat(tsnr_dir,'sub_rank_',num2str(s),'_tsnr_avg_over_tasks.nii'));
Data = suit_map2surf(dir,'space','FSL','stats',@nanmean,'depths',0:0.1:1);
cm = colorcet('L8');
if (s ==180) + (s ==182) + (s == 183)
sc = [0,750];
else
sc = [0,75];
end
suit_plotflatmap(Data,'cmap',cm,'cscale',sc);
hAxes = gca;
hAxes.XRuler.Axle.LineStyle = 'none';
axis off
set(gcf,'paperunits','inches','papersize',[3,3],'paperposition',[-1.1,-1.1,5,5])
fn = strcat(flatmap_dir,'tSNR_',num2str(s),'.pdf');
print(gcf,fn,'-dpdf','-r300');
close()
end
%% create tsnr maps
close('all')
% load data:
dir = char(strcat(tsnr_dir,'tsnr_rank_corrs.nii'));
Data = suit_map2surf(dir,'space','FSL','stats',@nanmean,'depths',0:0.1:1);
cm = colorcet('L8');
sc = [-0.5,0];
suit_plotflatmap(Data,'cmap',cm,'cscale',sc);
hAxes = gca;
hAxes.XRuler.Axle.LineStyle = 'none';
axis off
set(gcf,'paperunits','inches','papersize',[3,3],'paperposition',[-1.1,-1.1,5,5])
fn = strcat(flatmap_dir,'tSNR_rank_corrs.pdf');
print(gcf,fn,'-dpdf','-r300');
close()
%% new data
new_flat_dir = '/Users/daanvanes/disks/Aeneas_Shared/2018/visual/cerebellum_prf/derivatives/pp/prf/';
ses = '01020304';
postFix = 'hrf075_nongcv';
for r2thresh = [0.05,0.1,0.2]%0.05,0.1,0.2,0.3,0.4,0.5]
for sub = [2]%["01"]%,"02","03"]
fn = strcat(new_flat_dir,'sub-0',num2str(sub),'/sub-0',num2str(sub),'_new_prf_results_zscore_ses_',ses,postFix,'thresh_ang_',sprintf('%0.2f',r2thresh),'_cmask_pos.nii');
blue = [45,52,135];
red = [153,27,68];
yellow = [250,195,83];
green = [0,153,74];
magenta = [223,112,172];
cyan = [110,207,246];
rgbs = [yellow;green;green;green;cyan;blue;magenta;red;yellow]/255;
cm = interpolate_cvals_rgbspace(rgbs);
% % use circular mean
func = @circ_mean_adapted; % adapted such that it is appropriately used in suit toolbox
sc = [0,pi*2];
threshold=0;
% load data:
Data = suit_map2surf(fn,'space','FSL','stats',func,'depths',0:0.1:1);
% plot flatmap
suit_plotflatmap(Data,'cmap',cm,'cscale',sc,'threshold',threshold);
hAxes = gca;
hAxes.XRuler.Axle.LineStyle = 'none';
axis off
set(gcf,'paperunits','inches','papersize',[3,3],'paperposition',[-1.1,-1.1,5,5])
fn = strcat(new_flat_dir,'sub-0',num2str(sub),'/sub-0',num2str(sub),'_new_prf_results_zscore_ses_',ses,postFix,'thresh_ang_',sprintf('%0.2f',r2thresh),'_pos_flatmap.pdf');
print(gcf,fn,'-dpdf','-r300');
close()
end
end
%% new data 2
new_flat_dir = '/Users/daanvanes/disks/Aeneas_Shared/2018/visual/cerebellum_prf/derivatives/pp/prf/';
for sub = [1,2]%,3]%1,2,3]%["01"]%,"02","03"]
for var = ["r2"]%"ang","ecc","size"]
if (sub == 1) + (sub ==3)
ses = '010203';
elseif sub ==2
ses = '01020304';
end
fn = strcat(new_flat_dir,'sub-0',num2str(sub),'/sub-0',num2str(sub),'_new_prf_results_zscore_ses_',ses,'_cartfit_hrf0.75_gray_matter_cv_thresh_',var,'__spillmask_pos.nii');
if strcmp(var,'ang')
% create a colormap that is more focused on the lower
% visual fied:
blue = [45,52,135];
red = [153,27,68];
yellow = [250,195,83];
green = [0,153,74];
magenta = [223,112,172];
cyan = [110,207,246];
rgbs = [yellow;green;green;green;cyan;blue;magenta;red;yellow]/255;
cm = interpolate_cvals_rgbspace(rgbs);
% use circular mean
func = @circ_mean_adapted; % adapted such that it is appropriately used in suit toolbox
sc = [0,pi*2];
threshold=0;
elseif strcmp(var,'ecc')
cm = colorcet('R2');
sc = [0,15];
func=@nanmean;
elseif strcmp(var,'r2')
cm = colorcet('L8');
sc = [0.098,0.6];
threshold = 0.05;
func=@nanmean;
elseif strcmp(var,'size')
cm = colorcet('L5');
sc = [0,15];
func=@nanmean;
end
% load data:
Data = suit_map2surf(char(fn),'space','FSL','stats',func,'depths',0:0.1:1);
% plot flatmap
suit_plotflatmap(Data,'cmap',cm,'cscale',sc,'threshold',threshold);
hAxes = gca;
hAxes.XRuler.Axle.LineStyle = 'none';
axis off
set(gcf,'paperunits','inches','papersize',[3,3],'paperposition',[-1.1,-1.1,5,5])
fn = strcat(new_flat_dir,'sub-0',num2str(sub),'/sub-0',num2str(sub),'_new_prf_results_zscore_thresh_',var,'_pos_flatmap.pdf');
print(gcf,fn,'-dpdf','-r300');
close()
end
end
%% Brissenden CV R2
brissenden_dir = '/Users/daanvanes/Documents/Documenten/Research/data/hcp_retinotopy/brissenden_data/';
sc = [0.05,0.25];
threshold=0.05;
for s = [1,2,3,4,5]
fn = char(strcat(brissenden_dir,'S',num2str(s),'.xvalcorr.nii'));
Data = suit_map2surf(fn,'depths',0:0.1:1);
% plot flatmap
suit_plotflatmap(Data,'cmap',colorcet('coolwarm'),'cscale',sc,'threshold',threshold)%,'type','label')
hAxes = gca;
hAxes.XRuler.Axle.LineStyle = 'none';
axis off
set(gcf,'paperunits','inches','papersize',[3,3],'paperposition',[-1.1,-1.1,5,5])
fn = strcat(brissenden_dir,'S',num2str(s),'.pdf');
print(gcf,fn,'-dpdf','-r300');
close()
end
fn = char(strcat(brissenden_dir,'avg_over_subs.nii'));
Data = suit_map2surf(fn,'depths',0:0.1:1);
% plot flatmap
suit_plotflatmap(Data,'cmap',colorcet('L8'),'cscale',sc,'threshold',threshold)%,'type','label')
hAxes = gca;
hAxes.XRuler.Axle.LineStyle = 'none';
axis off
set(gcf,'paperunits','inches','papersize',[3,3],'paperposition',[-1.1,-1.1,5,5])
fn = strcat(brissenden_dir,'avg_over_subs.pdf');
print(gcf,fn,'-dpdf','-r300');
close()