-
Notifications
You must be signed in to change notification settings - Fork 0
/
sara_data_analysis.m
executable file
·562 lines (288 loc) · 11.7 KB
/
sara_data_analysis.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
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
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
pdflib.header
%% Analysis of gastric and pyloric rhythms at different temperatures
% In this document we look at pyloric and gastric rhtyhms at differnet temperatures.
% This data is from Sara Haddad and the experiments that go into this are:
if exist('sara_stacked_data.mat','file') == 2
load('sara_stacked_data','data')
disp([data.experiment_idx]')
else
data_root = '/Volumes/HYDROGEN/srinivas_data/temperature-data-for-embedding';
avail_exps = dir(data_root);
exp_ids = {};
neurons = {'PD','LG'};
% automatically figure out the usable data
for i = 1:length(avail_exps)
if strcmp(avail_exps(i).name(1),'.')
continue
end
allfiles = dir([avail_exps(i).folder filesep avail_exps(i).name filesep '*.crabsort']);
if length(allfiles) < 3
% can't be any data here
continue
end
not_sorted = crabsort.checkSorted(allfiles, neurons, true);
if ~not_sorted
exp_ids{end+1} = avail_exps(i).name;
end
end
data_s = struct;
for i = 1:length(exp_ids)
this_data = crabsort.consolidate('neurons',{'PD','LG'},'DataDir',[data_root filesep exp_ids{i}],'stack',true,'ForceStack',true);
data_s = structlib.merge(data_s,this_data);
end
data = data_s;
save('sara_stacked_data','data','-nocompression','-v7.3')
end
N = length(data);
% make sure spiketimes are sorted
for i = 1:N
data(i).PD = sort(data(i).PD);
data(i).LG = sort(data(i).LG);
end
% throw away data that is decentralized
for i = 1:N
idx = find(data(i).decentralized,1,'first');
if isempty(idx)
continue
end
data(i).PD(data(i).PD > idx) = [];
data(i).LG(data(i).LG > idx) = [];
end
%% PD bursts
figure('outerposition',[300 300 1200 1100],'PaperUnits','points','PaperSize',[1200 1100]); hold on
for i = 1:length(data)
subplot(5,3,i); hold on
isis = diff(data(i).PD);
% isis(isis>2) = NaN;
isis(isis<1e-2) = NaN;
spiketimes = data(i).PD(1:end-1);
plot(spiketimes,isis,'k.')
isis(isnan(isis)) = [];
ibi = nanmin(nanmax(veclib.stagger(isis,100,100)))/2;
plotlib.horzline(ibi);
set(gca,'YScale','log','YLim',[.01 5])
title(char(data(i).experiment_idx),'interpreter','none')
end
suptitle('PD neurons, Sara data')
figlib.pretty('fs',12)
pdflib.snap()
%% LG bursts
% How regular is LG bursting? Is it meaningful to measure LG burst metrics? To get a sense of this, I plot all ISIs from the LG neuron in all preps.
figure('outerposition',[300 300 1200 1100],'PaperUnits','points','PaperSize',[1200 1100]); hold on
for i = 1:length(data)
subplot(5,3,i); hold on
isis = diff(data(i).LG);
% isis(isis>2) = NaN;
isis(isis<1e-2) = NaN;
spiketimes = data(i).LG(1:end-1);
plot(spiketimes,isis,'k.')
isis(isnan(isis)) = [];
ibi = nanmin(nanmax(veclib.stagger(isis,100,100)))/2;
plotlib.horzline(ibi);
set(gca,'YScale','log','YLim',[.01 50])
title(char(data(i).experiment_idx),'interpreter','none')
end
suptitle('LG neurons, Sara data')
figlib.pretty('fs',12)
pdflib.snap()
return
data = crabsort.computePeriods(data,'neurons',{'PD'},'ibis',.15,'min_spikes_per_burst',2);
data = crabsort.computePeriods(data,'neurons',{'LG'},'ibis',1,'min_spikes_per_burst',5);
%% Burst period vs. temperature
% In the following figure, I plot burst periods of LG and PD neurons as a function of temperature for each prep. Black dots are PD bursts, red dots are LG bursts. Note that they both decrease at approximately the same rate.
figure('outerposition',[300 300 1001 901],'PaperUnits','points','PaperSize',[1001 901]); hold on
for i = 1:length(data)
subplot(4,4,i); hold on
x = round(data(i).PD_burst_starts*1e3);
plot(data(i).temperature(x),data(i).PD_burst_periods,'k.')
x = round(data(i).LG_burst_starts*1e3);
plot(data(i).temperature(x),data(i).LG_burst_periods,'r.')
set(gca,'YScale','log','XLim',[6 24])
title(char(data(i).experiment_idx),'interpreter','none')
if i == 7
xlabel('Temperature (C)')
ylabel('Burst period (s)')
end
end
figlib.pretty('fs',16)
pdflib.snap()
%% LG-PD coupling: PD spiking triggered by LG starts
% To look at the interaction between LG and PD (a proxy for the interaction b/w the gastric and pyloric rhythms), I will plot PD spikes triggered by LG burst starts.
figure('outerposition',[300 300 1002 901],'PaperUnits','points','PaperSize',[1002 901]); hold on
for i = 1:length(data)
subplot(4,4,i); hold on
gastric.plotRasterTriggeredBy(data(i),'PD', 'LG_burst_starts')
set(gca,'YTick',[])
ylabel(char(data(i).experiment_idx),'interpreter','none')
if i == 13
xlabel('Time since LG start (s)')
end
end
suptitle('PD spikes')
figlib.pretty
pdflib.snap()
%% LG-PD coupling
% I now look at the fine structure of the LG-PD coupling. The hypothesis here is that the gastric rhythm, in some manner, affects the pyloric rhythm. One way to look a this is to plot the PD inter-spike-intervals triggered by start of LG bursts. That's what the next figure shows. Notice the striking fan-like structure in all preps (different colours are different temperatures). This suggests that the PD neuron is in phase with the LG start (or the LG neuron is starting at a particular phase of PD).
%%
% Note also that the PD ISIs seem to increase and decrease with the LG start (this is expecially clear in 901_062). This suggests that the LG neuron is affecting the PD neuron, though we cannot rule out PD affecting LG.
figure('outerposition',[300 300 1002 901],'PaperUnits','points','PaperSize',[1002 901]); hold on
for i = 1:length(data)
subplot(4,4,i); hold on
[~, ph, ch] = gastric.plotISITriggeredBy(data(i), 'PD', 'LG_burst_starts',[7 33]);
if i == 13
ylabel(gca,'PD IBI (s)')
xlabel(gca,'Time since LG start (s)')
else
set(gca,'XTickLabel',{},'YTickLabel',{})
end
set(gca,'YLim',[0 1])
ph.SizeData = 10;
ph.Marker = 'o';
if i < length(data)
delete(ch)
end
end
figlib.pretty('fs',16)
ch.Position = [.55 .11 .01 .15];
pdflib.snap()
%% Phase coupling between LG and PD
% All of this hints at a phase coupling between LG and PD. Here I measure the phase in the PD cycle where LG starts and plot that as a function of temperature.
figure('outerposition',[300 300 1200 601],'PaperUnits','points','PaperSize',[1200 601]); hold on
temp_space = 7:2:31;
all_phase = [];
all_temp = [];
all_prep = [];
for i = 1:length(data)
[this_phase,this_temp] = gastric.measurePhase(data(i),'LG_burst_starts','PD');
all_phase = [all_phase; this_phase];
all_temp = [all_temp; this_temp];
all_prep = [all_prep; this_phase*0 + i];
end
subplot(1,2,1); hold on
gastric.groupAndPlotErrorBars(temp_space, all_temp, all_prep, all_phase);
set(gca,'YLim',[0 1],'YScale','linear')
ylabel('LG start in PD phase')
xlabel('Temperature (C)')
figlib.pretty('fs',16)
pdflib.snap()
%% Variability of PD period: dependence on the gastric rhythm
% One question in this data is if the gastric rhythm influences the pyloric rhythm in any way. If it does, one would expect the pyloric period to be a little more variable when the gastric rhythm is on compared to when the gastric rhythm is off. That's what the next figure shows: it compares the variability (CV) of the pyloric burst periods when the gastric rhythm is on and when it is off.
%%
% By "gastric rhythm on", we mean that PD bursts occur within 10 seconds following a LG spike, and by "gastric rhythm off", we mean PD bursts more than 100s since the last LG spike. Note that almost every dot lies below the diagonal, suggesting that G bursting makes PD bursting more variable.
figure('outerposition',[300 300 1200 600],'PaperUnits','points','PaperSize',[1200 600]); hold on
clear ax
ax(2) = subplot(1,2,2); hold on
ax(1) = subplot(1,2,1); hold on
set(ax(1),'XScale','log','YLim',[0 .5])
temp_space = 7:2:31;
c = parula(length(temp_space)+1);
all_x = [];
all_y = [];
all_temp = [];
for i = 1:length(data)
[cv_mean_on, cv_mean_off, cv_std_on, cv_std_off, time_since_gastric, PD_period_cv, temperature] = gastric.comparePDVariability(data(i), temp_space, 10, 2.5);
all_x = [time_since_gastric; all_x];
all_y = [PD_period_cv; all_y];
all_temp = [temperature; all_temp];
for j = 1:length(temp_space)
scatter(ax(2),cv_mean_on(j),cv_mean_off(j),64,c(j,:),'MarkerFaceColor',c(j,:),'MarkerEdgeColor',c(j,:),'MarkerFaceAlpha',.5)
end
end
for i = 1:length(temp_space)
ok = abs(temp_space(i) - all_temp) < 1;
plotlib.pieceWiseLinear(ax(1),all_x(ok),all_y(ok),'nbins',10,'Color',c(i,:));
end
xlabel(ax(1),'Time since LG spike (s)')
ylabel(ax(1),'PD burst variability')
plotlib.drawDiag(ax(2));
axis(ax(2),'square')
set(ax(2),'XLim',[0 .15],'YLim',[0 .15])
xlabel(ax(2),'Gastric rhythm on')
ylabel(ax(2),'Gastric rhythm off')
suptitle('Variability in PD periods')
ch = colorbar(ax(2));
caxis(ax(2),[min(temp_space) max(temp_space)]);
title(ch,'Temperature (C)')
figlib.pretty('fs',16)
pdflib.snap()
%% Integer coupling b/w PD and LG periods
% The periods of PD and LG neurons have previously been shown the be integer-coupled, that is, the LG periods is an integer mulitple of the PD period. Here we see the same thing: the following figure plots the LG period vs. the mean PD periods during taht LG burst. Note that the gray lines are not fits to the data -- they are merely lines with integer slopes. Note that the data naturally falls on top of these lines.
all_x = [];
all_temp = [];
all_y = [];
all_prep = [];
for i = 1:length(data)
[this_x,this_temp] = gastric.integerCoupling(data(i));
all_x = [all_x; this_x];
all_temp = [all_temp; this_temp];
all_y = [all_y; data(i).LG_burst_periods];
all_prep = [all_prep; this_x*0 + i];
end
figure('outerposition',[300 300 901 901],'PaperUnits','points','PaperSize',[1200 901]); hold on
% plot gridlines
for i = 4:30
xx = linspace(0,10,1e3);
yy = xx*i;
plot(gca,xx,yy,'Color',[.8 .8 .8])
end
plot(all_x(isnan(all_temp)),all_y(isnan(all_temp)),'.','Color',[.5 .5 .5],'MarkerSize',12);
[~,ch] = plotlib.cplot(all_x,all_y,all_temp);
set(gca,'XLim',[0.2 1.2],'YLim',[0 30])
xlabel('Mean PD period (s)')
ylabel('LG periods (s)')
ch.Location = 'southoutside';
ch.Position = [.52 .15 .4 .02];
title(ch,'Temperature (C)')
figlib.pretty('fs',16)
pdflib.snap()
%%
% Now I colour the dots in the integer coupling plot by prep ID.
figure('outerposition',[300 300 901 901],'PaperUnits','points','PaperSize',[1200 901]); hold on
% plot gridlines
for i = 4:30
xx = linspace(0,10,1e3);
yy = xx*i;
plot(gca,xx,yy,'Color',[.8 .8 .8])
end
for i = 1:length(data)
plot(all_x(all_prep == i),all_y(all_prep == i),'.','MarkerSize',12)
end
set(gca,'XLim',[0.2 1.2],'YLim',[0 30])
xlabel('Mean PD period (s)')
ylabel('LG periods (s)')
figlib.pretty('fs',16)
pdflib.snap()
%%
% How does integer coupling vary with temperature?
N_pyloric_gastric = round(all_y./all_x);
integerness = 1- abs(all_y./all_x - N_pyloric_gastric)*2;
figure('outerposition',[300 300 903 901],'PaperUnits','points','PaperSize',[903 901]); hold on
temp_space = 7:2:31;
PD_space = .2:.2:2;
% plot N/plyoric and group by temperature
subplot(2,2,1); hold on
gastric.groupAndPlotErrorBars(temp_space, all_temp, all_prep, N_pyloric_gastric);
set(gca,'YLim',[1 400],'YScale','log')
ylabel('N gastric/pyloric')
xlabel('Temperature (C)')
% plot integerness and group by temperature
subplot(2,2,2); hold on
gastric.groupAndPlotErrorBars(temp_space, all_temp, all_prep, integerness);
set(gca,'YLim',[0 1])
ylabel('Integerness')
xlabel('Temperature (C)')
% now group by PD periods
subplot(2,2,3); hold on
gastric.groupAndPlotErrorBars(PD_space, all_x, all_prep, N_pyloric_gastric);
set(gca,'YLim',[1 400],'YScale','log')
ylabel('N gastric/pyloric')
xlabel('PD period (s)')
subplot(2,2,4); hold on
gastric.groupAndPlotErrorBars(PD_space, all_x, all_prep, integerness);
ylabel('Integerness')
xlabel('PD period (s)')
figlib.pretty('plw',1)
pdflib.snap()
%% Metadata
% To reproduce this document:
pdflib.footer