-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfigure_neuron_R1_rois.m
313 lines (246 loc) · 12.6 KB
/
figure_neuron_R1_rois.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
function show_figure(figure_name)
switch figure_name
case 'plot_PETH_AAL2_GP_EMPA_GLM_102_GP__R1_rois'
% plot_PETHs.m
load('/n/holystore01/LABS/gershman_lab/Users/mtomov13/VGDL/mat/PETHs_atlas=Brodmann_what=GP__.mat')
ROI_ix = [5];
mask_filenames_ = mask_filenames(ROI_ix);
mask_name_ = mask_name(ROI_ix);
regions_ = regions(ROI_ix);
activations_ = activations(ROI_ix);
load('/n/holystore01/LABS/gershman_lab/Users/mtomov13/VGDL/mat/PETHs_atlas=AAL3v1_neuron_what=GP__.mat')
%ROI_ix = 1:length(mask_filenames);
ROI_ix = [7 8 9];
mask_filenames_ = [mask_filenames_ mask_filenames(ROI_ix)];
mask_name_ = [mask_name_ mask_name(ROI_ix)];
regions_ = [regions_; regions(ROI_ix)];
activations_ = [activations_ activations(ROI_ix)];
mask_filenames = mask_filenames_;
mask_name = mask_name_;
regions = regions_;
activations = activations_;
%figure('pos', [64 460 1296*0.5 799*0.5]);
figure('position', [147 605 700 134]);
% optionally plot theory change flag only
%fields(find(strcmp(fields, 'theory_change_flag'))) = [];
fields(find(strcmp(fields, 'sprite_change_flag'))) = [];
fields(find(strcmp(fields, 'interaction_change_flag'))) = [];
fields(find(strcmp(fields, 'termination_change_flag'))) = [];
fields(find(strcmp(fields, 'block_start'))) = [];
fields(find(strcmp(fields, 'block_end'))) = [];
fields(find(strcmp(fields, 'instance_start'))) = [];
fields(find(strcmp(fields, 'instance_end'))) = [];
subjs = 1:1:32;
cmap = colormap(jet(length(fields)));
t = PETH_dTRs * EXPT.TR; % s
titles = {'RSC', 'HC', 'PHC', 'TPO'};
% loop over masks
for m = 1:length(mask_filenames)
disp(mask_name{m});
subplot(1, 4, m);
hold on;
for i = 1:length(fields)
field = fields{i};
disp(field)
D = activations(m).(field)(subjs,:); % subj x TRs PETH's
[sem, me] = wse(D);
%me = nanmean(activations(m).(field), 1);
%sem = nanstd(activations(m).(field), 1) / sqrt(size(activations(m).(field), 1)); % TODO wse
[h,p,ci,stats] = ttest(D);
%errorbar(dTRs, m, se);
hh(i) = plot(t, me, 'color', cmap(i,:));
h = fill([t flip(t)], [me + sem flip(me - sem)], cmap(i,:));
set(h, 'facealpha', 0.3, 'edgecolor', 'none');
ax = gca;
xlim([t(1) - 1, t(end) + 1]);
if ismember(field, regs_fields)
ix = find(strcmp(field, regs_fields)) - 1;
j_init = find(PETH_dTRs > 0); % ignore baselines
for j = j_init:length(t)
if p(j) <= 0.05
if mean(me) < 0
y = ax.YLim(1) + 0.01 - ix * 0.01;
else
y = ax.YLim(2) - 0.01 - ix * 0.01;
end
h = text(t(j) + ix * 0.1, y, significance(p(j)), 'color', cmap(i,:), 'fontsize', 7, 'HorizontalAlignment', 'center');
set(h,'Rotation',90);
end
end
end
end
plot([0 0], ax.YLim, '--', 'color', [0.5 0.5 0.5]);
plot(ax.XLim, [0 0], '--', 'color', [0.5 0.5 0.5]);
if m == 1
%l = legend(hh, fields, 'interpreter', 'none');
%l = legend(hh, {'theory update', 'interaction', 'avatar interaction', 'new object', 'killed object', 'episode start', 'episode end'}, 'interpreter', 'none');
%l.Position = [0.4023 0.1654 0.1289 0.1314];
%ylabel('z');
ylabel('\Delta z');
end
xlabel('time (s)');
%title(regions{m}, 'interpreter', 'none');
title(titles{m}, 'interpreter', 'none');
end
%orient(gcf, 'landscape');
%print('pdf/plot_PETH_AAL2_GP_EMPA_GLM_102_GP.pdf', '-dpdf', '-bestfit');
print('svg/neuron_revision/plot_PETH_AAL2_GP_EMPA_GLM_102_GP__R1_rois.svg', '-dsvg');
case 'plot_PETH_bars_AAL2_GP_EMPA_GLM_102_GP__R1_rois'
% plot_PETHs_bars.m
load('/n/holystore01/LABS/gershman_lab/Users/mtomov13/VGDL/mat/PETHs_atlas=Brodmann_what=GP__.mat')
ROI_ix = [5];
mask_filenames_ = mask_filenames(ROI_ix);
mask_name_ = mask_name(ROI_ix);
regions_ = regions(ROI_ix);
activations_ = activations(ROI_ix);
load('/n/holystore01/LABS/gershman_lab/Users/mtomov13/VGDL/mat/PETHs_atlas=AAL3v1_neuron_what=GP__.mat')
%ROI_ix = 1:length(mask_filenames);
ROI_ix = [7 8 9];
mask_filenames_ = [mask_filenames_ mask_filenames(ROI_ix)];
mask_name_ = [mask_name_ mask_name(ROI_ix)];
regions_ = [regions_; regions(ROI_ix)];
activations_ = [activations_ activations(ROI_ix)];
mask_filenames = mask_filenames_;
mask_name = mask_name_;
regions = regions_;
activations = activations_;
% optionally plot theory change flag only
%fields(find(strcmp(fields, 'theory_change_flag'))) = [];
fields(find(strcmp(fields, 'sprite_change_flag'))) = [];
fields(find(strcmp(fields, 'interaction_change_flag'))) = [];
fields(find(strcmp(fields, 'termination_change_flag'))) = [];
fields(find(strcmp(fields, 'block_start'))) = [];
fields(find(strcmp(fields, 'block_end'))) = [];
fields(find(strcmp(fields, 'instance_start'))) = [];
fields(find(strcmp(fields, 'instance_end'))) = [];
subjs = 1:1:32;
nROIs = length(mask_filenames);
nregressors = length(fields);
nsubjects = length(subjs);
as = nan(nROIs,nregressors,nsubjects);
cmap = colormap(jet(length(fields)));
t = PETH_dTRs * EXPT.TR; % s
% loop over masks
for m = 1:nROIs
disp(mask_name{m});
for i = 1:nregressors
field = fields{i};
disp(field)
D = activations(m).(field)(subjs,:); % subj x TRs PETH's
as(m,i,:) = mean(D(:, PETH_dTRs > 0), 2); % average across time, ignoring baseline
%as(m,i,:) = mean(D(:, PETH_dTRs > 5), 2); % average across time, ignoring baseline
end
end
% Piggyback off of plot_gp_CV_rois.m
figure('position', [147 521 645 258]);
ix = 1:nregressors;
%h = plot_gp_CV_rois_helper(as(:,ix,:), 'ttest', 'mean', fields(ix), regions, 0, cmap, 2, 1, 4);
h = plot_gp_CV_rois_helper(as(:,ix,:), 'ttest', 'mean', fields(ix), regions, [], cmap, 2.5, 1, 2);
ylabel('\Delta z');
%l = legend(fields(ix), 'interpreter', 'none');
l = legend({'theory update', 'interaction', 'avatar interaction', 'new object', 'killed object', 'episode start', 'episode end'}, 'interpreter', 'none');
l.Position = [0.2597 0.5838 0.0807 0.1836];
l.FontSize = 7;
xticklabels({'RSC', 'HC', 'PHC', 'TPO'});
ylim([-0.03 0.11]);
%orient(gcf, 'landscape');
%print('pdf/plot_PETH_bars_AAL2_GP_EMPA_GLM_102_GP.pdf', '-dpdf', '-bestfit');
print('svg/neuron_revision/plot_PETH_bars_AAL2_GP_EMPA_GLM_102_GP__R1_rois.svg', '-dsvg');
case 'plot_PETH_components_AAL2_GP_EMPA_GLM_102_GP____R1_rois'
% plot_PETHs.m
load('/n/holystore01/LABS/gershman_lab/Users/mtomov13/VGDL/mat/PETHs_atlas=Brodmann_what=GP_sprite__.mat')
sprite_activations = activations;
load('/n/holystore01/LABS/gershman_lab/Users/mtomov13/VGDL/mat/PETHs_atlas=Brodmann_what=GP_interaction__.mat')
interaction_activations = activations;
load('/n/holystore01/LABS/gershman_lab/Users/mtomov13/VGDL/mat/PETHs_atlas=Brodmann_what=GP_termination__.mat')
termination_activations = activations;
clear activations;
ROI_ix = [5];
mask_filenames_ = mask_filenames(ROI_ix);
mask_name_ = mask_name(ROI_ix);
regions_ = regions(ROI_ix);
sprite_activations_ = sprite_activations(ROI_ix);
interaction_activations_ = interaction_activations(ROI_ix);
termination_activations_ = termination_activations(ROI_ix);
load('/n/holystore01/LABS/gershman_lab/Users/mtomov13/VGDL/mat/PETHs_atlas=AAL3v1_neuron_what=GP_sprite__.mat')
sprite_activations = activations;
load('/n/holystore01/LABS/gershman_lab/Users/mtomov13/VGDL/mat/PETHs_atlas=AAL3v1_neuron_what=GP_interaction__.mat')
interaction_activations = activations;
load('/n/holystore01/LABS/gershman_lab/Users/mtomov13/VGDL/mat/PETHs_atlas=AAL3v1_neuron_what=GP_termination__.mat')
termination_activations = activations;
clear activations;
ROI_ix = [7 8 9];
mask_filenames_ = [mask_filenames_ mask_filenames(ROI_ix)];
mask_name_ = [mask_name_ mask_name(ROI_ix)];
regions_ = [regions_; regions(ROI_ix)];
sprite_activations_ = [sprite_activations_ sprite_activations(ROI_ix)];
interaction_activations_ = [interaction_activations_ interaction_activations(ROI_ix)];
termination_activations_ = [termination_activations_ termination_activations(ROI_ix)];
mask_filenames = mask_filenames_;
mask_name = mask_name_;
regions = regions_;
sprite_activations = sprite_activations_;
interaction_activations = interaction_activations_;
termination_activations = termination_activations_;
%figure('pos', [64 460 1296*0.5 799*0.5]);
figure('position', [147 605 1211 134]);
% only look at the components
fields = {'sprite_change_flag', 'interaction_change_flag', 'termination_change_flag'};
subjs = 1:1:32;
cmap = [0.9 0.5 0.2]' * [0 0.4470 0.7410] + [0.1 0.5 0.8]' * [0 0 0];
t = PETH_dTRs * EXPT.TR; % s
% loop over masks
for m = 1:length(mask_filenames)
disp(mask_name{m});
subplot(1, 7, m);
hold on;
for i = 1:length(fields)
field = fields{i};
disp(field)
% hardcoded
if i == 1
D = sprite_activations(m).(field)(subjs,:); % subj x TRs PETH's
elseif i == 2
D = interaction_activations(m).(field)(subjs,:); % subj x TRs PETH's
elseif i == 3
D = termination_activations(m).(field)(subjs,:); % subj x TRs PETH's
else
assert(false, 'we are matching component update events with the corresponding component activations; unclear which activations to show for non-component update events');
end
[sem, me] = wse(D);
%me = nanmean(activations(m).(field), 1);
%sem = nanstd(activations(m).(field), 1) / sqrt(size(activations(m).(field), 1)); % TODO wse
[h,p,ci,stats] = ttest(D);
%errorbar(dTRs, m, se);
hh(i) = plot(t, me, 'color', cmap(i,:));
h = fill([t flip(t)], [me + sem flip(me - sem)], cmap(i,:));
set(h, 'facealpha', 0.3, 'edgecolor', 'none');
ax = gca;
xlim([t(1) - 1, t(end) + 1]);
if ismember(field, regs_fields)
ix = find(strcmp(field, regs_fields)) - 1;
j_init = find(PETH_dTRs > 0); % ignore baselines
for j = j_init:length(t)
if p(j) <= 0.05
%h = text(t(j) + ix * 0.5, ax.YLim(2) + 0.005 + ix * 0.002, significance(p(j)), 'color', cmap(i,:), 'fontsize', 7, 'HorizontalAlignment', 'center');
%set(h,'Rotation',90);
end
end
end
end
plot([0 0], ax.YLim, '--', 'color', [0.5 0.5 0.5]);
plot(ax.XLim, [0 0], '--', 'color', [0.5 0.5 0.5]);
if m == 1
%legend(hh, fields, 'interpreter', 'none');
%l = legend(hh, {'object update', 'relation update', 'goal update'}, 'interpreter', 'none');
%l.Position = [0.4162 0.1941 0.1073 0.0588];
%ylabel('z');
ylabel('\Delta z');
end
xlabel('time (s)');
title(regions{m}, 'interpreter', 'none');
end
print('svg/neuron_revision/plot_PETH_components_AAL2_GP_EMPA_GLM_102_GP__R1_rois.svg', '-dsvg');
otherwise
assert(false, 'Invalid figure name');
end