forked from LIMO-EEG-Toolbox/limo_tools
-
Notifications
You must be signed in to change notification settings - Fork 1
/
limo_import_tf.m
538 lines (444 loc) · 16.2 KB
/
limo_import_tf.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
function varargout = limo_import_tf(varargin)
% import function for getting timefreq data into limo
% created using GUIDE -- import the various
% information needed to process the data
% Based on Cyril's limo_import_t
% Andrew X Stewart, January 2014
% Fixed folder locations, time/freq components in .data
% updated data format Cyril v2. Feb 2014
% -----------------------------
% Copyright (C) LIMO Team 2013
%% GUI stuffs
% -------------------------
% Begin initialization code
% -------------------------
warning off
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @limo_import_tf_OpeningFcn, ...
'gui_OutputFcn', @limo_import_tf_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
% -----------------------
% --------------------------------------------------
% Executes just before the menu is made visible
% --------------------------------------------------
function limo_import_tf_OpeningFcn(hObject, eventdata, handles, varargin)
handles.output = hObject;
% define handles used for the save callback
try
clear LIMO
LIMO = [];
catch
LIMO = [];
end
handles.data_dir = [];
handles.data = [];
handles.chanlocs = [];
handles.type = 'Channels';
handles.type_of_analysis = 'Mass-univariate';
handles.method = 'OLS';
handles.rate = [];
handles.trim1 = [];
handles.trim2 = [];
handles.trim_lowf = [];
handles.trim_highf = [];
handles.Cat = [];
handles.Cont = [];
handles.bootstrap = 0;
handles.start = 0;
handles.end = 0;
handles.lowf = 0;
handles.highf = 0;
handles.tf_times = 0;
handles.tf_freqs = 0;
handles.dir = [];
handles.zscore = 1;
handles.fullfactorial = 0;
handles.dir = pwd;
handles.bootstrap = 0;
handles.tfce = 0;
handles.out = [];
guidata(hObject, handles);
uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = limo_import_tf_OutputFcn(hObject, eventdata, handles)
if isempty(handles.out)
varargout{1} = 'LIMO import terminated';
else
varargout{1} = handles.out;
end
delete(handles.figure1)
%% Callbacks
%-------------------------
% IMPORT
%------------------------
% load a data set -- EEG
% ---------------------------------------------------------------
function Import_data_set_Callback(hObject, eventdata, handles)
global EEGLIMO
[FileName,PathName,FilterIndex]=uigetfile('*.set','EEGLAB EEG epoch data with TF data');
if FilterIndex ~= 0
try
disp('loading TF EEGLAB dataset. Please wait ...');
EEGLIMO=pop_loadset([PathName FileName]);
handles.data_dir = PathName;
handles.data = FileName;
handles.chanlocs = EEGLIMO.chanlocs;
handles.rate = EEGLIMO.srate;
if isfield(EEGLIMO.etc,'timeersp') == 1 && isfield(EEGLIMO.etc,'freqersp') == 1
handles.start = EEGLIMO.etc.timeersp(1);
handles.end = EEGLIMO.etc.timeersp(end);
handles.lowf = EEGLIMO.etc.freqersp(1);
handles.highf = EEGLIMO.etc.freqersp(end);
handles.tf_times = EEGLIMO.etc.timeersp;
handles.tf_freqs = EEGLIMO.etc.freqersp;
cd(handles.dir)
fprintf('Data set %s loaded \n',FileName);
else
errordlg('Can''t load the data. Ensure that time-frequency information is stored in EEG.etc - see help.'); return
end
catch
errordlg('pop_loadset eeglab function error / not found','error'); return
end
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)
global EEGLIMO
start = str2double(get(hObject,'String'));
if start < EEGLIMO.etc.timeersp(1)
errordlg(['The earliest time possible is:',num2str(EEGLIMO.etc.timeersp(1)),'ms']);
else
% Find a possible frequency bin close to the requested one
[a1 ind] = min(abs(EEGLIMO.etc.timeersp-start));
closest_start = EEGLIMO.etc.timeersp(ind);
if start ~= closest_start
warndlg2(['this will be adjusted to sampling rate, start at:',num2str(closest_start),'ms']);
end
handles.start = closest_start;
handles.trim1 = ind; % gives the 1st column to start the analysis
end
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)
global EEGLIMO
ending = str2double(get(hObject,'String'));
if ending > EEGLIMO.etc.timeersp(end)
errordlg(['The latest time possible is:',num2str(EEGLIMO.etc.timeersp(end)),'ms']);
else
% Find a possible frequency bin close to the requested one
if isnan(ending)
[a1 ind] = max(EEGLIMO.etc.timeersp);
else
[a1 ind] = min(abs(EEGLIMO.etc.timeersp-ending));
end
closest_ending = EEGLIMO.etc.timeersp(ind);
if ending ~= closest_ending
warndlg2(['this will be adjusted to sampling rate, end at:',num2str(closest_ending),'ms']);
end
handles.end = closest_ending;
handles.trim2 = ind; % gives the 1st column to start the analysis
end
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)
global EEGLIMO
lowf = str2double(get(hObject,'String'));
if lowf < EEGLIMO.etc.freqersp(1)
errordlg(['The lowest frequency possible is:',num2str(EEGLIMO.etc.freqersp(1))]);
else
% Find a possible frequency bin close to the requested one
[a1 ind] = min(abs(EEGLIMO.etc.freqersp-lowf));
closest_lowf = EEGLIMO.etc.freqersp(ind);
if lowf ~= closest_lowf
warndlg2(['this will be adjusted to the closest frequency bin:',num2str(closest_lowf),'Hz']);
end
handles.lowf = closest_lowf;
handles.trim_lowf = ind; % gives the 1st column to start the analysis
end
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)
global EEGLIMO
highf = str2double(get(hObject,'String'));
if highf > EEGLIMO.etc.freqersp(end)
errordlg(['The highest frequency possible is:',num2str(handles.tf_freqs(end))]);
else
% Find a possible frequency bin close to the requested one
if isnan(highf)
[a1 ind] = max(EEGLIMO.etc.freqersp);
else
[a1 ind] = min(abs(EEGLIMO.etc.freqersp-highf));
end
closest_highf = EEGLIMO.etc.freqersp(ind);
if highf ~= closest_highf
warndlg2(['this will be adjusted to the closest frequency bin:',num2str(closest_highf),'Hz']);
end
handles.highf = closest_highf;
handles.trim_highf = ind; % gives the 1st column to start the analysis
end
guidata(hObject, handles);
%---------------------------
% ANALYSIS
% --------------------------
% type of analysis
% --- Executes on selection change in type_of_analysis.
function type_of_analysis_Callback(hObject, eventdata, handles)
% Hints: contents = cellstr(get(hObject,'String')) returns popupmenu4 contents as cell array
% contents{get(hObject,'Value')} returns selected item from popupmenu4
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);
% --- 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
% 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} = 'OLS'; contents{2} = 'WLS'; contents{3} = 'IRLS';
handles.method = contents{get(hObject,'Value')};
if isempty(handles.method)
handles.method = 'OLS';
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 = 800; % our simulations show that under 800 this is not stable
disp('bootstrap is on');
set(handles.TFCE,'Enable','on')
elseif M == 0
handles.bootstrap = 0;
disp('boostrap is off');
set(handles.TFCE,'Enable','off')
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)
[FileName,PathName,FilterIndex]=uigetfile('*.txt;*.mat','LIMO categorical data');
if FilterIndex == 1
cd(PathName);
if strcmp(FileName(end-3:end),'.txt')
handles.Cat = load(FileName);
else
cat = load(FileName);
handles.Cat = getfield(cat,cell2mat(fieldnames(cat)));
clear cat
end
% if there is more than one factor, allow factorial design
if size(handles.Cat,2) > 1
set(handles.full_factorial,'Enable','on')
handles.fullfactorial = 0;
else
handles.fullfactorial = 0;
end
disp('Categorical data loaded');
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)
[FileName,PathName,FilterIndex]=uigetfile('*.txt;*.mat','LIMO continuous data');
if FilterIndex == 1
cd(PathName);
if strcmp(FileName(end-3:end),'.txt')
handles.Cont = load(FileName);
else
cont = load(FileName);
handles.Cont = getfield(cont,cell2mat(fieldnames(cont)));
clear cont
end
% if the regressors are not zscored, allow option to leave it as such
% test mean = 0 with a margin of 10^-5
M = mean(mean(handles.Cont));
centered = M>-0.00001 && M<0.00001;
% if mean = 0 also test std = 1
if centered == 1
S = mean(std(handles.Cont));
reducted = S>0.99999 && S<1.00001;
else
reducted = 0;
end
if centered~=1 && reducted~= 1
set(handles.z_score,'Enable','on')
handles.zscore = 1;
else
handles.zscore = 1;
end
disp('Continuous data loaded');
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 Directory.
% ---------------------------------------------------------------
function Directory_Callback(hObject, eventdata, handles)
PathName=uigetdir(handles.dir,'select LIMO working directory');
if PathName ~= 0
cd(PathName);
handles.dir = PathName;
end
guidata(hObject, handles);
% --- Executes on button press in Help.
% ---------------------------------------------------------------
function Help_Callback(hObject, eventdata, handles)
global EEGLIMO LIMO
origin = which('limo_eeg'); origin = origin(1:end-10);
origin = sprintf('%shelp',origin); cd(origin)
web(['file://' which('limo_importtf.html')]);
cd (handles.dir)
% --- Executes on button press in Done.
% ---------------------------------------------------------------
function Done_Callback(hObject, eventdata, handles)
global EEGLIMO LIMO
LIMO.data.data_dir = handles.data_dir;
LIMO.data.data = handles.data;
LIMO.data.chanlocs = handles.chanlocs;
LIMO.data.sampling_rate = handles.rate;
LIMO.data.Cat = handles.Cat;
LIMO.data.Cont = handles.Cont;
LIMO.Type = handles.type;
LIMO.design.fullfactorial = handles.fullfactorial;
LIMO.design.zscore = handles.zscore;
LIMO.design.method = handles.method;
LIMO.design.type_of_analysis = handles.type_of_analysis;
LIMO.design.bootstrap = handles.bootstrap;
LIMO.design.tfce = handles.tfce;
LIMO.Level = 1;
LIMO.Analysis = 'Time-Frequency';
% set defaults - take from 1:numel if trim not set
if isempty(handles.trim_lowf)
LIMO.data.trim_low_f = 1;
else
LIMO.data.trim_low_f = handles.trim_lowf;
end
if isempty(handles.trim_highf)
LIMO.data.trim_high_f = numel(handles.tf_freqs);
else
LIMO.data.trim_high_f = handles.trim_highf;
end
LIMO.data.tf_freqs = handles.tf_freqs(LIMO.data.trim_low_f:LIMO.data.trim_high_f);
LIMO.data.lowf = handles.lowf ;
LIMO.data.highf = handles.highf ;
if isempty(handles.trim1)
LIMO.data.trim1 = 1;
else
LIMO.data.trim1 = handles.trim1;
end
if isempty(handles.trim2)
LIMO.data.trim2 = numel(handles.tf_times);
else
LIMO.data.trim2 = handles.trim2;
end
LIMO.data.tf_times = handles.tf_times(LIMO.data.trim1:LIMO.data.trim2);
LIMO.data.start = handles.start;
LIMO.data.end = handles.end ;
if isempty(handles.dir)
LIMO.dir = handles.data_dir;
else
LIMO.dir = handles.dir;
end
test = isempty(handles.Cat) + isempty(handles.Cont);
if test == 2
errordlg('no regressors were loaded','error')
else
cd (LIMO.dir);
save LIMO LIMO
uiresume
guidata(hObject, handles);
end
% --- Executes on button press in Quit.
% ---------------------------------------------------------------
function Quit_Callback(hObject, eventdata, handles)
clc
uiresume
handles.out = 'LIMO import aborded';
guidata(hObject, handles);
limo_gui