-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathstd_pop_dipoleDensity.m
executable file
·254 lines (231 loc) · 15.5 KB
/
std_pop_dipoleDensity.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
% std_pop_dipoleDensity(): plots STUDY cluster dipoles and their density.
%
% See also: eegplugin_std_dipoleDensity() std_dipoleDensity() dipplot()
% Author: Makoto Miyakoshi, JSPS/SCCN,INC,UCSD; Cincinnati Children's Hospital
%
% History
% 09/18/2024 Makoto. When STUDY.design.variable is empty, generate dummy variables for group labels.
% 08/23/2024 Makoto and Komal. Re-visiting this plugin to make it work again.
% 10/02/2018 Makoto. Path to the Talailach tool added.
% 03/06/2017 Makoto. FWHM used. Default is changed to Zeynep and Luca's calculation to have 9.8 mm error in Gaussian.
% 02/24/2015 ver 0.22 by Makoto. (none) for the non-selected. BrainBlobBrower layout.
% 01/16/2015 ver 0.20 by Makoto. Improved STUDY.design compatibility.
% 04/25/2014 ver 1.9 by Makoto. Change str2double -> str2num to avoid 'NaN' (Thanks Nikola Vukovic!)
% 05/22/2013 ver 1.8 by Makoto. Color red added.
% 03/29/2013 ver 1.7 by Makoto. Added cmin cmax. mir3dplot() is fixed accordingly.
% 02/19/2013 ver 1.6 by Makoto. STUDY = std_pop_dipoleDensity(). User inputs are now saved for the next use.
% 02/06/2013 ver 1.5 by Makoto. Color scale upper limit added.
% 01/28/2013 ver 1.4 by Makoto. Combined groups supported. Plot 1 - Plot 2 explained.
% 01/24/2013 ver 1.3 by Makoto. Group difference supported.
% 01/23/2013 ver 1.2 by Makoto. Single cluster supported.
% 12/03/2012 ver 1.1 by Makoto. Save figure added.
% 11/23/2012 ver 1.0 by Makoto. Created.
% Copyright (C) 2012, Makoto Miyakoshi JSPS/SCCN,INC,UCSD.
% 2024, Makoto Miyakoshi Cincinnati Children's Hospital.
%
% 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 STUDY = std_pop_dipoleDensity(STUDY, ALLEEG)
com = '';
if nargin < 2
help std_pop_dipoleDensity;
return;
end;
% Set path to 'dependency' folder.
currentFolderPath = which('std_pop_dipoleDensity');
addpathName = [currentFolderPath(1:end-24) filesep 'dependency' filesep 'Talairach'];
addpath(addpathName)
disp('Path set: (this_plugin_root)/dependency/Talairach added.')
% create a letter string for clusters
clsString = '(none)|Parentcluster';
if length(STUDY.cluster)>1
for n = 2:length(STUDY.cluster)
clsString = [clsString '|' STUDY.cluster(1,n).name];
end
end
% Check if there is STUDY.design.variable is empty.
if isempty(STUDY.design(STUDY.currentdesign).variable)
isEmptyStudyDesignVariable = 1;
STUDYorig = STUDY;
STUDY.design(STUDY.currentdesign).variable(1).label = 'group';
STUDY.design(STUDY.currentdesign).variable(1).value = {{'(autoGeneratedDummy)'}};
else
isEmptyStudyDesignVariable = 0;
end
% Group condition in the STUDY.design. I write this part based on prediction of current STUDY's behavior. (08/23/2024 Makoto)
variableLabels = cellfun(@(x) x, {STUDY.design(STUDY.currentdesign).variable.label}, 'UniformOutput', false);
groupLabelIndex = contains(variableLabels, 'group');
groupString = [{'(none)'} {'all'} cellfun(@(x) x{1}, STUDY.design(STUDY.currentdesign).variable(groupLabelIndex).value, 'UniformOutput', false)];
% var2 = STUDY.design(STUDY.currentdesign).variable(1,2).value;
% groupString = '(none)|all';
% if ~isempty(var2)
% for n = 1:length(var2)
% if iscell(var2{1,n}) % if groups are combined in the selected group condition
% tmpCell = var2{1,n}; % work on copy
% tmpCell(2,:) = {' & '};
% tmpCell{2,end} = '';
% tmpString = [tmpCell{:}];
% clear tmpCell
% else
% tmpString = var2{1,n};
% end
% groupString = [groupString '|' tmpString];
% end
% end
% collect user input
try
userInput = inputgui('title', 'std_pop_dipoleDensity()', 'geom', ...
{{4 14 [0 0] [1 1]} {4 14 [1 0] [1 1]} {4 14 [2 0] [1 1]} {4 14 [3 0] [1 1]} ...
{4 14 [0 1] [1 1]} {4 14 [1 1] [1 1]} {4 14 [2 1] [1 1]} {4 14 [3 1] [1 1]} ...
{4 14 [0 2] [1 1]} {4 14 [1 2] [1 1]} {4 14 [2 2] [1 1]} {4 14 [3 2] [1 1]} ...
{4 14 [0 3] [1 1]} {4 14 [1 3] [1 1]} {4 14 [2 3] [1 1]} {4 14 [3 3] [1 1]} ...
{4 14 [0 4] [1 1]} {4 14 [1 4] [1 1]} {4 14 [2 4] [1 1]} {4 14 [3 4] [1 1]} ...
{4 14 [0 5] [1 1]} {4 14 [1 5] [1 1]} {4 14 [2 5] [1 1]} {4 14 [3 5] [1 1]} ...
{4 14 [1 7] [1 1]} {8 14 [4 7] [1 1]} ...
{4 14 [1 8] [1 1]} {8 14 [4 8] [1 1]} ...
{4 14 [1 9] [1 1]} {8 14 [4 9] [1 1]} ...
{4 14 [1 11] [1 1]} {10 14 [4 11] [1 1]} {10 14 [5 11] [1 1]} {10 14 [6 11] [1 1]} {10 14 [7 11] [1 1]} {10 14 [8 11] [1 1]} ...
{4 14 [1 14] [1 1]} {8 14 [4 14] [1 1]}}, ...
'uilist',...
{{'style' 'text' 'string' ''} {'style' 'text' 'string' 'Cluster'} {'style' 'text' 'string' 'Group'} {'style' 'text' 'string' 'Color'} ...
{'style' 'text' 'string' 'Plot 1: Cluster, Group, and Color'} {'style' 'popupmenu' 'string' clsString 'tag' 'cluster' 'value' STUDY.dipplotWD{1,1}} {'style' 'popupmenu' 'string' groupString 'tag' 'group' 'value' STUDY.dipplotWD{1,2}} {'style' 'popupmenu' 'string' '(none)|White|Yellow|Fuchsia|Red|Silver|Gray|Olive|Purple|Maroon|Aqua|Lime|Teal|Green|Blue|Navy|Black' 'tag' 'color' 'value' STUDY.dipplotWD{1,3}} ...
{'style' 'text' 'string' 'Plot 2: Cluster, Group, and Color'} {'style' 'popupmenu' 'string' clsString 'tag' 'cluster' 'value' STUDY.dipplotWD{1,4}} {'style' 'popupmenu' 'string' groupString 'tag' 'group' 'value' STUDY.dipplotWD{1,5}} {'style' 'popupmenu' 'string' '(none)|White|Yellow|Fuchsia|Red|Silver|Gray|Olive|Purple|Maroon|Aqua|Lime|Teal|Green|Blue|Navy|Black' 'tag' 'color' 'value' STUDY.dipplotWD{1,6}} ...
{'style' 'text' 'string' 'Plot 3: Cluster, Group, and Color'} {'style' 'popupmenu' 'string' clsString 'tag' 'cluster' 'value' STUDY.dipplotWD{1,7}} {'style' 'popupmenu' 'string' groupString 'tag' 'group' 'value' STUDY.dipplotWD{1,8}} {'style' 'popupmenu' 'string' '(none)|White|Yellow|Fuchsia|Red|Silver|Gray|Olive|Purple|Maroon|Aqua|Lime|Teal|Green|Blue|Navy|Black' 'tag' 'color' 'value' STUDY.dipplotWD{1,9}} ...
{'style' 'text' 'string' 'Plot 4: Cluster, Group, and Color'} {'style' 'popupmenu' 'string' clsString 'tag' 'cluster' 'value' STUDY.dipplotWD{1,10}} {'style' 'popupmenu' 'string' groupString 'tag' 'group' 'value' STUDY.dipplotWD{1,11}} {'style' 'popupmenu' 'string' '(none)|White|Yellow|Fuchsia|Red|Silver|Gray|Olive|Purple|Maroon|Aqua|Lime|Teal|Green|Blue|Navy|Black' 'tag' 'color' 'value' STUDY.dipplotWD{1,12}} ...
{'style' 'text' 'string' 'Plot 5: Cluster, Group, and Color'} {'style' 'popupmenu' 'string' clsString 'tag' 'cluster' 'value' STUDY.dipplotWD{1,13}} {'style' 'popupmenu' 'string' groupString 'tag' 'group' 'value' STUDY.dipplotWD{1,14}} {'style' 'popupmenu' 'string' '(none)|White|Yellow|Fuchsia|Red|Silver|Gray|Olive|Purple|Maroon|Aqua|Lime|Teal|Green|Blue|Navy|Black' 'tag' 'color' 'value' STUDY.dipplotWD{1,15}} ...
{'style' 'text' 'string' 'Slice orientation'} {'style' 'popupmenu' 'string' 'Axial|Sagittal|Coronal' 'tag' 'slice' 'value' STUDY.dipplotWD{1,16}} ...
{'style' 'text' 'string' 'Smoothing Gaussian kernel FWHM [mm]'} {'style' 'edit' 'string' STUDY.dipplotWD{1,17}} ...
{'style' 'text' 'string' 'Color range [min max] blank=auto'} {'style' 'edit' 'string' STUDY.dipplotWD{1,18}} ...
{'style' 'text' 'string' 'If Plot 1 - Plot 2'} {'style' 'popupmenu' 'string' groupString 'value' STUDY.dipplotWD{1,19}} {'style' 'text' 'string' 'minus'} {'style' 'popupmenu' 'string' groupString 'value' STUDY.dipplotWD{1,20}} {'style' 'text' 'string' 'thresh. [%]'} {'style' 'edit' 'string' STUDY.dipplotWD{1,21}} ...
{'style' 'text' 'string' 'Save figures to the current folder'} {'style' 'checkbox', 'value', STUDY.dipplotWD{1,22}}});
catch
userInput = inputgui('title', 'std_pop_dipoleDensity()', 'geom', ...
{{4 14 [0 0] [1 1]} {4 14 [1 0] [1 1]} {4 14 [2 0] [1 1]} {4 14 [3 0] [1 1]} ...
{4 14 [0 1] [1 1]} {4 14 [1 1] [1 1]} {4 14 [2 1] [1 1]} {4 14 [3 1] [1 1]} ...
{4 14 [0 2] [1 1]} {4 14 [1 2] [1 1]} {4 14 [2 2] [1 1]} {4 14 [3 2] [1 1]} ...
{4 14 [0 3] [1 1]} {4 14 [1 3] [1 1]} {4 14 [2 3] [1 1]} {4 14 [3 3] [1 1]} ...
{4 14 [0 4] [1 1]} {4 14 [1 4] [1 1]} {4 14 [2 4] [1 1]} {4 14 [3 4] [1 1]} ...
{4 14 [0 5] [1 1]} {4 14 [1 5] [1 1]} {4 14 [2 5] [1 1]} {4 14 [3 5] [1 1]} ...
{4 14 [1 7] [1 1]} {8 14 [4 7] [1 1]} ...
{4 14 [1 8] [1 1]} {8 14 [4 8] [1 1]} ...
{4 14 [1 9] [1 1]} {8 14 [4 9] [1 1]} ...
{4 14 [1 11] [1 1]} {10 14 [4 11] [1 1]} {10 14 [5 11] [1 1]} {10 14 [6 11] [1 1]} {10 14 [7 11] [1 1]} {10 14 [8 11] [1 1]} ...
{4 14 [1 14] [1 1]} {8 14 [4 14] [1 1]}}, ...
'uilist',...
{{'style' 'text' 'string' ''} {'style' 'text' 'string' 'Cluster'} {'style' 'text' 'string' 'Group'} {'style' 'text' 'string' 'Color'} ...
{'style' 'text' 'string' 'Plot 1: Cluster, Group, and Color'} {'style' 'popupmenu' 'string' clsString 'tag' 'cluster' 'value' 1} {'style' 'popupmenu' 'string' groupString 'tag' 'group' 'value' 1} {'style' 'popupmenu' 'string' '(none)|White|Yellow|Fuchsia|Red|Silver|Gray|Olive|Purple|Maroon|Aqua|Lime|Teal|Green|Blue|Navy|Black' 'tag' 'color' 'value' 1} ...
{'style' 'text' 'string' 'Plot 2: Cluster, Group, and Color'} {'style' 'popupmenu' 'string' clsString 'tag' 'cluster' 'value' 1} {'style' 'popupmenu' 'string' groupString 'tag' 'group' 'value' 1} {'style' 'popupmenu' 'string' '(none)|White|Yellow|Fuchsia|Red|Silver|Gray|Olive|Purple|Maroon|Aqua|Lime|Teal|Green|Blue|Navy|Black' 'tag' 'color' 'value' 1} ...
{'style' 'text' 'string' 'Plot 3: Cluster, Group, and Color'} {'style' 'popupmenu' 'string' clsString 'tag' 'cluster' 'value' 1} {'style' 'popupmenu' 'string' groupString 'tag' 'group' 'value' 1} {'style' 'popupmenu' 'string' '(none)|White|Yellow|Fuchsia|Red|Silver|Gray|Olive|Purple|Maroon|Aqua|Lime|Teal|Green|Blue|Navy|Black' 'tag' 'color' 'value' 1} ...
{'style' 'text' 'string' 'Plot 4: Cluster, Group, and Color'} {'style' 'popupmenu' 'string' clsString 'tag' 'cluster' 'value' 1} {'style' 'popupmenu' 'string' groupString 'tag' 'group' 'value' 1} {'style' 'popupmenu' 'string' '(none)|White|Yellow|Fuchsia|Red|Silver|Gray|Olive|Purple|Maroon|Aqua|Lime|Teal|Green|Blue|Navy|Black' 'tag' 'color' 'value' 1} ...
{'style' 'text' 'string' 'Plot 5: Cluster, Group, and Color'} {'style' 'popupmenu' 'string' clsString 'tag' 'cluster' 'value' 1} {'style' 'popupmenu' 'string' groupString 'tag' 'group' 'value' 1} {'style' 'popupmenu' 'string' '(none)|White|Yellow|Fuchsia|Red|Silver|Gray|Olive|Purple|Maroon|Aqua|Lime|Teal|Green|Blue|Navy|Black' 'tag' 'color' 'value' 1} ...
{'style' 'text' 'string' 'Slice orientation'} {'style' 'popupmenu' 'string' 'Axial|Sagittal|Coronal' 'tag' 'slice' 'value' 1} ...
{'style' 'text' 'string' 'Smoothing Gaussian kernel FWHM [mm]'} {'style' 'edit' 'string' '14.2'} ...
{'style' 'text' 'string' 'Color range [min max] blank=auto'} {'style' 'edit' 'string' ''} ...
{'style' 'text' 'string' 'If Plot 1 - Plot 2'} {'style' 'popupmenu' 'string' groupString 'value' 1} {'style' 'text' 'string' 'minus'} {'style' 'popupmenu' 'string' groupString 'value' 1} {'style' 'text' 'string' 'thresh. [%]'} {'style' 'edit' 'string' '5'} ...
{'style' 'text' 'string' 'Save figures to the current folder'} {'style' 'checkbox', 'value', 0}});
end
% canceled
if isempty(userInput)
return
end
% store userInput to STUDY
STUDY.dipplotWD = userInput;
% create colorIndex
colorIndex = [1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16];
% 16 colors names officially supported by W3C specification for HTML
colors{1,1} = [1 1 1]; % White
colors{2,1} = [1 1 0]; % Yellow
colors{3,1} = [1 0 1]; % Fuchsia
colors{4,1} = [1 0 0]; % Red
colors{5,1} = [0.75 0.75 0.75]; % Silver
colors{6,1} = [0.5 0.5 0.5]; % Gray
colors{7,1} = [0.5 0.5 0]; % Olive
colors{8,1} = [0.5 0 0.5]; % Purple
colors{9,1} = [0.5 0 0]; % Maroon
colors{10,1} = [0 1 1]; % Aqua
colors{11,1} = [0 1 0]; % Lime
colors{12,1} = [0 0.5 0.5]; % Teal
colors{13,1} = [0 0.5 0]; % Green
colors{14,1} = [0 0 1]; % Blue
colors{15,1} = [0 0 0.5]; % Navy
colors{16,1} = [0 0 0]; % Black
colorName{1,1} = 'White';
colorName{2,1} = 'Yellow';
colorName{3,1} = 'Fuchsia';
colorName{4,1} = 'Red';
colorName{5,1} = 'Silver';
colorName{6,1} = 'Gray';
colorName{7,1} = 'Olive';
colorName{8,1} = 'Purple';
colorName{9,1} = 'Maroon';
colorName{10,1} = 'Aqua';
colorName{11,1} = 'Lime';
colorName{12,1} = 'Teal';
colorName{13,1} = 'Green';
colorName{14,1} = 'Blue';
colorName{15,1} = 'Navy';
colorName{16,1} = 'Black';
plotParams{1,1}.cluster = userInput{1,1};
plotParams{1,1}.group = userInput{1,2};
if userInput{1,3}>1
plotParams{1,1}.color = colors{colorIndex(userInput{1,3}-1)};
plotParams{1,1}.colorName = colorName{colorIndex(userInput{1,3}-1)};
end
plotParams{1,2}.cluster = userInput{1,4};
plotParams{1,2}.group = userInput{1,5};
if userInput{1,6}>1
plotParams{1,2}.color = colors{colorIndex(userInput{1,6}-1)};
plotParams{1,2}.colorName = colorName{colorIndex(userInput{1,6}-1)};
end
plotParams{1,3}.cluster = userInput{1,7};
plotParams{1,3}.group = userInput{1,8};
if userInput{1,9}>1
plotParams{1,3}.color = colors{colorIndex(userInput{1,9}-1)};
plotParams{1,3}.colorName = colorName{colorIndex(userInput{1,9}-1)};
end
plotParams{1,4}.cluster = userInput{1,10};
plotParams{1,4}.group = userInput{1,11};
if userInput{1,12}>1
plotParams{1,4}.color = colors{colorIndex(userInput{1,12}-1)};
plotParams{1,4}.colorName = colorName{colorIndex(userInput{1,12}-1)};
end
plotParams{1,5}.cluster = userInput{1,13};
plotParams{1,5}.group = userInput{1,14};
if userInput{1,15}>1
plotParams{1,5}.color = colors{colorIndex(userInput{1,15}-1)};
plotParams{1,5}.colorName = colorName{colorIndex(userInput{1,15}-1)};
end
plotParams{1,6} = userInput{1,16}; % slice orientation
% FWHM = 2.355*sigma See https://en.wikipedia.org/wiki/Full_width_at_half_maximum
plotParams{1,7} = str2num(userInput{1,17})/2.355; % Smoothing [mm] converted from Gauss sigma to FWHM
plotParams{1,8} = str2num(userInput{1,18}); % color scale scale range
plotParams{1,9} = userInput{1,19}; % group subtractor
plotParams{1,10} = userInput{1,20}; % group subtracted
plotParams{1,11} = str2num(userInput{1,21}); % threshold [%]
plotParams{1,12} = userInput{1,22}; % save figure or not
% Pass them to the main function.
%
% The items of the plotParams are as follows:
% 1-5: {ClusterIdx, GroupIdx, Color, Colorname}
% 6: Slice orientation
% 7: FWHM
% 8: Color scale lower and upper limits
% 9: Subtracting group index
% 10: Subtracted group index
% 11: Threshold [%] for plotting the difference
std_dipoleDensity(STUDY, ALLEEG, plotParams)
% Recover the orginal STUDY if modified.
if isEmptyStudyDesignVariable == 1
STUDY = STUDYorig;
end