-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathspDist_plotReconstructions_condAlign.m
More file actions
498 lines (325 loc) · 14.4 KB
/
spDist_plotReconstructions_condAlign.m
File metadata and controls
498 lines (325 loc) · 14.4 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
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
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
% spDist_pilot_plotReconstructions_thruTime.m
% adapted from MGSMap_plotReconstructions_cv_thruTime1.m
%
% for plotting WM reconstructions during trials with/without spatial
% distractor, plotting distractor-aligned reconstructions, and sorting
% trials based on relative distractor position
%
% for plotting cross-validated WM reconstructions from mapping task,
% computed using MGSMap_channelRespAmp* scripts
%
% TODO: extend to compareReconstruction, which can load multiple sets of
% sessions per subj, and will compare across sessions (and/or across sets
% of tpts, etc... - only one set of comparisons at a time?)
%
% TODO: automate colorlims across figures
function spDist_plotReconstructions_condAlign(subj,sess,ROIs)
root = spDist_loadRoot;
task_dir = 'spDist';
if nargin < 1 || isempty(subj)
subj = {'AY','CC','EK','KD','MR','SF','XL'}; %geh updated subj to alpha
end
if nargin < 2 || isempty(sess)
% each subj gets one cell, with strings for each sess
sess = {{'spDist1','spDist2'},{'spDist1','spDist2'},{'spDist1','spDist2'},{'spDist1','spDist2'},{'spDist1','spDist2'},{'spDist1','spDist2'},{'spDist1','spDist2'}};
end
if nargin < 3 || isempty(ROIs)
ROIs = {'V1V2V3','V3AB','hV4','LO1','IPS0IPS1','IPS2IPS3','sPCS'}; %update ROIs 103020
end
func_suffix = 'surf';
cat_mode = 1; % if 1, look for catSess1Ses...SessN_ files, otherwise, just look for each session in turn
nchan = 8;
which_vox = 0.1; % if > 1 , look for WHICH_VOXvox string; otherwise, look for VE<100*WHICH_VOX>
smooth_by = 1; % if this is 1, use regular files, otherwise, load smooth_by files
myTR = 0.75;
t_range_to_plot = [-inf 12]; % plot b/w these (s)
trn_tpts = 7:15; % if blank, load files w/ no _trn%ito%i, otherwise,
plot_tpts = 7:15; % for a plot where we average reconstructions over a fixed time window
dist_time = 4.5; % onset at 4 s
% set up file loading strings for below
if smooth_by == 1
smooth_str = '';
else
smooth_str = sprintf('_smooth%i',smooth_by);
end
if isempty(trn_tpts)
trn_str = '';
else
trn_str = sprintf('_trn%ito%i',trn_tpts(1),trn_tpts(end));
end
if which_vox < 1
vox_str = sprintf('_VE%03.f',100*which_vox);
else
vox_str = sprintf('_%ivox',which_vox);
end
delay_tpt_range = [2 5; 5 9;9 10.5; 10.5 12];
%% load data
startidx = 1;
for ss = 1:length(subj)
for vv = 1:length(ROIs)
% just one file to load
fn = sprintf('%s/%s_reconstructions/%s_%s_%s_%s_%ichan%s%s%s_recon_thruTime1.mat',root,task_dir,subj{ss},horzcat(sess{ss}{:}),ROIs{vv},func_suffix,nchan,vox_str,smooth_str,trn_str);
fprintf('loading %s...\n',fn);
data = load(fn);
if vv == 1 && ss == 1
% initialize variables...
nblankt = length(ROIs)*size(data.recons{1},1);
all_recons = cell(size(data.recons));
for aa = 1:length(data.recons)
all_recons{aa} = nan(nblankt,size(data.recons{aa},2),size(data.recons{aa},3));
end
all_recons_nodist = nan(nblankt,size(data.recons_nodist,2),size(data.recons_nodist,3));
all_conds = nan(nblankt,size(data.c_all,2));
all_angs = nan(nblankt,size(data.a_all,2));
all_fidelity = nan(nblankt,size(data.recons{1},3),length(data.recons)); % timecoruse of fidelity for each alignment condition
all_fidelity_nodist = nan(nblankt,size(data.recons_nodist,3));
all_subj = nan(nblankt,1);
all_ROIs = nan(nblankt,1);
all_sess = nan(nblankt,1);
angs = data.angs;
tpts = data.delay_tpts;
end
thisidx = startidx:(startidx+size(data.c_all,1)-1);
for aa = 1:length(all_recons)
all_recons{aa}(thisidx,:,:) = data.recons{aa};
all_fidelity(thisidx,:,aa) = squeeze(mean(cosd(angs) .* data.recons{aa},2));
end
all_recons_nodist(thisidx,:,:) = data.recons_nodist;
all_fidelity_nodist(thisidx,:) = squeeze(mean(cosd(angs) .* data.recons_nodist,2));
all_conds(thisidx,:) = data.c_all;
all_angs(thisidx,:) = data.a_all;
all_subj(thisidx) = ss;
all_ROIs(thisidx) = vv;
all_sess(thisidx) = data.sess_all;
startidx = thisidx(end)+1;
clear data;
end
end
%% which tpts are we plotting throughout?
% TCS: lte to lessthan
tpts_to_plot = (tpts*myTR) >= t_range_to_plot(1) & (tpts*myTR) < t_range_to_plot(2);
delay_tpts = cell(size(delay_tpt_range,1),1);
for dd = 1:size(delay_tpt_range,1)
delay_tpts{dd} = (tpts*myTR) >= delay_tpt_range(dd,1) & (tpts*myTR) < delay_tpt_range(dd,2);
end
%% plot each condition (target-locked) (average over subj)
% length(cu) x n_rois
% store all axes across figures
recon_ax = [];
cu = 1;
cond_str = {'No distractor trials'};
figure('name','Figure4A');
for cc = 1:length(cu)
for vv = 1:length(ROIs)
subplot(length(cu),length(ROIs),(cc-1)*length(ROIs)+vv);hold on;
thisd = nan(size(all_recons{1},3),size(all_recons{1},2),length(subj));
for ss = 1:length(subj)
thisidx = all_subj==ss & all_ROIs==vv & all_conds(:,1)==cu(cc);
thisd(:,:,ss) = squeeze(mean(all_recons{1}(thisidx,:,:),1)).';
end
% TCS: center each row over middle of TR
imagesc(angs,tpts(tpts_to_plot)*myTR + myTR/2,mean(thisd(tpts_to_plot,:,:),3));
colormap viridis
if cc == 1
title(ROIs{vv});
end
axis ij tight
set(gca,'XTick',-180:90:180);
if vv == 1
xlabel('Polar angle (\circ)');
ylabel(sprintf('%s - time (s)',cond_str{cc}));
set(gca,'XTickLabel',{'-180','','0','','180'});
else
set(gca,'YTick',[],'XTickLabel',[],'YTickLabel',[]);
end
xlim([-180 180]);
caxis([-1.4808 1.7960])
end
end
set(get(gcf,'Children'),'TickDir','out','Box','off','TickLength',[0.015 0.015],'YTick',[0 4.5 12]);
set(gcf,'Position',[102 405 1353 174]);
recon_ax = [recon_ax; get(gcf,'Children')];
%% plot each condition (target-locked) (average over subj)
% length(cu) x n_rois
cu = 2;
cond_str = {'Distractor trials'};
figure('name','Figure4B');
for cc = 1:length(cu)
for vv = 1:length(ROIs)
subplot(length(cu),length(ROIs),(cc-1)*length(ROIs)+vv);hold on;
thisd = nan(size(all_recons{1},3),size(all_recons{1},2),length(subj));
for ss = 1:length(subj)
thisidx = all_subj==ss & all_ROIs==vv & all_conds(:,1)==cu(cc);
thisd(:,:,ss) = squeeze(mean(all_recons{1}(thisidx,:,:),1)).';
end
% TCS: center each row over middle of TR
imagesc(angs,tpts(tpts_to_plot)*myTR + myTR/2,mean(thisd(tpts_to_plot,:,:),3));
colormap viridis
if cc == 1
title(ROIs{vv});
end
axis ij tight
set(gca,'XTick',-180:90:180);
if vv == 1
xlabel('Polar angle (\circ)');
ylabel(sprintf('%s - time (s)',cond_str{cc}));
set(gca,'XTickLabel',{'-180','','0','','180'});
else
set(gca,'YTick',[],'XTickLabel',[],'YTickLabel',[]);
end
xlim([-180 180]);
caxis([-1.4808 1.7960])
end
end
set(get(gcf,'Children'),'TickDir','out','Box','off','TickLength',[0.015 0.015],'YTick',[0 4.5 12]);
set(gcf,'Position',[102 405 1353 174]);
recon_ax = [recon_ax;get(gcf,'Children')];
%% plot distractor-locked (for distractor)
cond_str ={'Distractor locked'};
figure('name','Figure4C');
for vv = 1:length(ROIs)
subplot(1,length(ROIs),vv);hold on;
thisd = nan(size(all_recons{1},3),size(all_recons{1},2),length(subj));
for ss = 1:length(subj)
thisidx = all_subj==ss & all_ROIs==vv & all_conds(:,1)==2;
thisd(:,:,ss) = squeeze(mean(all_recons{2}(thisidx,:,:),1)).';
end
% TCS: as above...
imagesc(angs,tpts(tpts_to_plot)*myTR + myTR/2,mean(thisd(tpts_to_plot,:,:),3));
colormap viridis;
title(ROIs{vv});
axis ij tight
set(gca,'XTick',-180:90:180);
if vv == 1
xlabel('Polar angle (\circ)');
ylabel(sprintf('%s - time (s)',cond_str{cc}));
set(gca,'XTickLabel',{'-180','','0','','180'});
else
set(gca,'YTick',[],'XTickLabel',[],'YTickLabel',[]);
end
xlim([-180 180]);
caxis([-1.4808 1.7960])
end
set(get(gcf,'Children'),'TickDir','out','Box','off','TickLength',[0.015 0.015],'YTick',[0 4.5 12]);
set(gcf,'Position',[102 405 1353 174]);
recon_ax = [recon_ax;get(gcf,'Children')];
%% plot distractor-removed target representation (all positions)
cond_str ={'Target, dist removed'};
figure;
for vv = 1:length(ROIs)
subplot(1,length(ROIs),vv);hold on;
thisd = nan(size(all_recons_nodist,3),size(all_recons_nodist,2),length(subj));
for ss = 1:length(subj)
thisidx = all_subj==ss & all_ROIs==vv & all_conds(:,1)==2;
thisd(:,:,ss) = squeeze(mean(all_recons_nodist(thisidx,:,:),1)).';
end
% TCS: as above
imagesc(angs,tpts(tpts_to_plot)*myTR + myTR/2,mean(thisd(tpts_to_plot,:,:),3));
colormap viridis;
title(ROIs{vv});
axis ij tight
set(gca,'XTick',-180:90:180);
if vv == 1
xlabel('Polar angle (\circ)');
ylabel(sprintf('%s - time (s)',cond_str{cc}));
set(gca,'XTickLabel',{'-180','','0','','180'});
else
set(gca,'YTick',[],'XTickLabel',[],'YTickLabel',[]);
end
xlim([-180 180]);
caxis([-1.4808 1.7960])
end
set(get(gcf,'Children'),'TickDir','out','Box','off','TickLength',[0.015 0.015],'YTick',[0 4.5 12]);
set(gcf,'Position',[102 405 1353 174]);
recon_ax = [recon_ax;get(gcf,'Children')];
match_clim(recon_ax);
%% plot target fidelity on distractor-/+ trials and distractor fidelity
% row 1: target fidelity
% row 2: distractor fidelity
% row 3: target fidelity (after removing distractor)
% target: without and with distractor; distractor
fidelity_colors = lines(7); fidelity_colors = fidelity_colors(4:6,:);
t_markers = [0 4.5 12]; % onset of delay, distractor, response
mh1 = nan(length(ROIs),length(t_markers));
mh2 = nan(length(ROIs),length(t_markers));
mh3 = nan(length(ROIs),length(t_markers));
mu_fidelity = nan(length(ROIs),size(all_fidelity,2),4); % ROIs x tpts x targ w/ and w/out distractor; distractor; with-distractor after removing distractor...
figure;
% first, plot the target fidelity
for vv = 1:length(ROIs)
subplot(3,length(ROIs),vv); hold on;
for cc = 1:length(cu)
thisd = nan(length(subj),size(all_fidelity,2));
for ss = 1:length(subj)
thisidx = all_conds(:,1)==cu(cc) & all_subj==ss & all_ROIs==vv;
thisd(ss,:) = mean(all_fidelity(thisidx,:,1));
end
mu_fidelity(vv,:,cc) = mean(thisd,1);
thise = std(thisd,[],1)/sqrt(length(subj));
% TCS: updated x axis
% plot mean
plot(myTR*tpts + myTR/2,mean(thisd,1),'-','LineWidth',1.5,'Color',fidelity_colors(cc,:));
% plot error bars
plot((myTR*tpts.*[1;1]).' + myTR/2,(mean(thisd,1)+[-1;1].*thise).','--','LineWidth',1,'Color',fidelity_colors(cc,:));
yline(0);
% TODO: plot std error across subj
title(ROIs{vv});
if vv == 1
ylabel('Target fidelity');
else
set(gca,'YTickLabel',[]);
end
set(gca,'XTick',[0:6:24],'TickDir','out','XTickLabel',[]);
clear thisd thise;
end
mh1(vv,:) = plot(t_markers.*[1;1],[0 .1],'-','Color',[0.7 0.7 0.7],'LineWidth',0.75);
% ---------- SECOND ROW ---------------------
subplot(3,length(ROIs),vv+length(ROIs)); hold on;
thisd = nan(length(subj),size(all_fidelity,2));
for ss = 1:length(subj)
thisidx = all_conds(:,1)==2 & all_subj==ss & all_ROIs==vv;
thisd(ss,:) = mean(all_fidelity(thisidx,:,2));
end
mu_fidelity(vv,:,1+length(cu)) = mean(thisd,1);
thise = std(thisd,[],1)/sqrt(length(subj));
plot(myTR*tpts + myTR/2,mean(thisd,1),'-','LineWidth',1.5,'Color',fidelity_colors(3,:));
plot((myTR*tpts.*[1;1]).' + myTR/2,(mean(thisd,1)+[-1;1].*thise).','--','LineWidth',1,'Color',fidelity_colors(3,:));
yline(0);
if vv == 1
ylabel('Distractor fidelity');
xlabel('Time (s)');
else
set(gca,'YTickLabel',[]);
end
set(gca,'XTick',[0:6:24],'TickDir','out');
mh2(vv,:) = plot(t_markers.*[1;1],[0 .1],'-','Color',[0.7 0.7 0.7],'LineWidth',0.75);
clear thisd;
% ---------- THIRD ROW ------------
subplot(3,length(ROIs),vv+2*length(ROIs)); hold on;
thisd = nan(length(subj),size(all_fidelity,2));
for ss = 1:length(subj)
thisidx = all_conds(:,1)==2 & all_subj==ss & all_ROIs==vv;
thisd(ss,:) = mean(all_fidelity_nodist(thisidx,:));
end
mu_fidelity(vv,:,2+length(cu)) = mean(thisd,1);
thise = std(thisd,[],1)/sqrt(length(subj));
plot(myTR*tpts + myTR/2,mean(thisd,1),'-','LineWidth',1.5,'Color',fidelity_colors(2,:));
plot((myTR*tpts.*[1;1]).' + myTR/2,(mean(thisd,1)+[-1;1].*thise).','--','LineWidth',1,'Color',fidelity_colors(2,:));
yline(0);
if vv == 1
ylabel('WM fidelity (minus distractor)');
xlabel('Time (s)');
else
set(gca,'YTickLabel',[]);
end
set(gca,'XTick',[0:6:24],'TickDir','out');
mh3(vv,:) = plot(t_markers.*[1;1],[0 .1],'-','Color',[0.7 0.7 0.7],'LineWidth',0.75);
clear thisd;
end
%myy = cell2mat(get(get(gcf,'Children'),'YLim'));
myy = match_ylim(get(gcf,'Children'));
set(mh1,'YData',[min(myy(:,1)) max(myy(:,2))]);
set(mh2,'YData',[min(myy(:,1)) max(myy(:,2))]);
set(mh3,'YData',[min(myy(:,1)) max(myy(:,2))]);
set(gcf,'Position',[185 745 1843 470]);
return