This repository has been archived by the owner on Oct 23, 2020. It is now read-only.
forked from Brody-Lab/chronic_neuropixels
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfigure4.m
250 lines (245 loc) · 11.2 KB
/
figure4.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
% FIGURE4 Make figure 4 from the manuscrip written by Luo, Bondy, et al.
%
% The figure show that after an initial loss of units, spiking signals
% can be maintained >60 days in anterior, deeper brain regions.
%% Load data
from_scratch = false; % Do you want to reassemble the data files from scratch?
P=get_parameters;
if from_scratch
% note: regnerating these data files from scratch requires raw files
% not in the chronic_neuropixels repository.
Cells=collect_cells_files();
Cells=postprocess_Cells(Cells);
assemble_exp_decay_data(Cells)
else
if ~exist('Cells', 'var')
fprintf('Loading the variabe CELLS...')
load([P.data_folder_path filesep 'Cells.mat'])
end
if ~exist('T_ed', 'var')
load(P.sum_exp_data_path)
end
end
%% Parameters
exclude_3A = true; % verify that results are similar if the one 3A probe were excluded
%% Set up the figue
figure('Pos', [100, 50, 1600, 1300])
k = 0;
n_col = 3;
n_row = 4;
label_offset = 0;
fit_type = 'exponential';
ax_hdl={};
%% Plot individual recordings
for region = {'vmFC', 'MCtx', 'vmStr'}
k = k + 1;
ax_hdl{k} = subplot(n_row, n_col,k);
plot_indiv_recordings(Cells, region{:}, ...
'metric', 'single_unit', ...
'axes', gca,...
'ylabel_on', mod(k, n_col)==1);
ax_hdl{k}.OuterPosition(2) = ax_hdl{k}.OuterPosition(2) + 0.03; % shift the plots above
label_panel(ax_hdl{k}, P.panel_labels(k), 'FontSize', P.panel_label_font_size);
if k == 1
ylabel('Single unit/electrode')
end
set(gca, 'YLim', [0 1.5], 'YTick', 0:0.5:1.5)
end
%% Plot average across all conditions
T = get_metrics_from_Cells(Cells, 'exclude_3A', exclude_3A);
fprintf('\nANOVA with the factor days since implants and for data > 7 days:')
for metric = {'unit', 'single_unit'}
k = k + 1;
subplot(n_row, n_col,k);
if any(strcmp(metric{:}, {'unit', 'single_unit'}))
fit_type = 'exponential';
else
fit_type='';
end
plot_average_stability(T, 'metric', metric{:}, ...
'axes', gca, ...
'print_sample_size', mod(k,n_col)==1, ...
'normalize_by_electrodes', true, ...
'normalize_initial_value', false, ...
'fit_type', fit_type);
label_panel(gca, P.panel_labels(k+label_offset), 'FontSize', P.panel_label_font_size);
title(P.text.(metric{:}), 'fontweight', 'normal')
% report the pval based on the t-statistic
pval = stat_test_stability(T, 'metric', metric{:}, 'day_range', [8, inf]);
fprintf('\n %s: p=%0.3f', metric{:}, pval);
if metric == "single_unit"
ylim([0,1]);
else
ylim([0, 2.1])
end
end
fprintf('\n')
%% Skip a plot for the anatomical schematics
k= k + 1;
%% Plot average, conditioned on DV
T = get_metrics_from_Cells(Cells, 'condition_on', 'DV', ...
'exclude_3A', exclude_3A);
for metric = {'unit', 'single_unit'}
k = k + 1;
subplot(n_row, n_col,k);
plot_average_stability(T, 'metric', metric{:}, ...
'fit_type', fit_type, ...
'legend_on', false, ...
'print_sample_size', mod(k,n_col)==1, ...
'normalize_by_electrodes', true, ...
'normalize_initial_value', false, ...
'FaceAlpha', 0.3, ...
'axes', gca);
label_panel(gca, P.panel_labels(k+label_offset), 'FontSize', P.panel_label_font_size);
% Report the stats from the ANOVA
Pval.(metric{:}) = anova_DV_shank(Cells, 'DV_bin_edges', P.DV_bin_edges, ...
'EI_bin_edges', P.EI_bin_edges, ...
'metric', metric{:});
fprintf('\nANOVA with factors 1)bank and 2)DV on the change in %s:', metric{:});
fprintf('\n bank: p = %0.3f', Pval.(metric{:})(1));
fprintf('\n DV: p = %0.3f', Pval.(metric{:})(2));
if metric == "single_unit"
ylim([0,1]);
else
ylim([0, 2.1])
end
end
%% Plot model half life - DV
k = k + 1;
ax_hdl = subplot(n_row, 2*n_col,2*k-1);
plot_tau_mdl(T_ed, 'condition', 'DV', ...
'metric', 'unit', ...
'ax', gca, ...
'color_order_offset', 0);
ax_hdl.OuterPosition(1) = ax_hdl.OuterPosition(1) + 0.03; % shift the plots right
label_panel(gca, P.panel_labels(k+label_offset), 'FontSize', P.panel_label_font_size);
hdl = title('Days to decay to 37% of initial value');
hdl.HorizontalAlignment = 'left';
ax_hdl = subplot(n_row, 2*n_col,2*k);
plot_tau_mdl(T_ed, 'condition', 'DV', ...
'metric', 'single_unit', ...
'ax', gca, ...
'ylabel', 0, ...
'color_order_offset', 0);
ax_hdl.OuterPosition(1) = ax_hdl.OuterPosition(1) + 0.03; % shift the plots right
%% Plot average, conditioned on AP
T = get_metrics_from_Cells(Cells, 'condition_on', 'AP', ...
'exclude_3A', exclude_3A);
for metric = {'unit', 'single_unit'}
k = k + 1;
subplot(n_row, n_col,k);
legend_on = mod(k,n_row)==1;
plot_average_stability(T, 'metric', metric{:}, ...
'fit_type', fit_type, ...
'color_order_offset', 2, ...
'legend_on', false, ...
'print_sample_size', mod(k,n_col)==1, ...
'normalize_by_electrodes', true, ...
'normalize_initial_value', false, ...
'FaceAlpha', 0.3, ...
'axes', gca);
label_panel(gca, P.panel_labels(k+label_offset), 'FontSize', P.panel_label_font_size);
if metric == "single_unit"
ylim([0,1]);
else
ylim([0, 2.1])
end
end
%% Plot model half life - AP
k = k + 1;
ax_hdl = subplot(n_row, 2*n_col,2*k-1);
plot_tau_mdl(T_ed, 'condition', 'AP', ...
'metric', 'unit', ...
'ax', gca, ...
'color_order_offset', 2);
ax_hdl.OuterPosition(1) = ax_hdl.OuterPosition(1) + 0.03; % shift the plots right
label_panel(gca, P.panel_labels(k+label_offset), 'FontSize', P.panel_label_font_size);
ax_hdl = subplot(n_row, 2*n_col,2*k);
plot_tau_mdl(T_ed, 'condition', 'AP', ...
'metric', 'single_unit', ...
'ax', gca, ...
'ylabel', 0, ...
'color_order_offset', 2);
ax_hdl.OuterPosition(1) = ax_hdl.OuterPosition(1) + 0.03; % shift the plots right
%% Save
for i = 1:numel(P.figure_image_format)
saveas(gcf, [P.plots_folder_path filesep 'figure4'], P.figure_image_format{i})
end
%% Report additional statistics
T=get_metrics_from_Cells(Cells);
% he total number of isolated units on the day after implantation
n_unit_init = T.unit(T.days_elapsed==1);
boot_n_unit_init = bootstrp(1e3, @mean, n_unit_init);
n_unit_per_trode_init = T.unit(T.days_elapsed==1) ./ T.n_elec(T.days_elapsed==1);
boot_n_unit_per_trode_init = bootstrp(1e3, @mean, n_unit_per_trode_init);
fprintf(['\nThe total number of isolated units per electrode began at %0.2f [%0.2f, %0.2f]' ...
' (%0.0f [%0.0f, %0.0f] per bank per probe) on the day after implantation'], ...
mean(n_unit_per_trode_init), ...
2*mean(n_unit_per_trode_init) - quantile(boot_n_unit_per_trode_init, 0.975), ...
2*mean(n_unit_per_trode_init) - quantile(boot_n_unit_per_trode_init, 0.025), ...
mean(n_unit_init), ...
2*mean(n_unit_init) - quantile(boot_n_unit_init, 0.975), ...
2*mean(n_unit_init) - quantile(boot_n_unit_init, 0.025))
% The total number of isolated units per electrode 8 to 120 days after implant
idx = T.days_elapsed>=7 & T.days_elapsed <=120;
n_unit_stab = T.unit(idx);
boot_n_unit_stab = bootstrp(1e3, @mean, n_unit_stab);
n_unit_per_trode_stab = T.unit(idx) ./ T.n_elec(idx);
boot_n_unit_per_trode_stab = bootstrp(1e3, @mean, n_unit_per_trode_stab);
fprintf(['\nThe total number of isolated units per electrode 8 to 120 days after implant ' ...
'was on average at %0.2f [%0.2f, %0.2f]' ...
' (%0.0f [%0.0f, %0.0f] per bank per probe) on the day after implantation'], ...
mean(n_unit_per_trode_stab), ...
2*mean(n_unit_per_trode_stab) - quantile(boot_n_unit_per_trode_stab, 0.975), ...
2*mean(n_unit_per_trode_stab) - quantile(boot_n_unit_per_trode_stab, 0.025), ...
mean(n_unit_stab), ...
2*mean(n_unit_stab) - quantile(boot_n_unit_stab, 0.975), ...
2*mean(n_unit_stab) - quantile(boot_n_unit_stab, 0.025))
% Model's effective time constant: superficial vs deeper electrodes
idx_deep_unit = T_ed.resp_var == "unit/n_elec" & ...
T_ed.cond_name == "DV [-10, -2] mm";
idx_supf_unit = T_ed.resp_var == "unit/n_elec" & ...
T_ed.cond_name == "DV [-2, 0] mm";
idx_deep_SU = T_ed.resp_var == "single_unit/n_elec" & ...
T_ed.cond_name == "DV [-10, -2] mm";
idx_supf_SU = T_ed.resp_var == "single_unit/n_elec" & ...
T_ed.cond_name == "DV [-2, 0] mm";
fprintf('\n\n Model time constant: superficial vs. deep electrodes')
fprintf('\n superficial units: %0.0f [%0.0f, %0.0f], deep units: %0.0f [%0.0f, %0.0f]', ...
T_ed.tau_mdl(idx_supf_unit), ...
T_ed.tau_mdl_CI(idx_supf_unit,1), ...
T_ed.tau_mdl_CI(idx_supf_unit,2), ...
T_ed.tau_mdl(idx_deep_unit), ...
T_ed.tau_mdl_CI(idx_deep_unit,1), ...
T_ed.tau_mdl_CI(idx_deep_unit,2))
fprintf('\n superficial SUs only: %0.0f [%0.0f, %0.0f], deep SUs only: %0.0f [%0.0f, %0.0f]', ...
T_ed.tau_mdl(idx_supf_SU), ...
T_ed.tau_mdl_CI(idx_supf_SU,1), ...
T_ed.tau_mdl_CI(idx_supf_SU,2), ...
T_ed.tau_mdl(idx_deep_SU), ...
T_ed.tau_mdl_CI(idx_deep_SU,1), ...
T_ed.tau_mdl_CI(idx_deep_SU,2))
% Model's effective time constant: anterior vs posterior electrodes
idx_ant_unit = T_ed.resp_var == "unit/n_elec" & ...
T_ed.cond_name == "AP [0, 4] mm";
idx_pos_unit = T_ed.resp_var == "unit/n_elec" & ...
T_ed.cond_name == "AP [-8, 0] mm";
idx_ant_SU = T_ed.resp_var == "single_unit/n_elec" & ...
T_ed.cond_name == "AP [0, 4] mm";
idx_pos_SU = T_ed.resp_var == "single_unit/n_elec" & ...
T_ed.cond_name == "AP [-8, 0] mm";
fprintf('\n\n Model time constant: anterior vs. posterior electrodes')
fprintf('\n anterior units: %0.0f [%0.0f, %0.0f], posterior units: %0.0f [%0.0f, %0.0f]', ...
T_ed.tau_mdl(idx_ant_unit), ...
T_ed.tau_mdl_CI(idx_ant_unit,1), ...
T_ed.tau_mdl_CI(idx_ant_unit,2), ...
T_ed.tau_mdl(idx_pos_unit), ...
T_ed.tau_mdl_CI(idx_pos_unit,1), ...
T_ed.tau_mdl_CI(idx_pos_unit,2))
fprintf('\n anterior SUs only: %0.0f [%0.0f, %0.0f], posterior SUs only: %0.0f [%0.0f, %0.0f]', ...
T_ed.tau_mdl(idx_ant_SU), ...
T_ed.tau_mdl_CI(idx_ant_SU,1), ...
T_ed.tau_mdl_CI(idx_ant_SU,2), ...
T_ed.tau_mdl(idx_pos_SU), ...
T_ed.tau_mdl_CI(idx_pos_SU,1), ...
T_ed.tau_mdl_CI(idx_pos_SU,2))