-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAli_et_al_NatComm_2020_script.m
executable file
·348 lines (298 loc) · 13.8 KB
/
Ali_et_al_NatComm_2020_script.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
%For details, refer to Ali et al. (2020). Ketamine disinhibits dendrites
%and enhances calcium signals in prefrontal dendritic spines. Nature
%Communications.
%https://doi.org/10.1038/s41467-019-13809-8
%% Fig. 1f
% Note that for some animals, multiple imaging sessions were performed at
% different fields of view
clearvars;
load Fig1f.mat
allRawdFF; %raw dF/F for all cells for all fields of view
%allRawdFF{fov}{cell,prepost}, where fov is 1...n fields of view; cell is
%1...n number of cells within each fov; prepost is 1 (pre-injection), 2(post-injection)
allCalciumEvents; %peeled calcium events for all cells for all fields of view; same data structure as above
allCalciumEventRate; %mean calcium event rates (Hz) for all cells for all fields of view
%allCalciumEventRate{fov}(cell,prepost) where fov is 1...n fields of view; cell is
%1...n number of cells within each fov; prepost is 1 (pre-injection),
%2(post-injection), 3 ((post-injection minus pre-injection)/pre-injection)*100
drug; %drug treatment for each fov: 1=saline, 2=ketamine
frameRate; %imaging frame rate
dataToPlot = cellfun(@(x) x(:,3), allCalciumEventRate,'UniformOutput',0); %take normalized changes in 3rd column
[f,x]=ecdf(cell2mat(dataToPlot(drug==1))); %saline
figure;stairs(x,f,'k');
hold on;
[f,x]=ecdf(cell2mat(dataToPlot(drug==2))); %ketamine
stairs(x,f,'r'); box off;
xlim([-100 200]);
title ('Calcium events');
xlabel('Post-Pre/Pre(%)');
ylabel('Cumulative fraction');
% xline(0); %for Matlab 2018a and above
%% Fig. 1i
clearvars;
load Fig1i.mat
allRawdFF; %raw dF/F for all cells for all fields of view
allCalciumEvents; %peeled calcium events for all cells for all fields of view
allCalciumEventRate; %mean calcium event rates (Hz) for all cells for all fields of view
drug; %drug treatment for each fov: 1=saline, 2=ketamine
frameRate; %imaging frame rate
%All data structures similar to Fig. 1f
dataToPlot = cellfun(@(x) x(:,3), allCalciumEventRate,'UniformOutput',0); %take normalized changes in 3rd column
[f,x]=ecdf(cell2mat(dataToPlot(drug==1))); %saline
figure;stairs(x,f,'k');
hold on;
[f,x]=ecdf(cell2mat(dataToPlot(drug==2))); %ketamine
stairs(x,f,'r'); box off;
xlim([-100 250]);
title ('Calcium events');
xlabel('Post-Pre/Pre(%)');
ylabel('Cumulative fraction');
% xline(0); %for Matlab 2018a and above
%% Fig. 2b
clearvars;
load Fig2b.mat
allRawdFF; %raw dF/F for all cells for all fields of view
allCalciumEvents; %peeled calcium events for all cells for all fields of view
allCalciumEventRate; %mean calcium event rates (Hz) for all cells for all fields of view
drug; %drug treatment for each fov: 1=saline, 2=ketamine
frameRate; %imaging frame rate
%All data structures similar to Fig. 1f
dataToPlot = cellfun(@(x) x(:,3), allCalciumEventRate,'UniformOutput',0); %take normalized changes in 3rd column
[f,x]=ecdf(cell2mat(dataToPlot(drug==1))); %saline
figure;stairs(x,f,'k');
hold on;
[f,x]=ecdf(cell2mat(dataToPlot(drug==2))); %ketamine
stairs(x,f,'r'); box off;
xlim([-100 250]);
title ('Calcium events');
xlabel('Post-Pre/Pre(%)');
ylabel('Cumulative fraction');
% xline(0); %for Matlab 2018a and above
%% Fig. 2d-e
% Note the amplitude and frequency plots here are slightly different than
% the figures presented in the manuscript. This is because here we binned
% calcium events in 1-second bin, whereas in the manuscript the figures
% were generated using calcium events in 0.28-second bins (i.e. the frame
% rate)
clearvars;
load Fig2d-e.mat
%Dendritic spine data
allRawdFF; %raw dF/F for all spines with dendritic shaft subtraction for all fields of view
%allRawdFF{fov}{spine,prepost}, where fov is 1...n fields of view; spine is
%1...n number of spines within each fov; prepost is 1 (pre-injection), 2(post-injection)
allRawdFFUnsubtracted; %raw dF/F for all spines without dendritic shaft subtraction
%data structure similar to allRawdFF
allCalciumEvents; %peeled calcium events for all spines for all fields of view; same data structure as above
allCalciumEventRate; %mean calcium event rates (Hz) for all spines for all fields of view
%allCalciumEventRate{fov}(spine,prepost) where fov is 1...n fields of view; spine is
%1...n number of spines within each fov; prepost is 1 (pre-injection),
%2(post-injection), 3 ((post-injection minus pre-injection)/pre-injection)*100
allAmpCalcium; %mean calcium amplitude for all spines for all fields of view; sata data ssructure as allCalciumEventRate
allFreqCalcium; %mean frequency of calcium events for all spines for all fields of view; same data structure as allCalciumEventRate
drug; %drug treatment for each fov: 1=saline, 2=ketamine
frameRate; %imaging frame rate
%Dendritic shaft data
allRawdFFShaft; %raw dF/F for all dendritic shaft
%data structure similar to above
shaftIdx; %indices mapping assignment of spines to shafts (many spines to one shaft mapping)
% shaftIdx{fov}{spine} where where fov is 1...n fields of view; spine is
% 1...n number of spines; entries in shaftIdx{fov} correspond to the indices in
% allRawdFFShaft{fov}. For example, to get dF/F for spine-shaft pair
% fov=1,spine=5,prepost=1
% spinedFF = allRawdFFUnsubtracted{fov,1}{spine,prepost};
% shaftdFF = allRawdFFShaft{fov,1}{shaftIdx{fov,1}(spine,1),prepost};
dataToPlot = cellfun(@(x) x(:,3), allCalciumEventRate,'UniformOutput',0); %take normalized changes in 3rd column
[f,x]=ecdf(cell2mat(dataToPlot(drug==1))); %saline
figure;stairs(x,f,'k');
hold on;
[f,x]=ecdf(cell2mat(dataToPlot(drug==2))); %ketamine
stairs(x,f,'r'); box off;
xlim([-100 200]);
title ('Calcium events');
xlabel('Post-Pre/Pre(%)');
ylabel('Cumulative fraction');
% xline(0); %for Matlab 2018a and above
dataToPlot = cellfun(@(x) x(:,3), allAmpCalcium,'UniformOutput',0); %take normalized changes in 3rd column
[f,x]=ecdf(cell2mat(dataToPlot(drug==1))); %saline
figure;stairs(x,f,'k');
hold on;
[f,x]=ecdf(cell2mat(dataToPlot(drug==2))); %ketamine
stairs(x,f,'r'); box off;
xlim([-100 200]);
title ('Amplitude');
xlabel('Post-Pre/Pre(%)');
ylabel('Cumulative fraction');
% xline(0); %for Matlab 2018a and above
dataToPlot = cellfun(@(x) x(:,3), allFreqCalcium,'UniformOutput',0); %take normalized changes in 3rd column
[f,x]=ecdf(cell2mat(dataToPlot(drug==1))); %saline
figure;stairs(x,f,'k');
hold on;
[f,x]=ecdf(cell2mat(dataToPlot(drug==2))); %ketamine
stairs(x,f,'r'); box off;
xlim([-100 200]);
title ('Frequency');
xlabel('Post-Pre/Pre(%)');
ylabel('Cumulative fraction');
% xline(0); %for Matlab 2018a and above
%% Fig. 3b-c
% Note the amplitude and frequency plots here are slightly different than
% the figures presented in the manuscript. This is because here we binned
% calcium events in 1-second bin, whereas in the manuscript the figures
% were generated using calcium events in 0.28-second bins (i.e. the frame
% rate)
clearvars;
load Fig3b-c.mat
%Dendritic spine data
allRawdFF; %raw dF/F for all spines with dendritic shaft subtraction for all fields of view
allRawdFFUnsubtracted; %raw dF/F for all spines without dendritic shaft subtraction
allCalciumEvents; %peeled calcium events for all spines for all fields of view; same data structure as above
allCalciumEventRate; %mean calcium event rates (Hz) for all spines for all fields of view
allAmpCalcium; %mean calcium amplitude for all spines for all fields of view; sata data ssructure as allCalciumEventRate
allFreqCalcium; %mean frequency of calcium events for all spines for all fields ofAli_ view; same data structure as allCalciumEventRate
drug; %drug treatment for each fov: 1=saline, 2=ketamine
frameRate; %imaging frame rate
%Dendritic shaft data
allRawdFFShaft; %raw dF/F for all dendritic shaft
shaftIdx; %indices mapping assignment of spines to shafts (many spines to one shaft mapping)
%All data structures similar to Fig. 2d-e
dataToPlot = cellfun(@(x) x(:,3), allCalciumEventRate,'UniformOutput',0); %take normalized changes in 3rd column
[f,x]=ecdf(cell2mat(dataToPlot(drug==1))); %saline
figure;stairs(x,f,'k');
hold on;
[f,x]=ecdf(cell2mat(dataToPlot(drug==2))); %ketamine
stairs(x,f,'r'); box off;
xlim([-100 200]);
title ('Calcium events');
xlabel('Post-Pre/Pre(%)');
ylabel('Cumulative fraction');
% xline(0); %for Matlab 2018a and above
dataToPlot = cellfun(@(x) x(:,3), allAmpCalcium,'UniformOutput',0); %take normalized changes in 3rd column
[f,x]=ecdf(cell2mat(dataToPlot(drug==1))); %saline
figure;stairs(x,f,'k');
hold on;
[f,x]=ecdf(cell2mat(dataToPlot(drug==2))); %ketamine
stairs(x,f,'r'); box off;
xlim([-100 200]);
title ('Amplitude');
xlabel('Post-Pre/Pre(%)');
ylabel('Cumulative fraction');
% xline(0); %for Matlab 2018a and above
dataToPlot = cellfun(@(x) x(:,3), allFreqCalcium,'UniformOutput',0); %take normalized changes in 3rd column
[f,x]=ecdf(cell2mat(dataToPlot(drug==1))); %saline
figure;stairs(x,f,'k');
hold on;
[f,x]=ecdf(cell2mat(dataToPlot(drug==2))); %ketamine
stairs(x,f,'r'); box off;
xlim([-100 200]);
title ('Frequency');
xlabel('Post-Pre/Pre(%)');
ylabel('Cumulative fraction');
% xline(0); %for Matlab 2018a and above
%% Fig. 4d
clearvars;
load Fig4d.mat
salPre; %spines x stim levels (1,2,4...64) of calcium responses pre-injection of saline
salPost; %same as above for post-injection of saline
ketPre; %same as above for pre-injection of saline
ketPost; %same as above for post-injection of ketamine
figure;
errorbar([1:1:7],mean(salPre),std(salPre,0,1)./sqrt(size(salPre,1)),'k--'); ylim([0 3.5]); box off;
hold on; errorbar([1:1:7],mean(salPost),std(salPost,0,1)./sqrt(size(salPost,1)),'k'); ylim([0 3.5]); box off;
xticks([1:1:7]);
xticklabels({'1','2','4','8','16','32','64'});
xlabel('Number of pulses');
ylabel('dF/F');
figure; errorbar([1:1:7],mean(ketPre),std(ketPre,0,1)./sqrt(size(ketPre,1)),'r--'); ylim([0 3.5]); box off;
hold on; errorbar([1:1:7],mean(ketPost),std(ketPost,0,1)./sqrt(size(ketPost,1)),'r'); ylim([0 3.5]); box off;
xticks([1:1:7]);
xticklabels({'1','2','4','8','16','32','64'});
xlabel('Number of pulses');
ylabel('dF/F');
%% Fig. 5c
clearvars;
load Fig5c.mat
allRawdFF; %raw dF/F for all cells for all fields of view
allCalciumEvents; %peeled calcium events for all cells for all fields of view
allCalciumEventRate; %mean calcium event rates (Hz) for all cells for all fields of view
frameRate; %imaging frame rate
genotypes; %1=control, no knockdown, 2=knockdown
%All data structures similar to Fig. 1f
dataToPlot = cellfun(@(x) x(:,1), allCalciumEventRate,'UniformOutput',0);
[f,x]=ecdf(cell2mat(dataToPlot(genotypes==1))); %control
figure;stairs(x,f,'k');
hold on;
[f,x]=ecdf(cell2mat(dataToPlot(genotypes==2))); %knockdown
stairs(x,f,'k--'); box off;
xlim([0 4]);
title ('Calcium events at baseline');
xlabel('Rate (s^-1)');
ylabel('Cumulative fraction');
%% Fig. 5d
clearvars;
load Fig5d.mat
allRawdFF; %raw dF/F for all cells for all fields of view
allCalciumEvents; %peeled calcium events for all cells for all fields of view
allCalciumEventRate; %mean calcium event rates (Hz) for all cells for all fields of view
drug; %drug treatment for each fov: 1=saline, 2=ketamine
frameRate; %imaging frame rate
%All data structures similar to Fig. 1f
dataToPlot = cellfun(@(x) x(:,3), allCalciumEventRate,'UniformOutput',0); %take normalized changes in 3rd column
[f,x]=ecdf(cell2mat(dataToPlot(drug==1))); %saline
figure;stairs(x,f,'k');
hold on;
[f,x]=ecdf(cell2mat(dataToPlot(drug==2))); %ketamine
stairs(x,f,'r'); box off;
xlim([-100 250]);
title ('Calcium events');
xlabel('Post-Pre/Pre(%)');
ylabel('Cumulative fraction');
% xline(0); %for Matlab 2018a and above
%% Fig. 5e
clearvars;
load Fig5e.mat
%Dendritic spine data
allRawdFF; %raw dF/F for all spines with dendritic shaft subtraction for all fields of view
allRawdFFUnsubtracted; %raw dF/F for all spines without dendritic shaft subtraction
allCalciumEvents; %peeled calcium events for all spines for all fields of view; same data structure as above
allCalciumEventRate; %mean calcium event rates (Hz) for all spines for all fields of view
genotypes; %drug treatment for each fov: 1=saline, 2=ketamine
frameRate; %imaging frame rate
%Dendritic shaft data
allRawdFFShaft; %raw dF/F for all dendritic shaft
shaftIdx; %indices mapping assignment of spines to shafts (many spines to one shaft mapping)
%All data structures similar to Fig. 2d
dataToPlot = cellfun(@(x) x(:,1), allCalciumEventRate,'UniformOutput',0);
[f,x]=ecdf(cell2mat(dataToPlot(genotypes==1))); %control
figure;stairs(x,f,'k');
hold on;
[f,x]=ecdf(cell2mat(dataToPlot(genotypes==2))); %knockdown
stairs(x,f,'k--'); box off;
xlim([0 4]);
title ('Calcium events at baseline');
xlabel('Rate (s^-1)');
ylabel('Cumulative fraction');
%% Fig. 5f
clearvars;
load Fig5f.mat
%Dendritic spine data
allRawdFF; %raw dF/F for all spines with dendritic shaft subtraction for all fields of view
allRawdFFUnsubtracted; %raw dF/F for all spines without dendritic shaft subtraction
allCalciumEvents; %peeled calcium events for all spines for all fields of view; same data structure as above
allCalciumEventRate; %mean calcium event rates (Hz) for all spines for all fields of view
drug; %drug treatment for each fov: 1=saline, 2=ketamine
frameRate; %imaging frame rate
%Dendritic shaft data
allRawdFFShaft; %raw dF/F for all dendritic shaft
shaftIdx; %indices mapping assignment of spines to shafts (many spines to one shaft mapping)
%All data structures similar to Fig. 2d
dataToPlot = cellfun(@(x) x(:,3), allCalciumEventRate,'UniformOutput',0); %take normalized changes in 3rd column
[f,x]=ecdf(cell2mat(dataToPlot(drug==1))); %saline
figure;stairs(x,f,'k--');
hold on;
[f,x]=ecdf(cell2mat(dataToPlot(drug==2))); %ketamine
stairs(x,f,'r--'); box off;
xlim([-100 250]);
title ('Calcium events');
xlabel('Post-Pre/Pre(%)');
ylabel('Cumulative fraction');
% xline(0); %for Matlab 2018a and above