forked from infant-cognition-tampere/eegtool
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patheegtoolAnalysis.m
152 lines (120 loc) · 6.03 KB
/
eegtoolAnalysis.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
function eegtoolAnalysis
% ------------------------------------------------------------------------------
% Help for eegtoolAnalysis.m
% ------------------------------------------------------------------------------
%
% A function that creates a GUI for the user to run various EEG analyses.
% On the upper part of the GUI, a working directory path is shown. It must
% be selected with the button "Choose directory". The program displays the
% .set files in the working directory. Files chosen for the analysis must
% be highlighted by clicking. Analysis type can be selected from the
% "Choose analysis"-menu (refer to help on each function for additional information).
% The ?Run analysis? button will perform and visualize the specified
% analysis for the selected datafiles.
%
% Extracting metrics: After computation, the visualization for the specified
% analysis is displayed. In the visualization, a button "Extract" is shown.
% By selecting the desired method and range for extraction, the ?Extract?
% button makes an output file with the computations listed from each input
% file.
%
% The input EEG files need to be of same form for the analysis to work.
% Some analyses might impose additional requirements to files. For example,
% in some analyses the duration of pre- and post-stimulus time must match
% in duration.
%
% eegtoolAnalysis implements some of the commonly used analyses for epoched
% EEG files. New analysis functions can be added as user-made MATLAB
% functions. To do so, the functions must be located in the folder:
% '?/eegtool_root/functions/?.
% Analysis functions must also accept two
% parameters: dpath and filenames (cell vector). Analyses placed on the
% folder will automatically appear on the drop-down menu after restart of
% eegtoolAnalysis.
%
% WARNING! This software has been carefully tested, but there could still be
% some bugs left. Use it at your own risk! The authors hold no
% responsibility for any damages caused by using the software nor promise
% any guarantee of suitability of the software for any particular purpose.
rootdir = fileparts(mfilename('fullpath'));
% construct the pathing required to run the program and find functions
constructEegtoolPaths(rootdir);
% generate figure and switch off unneeded figure controls
h.fig = figure('units', 'normalized', 'position', [0.4 0.4 0.17 0.4], 'menubar', 'none', ...
'numbertitle', 'off', 'color', 'white');
set(h.fig, 'name', 'eegtoolAnalysis');
% define ui controls
h.dirbutton = uicontrol('Style', 'pushbutton', 'string', 'Choose directory', ...
'horizontalalignment', 'center', 'units', 'normalized', 'position', [0.05 0.91 0.9 0.07]);
h.dirtext = uicontrol('Style', 'text', 'string', '-', 'units', 'normalized', ...
'horizontalalignment', 'center', 'position', [0.05 0.79 0.9 0.10]);
h.filetext = uicontrol('Style', 'text', 'string', ...
'Choose files', ...
'units', 'normalized', 'horizontalalignment', 'center', 'position', [0.05 0.68 0.9 0.07]);
h.filelistbox = uicontrol('Style', 'listbox', 'string', '', 'units', 'normalized', ...
'position', [0.05 0.2 0.9 0.46], 'horizontalalignment', ...
'center');
h.chanalysispopup = uicontrol('Style', 'popupmenu', 'string', {''}, 'units', 'normalized', 'position', ...
[0.05 0.13 0.9 0.05], 'horizontalalignment', 'center');
h.analyzebutton = uicontrol('Style', 'pushbutton', 'string', 'Run analysis', 'units', 'normalized', ...
'horizontalalignment', 'center', 'position', [0.05 0.01 0.9 0.10]);
% set some objects backgrounds to white
hChildren = get(gcf, 'Children');
set(hChildren(strcmp(get(hChildren, 'style'), 'text')), 'backgroundcolor', [1 1 1]);
set(hChildren(strcmp(get(hChildren, 'style'), 'checkbox')), 'backgroundcolor', [1 1 1]);
set(h.dirbutton, 'callback', {@dirbutton_callback, h});
set(h.analyzebutton, 'callback', {@analyzebutton_callback,h});
analyses = dir([rootdir filesep 'functions' filesep 'analyses' filesep '*.m']);
% generate list of available analyses from the analyses-folder
for i=1:length(analyses)
[a b c] = fileparts(analyses(i).name);
listanalyses{i} = b;
end
set(h.chanalysispopup, 'string', listanalyses);
function dirbutton_callback(~, ~, h)
% Callback for dirbutton
% get folder
folder = uigetdir;
% user picked no folder
if folder == 0
return;
end
set(h.dirtext, 'String', [folder filesep]);
r = dir(folder);
% filter proper files
nfiles = length(r);
filenames = cell(1);
j=1;
for i=1:nfiles
if(r(i).isdir == 0)
if strcmp(r(i).name(find(r(i).name=='.'):end), '.set')
filenames{j} = r(i).name;
j=j+1;
end
end
end
set(h.filelistbox, 'String', filenames);
set(h.filelistbox, 'max', length(filenames), 'value', 1:length(filenames))
function analyzebutton_callback(~, ~, h)
% Callback for analyzebutton
% parse analyzable files
filenames = get(h.filelistbox, 'string');
chosen_filenames = get(h.filelistbox, 'value');
dpath = get(h.dirtext, 'String');
if isempty(filenames) || isempty(chosen_filenames)
return;
end
chosen_files = filenames(chosen_filenames);
% COMMON error detection here?
% analysis type
analyses = get(h.chanalysispopup, 'string');
analysis_num = get(h.chanalysispopup, 'Value');
analysis_type = analyses{analysis_num};
% if no files chosen -> return
if strcmp(chosen_files{1}, '')
return;
end
% construct the function call as a string
runme = [analysis_type '(dpath,chosen_files);' ];
% evaluate analysis function
eval(runme);