-
Notifications
You must be signed in to change notification settings - Fork 0
/
extract_reactiontime_accuracy_fromlogs
277 lines (177 loc) · 6.3 KB
/
extract_reactiontime_accuracy_fromlogs
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
% Extract Reaction Times and Accuracy from Presentation Logs for each subject
[filename, pathname, filterindex] = uigetfile('*.log', 'select your log file');
infile = [pathname filename];
% start text in log file!!
starttext = 'fixation_block';
fid=fopen(infile);
lines={};
while ~feof(fid)
lines{end+1}=fgetl(fid);
end
fclose(fid);
l_header=4;
l_start=6;
%scan through the lines... and get all the unique types.
l_ind=l_start;
stop=0;
types={};
while ~stop
str=lines{l_ind};
if numel(str)>0
tmp=regexp(str,'[^\t]*','match');
types{end+1}=tmp{3};
l_ind=l_ind+1;
end
if l_ind > numel(lines)||strcmp(types{end},'Quit')
types(end)=[];
stop=1;
end
end
alltypes=unique(types);
% build our struct, based on the types!
s=struct();s(:)=[];
for i=1:numel(alltypes)
s(1).(alltypes{i})={};
end
% do something for some things.
l_ind=l_start;
stop=0;
while ~stop
str=lines{l_ind};
if numel(str)>0
tmp=regexp(str,'[^\t]*','match');
tmp_inds=regexp(str,'[^\t]*');
currenttype=tmp{3};
rest_str = tmp(4:end);
switch currenttype
case 'Response'
s(1).Response(end+1,:) = rest_str;
case 'Pulse'
s(1).Pulse(end+1,:) = rest_str;
case 'Picture'
s(1).Picture(end+1,:) = rest_str;
end
l_ind=l_ind+1;
end
if l_ind > numel(lines)||strcmp(currenttype,'Quit')
types(end)=[];
stop=1;
end
end
% now task specific. use only if you start the scanner with a Picture!!
str = s.Picture(strcmp(s.Picture(:,1),starttext),:);
str=str(1,:);
%Ramona: strat time 4th Pulse
% keyboard;
scanner_start_time = str2num(str{2}); % + str2num(str{6});
% here comes some logic w.r.t. the faces...
str_condition={'neutral','interference','fixation'};
str_regex={'.*neutral.*','.*_interference_.*','.*fixation_block.*'};
m=struct('onset','duration','name','value');
m(:)=[];
for i=1:numel(str_regex)
tmp=regexp([s.Picture(:,1)]',str_regex{i});mark=[];for i_tmp=1:numel(tmp);if numel(tmp{i_tmp})>0;mark(end+1)=i_tmp;end;end
t_onset = str2double(s.Picture(mark,2))' - scanner_start_time;
%t_duration = str2double(s.Picture(mark,5))';
% until the NEXT picture!
t_duration=[];
hitmiss = [];
hitmiss_rt = [];
for i_mark = 1:numel(mark)
tmp_index = mark(i_mark);
if tmp_index+1 <= size(s.Picture,1)
t_duration(end+1) = str2double(s.Picture(tmp_index+1,2))' - str2double(s.Picture(tmp_index,2))';
else
t_duration(end+1) = str2num(s.Response{end,2}) - str2double(s.Picture(tmp_index,2))';
end
this_hitmiss_rt = str2num(s.Picture{tmp_index,5})/10000;
this_hitmiss_val = s.Picture{tmp_index,9};
switch this_hitmiss_val
case 'hit'
hitmiss(end+1) = 1;
case 'miss'
hitmiss(end+1) = 0;
case 'other'
hitmiss(end+1) = -1;
end
hitmiss_rt(end+1) = this_hitmiss_rt;
end
t_onset = t_onset/10000;
t_duration = t_duration/10000;
m(end+1).onset = t_onset;
m(end).duration = t_duration;
m(end).name = str_condition{i};
m(end).value = 1*ones(size(t_onset));
m(end).hitmiss = hitmiss;
m(end).rt = hitmiss_rt;
%outm=[]; for i=1:numel(hm); switch hm{i}; case 'hit'; outm(end+1)=1; case 'miss'; outm(end+1) = 0; case 'other'; outm(end+1) = -1;end; end
end
times_allpresses = (str2double(s.Response(:,2))' - scanner_start_time) / 10000;
durations_allpresses = (str2double(s.Response(:,3)))' / 10000;
mark_during_experiment = times_allpresses>0;
m(end+1).onset = times_allpresses(mark_during_experiment);
m(end).duration = durations_allpresses(mark_during_experiment);
m(end).name = 'press';
m(end).value = 1*ones(size(m(end).onset));
% so... write it all away to txt files!
% .txt files for FEAT.
outdir = [pathname 'out'];
%mkdir(outdir);
for i=1:numel(m)
fid=fopen(sprintf('%s/%s.txt',outdir,m(i).name),'w+');
for j=1:numel(m(i).onset);
str = sprintf('%f\t%f\t%f\n',m(i).onset(j),m(i).duration(j),m(i).value(j));
if j==numel(m(i).onset);str(end)=[];end
fprintf(fid,str);
end
fclose(fid);
end
% names, onsets, durations for SPM...
names={};
onsets={};
durations={};
pmods={};
% neutrals... %(accurate)
%names{end+1} = 'neu';
%onsets{end+1} = m(1).onset(logical(m(1).hitmiss));
%durations{end+1} = m(1).duration(logical(m(1).hitmiss));
%pmods{end+1} = m(1).rt(logical(m(1).hitmiss));
% neutrals... % see below
names{end+1} = 'neu';
onsets{end+1} = m(1).onset;
durations{end+1} = m(1).duration;
pmods{end+1} = m(1).rt;
%these are the errors only!
%names{end+1} = 'neu - errors';
%onsets{end+1} = m(1).onset(~logical(m(1).hitmiss));
%durations{end+1} = m(1).duration(~logical(m(1).hitmiss));
%pmods{end+1} = m(1).rt(~logical(m(1).hitmiss));
% interference... (only the accurate ones)
%names{end+1} = 'int';
%onsets{end+1} = m(2).onset(logical(m(2).hitmiss));
%durations{end+1} = m(2).duration(logical(m(2).hitmiss));
%pmods{end+1} = m(2).rt(logical(m(2).hitmiss));
% ALL - inaccurate + accurate trials - will become a block in the GLM
names{end+1} = 'int';
onsets{end+1} = m(2).onset;
durations{end+1} = m(2).duration;
pmods{end+1} = m(2).rt;
% these are the errors only!
%names{end+1} = 'int - errors';
%onsets{end+1} = m(2).onset(~logical(m(2).hitmiss));
%durations{end+1} = m(2).duration(~logical(m(2).hitmiss));
%pmods{end+1} = m(2).rt(~logical(m(2).hitmiss));
% fixation...
names{end+1} = 'fix';
onsets{end+1} = m(3).onset;
durations{end+1} = m(3).duration;
pmods{end+1} = m(3).rt;
%m(1).onset(logical(m(1).hitmiss))
%names = {m.name};
%onsets = {m.onset};
%durations = {m.duration};
% new = 'negative';
% new.onset = [onset{1,1} onset{1,2}];
% names(end)=[];onsets(end)=[];durations(end)=[];
% save model.mat names onsets durations pmod ? maybe
save model_pmods_fix.mat names onsets durations pmods