-
Notifications
You must be signed in to change notification settings - Fork 1
/
eegplugin_hedtools.m
124 lines (113 loc) · 5.43 KB
/
eegplugin_hedtools.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
% eegplugin_hedtools makes a HEDTools plugin for EEGLAB
%
% Usage:
% >> eegplugin_hedtools(fig, trystrs, catchstrs)
%
%% Description
% eegplugin_hedtools(fig, trystrs, catchstrs) makes a HEDTools
% plugin for EEGLAB. The plugin automatically
% extracts the items and the current tagging structure from the
% current EEG structure in EEGLAB.
%
% The fig, trystrs, and catchstrs arguments follow the
% convention for plugins to EEGLAB. The fig argument holds the figure
% number of the main EEGLAB GUI. The trystrs and catchstrs arguments
% hold the try and catch strings for EEGLAB menu callbacks.
%
% Place the HEDTools folder in the |plugins| subdirectory of EEGLAB.
% EEGLAB should detect the plugin on start up.
%
%
% See also: eeglab
%
% Copyright (C) 2012-2013
% Jeremy Cockfield, UTSA, [email protected]
% Kay Robbins, UTSA, [email protected]
%
% This program is free software; you can redistribute it and/or modify
% it under the terms of the GNU General Public License as published by
% the Free Software Foundation; either version 2 of the License, or
% (at your option) any later version.
%
% This program is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
% GNU General Public License for more details.
%
% You should have received a copy of the GNU General Public License
% along with this program; if not, write to the Free Software
% Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1.07 USA
function vers = eegplugin_hedtools(fig, trystrs, catchstrs)
vers = 'HEDTools5.0.0';
% Check the number of input argumentsedit
if nargin < 3
error('eegplugin_hedtools requires 3 arguments');
end
% Find the path of the current directory
addhedpaths();
% Find 'Memory and other options' in the figure
parentMenu = findobj(fig, 'Label', 'Edit', 'Type', 'uimenu');
positionMenu = findobj(fig, 'Label', 'Event values', 'Type', 'uimenu');
% if isempty(positionMenu)
% positionMenu = findobj(fig, 'Label', 'Memory and other options', 'Type', 'uimenu');
% end
position = get(positionMenu, 'Position') + 1;
%% Adding HEDTools submenu items to 'File'. Order of insertion in script is opposite to order of appearance in 'File' menu
%% Add validation submenu to 'Edit'
callbackCmd = [trystrs.no_check ...
'if exist(''STUDY'',''var'') && exist(''CURRENTSTUDY'',''var'') && length(EEG) > 1 && CURRENTSTUDY == 1, ' ...
'[~, LASTCOM] = pop_validatestudy(STUDY, EEG);' ...
'else ' ...
'[~, LASTCOM] = pop_validateeeg(EEG);' ...
'end;' ...
catchstrs.add_to_hist];
uimenu(parentMenu, 'Label', 'Validate event HED tags', ...
'Separator', 'off', 'Position', position, 'userdata', 'startup:off;study:on', 'Callback', callbackCmd);
%% Add Tagging submenu to 'Edit'
callbackCmd = [trystrs.no_check ...
'if exist(''STUDY'',''var'') && exist(''CURRENTSTUDY'',''var'') && length(EEG) > 1 && CURRENTSTUDY == 1, ' ...
'[STUDY, EEG, LASTCOM] = pop_tagstudy(STUDY, EEG);' ...
'else ' ...
'[EEG, fMap, LASTCOM] = pop_tageeg(EEG);' ...
'if ~isempty(LASTCOM) && ~isempty(EEG.event),' ...
'[ALLEEG EEG CURRENTSET] = pop_newset(ALLEEG, EEG, CURRENTSET);' ...
'eeglab redraw;' ...
'end;' ...
'end;' ...
catchstrs.add_to_hist];
uimenu(parentMenu, 'Label', 'Add/Edit event HED tags', ...
'Separator', 'off', 'Position', position, 'userdata', 'startup:off;study:on', 'Callback', callbackCmd);
%% Add Clear tagging submenu to 'Edit'
callbackCmd = [trystrs.no_check ...
'if exist(''STUDY'',''var'') && exist(''CURRENTSTUDY'',''var'') && length(EEG) > 1 && CURRENTSTUDY == 1, ' ...
'[STUDY, EEG, tags] = removeTagsSTUDY(STUDY, EEG);' ...
'else ' ...
'[EEG, tags] = removeTagsEEG(EEG);' ...
'if ~isempty(EEG.event),' ...
'[ALLEEG EEG CURRENTSET] = pop_newset(ALLEEG, EEG, CURRENTSET);' ...
'eeglab redraw;' ...
'end;' ...
'end;' ...
catchstrs.add_to_hist];
uimenu(parentMenu, 'Label', 'Clear HED tags', ...
'Separator', 'off', 'Position', position, 'userdata', 'startup:off;study:on', 'Callback', callbackCmd);
% Find 'Remove baseline' in the figure
parentMenu = findobj(fig, 'Label', 'Tools');
positionMenu = findobj(fig, 'Label', 'Remove epoch baseline', 'Type', 'uimenu');
if isempty(positionMenu)
positionMenu = findobj(fig, 'Label', 'Remove baseline', 'Type', 'uimenu');
end
position = get(positionMenu, 'Position');
% Processing for 'Extract epochs by tags'
finalcmd = '[EEG, ~, LASTCOM] = pop_epochhed(EEG);';
ifeegcmd = 'if ~isempty(LASTCOM) && ~isempty(EEG)';
savecmd = '[ALLEEG EEG CURRENTSET] = pop_newset(ALLEEG, EEG, CURRENTSET);';
redrawcmd = 'eeglab redraw;';
rmbasecmd = '[EEG, LASTCOM] = pop_rmbase(EEG);';
finalcmd = [trystrs.no_check finalcmd ifeegcmd savecmd ...
redrawcmd 'end;' rmbasecmd ifeegcmd savecmd redrawcmd ...
'end;' catchstrs.add_to_hist];
% Add 'Extract epochs by tags' to 'Tools'
uimenu(parentMenu, 'Label', 'Extract epochs by tags', ...
'Position', position, 'userdata', 'startup:off;study:off', 'Callback', finalcmd);
end