forked from nigelrogasch/TESA
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpop_tesa_plot.m
More file actions
209 lines (186 loc) · 8.87 KB
/
pop_tesa_plot.m
File metadata and controls
209 lines (186 loc) · 8.87 KB
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
% pop_tesa_plot() - plots TMS-evoked activity averaged over trials. Timing of
% the TMS pulse is indicated with a red dashed line. Output
% from peak analyses can also be plotted as well as
% confidence intervals across trials.
%
% Usage:
% >> pop_tesa_plot( EEG ); % pop up window
% >> pop_tesa_plot( EEG, 'key1',value1... );
%
% Inputs:
% EEG - EEGLAB EEG structure
%
% Optional input pairs:
% 'xlim', [min,max] - integers describing the x axis limits in ms.
% default = [-100,500]
% 'ylim', [min,max] - integers describing the y axis limits in ms. If
% left blank, the plot will automatically scale.
% default = []
% Examples: [-10,10]
% 'elec','str' - string describing a single electrode
% for plotting. If left blank, a butterfly plot of all electrodes
% will be plotted.
% default = [];
% Example: 'Cz'
% 'CI','str' - 'on' | 'off'. Plot confidence interval calculated
% across trials. This option is not available for GMFA
% and butterfly plots.
% default = 'off';
%
% Options for plotting output from tesa_tepextract and tesa_peakanalysis
% 'tepType','str' - 'data' | 'ROI' | 'GMFA'. 'Data' input extracts data
% for plotting from EEG.data. 'ROI' input selects a ROI
% generated by tesa_tepextract. 'GMFA' input selects a
% GMFA generated by tesa_tepextract. Note that if
% multiple ROIs or GMFAs are present, 'tepName' must also
% be included to determine which one to plot.
% Default = 'data';
% 'tepName', 'str' - String is either the name of a ROI or GMFA generated
% by tesa_tepextract. The default names generated by
% tesa_tepextract are 'R1','R2'... etc. however the user
% can also define names. This is required if multiple ROIs or GMFAs are present.
% Default = [];
% 'plotPeak','str' - 'off' | 'on'. If 'on', peaks identified with
% tesa_peakanalysis will also be plotted. A box defining
% the lower and upper time limits in which the peak was
% searched will also be plotted. Green indiciates that a
% peak was found, red a peak was not detected. Note that
% tesa_peakanalysis must be run prior to using this
% function and 'tepType' must also be called.
%
% Examples:
% pop_tesa_plot(EEG, 'xlim', [-200,600], 'ylim', [-10,10], 'elec', 'P1', 'CI', 'on'); % plot electrode P1, rescale the axes and include confidence intervals.
% pop_tesa_plot(EEG, 'tepType','ROI','tepName','parietal','plotPeak','on','CI','on'); % plot the output from a ROI analysis called parietal including detected peaks and confidence intervals
% pop_tesa_plot(EEG, 'tepType','GMFA','plotPeak','on'); % plot output from a GMFA analysis including detected peaks
%
% See also:
% tesa_tepextract, tesa_peakanalysis, tesa_peakoutput
% Copyright (C) 2016 Nigel Rogasch, Monash University,
% nigel.rogasch@monash.edu
%
% 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-1307 USA
function com = pop_tesa_plot( EEG, varargin )
com = '';
%check that data is present
if isempty(EEG.data)
error('Data is empty');
end
% pop up window
% -------------
if nargin < 2
chanAll = {EEG.chanlocs.labels};
if isfield(EEG,'ROI')
roiFields = fieldnames(EEG.ROI);
roi = 'yes';
for a = 1:size(roiFields,1)
roiFields{a,1} = ['ROI ',roiFields{a,1}];
end
else
roi = 'no';
end
if isfield(EEG,'GMFA')
gmfaFields = fieldnames(EEG.GMFA);
gmfa = 'yes';
for a = 1:size(gmfaFields,1)
gmfaFields{a,1} = ['GMFA ',gmfaFields{a,1}];
end
else
gmfa = 'no';
end
if strcmpi(roi,'yes') && strcmpi(gmfa,'yes')
tepInput = ['All', chanAll, roiFields', gmfaFields'];
elseif strcmpi(roi,'yes') && strcmpi(gmfa,'no')
tepInput = ['All', chanAll, roiFields'];
elseif strcmpi(roi,'no') && strcmpi(gmfa,'yes')
tepInput = ['All', chanAll, gmfaFields'];
elseif strcmpi(roi,'no') && strcmpi(gmfa,'no')
tepInput = ['All', chanAll];
end
tepAll = tepInput;
for a = 1:size(tepInput,1)-1
tepInput{a,1} = [tepInput{a,1},'|'];
end
geometry = {1 [0.5 0.5] 1 1 [1 0.5] [1 0.5] 1 [1 0.5] 1 1 1 [1 0.5]};
uilist = {{'style', 'text', 'string', 'Plot TMS-evoked potentials','fontweight','bold'} ...
{'style', 'text', 'string', 'Data to plot'} ...
{'style', 'popupmenu', 'string', tepInput 'tag' 'data' } ...
{}...
{'style', 'text', 'string', 'Plot options','fontweight','bold'} ...
{'style', 'text', 'string', 'Time limits (ms) (e.g. -100,500)'} ...
{'style', 'edit', 'string', '-100,500'} ...
{'style', 'text', 'string', 'Amplitude limits (uV) (e.g. -30,30)'} ...
{'style', 'edit', 'string', ''}...
{'style', 'text', 'string', ' Leave empty for auto-scale', 'fontangle','italic'} ...
{'style', 'text', 'string', 'Plot confidence interval',} ...
{'Style', 'checkbox', 'string' 'on/off' 'value' 0 'tag' 'CI' }...
{'style', 'text', 'string', ' Single electrode and ROI only','fontangle','italic'}...
{} ...
{'style', 'text', 'string', 'For analysed data (ROI, GMFA)','fontweight','bold'} ....
{'style', 'text', 'string', 'Plot peak analysis results',} ...
{'Style', 'checkbox', 'string' 'on/off' 'value' 0 'tag' 'peaks' } ...
};
result = inputgui('geometry', geometry, 'uilist', uilist, 'title', 'Plot TEPs -- pop_tesa_plot()', 'helpcom', 'pophelp(''pop_tesa_plot'')');
if isempty(result), return; end;
%Extract data from result
chanInput = tepAll{1,result{1,1}};
if strcmp(chanInput,'All')
elec = [];
tepType = 'data';
elseif ~strncmp(chanInput,'ROI',3) && ~strncmp(chanInput,'GMF',3) && ~strcmp(chanInput,'All')
elec = chanInput;
tepType = 'data';
elseif strncmp(chanInput,'ROI',3)
tepFor = strtrim(strsplit(chanInput,' '));
tepType = 'ROI';
tepName = tepFor{1,2};
elseif strncmp(chanInput,'GMF',3)
tepFor = strtrim(strsplit(chanInput,' '));
tepType = 'GMFA';
tepName = tepFor{1,2};
end
xlim = str2num(result{1,2});
if strcmp(result{1,3},'')
ylim = [];
else
ylim = str2num(result{1,3});
end
if result{1,4} == 0
CI = 'off';
elseif result{1,4} == 1
CI = 'on';
end
if result{1,5} == 0
plotPeak = 'off';
elseif result{1,5} == 1;
plotPeak = 'on';
end
end
%Run script from input
if nargin > 2
tesa_plot(EEG,varargin{:});
com = sprintf('pop_tesa_plot( %s, %s );', inputname(1), vararg2str(varargin) );
elseif nargin < 2
if strcmp(tepType,'data') && isempty(elec)
tesa_plot(EEG,'tepType',tepType,'xlim',xlim,'ylim',ylim,'CI',CI,'plotPeak',plotPeak);
com = sprintf('pop_tesa_plot( %s, ''tepType'', ''%s'', ''xlim'', %s, ''ylim'', %s, ''CI'',''%s'',''plotPeak'',''%s'' );', inputname(1), tepType, mat2str(xlim), mat2str(ylim), CI, plotPeak );
elseif strcmp(tepType,'data') && ~isempty(elec)
tesa_plot(EEG,'tepType',tepType,'elec',elec,'xlim',xlim,'ylim',ylim,'CI',CI,'plotPeak',plotPeak);
com = sprintf('pop_tesa_plot( %s, ''tepType'', ''%s'', ''elec'', ''%s'', ''xlim'', %s, ''ylim'', %s, ''CI'',''%s'',''plotPeak'',''%s'' );', inputname(1), tepType, elec, mat2str(xlim), mat2str(ylim), CI, plotPeak );
elseif strcmp(tepType,'ROI') || strcmp(tepType,'GMFA')
tesa_plot(EEG,'tepType',tepType,'tepName',tepName,'xlim',xlim,'ylim',ylim,'CI',CI,'plotPeak',plotPeak);
com = sprintf('pop_tesa_plot( %s, ''tepType'', ''%s'', ''tepName'', ''%s'', ''xlim'', %s, ''ylim'', %s, ''CI'',''%s'',''plotPeak'',''%s'' );', inputname(1), tepType, tepName, mat2str(xlim), mat2str(ylim), CI, plotPeak );
end
end
end