-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathtaskdetect.m
268 lines (257 loc) · 10.8 KB
/
taskdetect.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
function [curtasktype, ecodecueon, ecodesacstart, ecodesacend]=taskdetect(codes, curtasktype)
% identifies task, and also tells which ecodes correspond to which event
% called by rex_process_inGUI and by data_info
if nargin<2
curtasktype=[];
end
global tasktype;
ecodecueon=[];
ecodesacstart=[];
ecodesacend=[];
if size(codes,2)==1
codes=codes';
end
if iscell(curtasktype)
curtasktype=cell2mat(curtasktype);
end
firstind = find(codes(1, :) >= 4000 & codes(1, :) < 8000, 1); % finds the index of the basecode, only works if basecode is dropped at same index in each row
alltasktypes={'vg_saccades','base2rem50','memguided',...
'st_saccades','gapstop','gapsac','delayedsac',...
'optiloc','tokens','fixation','twoafc','periodCmd'};
%fsttlecode=floor(allcodes(1,2)/10)*10;
if size(codes,1)>1 %for a full file of ecodes
ecodetypes=unique(floor(codes(:,firstind)/10)*10); %gives away the different ecode if mixed task
else %if called during a trial, there's only one line
ecodetypes=floor(codes(firstind)/10)*10;
end
if ecodetypes(1) < 4000; %twoafc task has basecode (4050) dropped as codes(5), not codes(2)
ecodetypes(1) = 4050;
end
if ~sum(curtasktype) || strcmp(curtasktype,'Task') %then find task!
if ecodetypes(1)==6010 % Visually guided saccades task type, including 'amp', 'dir' and 'optiloc'
if strcmp(tasktype,'optiloc')
curtasktype=alltasktypes(8); %optiloc
tasktype=alltasktypes(8);
elseif size(codes,1)>1 && logical(sum(find(codes==16386,1)))
curtasktype=alltasktypes(8); %optiloc
else
if find(codes==16386)
curtasktype='reproc';
tasktype=alltasktypes(8);
return;
else
curtasktype=alltasktypes(1);
end
end
elseif ecodetypes(1)==6020
%make sure this is consistent over older recordings
% default memory guided saccade is the self-timed saccade, but check if it is correct
if isempty(find(codes==16386, 1))
if length(ecodetypes)>1 && find(ecodetypes==6040) && find(ecodetypes==6080)
curtasktype=alltasktypes(2); %base2rem50
else
if ~size(codes,2)
taskdisambig = questdlg('Is this a Memory guided task ?','Ambiguous Task','Yes','Yes but self timed','Cancel','Yes');
switch taskdisambig
case 'Yes'
curtasktype=alltasktypes(3); %memory guided
case 'Yes but self timed'
curtasktype=alltasktypes(4); %self timed saccade task
case 'Cancel'
return;
end
else %single trial
%if isempty(tasktype) %instead of asking question, assume that it's the rare
%ambiguous case where it's memory
%guided task. Later on, if it
%appears to be a self-timed
%saccade task, the file will be
%reprocessed
% taskdisambig = questdlg('Is this a Memory guided task ?','Ambiguous Task','Yes','Yes but self timed','Cancel','Yes');
% switch taskdisambig
% case 'Yes'
% curtasktype=alltasktypes(3); %memory guided
% tasktype=alltasktypes(3); %memory guided
% case 'Yes but self timed'
% curtasktype=alltasktypes(4); %self timed saccade task
% tasktype=alltasktypes(4);
% case 'Cancel'
% return;
% end
if strcmp(tasktype,'memguided')
curtasktype=alltasktypes(3); %memory guided
tasktype=alltasktypes(3); %memory guided
elseif strcmp(tasktype,'st_saccades')
curtasktype=alltasktypes(4); %self timed saccade task
tasktype=alltasktypes(4);
elseif strcmp(tasktype,'base2rem50')
curtasktype=alltasktypes(2); %base2rem50
tasktype=alltasktypes(2);
else
%have to assume the default is self timed saccade,
%because Rigel managed to do entire recordings
%without the 16386 error code!
curtasktype=alltasktypes(4); %self timed saccade task
tasktype=alltasktypes(4); %self timed saccade task
end
end
end
else
if strcmp(tasktype,'memguided')
curtasktype='reproc';
tasktype=alltasktypes(4);
return;
else
curtasktype=alltasktypes(4); %self timed saccade task
tasktype=alltasktypes(4);
end
end
elseif ecodetypes(1)==6040
if (length(ecodetypes)>1 && find(ecodetypes==6020) && find(ecodetypes==6080)) || strcmp(tasktype,'base2rem50')
curtasktype=alltasktypes(2); %base2rem50
tasktype=alltasktypes(2);
elseif length(ecodetypes)>1 && find(ecodetypes==4070)
curtasktype=alltasktypes(5); %gapstop
tasktype=alltasktypes(5);
elseif ~strcmp(tasktype,'gapstop')
curtasktype=alltasktypes(6); %gapsac
tasktype=alltasktypes(6);
else
curtasktype=alltasktypes(5); %gapstop
tasktype=alltasktypes(5);
end
elseif ecodetypes(1)==6050
return;
elseif ecodetypes(1)==6080
if (length(ecodetypes)>1 && find(ecodetypes==6020) && find(ecodetypes==6040)) || strcmp(tasktype,'base2rem50')
curtasktype=alltasktypes(2); %base2rem50
tasktype=alltasktypes(2);
else
if strcmp(tasktype,'memguided') || strcmp(tasktype,'gapsac') || strcmp(tasktype,'st_saccades')
curtasktype='reproc';
tasktype=alltasktypes(2);
return;
else
curtasktype=alltasktypes(7);% delayedsac
end
end
elseif ecodetypes(1)==4010
curtasktype=alltasktypes(10);
elseif ecodetypes(1)==4050
curtasktype=alltasktypes(11);
elseif ecodetypes(1)==4060
curtasktype=alltasktypes(9);% tokens
elseif ecodetypes(1)==4070
if length(ecodetypes)>1 && find(ecodetypes==6040) % for full set of ecodes
curtasktype=alltasktypes(5); %gapstop
else
curtasktype=alltasktypes(5); %gapstop
if strcmp(tasktype,'st_saccades') %for that one weird mixed-up file
curtasktype='gapstop';
tasktype=alltasktypes(5);
elseif ~strcmp(tasktype,'gapstop')
curtasktype='reproc';
tasktype=alltasktypes(5);
return;
end
end
elseif ecodetypes(1)==4080
curtasktype=alltasktypes(12);
tasktype=alltasktypes(12);
end
end
%%
% if ~isempty(curtasktype) && strcmp(curtasktype,'gapstop') && find(codes==17385,1)>8
if ~isempty(curtasktype) %&& ~sum(find(codes==17385))
if iscell(curtasktype)
curtasktype=cell2mat(curtasktype);
end
switch curtasktype
case 'vg_saccades'
ecodecueon=7;
ecodesacstart=8;
ecodesacend=9;
case 'base2rem50' %variable
if ecodetypes==6020 %memory guided
ecodecueon=6;
ecodesacstart=9;
ecodesacend=10;
elseif ecodetypes==6040 % gap sac
ecodecueon=7;
ecodesacstart=8;
ecodesacend=9;
elseif ecodetypes==6080 %delayed sac
ecodecueon=6;
ecodesacstart=8;
ecodesacend=9;
end
case 'st_saccades'
ecodecueon=6;
ecodesacstart=8;
ecodesacend=9;
case 'gapstop'
ecodecueon=7;
if ~isempty(find(codes==1503, 1))
ecodesacstart=9;
% ecode to control for stop signal delay value, introduced between target code and stop code
% stopcode is at 9, not 8 anymore
else
ecodesacstart=8;
end
ecodesacend=9;
case 'memguided'
disp('check task ecodes in taskdetect');
ecodecueon=6;
ecodesacstart=9;
ecodesacend=10;
case 'gapsac'
ecodecueon=7;
ecodesacstart=8;
ecodesacend=9;
case 'delayedsac' % to change ?!
disp('check task ecodes for delayedsac in taskdetect');
ecodecueon=6;
ecodesacstart=8;
ecodesacend=9;
case 'tokens'
%multiple cues. returns all tokens event numbers
ecodecueon=find(codes==1501);
%sacstart is variable too.
ecodesacstart=find(floor(codes/10)==466);
if find(codes==16386) %in case it's a saccade to the wrong target, there's no saccade end ecode, but we want the other informations still
ecodesacend=ecodesacstart;
else
ecodesacend=find(floor(codes/10)==486);
end
case 'optiloc'
ecodecueon=7;
ecodesacstart=8;
ecodesacend=9;
case 'twoafc'
ecodecueon=8;
ecodesacstart=10;
ecodesacend=12;
case 'periodCmd'
%returns all periodic cues
nxttgt=find(floor(codes/10)==428);
codediff=codes(nxttgt)-codes(2);
while codediff==200
codediff=codes(nxttgt+1)-codes(nxttgt);
nxttgt=nxttgt+1;
end
%series of four spec_cd codes:
% fix off (6)
% tgt on (7)
% sac detected (8)
% eye in window (9)
% except for the first two: fix on (4) / eye in window (5)
ecodecueon=find(floor(codes/10)==428)+3:4:nxttgt-1;
%sac / stop signal is following code.
if ~isempty(ecodecueon)
ecodesacstart=nxttgt+1;
ecodesacend=nxttgt+2;
else
[ecodecueon,ecodesacstart,ecodesacend]=deal(0);
end
end
end