forked from LIMO-EEG-Toolbox/limo_tools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
limo_batch_gui.m
501 lines (410 loc) · 15.5 KB
/
limo_batch_gui.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
function varargout = limo_batch_gui(varargin)
% BATCH INTERFACE
% created using GUIDE
% Based on limo_import_tf
% ------------------------------
% Copyright (C) LIMO Team 2019
%% GUI stuffs
% -------------------------
% Begin initialization code
% -------------------------
warning off
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @limo_batch_gui_OpeningFcn, ...
'gui_OutputFcn', @limo_batch_gui_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end
if nargout
[varargout{1:4}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
% -----------------------
% End initialization code
% -----------------------
% --------------------------------------------------
% Executes just before the menu is made visible
% --------------------------------------------------
function limo_batch_gui_OpeningFcn(hObject, eventdata, handles, varargin)
handles.output = hObject;
% define handles used for the save callback
handles.FileName = [];
handles.CatName = [];
handles.fullfactorial = 0;
handles.ContName = [];
handles.zscore = 1;
handles.start = [];
handles.end = [];
handles.lowf = [];
handles.highf = [];
handles.Analysis = [];
handles.type = 'Channels';
handles.type_of_analysis = 'Mass-univariate';
handles.method = 'WLS';
handles.bootstrap = 0;
handles.tfce = 0;
handles.quit = 0;
guidata(hObject, handles);
uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = limo_batch_gui_OutputFcn(hObject, eventdata, handles)
if handles.quit == 1
varargout{1} = [] ;
varargout{2} = [] ;
varargout{3} = [] ;
varargout{4} = [] ;
else
varargout{1} = handles.FileName;
varargout{2} = handles.CatName;
varargout{3} = handles.ContName;
varargout{4} = handles.defaults ;
end
delete(handles.figure1); return
%% Callbacks
%-------------------------
% IMPORT_DATA
%------------------------
% load a data set -- EEG
% ---------------------------------------------------------------
% --- Executes during object creation, after setting all properties.
function Import_data_CreateFcn(hObject, eventdata, handles)
function Import_data_Callback(hObject, eventdata, handles)
[FileName,PathName,FilterIndex]=uigetfile({'*.txt; *.mat; *.set'}, 'Pick sets or list', 'MultiSelect', 'on');
if FilterIndex ~= 0
if iscell(FileName) % multiselect for .sets
for f=1:size(FileName,2)
if ~strcmp(FileName{f}(end-3:end),'.set')
errordlg('only set files are allowed or use a single .mat/.txt list')
return
end
end
elseif ischar(FileName) && strcmp(FileName(end-3:end),'.set') % single subject
tmp = FileName; clear FileName;
FileName{1} = [PathName tmp]; clear tmp; % a single subject
elseif strcmp(FileName(end-3:end),'.txt') || strcmp(FileName(end-3:end),'.mat') % use .mat or .txt
if strcmp(FileName(end-3:end),'.txt')
FileName = importdata(FileName);
elseif strcmp(FileName(end-3:end),'.mat')
FileName = load([PathName FileName]);
FileName = getfield(FileName,cell2mat(fieldnames(FileName)));
end
disp('checking files .. ')
for f=1:size(FileName,1)
if ~exist(FileName{f},'file')
errordlg(sprintf('%s \n file not found',FileName{f}));
return
else
fprintf('%s found \n',FileName{f});
end
end
end
handles.FileName = FileName;
end
guidata(hObject, handles);
% --- Executes on selection change in analysis_type.
% ---------------------------------------------------------------
function analysis_type_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function analysis_type_Callback(hObject, eventdata, handles)
content = get(hObject,'Value');
if content == 2
handles.Analysis = 'Time';
set(handles.Starting_point,'Enable','on')
set(handles.ending_point,'Enable','on')
set(handles.low_freq,'Enable','off')
set(handles.high_freq,'Enable','off')
elseif content == 3
handles.Analysis = 'Frequency';
set(handles.Starting_point,'Enable','off')
set(handles.ending_point,'Enable','off')
set(handles.low_freq,'Enable','on')
set(handles.high_freq,'Enable','on')
elseif content == 4
handles.Analysis = 'Time-Frequency';
set(handles.Starting_point,'Enable','on')
set(handles.ending_point,'Enable','on')
set(handles.low_freq,'Enable','on')
set(handles.high_freq,'Enable','on')
end
guidata(hObject, handles);
% get the starting time point of the analysis
% ---------------------------------------------------------------
function Starting_point_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function Starting_point_Callback(hObject, eventdata, handles)
handles.start = str2double(get(hObject,'String'));
guidata(hObject, handles);
% get the ending time point of the analysis
% ---------------------------------------------------------------
function ending_point_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function ending_point_Callback(hObject, eventdata, handles)
handles.end = str2double(get(hObject,'String'));
guidata(hObject, handles);
% get the starting frequency point of the analysis
% ---------------------------------------------------------------
function low_freq_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function low_freq_Callback(hObject, eventdata, handles)
handles.lowf = str2double(get(hObject,'String'));
guidata(hObject, handles);
% get the ending frequency point of the analysis
% ---------------------------------------------------------------
function high_freq_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function high_freq_Callback(hObject, eventdata, handles)
handles.highf = str2double(get(hObject,'String'));
guidata(hObject, handles);
%---------------------------
% ANALYSIS
% --------------------------
% --- Executes on button press in scalp_data.
function scalp_data_Callback(hObject, eventdata, handles)
h = get(hObject,'Value');
if h == 0
handles.type = 'Components';
set(handles.component_data,'Value',1)
set(handles.scalp_data,'Value',0)
elseif h == 1
handles.type = 'Channels';
set(handles.component_data,'Value',0)
set(handles.scalp_data,'Value',1)
end
guidata(hObject, handles);
% --- Executes on button press in component_data.
function component_data_Callback(hObject, eventdata, handles)
h = get(hObject,'Value');
if h == 0
handles.type = 'Channels';
set(handles.component_data,'Value',0)
set(handles.scalp_data,'Value',1)
elseif h == 1
handles.type = 'Components';
set(handles.component_data,'Value',1)
set(handles.scalp_data,'Value',0)
end
guidata(hObject, handles);
% type of analysis
% --- Executes on selection change in type_of_analysis.
% --- Executes during object creation, after setting all properties.
function type_of_analysis_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function type_of_analysis_Callback(hObject, eventdata, handles)
contents{1} = 'Mass-univariate';
contents{2} = 'Multivariate';
handles.type_of_analysis = contents{get(hObject,'Value')};
if isempty(handles.type_of_analysis)
handles.type_of_analysis = 'Mass-univariate';
end
fprintf('analysis selected %s \n',handles.type_of_analysis);
guidata(hObject, handles);
% method
function method_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function method_Callback(hObject, eventdata, handles)
contents{1} = 'WLS'; contents{2} = 'OLS'; contents{3} = 'IRLS';
handles.method = contents{get(hObject,'Value')};
if isempty(handles.method)
handles.method = 'WLS';
end
fprintf('method selected %s \n',handles.method);
guidata(hObject, handles);
% bootstrap
% --- Executes on button press in boostrap_check_box.
function boostrap_check_box_Callback(hObject, eventdata, handles)
M = get(hObject,'Value');
if M == 1
handles.bootstrap = 1;
disp('bootstrap is on');
set(handles.TFCE,'Enable','on')
elseif M == 0
handles.bootstrap = 0;
disp('boostrap is off');
set(handles.TFCE,'Enable','off')
set(handles.TFCE,'Value',0)
end
guidata(hObject, handles);
% TFCE
% --- Executes on button press in TFCE.
function TFCE_CreateFcn(hObject, eventdata, handles)
function TFCE_Callback(hObject, eventdata, handles)
M = get(hObject,'Value');
if M == 1
handles.tfce = 1;
disp('tfce is on');
elseif M == 0
handles.tfce = 0;
disp('tfce is off');
end
guidata(hObject, handles);
%-------------------------
% SPECIFY
%------------------------
% --- Executes on button press in categorical_variable_input.
% ---------------------------------------------------------------
function categorical_variable_input_Callback(hObject, eventdata, handles)
[CatName,PathName,FilterIndex]=uigetfile('*.txt;*.mat','LIMO categorical data','Multiselect','on');
if FilterIndex == 1
if ischar(CatName) % NOT multiselect
if strcmp(CatName(end-3:end),'.txt')
if ~isnumeric(importdata([PathName CatName]))
CatName = importdata([PathName CatName]);
else
tmp = CatName; clear CatName;
CatName{1} = [PathName tmp]; clear tmp; % a single subject
end
elseif strcmp(CatName(end-3:end),'.mat')
CatName = load([PathName CatName]);
CatName = getfield(CatName,cell2mat(fieldnames(CatName)));
end
for f=1:size(CatName,1)
if ~exist(CatName{f},'file')
errordlg(sprintf('%s \n file not found',CatName{f}));
return
else
fprintf('%s found \n',CatName{f});
end
end
else
errordlg('file selection not supported'); return
end
handles.CatName = CatName;
end
guidata(hObject, handles);
% --- Executes on button press in full_factorial.
% ---------------------------------------------------------------
function full_factorial_Callback(hObject, eventdata, handles)
M = get(hObject,'Value');
if M == 1
handles.fullfactorial = 1;
disp('full factorial on');
elseif M == 0
handles.fullfactorial = 0;
disp('full factorial off');
end
guidata(hObject, handles);
% --- Executes on button press in continuous_variable_input.
% ---------------------------------------------------------------
function continuous_variable_input_Callback(hObject, eventdata, handles)
[ContName,PathName,FilterIndex]=uigetfile('*.txt;*.mat','LIMO continuous data','Multiselect','on');
if FilterIndex == 1
if ischar(ContName) % NOT multiselect
if strcmp(ContName(end-3:end),'.txt')
if ~isnumeric(importdata([PathName ContName]))
ContName = importdata([PathName ContName]);
else
tmp = ContName; clear ContName;
ContName{1} = [PathName tmp]; clear tmp; % a single subject
end
elseif strcmp(ContName(end-3:end),'.mat')
ContName = load([PathName ContName]);
ContName = getfield(ContName,cell2mat(fieldnames(ContName)));
end
for f=1:size(ContName,1)
if ~exist(ContName{f},'file')
errordlg(sprintf('%s \n file not found',ContName{f}));
return
else
fprintf('%s found \n',ContName{f});
end
end
else
errordlg('file selection not supported'); return
end
handles.ContName = ContName;
end
guidata(hObject, handles);
% --- Executes on button press in z_score.
% ---------------------------------------------------------------
function z_score_Callback(hObject, eventdata, handles)
M = get(hObject,'Value');
if M == 0
handles.zscore = 1;
disp('zscoring on');
elseif M == 1
handles.zscore = 0;
disp('zscoring off');
end
guidata(hObject, handles);
%-------------------------
% OTHERS
%------------------------
% --- Executes on button press in Done.
% ---------------------------------------------------------------
function Done_Callback(hObject, eventdata, handles)
if isempty(handles.Analysis)
errordlg('choose a type of analysis to perfom','error')
return
end
defaults.analysis = handles.Analysis;
defaults.fullfactorial = handles.fullfactorial;
defaults.zscore = handles.zscore;
defaults.start = handles.start;
defaults.end = handles.end ;
defaults.lowf = handles.lowf;
defaults.highf = handles.highf;
defaults.method = handles.method;
defaults.type_of_analysis = handles.type_of_analysis;
defaults.bootstrap = handles.bootstrap;
defaults.tfce = handles.tfce;
defaults.type = handles.type;
% -----------------------------------------
% load the expected channel locations
% -----------------------------------------
if handles.bootstrap == 1 && ~strcmp(handles.type,'Components')
[chan_file,chan_path,whatsup]=uigetfile('expected_chanlocs.mat','Select channel location file');
if whatsup == 1
try
channeighbstructmat = load(sprintf('%s%s',chan_path,chan_file));
fn = fieldnames(channeighbstructmat);
index = find(ismember(fn,'expected_chanlocs'));
test = getfield(channeighbstructmat,fn{index});
catch
test = eval(chan_file(1:end-4));
end
if isstruct(test) && ~isempty(test(1).labels) && ~isempty(test(1).theta) && ~isempty(test(1).radius) ...
&& ~isempty(test(1).X) && ~isempty(test(1).Y) && ~isempty(test(1).Z) && ~isempty(test(1).sph_theta) ...
&& ~isempty(test(1).sph_phi) && ~isempty(test(1).sph_radius)
defaults.chanloc = test; disp('channel location loaded');
else
warndlg('this file is not recognize as a channel location file or informations are missing','file error')
end
else
disp('exiting batch mode'); limo_gui; return
end
end
handles.defaults = defaults;
if isempty(handles.CatName) && isempty(handles.ContName)
warndlg2('no regressors loaded, only the mean will be created','no regressors')
end
uiresume
guidata(hObject, handles);
limo_gui
% --- Executes on button press in Quit.
% ---------------------------------------------------------------
function Quit_Callback(hObject, eventdata, handles)
persistent out
clc
uiresume
handles.quit = 1;
guidata(hObject, handles);
limo_gui