-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathpspm_review.m
550 lines (469 loc) · 20 KB
/
pspm_review.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
function varargout = pspm_review(varargin)
% ● Description
% pspm_review is the MATLAB code for pspm_review.fig
% ● History
% Introduced in PsPM 3.0
% Written in 2008-2015 by Gabriel Graeni (University of Zurich)
% Maintained in 2022 by Teddy Chao (UCL)
%% Initialise
global settings
if isempty(settings)
pspm_init;
end
sts = -1;
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @pspm_review_OpeningFcn, ...
'gui_OutputFcn', @pspm_review_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end
if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT
% --- Executes just before pspm_review is made visible.
function pspm_review_OpeningFcn(hObject, ~, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% varargin command line arguments to pspm_review (see VARARGIN)
% Left alignment of text fields
set(handles.textPlot1,'HorizontalAlignment','left')
set(handles.textPlot2,'HorizontalAlignment','left')
set(handles.textPlot3,'HorizontalAlignment','left')
set(handles.textPlot4,'HorizontalAlignment','left')
set(handles.textPlot5,'HorizontalAlignment','left')
set(handles.textPlot6,'HorizontalAlignment','left')
set(handles.textStatus,'HorizontalAlignment','left')
set(handles.textStatus,'String','Select a model...');
handles.nrPlot = 6;
%handles.figCnt = 0;
handles.modelCnt = 0;
handles.currentModel = 1;
handles.listModelEntry{1} = '';
% buffer figure handles to keep
handles.figToKeep = findall(0, 'type', 'figure');
% Choose default command line output for pspm_review
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
pspm_ui(hObject, handles, 'review');
% UIWAIT makes pspm_review wait for user response (see UIRESUME)
% uiwait(handles.pspm_review);
% --- Outputs from this function are returned to the command line.
function varargout = pspm_review_OutputFcn(~, ~, handles)
% varargout cell array for returning output args (see VARARGOUT);
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Get default command line output from handles structure
varargout{1} = handles.output;
% --- Executes on button press in buttonAddModel_old.
function buttonAddModel_Callback(hObject, ~, handles)
% hObject handle to buttonAddModel_old (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
filt='.*\.mat$';
[modelfileArray, sts]=spm_select([1 inf], filt, 'Select model file');
if sts==0, return; end
% check each model file
setButtonDisable(handles)
set(handles.textStatus,'String','Loading model. Please wait...');
drawnow
for iFile = 1:size(modelfileArray, 1)
modelfile = spm_file(modelfileArray(iFile, :));
[sts, model, modeltype] = pspm_load1(modelfile, 'all', 'any');
if sts == -1 || ~any(strcmp(modeltype,{'glm','dcm','sf'}))
set(handles.textStatus,'String','No supported modeltype detected');
drawnow
return;
elseif strcmp(modeltype,'sf')
dcm = cellfun(@(field) strcmpi(field(1).modeltype, 'dcm'), model.model);
if ~any(dcm)
set(handles.textStatus,'String','No supported modeltype detected');
drawnow
return;
end
end
handles.modelCnt = handles.modelCnt+1;
handles.modelData{handles.modelCnt}.modeltype = modeltype;
handles.modelData{handles.modelCnt}.model = model;
handles.modelData{handles.modelCnt}.modelfile = modelfile;
if strcmp(modeltype,'dcm')
handles.modelData{handles.modelCnt}.maxSessionNr = numel(model.sn);
end
if strcmp(modeltype,'sf')
handles.modelData{handles.modelCnt}.maxEpochNr = numel(model.model{dcm});
end
[~,modelfileName,~] = fileparts(modelfile);
handles.listModelEntry{handles.modelCnt} = modelfileName;
set(handles.listModel, 'String', handles.listModelEntry);
set(handles.listModel, 'Value', handles.modelCnt);
handles.currentModel = handles.modelCnt;
handles.modelData{handles.modelCnt}.fig = setFigureHandle(handles);
showModel(handles);
end
setButtonEnable(handles)
if handles.modelCnt > 1
set(handles.buttonRemoveModel2, 'Enable', 'on');
end
guidata(hObject, handles);
% --- Executes on button press in buttonRemoveModel2.
function buttonRemoveModel_Callback(hObject, ~, handles)
% hObject handle to buttonRemoveModel2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
handles.modelData{handles.currentModel} = [];
handles.modelData(cellfun('isempty',handles.modelData)) = [];
handles.listModelEntry{handles.currentModel} = [];
handles.listModelEntry(cellfun('isempty',handles.listModelEntry)) = [];
handles.modelCnt = handles.modelCnt - 1;
set(handles.listModel, 'String', handles.listModelEntry);
if handles.currentModel > handles.modelCnt
handles.currentModel = handles.modelCnt;
end
set(handles.listModel, 'Value', handles.currentModel);
if handles.modelCnt < 2
set(handles.buttonRemoveModel2, 'Enable', 'off');
end
showModel(handles);
guidata(hObject, handles);
% --- Executes on button press in buttonExit.
function buttonExit_Callback(~, ~, handles)
% hObject handle to buttonExit (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
closeFigures(handles);
delete(gcbf)
% --- Executes when user attempts to close pspm_review.
function pspm_review_CloseRequestFcn(~, ~, handles)
% hObject handle to pspm_review (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hint: delete(hObject) closes the figure
closeFigures(handles);
delete(gcbf)
% --- Executes on button press in buttonPlot1.
function buttonPlot1_Callback(hObject, ~, handles)
% hObject handle to buttonPlot1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
tmpStatusString = get(handles.textStatus,'String');
set(handles.textStatus,'String','Plotting is in progress. Please wait...');
switch handles.modelData{handles.currentModel}.modeltype
case 'glm'
handles.modelData{handles.currentModel}.fig = ...
pspm_rev_glm(handles.modelData{handles.currentModel}.modelfile, ...
handles.modelData{handles.currentModel}.model, 1);
case 'dcm'
sessionNr = checkSessionNr(handles);
if sessionNr
pspm_rev_dcm(handles.modelData{handles.currentModel}.model, 'sum', sessionNr, [])
end
case 'sf'
epochNr = str2double(get(handles.editEpochNr,'String'));
if isempty(epochNr) || epochNr > handles.modelData{handles.currentModel}.maxEpochNr || epochNr < 1
uiwait(msgbox(sprintf('Epoch number has to be within the range [1 - %d]',...
handles.modelData{handles.currentModel}.maxEpochNr),'Warning'));
else
dcm_method = cellfun(@(field) strcmpi(field(1).modeltype, 'dcm'),...
handles.modelData{handles.currentModel}.model.model);
pspm_rev_dcm(handles.modelData{handles.currentModel}.model.model{dcm_method}, 'sf', epochNr, []);
end
end
set(handles.textStatus,'String',tmpStatusString);
guidata(hObject, handles);
% --- Executes on button press in buttonPlot2.
function buttonPlot2_Callback(hObject, ~, handles)
% hObject handle to buttonPlot2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
tmpStatusString = get(handles.textStatus,'String');
set(handles.textStatus,'String','Plotting is in progress. Please wait...');
switch handles.modelData{handles.currentModel}.modeltype
case 'glm'
handles.modelData{handles.currentModel}.fig = ...
pspm_rev_glm(handles.modelData{handles.currentModel}.modelfile, ...
handles.modelData{handles.currentModel}.model, 2);
case 'dcm'
sessionNr = checkSessionNr(handles);
if sessionNr
maxTrialNr = numel(handles.modelData{handles.currentModel}.model.sn{sessionNr}.u);
trialNr = str2double(get(handles.editTrialNr,'String'));
if isempty(trialNr) || trialNr > maxTrialNr || trialNr < 1
uiwait(msgbox(sprintf('Trial number has to be within the range [1 - %d]',maxTrialNr),'Warning'));
else
pspm_rev_dcm(handles.modelData{handles.currentModel}.model, 'inv', sessionNr, trialNr);
end
end
end
set(handles.textStatus,'String',tmpStatusString);
guidata(hObject, handles);
% --- Executes on button press in buttonPlot3.
function buttonPlot3_Callback(hObject, ~, handles)
% hObject handle to buttonPlot3 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
tmpStatusString = get(handles.textStatus,'String');
set(handles.textStatus,'String','Plotting is in progress. Please wait...');
switch handles.modelData{handles.currentModel}.modeltype
case 'glm'
handles.modelData{handles.currentModel}.fig = ...
pspm_rev_glm(handles.modelData{handles.currentModel}.modelfile, ...
handles.modelData{handles.currentModel}.model, 3);
case 'dcm'
sessionNr = checkSessionNr(handles);
if sessionNr
pspm_rev_dcm(handles.modelData{handles.currentModel}.model, 'scrf', sessionNr, []);
end
end
set(handles.textStatus,'String',tmpStatusString);
guidata(hObject, handles);
% --- Executes on button press in buttonPlot4.
function buttonPlot4_Callback(hObject, ~, handles)
% hObject handle to buttonPlot4 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
tmpStatusString = get(handles.textStatus,'String');
set(handles.textStatus,'String','Plotting is in progress. Please wait...');
switch handles.modelData{handles.currentModel}.modeltype
case 'glm'
handles.modelData{handles.currentModel}.fig = ...
pspm_rev_glm(handles.modelData{handles.currentModel}.modelfile, ...
handles.modelData{handles.currentModel}.model, 4);
case 'dcm'
pspm_rev_dcm(handles.modelData{handles.currentModel}.model, 'names');
end
set(handles.textStatus,'String',tmpStatusString);
guidata(hObject, handles);
% --- Executes on button press in buttonPlot5.
function buttonPlot5_Callback(hObject, ~, handles)
% hObject handle to buttonPlot5 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
tmpStatusString = get(handles.textStatus,'String');
set(handles.textStatus,'String','Plotting is in progress. Please wait...');
switch handles.modelData{handles.currentModel}.modeltype
case 'glm'
handles.modelData{handles.currentModel}.fig = ...
pspm_rev_glm(handles.modelData{handles.currentModel}.modelfile, ...
handles.modelData{handles.currentModel}.model, 5);
case 'dcm'
handles.modelData{handles.currentModel}.fig = ...
pspm_rev_con(handles.modelData{handles.currentModel}.model);
end
set(handles.textStatus,'String',tmpStatusString);
guidata(hObject, handles);
% --- Executes on button press in buttonPlot6.
function buttonPlot6_Callback(hObject, ~, handles)
% hObject handle to buttonPlot6 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
tmpStatusString = get(handles.textStatus,'String');
set(handles.textStatus,'String','Plotting is in progress. Please wait...');
switch handles.modelData{handles.currentModel}.modeltype
case 'glm'
handles.modelData{handles.currentModel}.fig = pspm_rev_con(handles.modelData{handles.currentModel}.model);
end
set(handles.textStatus,'String',tmpStatusString);
guidata(hObject, handles);
% --- Executes on button press in buttonPlotClose.
function buttonPlotClose_Callback(~, ~, handles)
% hObject handle to buttonPlotClose (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
closeFigures(handles)
function editTrialNr_Callback(~, ~, ~)
% hObject handle to editTrialNr (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of editTrialNr as text
% str2double(get(hObject,'String')) returns contents of editTrialNr as a double
% --- Executes during object creation, after setting all properties.
function editTrialNr_CreateFcn(hObject, ~, ~)
% hObject handle to editTrialNr (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% --- Executes on selection change in listModel.
function listModel_Callback(hObject, ~, handles)
% hObject handle to listModel (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: contents = cellstr(get(hObject,'String')) returns listModel contents as cell array
% contents{get(hObject,'Value')} returns selected item from listModel
entryNr = get(handles.listModel,'Value');
if ~isempty(entryNr)
handles.currentModel = entryNr;
showModel(handles);
guidata(hObject, handles)
end
% --- Executes during object creation, after setting all properties.
function listModel_CreateFcn(hObject, ~, ~)
% hObject handle to listModel (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: listbox controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), ...
get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
%--------------------------------------------------------------------------
% Functions
%--------------------------------------------------------------------------
function setInvisble(handles)
for i=1:handles.nrPlot
eval(sprintf('set(handles.buttonPlot%d,''Visible'',''off'')',i));
eval(sprintf('set(handles.textPlot%d,''Visible'',''off'')',i));
end
set(handles.buttonPlotClose,'Visible','off');
set(handles.editTrialNr,'Visible','off');
set(handles.editEpochNr,'Visible','off');
set(handles.editSessionNr,'Visible','off');
set(handles.textSessionNr,'Visible','off');
set(handles.textSessionRange,'Visible','off');
function setButtonPlotString(handles, inString)
for i=1:size(inString,2)
if ~isempty(inString{i})
eval(sprintf('set(handles.buttonPlot%d,''String'',inString{%d})',i,i));
eval(sprintf('set(handles.buttonPlot%d,''Visible'',''on'')',i));
end
end
set(handles.buttonPlotClose,'Visible','on');
function setButtonDisable(handles)
for i=1:handles.nrPlot
eval(sprintf('set(handles.buttonPlot%d,''Enable'',''off'')',i));
end
function setButtonEnable(handles)
for i=1:handles.nrPlot
eval(sprintf('set(handles.buttonPlot%d,''Enable'',''on'')',i));
end
function setTextPlotString(handles, inString)
for i=1:size(inString,2)
if ~isempty(inString{i})
eval(sprintf('set(handles.textPlot%d,''String'',inString{%d})',i,i));
eval(sprintf('set(handles.textPlot%d,''Visible'',''on'')',i));
end
end
function setTrial(handles)
set(handles.editTrialNr,'Visible','on');
function setSession(handles)
nr = handles.modelData{handles.currentModel}.maxSessionNr;
set(handles.editSessionNr,'Visible','on');
set(handles.textSessionNr,'Visible','on');
set(handles.textSessionRange,'Visible','on');
set(handles.textSessionRange,'String',sprintf('[1 - %d]',nr));
function setEpoch(handles)
set(handles.editEpochNr,'Visible','on');
function fig = setFigureHandle(handles)
for i = 1:handles.nrPlot
fig(i).h=-1;
end
function closeFigures(handles)
if isfield(handles, 'figToKeep')
close(setdiff(findobj('type','figure'),handles.figToKeep));
else
close(setdiff(findobj('type','figure'),handles));
end
function sessionNr = checkSessionNr(handles)
sessionNr = str2double(get(handles.editSessionNr,'String'));
if isempty(sessionNr) || sessionNr > handles.modelData{handles.currentModel}.maxSessionNr || sessionNr < 1
uiwait(msgbox(sprintf('Session number has to be within the range [1 - %d]',...
handles.modelData{handles.currentModel}.maxSessionNr),'Warning'));
sessionNr = [];
end
function showModel(handles)
% detect model
switch handles.modelData{handles.currentModel}.modeltype
case 'glm'
buttonPlotString = {'Plot', ...
'Plot', ...
'Plot', ...
'Show', ...
'Plot'};
textPlotString = {'Design matrix in SPM style', ...
'Orthogonality in SPM style', ...
'Predicted & observed', ...
'Regressors in command window', ...
'Reconstructed responses'};
% detect contrasts
if isfield(handles.modelData{handles.currentModel}.model, 'con')
buttonPlotString{6} = 'Show';
textPlotString{6} = 'Contrast names in command window';
end
setInvisble(handles);
setButtonPlotString(handles, buttonPlotString);
setTextPlotString(handles, textPlotString);
set(handles.textStatus,'String','Detected modeltype: GLM');
drawnow
case 'dcm'
buttonPlotString = {'Display', ...
'Display', ...
'Display', ...
'Show'};
textPlotString = {'All trials for one session', ...
'Diagnostics for trial nr.', ...
'Skin conductance response function (SCR)', ...
'Trial and condition names in command window'};
% detect contrasts
if isfield(handles.modelData{handles.currentModel}.model, 'con')
buttonPlotString{5} = 'Show';
textPlotString{5} = 'Contrast names in command window';
end
setInvisble(handles);
setButtonPlotString(handles, buttonPlotString);
setTextPlotString(handles, textPlotString);
setSession(handles);
setTrial(handles);
set(handles.textStatus,'String','Detected modeltype: DCM')
drawnow
case 'sf'
buttonPlotString = {'Display'};
textPlotString = {'Diagnostics for epoch nr.'};
if isfield(handles.modelData{handles.currentModel}.model, 'con')
buttonPlotString{2} = 'Show';
textPlotString{2} = 'Contrast names in command window';
end
setInvisble(handles);
setButtonPlotString(handles, buttonPlotString);
setTextPlotString(handles, textPlotString);
setEpoch(handles);
set(handles.textStatus,'String','Detected modeltype: SF')
drawnow
end
% --- Executes during object creation, after setting all properties.
function editEpochNr_CreateFcn(hObject, ~, ~)
% hObject handle to editEpochNr (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function editEpochNr_Callback(~, ~, ~)
% hObject handle to editEpochNr (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of editEpochNr as text
% str2double(get(hObject,'String')) returns contents of editEpochNr as a double
% --- Executes on button press in pushbutton_quit.
function pushbutton_quit_Callback(~, ~, handles)
% hObject handle to pushbutton_quit (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
closeFigures(handles);
delete(gcbf)