-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcreate_mpt_submenu.m
354 lines (285 loc) · 17.2 KB
/
create_mpt_submenu.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
function create_mpt_submenu(measureMenuItem, measureString)
n_maxdomain = 30; %allowing max of 5 domains for demo
% global variables thet are used in the visualization function below.
global visualize_menu_label
global visualize_by_measure_menu_label
global visualize_by_domain_menu_label
global visualize_by_significance_menu_label
uimenu(measureMenuItem, 'Label', 'Project','Callback', {@command_measure_project, measureString}, 'userdata', 'study:on');
uimenu(measureMenuItem, 'Label', 'Create Domains','Callback',{@command_measure_create_domain, measureString}, 'userdata', 'study:on');
domains_menu = uimenu(measureMenuItem, 'Label', 'Domains','enable','off', 'userdata', 'study:on');
for j = 1:n_maxdomain
domain_menu = uimenu(domains_menu, 'Label', ['Domain ' num2str(j)], 'userdata', 'study:on');
uimenu(domain_menu,'Label', 'Show condition difference','Callback',{@command_measure_show_domain_condition_difference, measureString}, 'tag',[measureString 'ConditionDiffForDomain ' num2str(j)], 'userdata', 'study:on');
uimenu(domain_menu,'Label', 'Show group difference','Callback',{@command_measure_show_domain_group_difference, measureString}, 'tag',[measureString 'GroupDiffForDomain ' num2str(j)], 'userdata', 'study:on');
uimenu(domain_menu,'Label', 'Show measure','Callback',{@command_measure_show_domain_measure, measureString}, 'tag',[measureString 'MeasureForDomain ' num2str(j)], 'userdata', 'study:on');
uimenu(domain_menu,'Label', 'Show volume','Callback',{@command_measure_show_domain_volume, measureString},'tag',[measureString 'VolumeForDomain ' num2str(j)],'separator','on', 'userdata', 'study:on');
uimenu(domain_menu,'Label', 'Show cortex','Callback',{@command_measure_show_domain_on_cortex, measureString},'tag',[measureString 'VolumeForDomain ' num2str(j)], 'userdata', 'study:on');
uimenu(domain_menu,'Label', 'Show volume as MRI','Callback',{@command_measure_show_domain_volume_as_mri, measureString},'tag',[measureString 'VolumeMRIForDomain ' num2str(j)], 'userdata', 'study:on');
uimenu(domain_menu,'Label', 'Show high contributing dipoles','Callback',{@command_measure_show_domain_dipole, measureString},'tag',[measureString 'DipoleForDomain ' num2str(j)], 'userdata', 'study:on');
uimenu(domain_menu,'Label', 'Show high contributing scalp maps','Callback',{@command_measure_show_domain_scalpmap, measureString},'tag',[measureString 'ScalpMapForDomain ' num2str(j)], 'userdata', 'study:on');
uimenu(domain_menu,'Label', 'Anatomical information','Callback',{@command_measure_show_domain_anatomical_information, measureString},'tag',[measureString 'ScalpMapForDomain ' num2str(j)], 'userdata', 'study:on', 'separator','on');
end
uimenu(measureMenuItem, 'Label', visualize_menu_label,'Callback',{@command_measure_visualize, measureString, visualize_menu_label},'separator','on', 'userdata', 'study:on');
uimenu(measureMenuItem, 'Label', 'Show cortex','Callback',{@command_measure_visualize_on_cortex, measureString},'separator','off', 'userdata', 'study:on');
uimenu(measureMenuItem, 'Label', visualize_by_significance_menu_label,'Callback',{@command_measure_visualize, measureString, visualize_by_significance_menu_label},'separator','off', 'userdata', 'study:on');
uimenu(measureMenuItem, 'Label', visualize_by_measure_menu_label,'Callback',{@command_measure_visualize, measureString, visualize_by_measure_menu_label},'separator','off', 'userdata', 'study:on');
uimenu(measureMenuItem, 'Label', visualize_by_domain_menu_label,'Callback',{@command_measure_visualize, measureString, visualize_by_domain_menu_label},'separator','off', 'userdata', 'study:on');
uimenu(measureMenuItem, 'Label', 'Show volume as MRI','Callback',{@command_measure_visualize_as_mri, measureString}, 'userdata', 'study:on');
end
function command_measure_project(callerHandle, evnt, measureName)
% get the STUDY and ALLEEG variables from workspace
STUDY = evalin('base', 'STUDY;');
ALLEEG = evalin('base', 'ALLEEG;');
% populate STUDY.measureProjection.option field with default option values.
if ~isfield(STUDY, 'measureProjection') || ~isfield(STUDY.measureProjection, 'option') || isempty(STUDY.measureProjection.option)
% initialize the field
if ~isfield(STUDY, 'measureProjection')
STUDY.measureProjection = struct;
end;
assignin('base', 'STUDY', STUDY);
show_gui_options(0, true);
STUDY = evalin('base', 'STUDY;'); % get it back into this workspace.
end;
switch measureName
case 'erp'
STUDY.measureProjection.(measureName).object = pr.dipoleAndMeasureOfStudyErp(STUDY, ALLEEG);
case 'ersp'
STUDY.measureProjection.(measureName).object = pr.dipoleAndMeasureOfStudyErsp(STUDY, ALLEEG);
case 'itc'
STUDY.measureProjection.(measureName).object = pr.dipoleAndMeasureOfStudyItc(STUDY, ALLEEG);
case 'spec'
STUDY.measureProjection.(measureName).object = pr.dipoleAndMeasureOfStudySpec(STUDY, ALLEEG);
case 'sift'
if ~exist('grp_mpa_prjGraphMetric','file')
error('You must install the SIFT toolbox to use this feature');
end
cfg = arg_guipanel('Function',@grp_mpa_prjGraphMetric,'Parameters',{'STUDY',STUDY,'ALLEEG',ALLEEG},'PanelOnly',false);
[~, STUDY.measureProjection.(measureName).object] = grp_mpa_prjGraphMetric('STUDY',STUDY,'ALLEEG',ALLEEG,cfg);
end;
STUDY.measureProjection.(measureName).headGrid = pr.headGrid(STUDY.measureProjection.option.headGridSpacing);
STUDY.measureProjection.(measureName).projection = pr.meanProjection(STUDY.measureProjection.(measureName).object, STUDY.measureProjection.(measureName).object.getPairwiseMutualInformationSimilarity, STUDY.measureProjection.(measureName).headGrid, 'numberOfPermutations', STUDY.measureProjection.option.numberOfPermutations, 'stdOfDipoleGaussian', STUDY.measureProjection.option.standardDeviationOfEstimatedDipoleLocation,'numberOfStdsToTruncateGaussian', STUDY.measureProjection.option.numberOfStandardDeviationsToTruncatedGaussaian, 'normalizeInBrainDipoleDenisty', fastif(STUDY.measureProjection.option.normalizeInBrainDipoleDenisty,'on', 'off'));
STUDY = place_components_for_projection_of_measure(STUDY, measureName);
% put the STUDY variable back from workspace
assignin('base', 'STUDY', STUDY);
% show significant areas as volume.
significanceLevel = getVoxelSignificance(STUDY, measureName);
STUDY.measureProjection.(measureName).projection.plotVolume(significanceLevel);
end
function significanceLevel = getVoxelSignificance(STUDY, measureName)
if STUDY.measureProjection.option.([measureName 'FdrCorrection'])
significanceLevel = fdr(STUDY.measureProjection.(measureName).projection.convergenceSignificance(STUDY.measureProjection.(measureName).headGrid.insideBrainCube(:)), STUDY.measureProjection.option.([measureName 'Significance']));
else
significanceLevel = STUDY.measureProjection.option.([measureName 'Significance']);
end;
end
function command_measure_visualize(callerHandle, evnt, measureName, visualizationType)
if nargin<2
visualizationType = 'by color';
end;
% get the STUDY and ALLEEG variables from workspace
STUDY = evalin('base', 'STUDY;');
if ~are_the_same_components(STUDY, measureName)
command_measure_project([], [], measureName);
STUDY = evalin('base', 'STUDY;');
end;
significanceLevel = getVoxelSignificance(STUDY, measureName);
global visualize_menu_label
global visualize_by_measure_menu_label
global visualize_by_domain_menu_label
global visualize_by_significance_menu_label
switch visualizationType
case visualize_by_measure_menu_label % color by projected measure.
STUDY.measureProjection.(measureName).projection.plotVolumeColoredByMeasure(significanceLevel, STUDY.measureProjection.(measureName).object);
case visualize_menu_label % only use a single uniform color.
STUDY.measureProjection.(measureName).projection.plotVolume(significanceLevel);
case visualize_by_domain_menu_label % plot domains with different colors
% check if domains are present, if not it will create them before visualiziation.
if isempty(STUDY.measureProjection.(measureName).projection.domain)
fprintf('Measure Projection: No Domain is present, creating Domains now...\n');
command_measure_create_domain(measureName);
% update our copy of study;
STUDY = evalin('base', 'STUDY;');
end;
STUDY.measureProjection.(measureName).projection.plotVolumeColoredByDomain;
case visualize_by_significance_menu_label
STUDY.measureProjection.(measureName).projection.plotVoxelColoredBySignificance;
end;
% put the STUDY variable back from workspace
assignin('base', 'STUDY', STUDY);
end
function command_measure_visualize_as_mri(callerHandle, evnt, measureName)
% get the STUDY and ALLEEG variables from workspace
STUDY = evalin('base', 'STUDY;');
componentsAreTheSame = are_the_same_components(STUDY, measureName);
if ~componentsAreTheSame
command_measure_project([], [], measureName);
STUDY = evalin('base', 'STUDY;');
end;
significanceLevel = getVoxelSignificance(STUDY, measureName);
STUDY.measureProjection.(measureName).projection.plotMri(significanceLevel);
% put the STUDY variable back from workspace
if ~componentsAreTheSame
assignin('base', 'STUDY', STUDY);
eeglab redraw;
end;
end
function command_measure_visualize_on_cortex(callerHandle, evnt, measureName)
% get the STUDY and ALLEEG variables from workspace
STUDY = evalin('base', 'STUDY;');
componentsAreTheSame = are_the_same_components(STUDY, measureName);
if ~componentsAreTheSame
command_measure_project([], [], measureName);
STUDY = evalin('base', 'STUDY;');
end;
% put the STUDY variable back from workspace
if ~componentsAreTheSame
assignin('base', 'STUDY', STUDY);
eeglab redraw;
end;
significanceLevel = getVoxelSignificance(STUDY, measureName);
STUDY.measureProjection.(measureName).projection.plotCortex(significanceLevel);
end
function command_measure_create_domain(callerHandle, evnt, measureName)
% get the STUDY and ALLEEG variables from workspace
STUDY = evalin('base', 'STUDY;');
if ~are_the_same_components(STUDY, measureName)
command_measure_project([], [], measureName);
STUDY = evalin('base', 'STUDY;');
end;
significanceLevel = getVoxelSignificance(STUDY, measureName);
maxDomainExemplarCorrelation = STUDY.measureProjection.option.([measureName 'MaxCorrelation']);
STUDY.measureProjection.(measureName).projection = STUDY.measureProjection.(measureName).projection.createDomain(STUDY.measureProjection.(measureName).object, maxDomainExemplarCorrelation, significanceLevel);
% put the STUDY variable back from workspace
assignin('base', 'STUDY', STUDY);
update_measure_projection_menu;
% show the newly created domain with different colors.
STUDY.measureProjection.(measureName).projection.plotVolumeColoredByDomain;
end
function command_measure_show_domain_volume(callerHandle, evnt, measureName)
tagForHandle = get(gcbo, 'tag');
if ischar(tagForHandle(end)) && ~isempty(tagForHandle(end))
domainIndex = str2num(tagForHandle(end));
STUDY = evalin('base', 'STUDY;');
STUDY.measureProjection.(measureName).projection.domain(domainIndex).plotVolume;
else
return;
end
end
function command_measure_show_domain_on_cortex(callerHandle, evnt, measureName)
tagForHandle = get(gcbo, 'tag');
if ischar(tagForHandle(end)) && ~isempty(tagForHandle(end))
domainIndex = str2num(tagForHandle(end));
STUDY = evalin('base', 'STUDY;');
STUDY.measureProjection.(measureName).projection.domain(domainIndex).plotCortex;
else
return;
end
end
function command_measure_show_domain_measure(callerHandle, evnt, measureName)
tagForHandle = get(gcbo, 'tag');
if ischar(tagForHandle(end)) && ~isempty(tagForHandle(end))
domainIndex = str2num(tagForHandle(end));
STUDY = evalin('base', 'STUDY;');
STUDY.measureProjection.(measureName).projection.domain(domainIndex).plotMeasure;
else
return;
end
end
function command_measure_show_domain_condition_difference(callerHandle1, evnt1, measureName)
tagForHandle = get(gcbo, 'tag');
if ischar(tagForHandle(end)) && ~isempty(tagForHandle(end))
domainIndex = str2num(tagForHandle(end));
STUDY = evalin('base', 'STUDY;');
if isfield(STUDY, 'measureProjection') && isfield(STUDY.measureProjection, 'option') && isfield(STUDY.measureProjection.option, 'conditionDifferenceOption') && ~isempty(STUDY.measureProjection.option.conditionDifferenceOption)
STUDY.measureProjection.option.conditionDifferenceOption = STUDY.measureProjection.(measureName).projection.domain(domainIndex).plotConditionDifferenceGui(STUDY.measureProjection.(measureName).object, STUDY.measureProjection.option.conditionDifferenceOption);
else
STUDY.measureProjection.option.conditionDifferenceOption = STUDY.measureProjection.(measureName).projection.domain(domainIndex).plotConditionDifferenceGui(STUDY.measureProjection.(measureName).object);
end;
% put the STUDY variable back from workspace
assignin('base', 'STUDY', STUDY);
else
return;
end
end
function command_measure_show_domain_group_difference(callerHandle, evnt, measureName)
tagForHandle = get(gcbo, 'tag');
if ischar(tagForHandle(end)) && ~isempty(tagForHandle(end))
domainIndex = str2num(tagForHandle(end));
STUDY = evalin('base', 'STUDY;');
if isfield(STUDY, 'measureProjection') && isfield(STUDY.measureProjection, 'option') && isfield(STUDY.measureProjection.option, 'groupDifferenceOption') && ~isempty(STUDY.measureProjection.option.groupDifferenceOption)
STUDY.measureProjection.option.groupDifferenceOption = STUDY.measureProjection.(measureName).projection.domain(domainIndex).plotGroupDifferenceGui(STUDY.measureProjection.(measureName).object, STUDY.measureProjection.option.groupDifferenceOption);
else
STUDY.measureProjection.option.groupDifferenceOption = STUDY.measureProjection.(measureName).projection.domain(domainIndex).plotGroupDifferenceGui(STUDY.measureProjection.(measureName).object);
end;
% put the STUDY variable back from workspace
assignin('base', 'STUDY', STUDY);
else
return;
end
end
function command_measure_show_domain_volume_as_mri(callerHandle, evnt, measureName)
tagForHandle = get(gcbo, 'tag');
if ischar(tagForHandle(end)) && ~isempty(tagForHandle(end))
domainIndex = str2num(tagForHandle(end));
STUDY = evalin('base', 'STUDY;');
STUDY.measureProjection.(measureName).projection.domain(domainIndex).plotMri;
eeglab redraw;
else
return;
end
end
function command_measure_show_domain_dipole(callerHandle, evnt, measureName)
tagForHandle = get(gcbo, 'tag');
if ischar(tagForHandle(end)) && ~isempty(tagForHandle(end))
domainIndex = str2num(tagForHandle(end));
STUDY = evalin('base', 'STUDY;');
STUDY.measureProjection.(measureName).projection.domain(domainIndex).plotDipole(STUDY.measureProjection.(measureName).object);
else
return;
end
end
function command_measure_show_domain_scalpmap(callerHandle, evnt, measureName)
tagForHandle = get(gcbo, 'tag');
if ischar(tagForHandle(end)) && ~isempty(tagForHandle(end))
domainIndex = str2num(tagForHandle(end));
STUDY = evalin('base', 'STUDY;');
STUDY.measureProjection.(measureName).projection.domain(domainIndex).plotScalpMap;
else
return;
end
end
function command_measure_show_domain_anatomical_information(callerHandle, evnt, measureName)
tagForHandle = get(gcbo, 'tag');
if ischar(tagForHandle(end)) && ~isempty(tagForHandle(end))
domainIndex = str2num(tagForHandle(end));
STUDY = evalin('base', 'STUDY;');
STUDY.measureProjection.(measureName).projection.domain(domainIndex).describeInPopup;
else
return;
end
end
function show_about(callerHandle, tmp)
handle = open ('about.fig');
icadefs; % provides GUIBACKCOLOR in current workspace.
set(handle, 'color', GUIBACKCOLOR);
% change background color of text elements to background color of the figure (which is EEGLAB
% GUI color)
set(findobj(get(handle,'children'), 'style','text'), 'backgroundcolor', GUIBACKCOLOR);
end
function res = are_the_same_components(STUDY, measureName)
res = false;
if isfield(STUDY,'cluster') && isfield(STUDY.cluster,'comps') && isfield(STUDY.cluster,'sets')
if isfield(STUDY,'measureProjection') && isfield(STUDY.measureProjection, measureName) && isfield(STUDY.measureProjection.(measureName),'lastCalculation') && isfield(STUDY.measureProjection.(measureName).lastCalculation,'comps') && isfield(STUDY.measureProjection.(measureName).lastCalculation,'sets')
if isequal(STUDY.measureProjection.(measureName).lastCalculation.sets,STUDY.cluster(1).sets) && isequal(STUDY.measureProjection.(measureName).lastCalculation.comps,STUDY.cluster(1).comps)
res = true;
else
res = false;
end
end
end
end
function STUDY = place_components_for_projection_of_measure(STUDY, measureName)
STUDY.measureProjection.(measureName).lastCalculation.sets = STUDY.cluster(1).sets;
STUDY.measureProjection.(measureName).lastCalculation.comps = STUDY.cluster(1).comps;
end