-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathanalysis_events_trials.m
315 lines (251 loc) · 13.5 KB
/
analysis_events_trials.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
%function analysis_events_trials
%function analysis_events_trials
% Analysis of data trial-by-trial recorded with a laminar probe (LMA)
%
% Corentin Massot
% Cognition and Sensorimotor Integration Lab, Neeraj J. Gandhi
% University of Pittsburgh
% created 07/29/2016 last modified 01/09/2017
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%TO DO: display subplot only shifted FR or LFP and wihtout shift like
%compute_features_trials
%set paths
[root_path data_path save_path]=set_paths;
%screen size
scrsz = get(groot,'ScreenSize');
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%parameters
%print figures and save data
savefigs=0;
figtype='epsc2';%'png';%'epsc2';
%alignement
%alignlist={'no' 'targ' 'go' 'sacc'};
alignlist={'sacc'};
%window of analysis
%wind=[];%all
%wind=[0 600];%targ align
%wind=[-550 50];%sacc align
wind=[-1000 100];%sacc align
%window of burst
windb=[30 200];
%sigma FR
sigma_FR=6;
%vshift
%vshift_fr=150;
%vshift_lfp=30;
%newdata directory
savedata=0;
newdata_dir='Data_SC_Joy\';
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%get data
datalist=load_data_gandhilab(data_path);
%colorlist
colorlist=get_colorlist;
%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%analyzing data
dlist=get_dlist;
data=[];
info=[];
for d=dlist
%get data and info
clear('data');
info.datafile=datalist{d};
load ([data_path info.datafile]);
display(info.datafile)
%getting channel mapping and discard selected bad channels
[info.chmap info.nchannels info.depths]=get_chmap(data(1).info.electrode{2},[]);
%getting trial type
info.trialtype=data(1).sequence(1);
%getting list of targets
targslist=data(1).offline.targslist;
%targets index
targs_ind=get_targsindex(targslist,info);
%target tuning (after compute_tuning)
info.targ_tuning=data(1).offline.targ_tuning;
%select trials
seltrials=get_seltrials(data,'rpt');
%loop across all alignements
for al=1:numel(alignlist)
info.align=alignlist{al};
%[alltrials_lfp ~]=get_alltrials_align(data,seltrials,wind,'lfp',info,targslist,sigma_FR,1);
%correct for shift introduced by ripple filtering
[alltrials_lfp ~]=get_alltrials_align(data,seltrials,wind+4,'lfp',info,targslist,sigma_FR,1);
%get all neural and behavioral data with specific alignement
[alltrials_fr_tuning ~]=get_alltrials_align(data,seltrials,[],'fr',info,targslist,sigma_FR,1);
[alltrials_fr info.aligntime]=get_alltrials_align(data,seltrials,wind,'fr',info,targslist,sigma_FR,1);
[alltrials_spk ~]=get_alltrials_align(data,seltrials,wind,'spk',info,targslist,sigma_FR,1);
[allgazepos,allevents]=get_alldatagaze_align(data,seltrials,info,targslist);
%save data
newdata=cell(1,length(targslist));
%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%analysis of trials for each target
for tg=info.targ_tuning;%targs_ind,
%target index
info.targ=tg;
%neural and behavioral signals for target tg
trials_fr=alltrials_fr{tg};
[info.nchannels,info.ntrials,info.triallen]=size(trials_fr);
trials_lfp=alltrials_lfp{tg};
%[info.nchannels,info.ntrials,info.triallen]=size(trials_lfp);
trials_spk=alltrials_spk{tg};
gazepos=allgazepos{tg};
events=allevents{tg};
%loop on trials
for t=11:20%:info.ntrials,
figtrials=figure('Position',[1 100 scrsz(3)-100 scrsz(4)-200]);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%display all targets
hdlfig=subplot(2,3,1);hold on;
display_alltargets(targslist,info,hdlfig);
%compute target tuning
hdlfig=subplot(2,3,3);hold on;
plot_targtuning(alltrials_fr_tuning,targs_ind,info,hdlfig,'Target tuning');
%%
%%%%%%%%%%%%%%%%%%
%gaze data
gazepos_t=gazepos{t};
events_t=events{t};
event_align=get_eventalign(events_t,info.align);
if ~isempty(event_align)
hdlfig1=subplot(2,3,1);hold on;
hdlfig2=subplot(2,3,4);hold on;
%%
%%%%%%%%%%%%%%%%%%
%gaze data
plot_gazedata(gazepos_t,events_t,event_align,wind,info,hdlfig1,'',hdlfig2,'XY Eye Traces');
ax=axis;
axis([ax(1) ax(2) -4 4]);
%%
%%%%%%%%%%%%%%%%%%
%spk
trials_fr_t=squeeze(trials_fr(:,t,:));
%remove trials with amplitude that is too small
[trials_fr_tc index_fr_tc]=clean_trials(trials_fr_t,'fr');
hdlfig=subplot(2,3,2);hold on;
titlestr={info.datafile ; ['FR ' info.align ' t' num2str(info.targ) ' trial:' num2str(t) '/' num2str(info.ntrials)]};
plot_trials(trials_fr_tc,[],index_fr_tc,[],events_t,event_align,info,hdlfig,titlestr,[],[]);
%%%%%%%%%%%%%%%%%%
%lfp
trials_lfp_t=squeeze(trials_lfp(:,t,:));
%remove trials with amplitude that is too small
[trials_lfp_tc index_lfp_tc]=clean_trials(trials_lfp_t,'lfp');
hdlfig=subplot(2,3,5);hold on;
titlestr='LFP';
plot_trials(trials_lfp_tc,[],index_lfp_tc,[],events_t,event_align,info,hdlfig,titlestr,[],[]);
%%
%%%%%%%%%%%%%%%%%%
%plot CSD
hdlfig=subplot(2,3,6);hold on;
titlestr='CSD';
plot_csdtrials(trials_lfp_tc,index_lfp_tc,events_t,event_align,[],info,hdlfig,titlestr);
%%
%%%%%%%%%%%%%%%%%%
%plot spk lfp burst detection per channel
for ch=index_fr_tc%1:info.nchannels
%figtrial=figure('Position',[scrsz(3)*0.6 200 scrsz(3)-scrsz(3)*0.6 scrsz(4)*0.5]);
figtrial=figure('Position',[scrsz(1) scrsz(2) scrsz(3) scrsz(4)*0.5]);
hdlfigtrial=subplot(1,1,1);hold on;
%fr
trials_fr_tch=squeeze(trials_fr(ch,t,:))';
titlestr={info.datafile ; ['FR ' info.align ' t' num2str(info.targ) ' ch:' num2str(ch) ' trial:' num2str(t) '/' num2str(info.ntrials)]};
plot_trials(trials_fr_tch,[],[],[],events_t,event_align,info,hdlfigtrial,titlestr,[],[]);
%lfp
trials_lfp_tch=squeeze(trials_lfp(ch,t,:))';
%plot_trials(trials_lfp_tch,[],index_lfp_tc,[],events_t,event_align,info,hdlfigtrial,titlestr,[],[]);
plot_trials(trials_lfp_tch,[],[],[],[],[],info,hdlfigtrial,titlestr,[],[]);
ylabel(['Channel ' num2str(ch)]);
set(gca,'ytick',[],'yticklabel',[]);
%spk and bursts
%timestamps
trials_ts=find(squeeze(trials_spk(ch,t,:))>=1);%-info.aligntime;
for algo=1:2
if ~isempty(trials_ts)
switch algo
case 1
%p_burst (Hanes et al.)
[bob,eob,sob]=p_burst(trials_ts,min(trials_ts),max(trials_ts));
titlestr=[titlestr ; [' sob_pburst:' num2str(sob)]];
if ~isempty(bob) | ~isempty(eob) | ~isempty(sob)
bobs=trials_ts(bob);
eobs=trials_ts(eob);
sobs_pburst=sob;
%burts in windb window
ind=[1:numel(bobs)];%find(bobs>windb(1) & bobs<windb(2));
%in case 2 candidate bursts
[v ind_max]=max(sobs_pburst(ind));
ind=ind(ind_max);
if ~isempty(ind)
%[val ind]=max(sobs);
bob_sel=bobs(ind);
eob_sel=eobs(ind);
%plot
hl=line([bob_sel bob_sel] ,[0 max(trials_fr_tch)]);
set(hl,'Color',colorlist(4,:),'LineStyle','--','Linewidth',1);
hl=line([eob_sel eob_sel] ,[0 max(trials_fr_tch)]);
set(hl,'Color',colorlist(4,:),'LineStyle','--','Linewidth',1);
%pause
end
end
case 2
%rs_burst (Gourevich et al.)
[sob,lob,bob]=rs_burst(trials_ts);
bob
eob=bob+lob-1;
titlestr=[titlestr ; [' sob_rsburst:' num2str(sob)]];
if ~isempty(bob) | ~isempty(eob) | ~isempty(sob)
bobs=trials_ts(bob);%-info.aligntime
eobs=trials_ts(eob);%-info.aligntime
sobs_rsburst=sob;
%burts in windb window
ind=[1:numel(bobs)];%find(bobs>windb(1) & bobs<windb(2));
%in case 2 candidate bursts
[v ind_max]=max(sobs_rsburst(ind));
ind=ind(ind_max);
if ~isempty(ind)
%[val ind]=max(sobs);
bob_sel=bobs(ind);
eob_sel=eobs(ind);
%plot
hl=line([bob_sel bob_sel] ,[0 max(trials_fr_tch)/2]);
set(hl,'Color',colorlist(5,:),'LineStyle','--','Linewidth',2);
hl=line([eob_sel eob_sel] ,[0 max(trials_fr_tch)/2]);
set(hl,'Color',colorlist(5,:),'LineStyle','--','Linewidth',2);
%pause
end
end
end
end
end
title(titlestr)
%%%%%%%%%%%%%%%%%%
pause
close(figtrial)
end
%%
end
%%%%%%%%%%%%%%%%%%
%save figs
if savefigs==1
saveas(figtrials,[save_path info.datafile '_' info.align '_t' num2str(info.targ) '_trial' num2str(t) '.' figtype],figtype);
end;
pause
close(figtrials)
end
%%%%%%%%%%%%%%%%%%
%save data
if savedata
newdata{tg}.lfp=trials_lfp;
newdata{tg}.fr=trials_fr;
newdata{tg}.info=info;
else
%pause
%close(figtrials)
end
end
if savedata
save_data(newdata,root_path,newdata_dir,info);
end
end
end