-
Notifications
You must be signed in to change notification settings - Fork 6
/
gui_erp.m
executable file
·2204 lines (2068 loc) · 92.9 KB
/
gui_erp.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
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
% gui_erp() - Open a GUI for visualzing ERP butterfly plots and
% topographies. ERP t-scores, standard error and global field
% power (Lehmann & Skrandies, 1980) can also be visualized. Hold
% mouse cursor over GUI controls for an explanation of what they
% do. Click on waveform axes to visualize the scalp
% topography at that point in time. Click on electrodes in scalp
% topography to see electrode name. Note, you can open more
% than one "gui_erp" at a time in different windows, but you
% cannot animate more than one gui_erp window at a time.
%
% Usage:
% >> gui_erp(cmnd_str,varargin);
% or
% >> gui_erp(GND_or_GRP,varargin);
%
% Required Input:
% cmnd_str - One of the following strings:
% 1. 'initialize'(intialize the GUI)
% 2. 'time jump'(change the time point whose topography
% is visualized)
% 3. 'back one'(go back one time point)
% 4. 'forward one'(go forward one time point)
% 5. 'back'(animate topography going backwards in time)
% 6. 'forward'(animate topography going forwards in time)
% 7. 'change stat'(change the ERP statistic that is being
% visualized [t-score or standard error])
% 8. 'new time limits'(change the x-axis range on the
% waveform x time axes)
% 9. 'new statistic limitsA'(change the y-axis range on the
% ERP x time axis--i.e., Axis A)
% 10. 'new statistic limitsB' (change the y-axis range on the
% t-score/stderr x time axis--i.e., Axis B)
% 11. 'change bin' (visualize a different bin)
% 12. 'update dashed lines' (redraws dashed lines
% representing t-test time window and critical
% t-scores)
% 13. 'redraw topo' (redraws ERP/t-score topography)
%
%
% Optional Inputs:
% fig_id - [integer] ID number of the figure window in which GUI is
% displayed (or will be displayed).
% bin - [integer] The ID number of the bin whose ERPs will be
% visualized. Note, Kutaslab Bin 0 is ignored and is
% assumed to contain cal pulses. Thus bin indexing starts
% at 1. Use headinfo.m to see the set of bins stored in
% a GND or GRP variable
% t_test - [integer] The ID number of the set of t-tests whose
% results will be visualized. If specified, any optional
% input arguments inconsistent with this test's parameters
% (e.g., 'bin') will be ignored. Note, the results of
% t-tests performed on voltages averaged across
% windows is not possible with this GUI; use sig_topo.m
% or sig_raster.m instead. Use headinfo.m to see the
% sets of t-test results stored in a GND or GRP variable
% show_wind - [vector] Two numbers (in milliseconds) indicating
% beginning and end time points to visualize (e.g., [20 800]);
% GNDorGRP - MATLABmk GND structure variable containing the
% ERP/t-score data and t-test results to visualize.
% critical_t - [vector] One or two numbers indicating critical
% t-score(s). Time points/channels with t-scores that
% exceed the critical t-score(s) are significantly
% different from the mean of the null hypothesis.
% alpha_or_q - [number] Number between 0 and 1 indicating the family-
% wise alpha or FDR q level of the critical t-scores.
% test_wind - [vector] Pairs of numbers (in milliseconds) indicating
% beginning and end time points of the t-test
% time window(s) (e.g., [300 500]). Multiple time windows
% can be specified by using semicolons to separate pairs
% of time points (e.g., [160 180; 300 500]).
% ydir - [-1 or 1] If -1, negative voltage is plotted up. If 1
% positive voltage is plotted up. {default: -1}
% stat - ['t', 'gfp', or 'stder'] Statistic shown in lower GUI axis.
% If 't', ERPs will be shown in units of t-scores. If 'GFP',
% ERPs will be visualized using global field power. If
% 'stder', the standard error of the ERPs will be showin
% in units of microvolts.
% exclude_chans - Cell array of channel labels to exclude from
% visualization (e.g., {'A2','lle','rhe'}). If only one
% channel, a single string (e.g., 'A2') is acceptable.
% You cannot use this option AND the 't_test' option.
% include_chans - Cell array of channel labels to include in the
% visualization (e.g., {'MiPf','MiCe','MiPa','MiOc'}). If
% only one channel, a single string (e.g., 'MiCe') is
% acceptable. All other channels will be ignored. You
% cannot use this option AND the 't_test' option.
%
%
% Outputs:
% None
%
%
% Author:
% David Groppe
% Kutaslab, 2/2010
%
%
% Notes:
% -If you try to use this function to visualize only channels that
% have no scalp coordinates (e.g., the difference between left and right
% hemisphere homologues), the function will automatically use sig_wave.m or
% plot_wave.m instead.
%
% -If you try to use this function to visualize only two channels that
% have scalp coordinates (e.g., MiPf & MiCe), the function will
% automatically plot the channel locations instead of the scalp topographies.
% This is because you can't interpolate a topography with only two
% channels. sig_wave.m is probably a better method than gui_pow.m for
% visualizing test results at only two channels since when you click on the
% waveforms the name of the channel corresponding to the waveform appears
% (i.e., it's easier to determine which waveform corresponds to which channel).
% plot_wave.m is also better than gui_erp.m for one or two channels of
% data.
%
%
% References:
% Lehmann D. & Skrandies, W. (1980) Reference-free identification of
% components of checkerboard-evoked multichannel potential fields.
% Electroencephalography and Clinical Neurophysiology. 48:609-621.
%%%%%%%%%%%%%%%%%% NOTES %%%%%%%%%%%%%%%%%%%%%
% -Much of the mechanics of this GUI is based on information that is stored
% in the figure's 'userdata' field. The fields of the 'userdata are as
% follows:
% >>dat=get(gcf,'userdata')
% dat =
%
% fig_id: 1<-The Figure ID # of the GUI
% psbl_tests: [1 2 3 4]<-The sets of t-tests stored in the GND or
% GRP variable that can be visualized (mean time window
% tests or tests based on channels not loaded cannot be
% visualized)
% t_tests: [1x4 struct]<-GND/GRP.t_test info for the possible tests
% mltplcmp_crct: 'fdr'<-General method that was used to correct for multiple
% comparisons ('fdr' or 'perm')
% alpha: 0.0532<-q or estimated alpha level of the currently
% visualized test
% n_wind: 1<-# of time windows of the currently visualized test
% critical_t: [-9.4493 9.4493]<-critical t-scores of the currently
% visualized test
% null_mean: 0<-mean of the null hypothesis of the currently
% visualized test
% erp: [31x256x42 double]<-GND/GRP.grands
% t_scores: [31x256x42 double]<-GND/GRP.grands_t
% stder: [31x256x42 double]<-GND/GRP.grands_stder
% showing_t: [26x256 double]<- t-scores of the data in dat.showing.
% These will differ from the values in dat.t_scores if
% the mean of the null hypothesis of the test being
% visualized is not 0
% showingB: [26x256 double]<-waveforms currently shown in lower
% butterfly plot in GUI
% showingA: [26x256 double]<-waveforms currently shown in upper
% butterfly plot in GUI
% bindesc: {1x42 cell}<-bin descriptors for dat.erp
% times: [1x256 double]<-time points (in ms) for dat.erp
% plt_times: [-100 920]<-start and stop end points for waveforms
% currently shown
% chanlocs: [1x31 struct]<-GND/GRP.chanlocs
% loaded_chans: [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]<-biggest possible set of channels
% that can be visualized
% showing_chans: [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]<-set of channels currently
% visualized
% h_timeA: 1.0099<-handle of upper butterfly plot axis
% start_pt: 1<-first waveform time point to visualize
% end_pt: 256<-last waveform time point to visualize
% absmxA: 17.1658<-maximum value of absolute value of waveforms
% being visualized for upper butterfly plot
% h_t0lineA: 3.0099<-handle for line marking time=0 in upper
% butterfly plot
% h_showingA: [31x1 double]<-[26x1 double]<-handle for shown
% waveforms in upper butterfly plot
% h_lineA: 35.0099<-handle for vertical line indicating which
% topography is being visualized in upper butterfly plot
% h_wind1A: 36.0099<-handle for start points of test time
% window(s) in upper butterfly plot
% h_wind2A: 37.0099<-handle for stop points of test time
% window(s) in upper butterfly plot
% h_time_ylabA: 38.0099<-handle for y-axis label on the waveform axis
% for upper butterfly plot
% h_time_title: 39.0099<-handle for title on the waveform axis
% h_timeB: 41.0099<-handle of lower butterfly plot axis
% absmxB: 14.5909<-maximum value of absolute value of waveforms
% being visualized for lower butterfly plot
% h_t0lineB: 43.0099<-handle for line marking time=0 in lower
% butterfly plot
% h_showingB: [31x1 double]<-handle for shown waveforms in lower
% butterfly plot
% h_lineB: 75.0099<-handle for vertical line indicating which
% topography is being visualized in lower butterfly plot
% h_wind1B: 76.0099<-handle for start points of test time
% window(s) in lower butterfly plot
% h_wind2B: 77.0099<-handle for stop points of test time
% window(s) in lower butterfly plot
% h_crit1: 78.0099<-handle for red horizontal dashed line indicating
% critical t-score
% h_crit2: 80.0099<-handle for 2nd red horizontal dashed line indicating
% critical t-score (used if two tailed test [i.e., two
% critical t-scores])
% h_alph1: 79.0099<-handle for text box indicating alpha level.
% h_alph2: 81.0099<-handle for 2nd text box indicating alpha level.
% (used if two tailed test [i.e., two critical
% t-scores])
% h_time_ylabB: 83.0099<-handle for y-axis label on the waveform axis
% for lower butterfly plot
% h_topoA: 85.0099<-handle of upper topography axis
% h_cbarA: 167.0099<-handle of topography colorbar legend for
% upper axis
% h_topo_time: 171.0099<-handle of text box indicating the time point
% whose topography is currently being visualized
% h_topoB: 173.0099<-handle of lower topography axis
% h_cbarB: 254.0099<-handle of topography colorbar legend for
% lower axis
% h_back1: 257.0099<-handle of button that moves the vertical
% waveform line (i.e., the point whose topography
% is currently being visualized) back one time point
% h_forward1: 258.0099<-handle of button that moves the vertical
% waveform line (i.e., the point whose topography
% is currently being visualized) forward one time
% point
% h_back: 259.0099<-handle of button that animates the vertical
% waveform line (i.e., the point whose topography
% is currently being visualized) back in time
% h_forward: 260.0099<-handle of button that animates the vertical
% waveform line (i.e., the point whose topography
% is currently being visualized) forward in time
% h_stop: 261.0099<-handle of button that stops animation of the
% vertical waveform line (i.e., the point whose
% topography is currently being visualized)
% h_bin: 264.0099<-handle of the scroll menu indicating which
% bin is being visualized
% h_ptest: 266.0099<-handle of the scroll menu indicating which
% set of t-tests are being visualized
% h_testwind: 268.0099<-handle of the text box indicating the
% boundaries of the t-test time windows
% h_critval: 270.0099<-handle of the text box indicating the
% critical t-score values of the set of t-tests
% h_stat: 272.0099<-handle of the scroll menu indicating which
% statistic to plot (t-score of ERPs, standard
% error of ERPs)
% h_timerange: 274.0099<-handle of the text box indicating the
% minimum and maximum time values on the waveform axis
% h_statrangeA: 276.0099<-handle of the text box indicating the
% minimum and maximum statistics values on the
% upper butterfly plot (i.e., Axis A: ERPs)
% h_statrangeB: 278.0099<-handle of the text box indicating the
% minimum and maximum statistics values on the
% lower butterfly plot (i.e., Axis A: t-scores,
% standard error)
% help_msg: [1x447 char]<-message displayed when help button is
% pressed
% interrupt: 1<- field for topography animation
%%%%%%%%% POSSIBLE FUTURE DEVELOPMENT %%%%%%%%%
%
%-Make it possible to animate more than one GUI at a time?
%
%-Make it possible to change topo color limits? I don't know how do-able
%this is since values that exceed topo color limits are impossible to
%distinguish from values that are at the topo color limits. Currently topo
%is automatically scaled to +/- the absolute maxima of the waveforms
%currently shown (parts of the waveform before/after the "showing time
%window" are ignored).
%
%-Make it possible to right-click on axis to get them to pop-up in a new
%figure?
%
%-Make color scheme same as EEGLAB GUIs (see variabl frm_col)?
%
%-Make time x erp axis title an optional input argument?
%
%-Make topo scale an option
%
%-Set topo color scale to green or empty when only one channel?, or delete
% it?
%
%-Add Cohen's d as a possible statistic?
%
%-Possibly fix use of axes command (see yellow warnings) to speed up
% animations?
%
%-Make frm_col=[1 1 1]*.702 the same light blue color as EEGLAB later
% (currently it's gray)?
%%%%%%%%%%%%%%%% REVISION LOG %%%%%%%%%%%%%%%%%
% 4/9/2010-GUI now can visualize standard error, has a permutation test menu,
% can deal with tests on multiple time windows and tests with a non-zero
% null mean. Code was tidied up a bit as well.
%
% 4/12/2010-GUI now simultaneously visualizes ERPs and t-score of ERPs or
% standard error of ERPs
%
% 5/5/2010-Revised to be compatible with FDR correction code. Revised to
% accept FDR control of t-tests.
%
% 5/12/2010-Revised so that topographies update at same time (instead of
% staggered)
%
% 10/4/2010-Add global field power as possible statistic with which to
% visualize ERPs in the lower waveform plot. GFP is the only waveform
% option usable if there's only one participant in the bin being visualized
%
% 10/25/2010-Revised to be able to deal with GRP variables that don't
% contain data from sufficient subjects for calculating t-scores
%
% 11/1/2010-Now checks to make sure GND or GRP variable contains at least
% one ERP and returns an error if not
%
% 12/10/2010-'show_wind' option was ineffectual. Now it works.
%
% 12/17/2010-topoplotMK can't plot topographies if there are only two
% channels of data. Now, if there are only two channels with scalp
% coordinates, only the electrode locations are shown. Code checks to make
% sure requested bin exists
%
% 3/9/2011-Code now checks to make sure there are data in a bin before
% trying to visualize them.
%
% 6/3/2011-Fixed minor bug with viewing GRP variables and made compatible
% with cluster-based tests
function gui_erp(cmnd_str,varargin)
p=inputParser;
p.addRequired('cmnd_str',@(x) ischar(x) || isstruct(x));
p.addParamValue('fig_id',[],@(x) isempty(x) || (isnumeric(x) && (length(x)==1)));
p.addParamValue('bin',1,@(x) isnumeric(x) && (length(x)==1));
p.addParamValue('show_wind',[],@(x) isempty(x) || (isnumeric(x) && (length(x)==2)));
p.addParamValue('GNDorGRP',[],@isstruct);
p.addParamValue('critical_t',[],@(x) isempty(x) || (isnumeric(x) && (length(x)<=2)));
p.addParamValue('test_wind',[],@(x) isempty(x) || (isnumeric(x) && (size(x,2)==2)));
p.addParamValue('ydir',-1,@(x) isnumeric(x) && (length(x)==1));
p.addParamValue('stat','t',@(x) ischar(x) || strcmpi(x,'t') || strcmpi(x,'stder'));
p.addParamValue('exclude_chans',[],@(x) ischar(x) || iscell(x) || isempty(x));
p.addParamValue('include_chans',[],@(x) ischar(x) || iscell(x) || isempty(x));
p.addParamValue('alpha_or_q',[],@(x) isempty(x) || isnumeric(x));
p.addParamValue('t_test',[],@(x) isempty(x) || (isnumeric(x) && (length(x)==1) && (x>0)));
p.addParamValue('verblevel',2,@(x) isnumeric(x) && (length(x)==1));
p.parse(cmnd_str,varargin{:});
if isstruct(cmnd_str)
% Assume cmnd_str is really a GND or GRP variable and that the desired
% command string is 'initialize'. Call gui_erp with same
% optional arguments
gui_erp('initialize','GNDorGRP',cmnd_str,'fig_id',p.Results.fig_id, ...
'bin',p.Results.bin, ...
'critical_t',p.Results.critical_t, ...
'test_wind',p.Results.test_wind, ...
'show_wind',p.Results.show_wind, ...
'ydir',p.Results.ydir, ...
'stat',p.Results.stat, ...
'exclude_chans',p.Results.exclude_chans, ...
'include_chans',p.Results.include_chans, ...
'alpha_or_q',p.Results.alpha_or_q, ...
't_test',p.Results.t_test, ...
'verblevel',p.Results.verblevel);
return;
end
% Ensure passed command is legal
psbl_cmnds{1}='initialize';
psbl_cmnds{2}='time jump';
psbl_cmnds{3}='back one';
psbl_cmnds{4}='forward one';
psbl_cmnds{5}='back';
psbl_cmnds{6}='forward';
psbl_cmnds{7}='change stat';
psbl_cmnds{8}='new time limits';
psbl_cmnds{9}='new statistic limitsA';
psbl_cmnds{10}='change bin';
psbl_cmnds{11}='new statistic limitsB';
psbl_cmnds{12}='update dashed lines';
psbl_cmnds{13}='update critical t';
psbl_cmnds{14}='redraw topo';
psbl_cmnds{15}='change test';
if ~ismember(cmnd_str,psbl_cmnds),
error('''%s'' is not a valid value of cmnd_str for gui_erp.m',cmnd_str);
end
if ~strcmp(cmnd_str,'initialize')
if isempty(p.Results.fig_id),
fig_id=gcbf;
else
fig_id=p.Results.fig_id;
end
if ~strcmp(get(fig_id,'tag'),'gui_erp')
% If the current figure does not have the right
% tag, find the one that does.
h_figs = get(0,'children');
fig_id = findobj(h_figs,'flat',...
'tag','gui_erp');
if isempty(fig_id),
% If gui_erp does not exist
% initialize it. Then run the command string
% that was originally requested.
gui_erp('initialize');
gui_erp(cmnd_str);
return;
end
end
% At this point we know that h_fig is the handle
% to a figure containing the GUI of interest to
% this function (it's possible that more than one of these
% GUI figures is open). Therefore we can use this figure
% handle to cut down on the number of objects
% that need to be searched for tag names as follows:
dat=get(gcbf,'userdata');
end
% Manage VERBLEVEL
if isempty(p.Results.verblevel),
VERBLEVEL=2; %not global, just local
else
VERBLEVEL=p.Results.verblevel;
end
% INITIALIZE THE GUI SECTION.
if strcmp(cmnd_str,'initialize')
if isempty(p.Results.GNDorGRP.grands)
error('There are no bins (i.e., ERPs) in this GND or GRP variable. You need to add bins before you can visualize them with the ERP GUI.');
end
% Creates a new GUI (even if one already exists)
if isempty(p.Results.fig_id),
dat.fig_id=figure;
else
dat.fig_id=p.Results.fig_id;
figure(dat.fig_id);
clf
end
set(dat.fig_id,'name',['ERP GUI ' p.Results.GNDorGRP.exp_desc],'tag','gui_erp', ...
'MenuBar','none','position',[139 42 690 700]);
%% Manage t-test results
n_t_tests=length(p.Results.GNDorGRP.t_tests);
dat.psbl_tests=[];
temp_bins=zeros(1,n_t_tests);
for d=1:n_t_tests,
if ~strcmpi(p.Results.GNDorGRP.t_tests(d).mean_wind,'yes'),
dat.psbl_tests=[dat.psbl_tests d];
temp_bins(d)=p.Results.GNDorGRP.t_tests(d).bin;
end
end
temp_bins=temp_bins(dat.psbl_tests);
n_psbl_tests=length(dat.psbl_tests);
dat.t_tests=p.Results.GNDorGRP.t_tests(dat.psbl_tests);
crnt_ttest=n_psbl_tests+1; %set of t-tests being visualized, default is None/Manual
use_ttest=0;
if isempty(p.Results.t_test),
if isempty(p.Results.include_chans) && isempty(p.Results.exclude_chans) ...
&& isempty(p.Results.critical_t) && isempty(p.Results.alpha_or_q) ...
&& isempty(p.Results.test_wind),
%search for set of t-tests that have been performed on bin being
%visualized (if potentially incompatible optional input
%arguments have NOT been specified)
test_ids=find(p.Results.bin==temp_bins);
if ~isempty(test_ids),
use_ttest=1;
crnt_ttest=test_ids(1); %in case there's more than one test
if VERBLEVEL>=2
fprintf('Plotting results of t-tests set %d. Any input arguments (e.g., ''critical_t'') inconsistent with this test will be ignored.\n', ...
dat.psbl_tests(crnt_ttest));
end
end
end
else
if p.Results.t_test>n_t_tests,
error('Argument ''t_test'' value of %d exceeds the number of test results stored in this GND/GRP variable (i.e., %d).', ...
p.Results.t_test,n_t_tests);
elseif ~ismember(p.Results.t_test,dat.psbl_tests),
error('t-test set %d in this GND/GRP variable was performed on mean amplitudes within one or more time windows. You cannot visualize such tests with gui_erp.m.', ...
p.Results.t_test);
else
use_ttest=1;
crnt_ttest=find(dat.psbl_tests==p.Results.t_test);
if VERBLEVEL>=2
fprintf('Plotting results of t-test set %d. Any input arguments (e.g., ''bin'') inconsistent with this test will be ignored.\n', ...
p.Results.t_test);
end
end
end
if use_ttest,
% set all other optional arguments to be
% consistent with t-test
bin=dat.t_tests(crnt_ttest).bin;
if isnan(dat.t_tests(crnt_ttest).estimated_alpha)
dat.alpha=dat.t_tests(crnt_ttest).desired_alphaORq;
dat.mltplcmp_crct='fdr';
else
dat.alpha=dat.t_tests(crnt_ttest).estimated_alpha;
dat.mltplcmp_crct='perm';
end
test_wind=dat.t_tests(crnt_ttest).time_wind;
dat.n_wind=size(test_wind,1);
include_chans=dat.t_tests(crnt_ttest).include_chans;
dat.critical_t=dat.t_tests(crnt_ttest).crit_t;
dat.null_mean=dat.t_tests(crnt_ttest).null_mean;
else
% no t-test, use optional inputs or defaults
bin=p.Results.bin;
test_wind=p.Results.test_wind;
include_chans=p.Results.include_chans;
dat.alpha=p.Results.alpha_or_q;
dat.critical_t=p.Results.critical_t;
dat.null_mean=0;
end
%% Make sure user hasn't asked for a bin that doesn't exist or that
% doesn't contain any data
if bin>length(p.Results.GNDorGRP.bin_info)
close(gcf);
error('You asked to visualize Bin %d, but your GND/GRP variable only contains %d bins.', ...
bin,length(p.Results.GNDorGRP.bin_info));
elseif (isfield(p.Results.GNDorGRP,'sub_ct') && ~p.Results.GNDorGRP.sub_ct(bin)) || ...
(isfield(p.Results.GNDorGRP.bin_info(bin),'n_subsA') && ( ~p.Results.GNDorGRP.bin_info(bin).n_subsA || ~p.Results.GNDorGRP.bin_info(bin).n_subsB))
close(gcf);
error('You asked to visualize Bin %d, but your GND/GRP variable doesn''t have any data in that bin.', ...
bin);
end
%% Figure out which channels to ignore if any
n_chan=length(p.Results.GNDorGRP.chanlocs);
%Make sure exclude & include options were not both used.
if ~isempty(include_chans) && ~isempty(p.Results.exclude_chans)
if use_ttest,
error('You cannot specify a set of t-tests to visualize and use the ''exclude_chans'' option.');
else
error('You cannot use BOTH ''include_chans'' and ''exclude_chans'' options.');
end
end
if ischar(p.Results.exclude_chans),
exclude_chans{1}=p.Results.exclude_chans;
elseif isempty(p.Results.exclude_chans)
exclude_chans=[];
else
exclude_chans=p.Results.exclude_chans;
end
if ischar(include_chans),
temp_var=include_chans;
clear include_chans;
include_chans{1}=temp_var;
clear temp_var;
end
if ~isempty(exclude_chans),
ignore_chans=zeros(1,length(exclude_chans)); %preallocate mem
ct=0;
for x=1:length( exclude_chans),
found=0;
for c=1:n_chan,
if strcmpi(exclude_chans{x},p.Results.GNDorGRP.chanlocs(c).labels),
found=1;
ct=ct+1;
ignore_chans(ct)=c;
end
end
if ~found,
watchit(sprintf('I attempted to exclude %s. However no such electrode was found in GND/GRP variable.', ...
exclude_chans{x}));
end
end
ignore_chans=ignore_chans(1:ct);
loaded_chans=setdiff(1:n_chan,ignore_chans);
elseif ~isempty(include_chans),
loaded_chans=zeros(1,length(include_chans)); %preallocate mem
ct=0;
for x=1:length(include_chans),
found=0;
for c=1:n_chan,
if strcmpi(include_chans{x},p.Results.GNDorGRP.chanlocs(c).labels),
found=1;
ct=ct+1;
loaded_chans(ct)=c;
end
end
if ~found,
watchit(sprintf('I attempted to include %s. However no such electrode was found in GND/GRP variable.', ...
include_chans{x}));
end
end
loaded_chans=loaded_chans(1:ct);
else
loaded_chans=1:n_chan;
end
if isempty(loaded_chans),
error('No channels selected for visualization!');
end
%Check to see if any channels are missing coordinates
yes_coord=zeros(1,n_chan);
for c=loaded_chans,
if ~isempty(p.Results.GNDorGRP.chanlocs(c).theta) && ~isnan(p.Results.GNDorGRP.chanlocs(c).theta)
yes_coord(c)=1;
end
end
if (sum(yes_coord)==0)
if use_ttest
%t-test results should be shown
watchit(sprintf('None of the channels you wish to visualize have scalp coordinates.\nIt is pointless to use the ERP GUI. Using sig_wave.m instead.'));
close(gcf);
sig_wave(p.Results.GNDorGRP,crnt_ttest,'ydir',p.Results.ydir, ...
'verblevel',p.Results.verblevel);
else
watchit('None of the channels you wish to visualize have scalp coordinates. It is pointless to use the ERP GUI. Using plot_wave.m instead.');
close(gcf);
if ~isempty(include_chans),
plot_wave(p.Results.GNDorGRP,bin,'ydir',p.Results.ydir, ...
'verblevel',p.Results.verblevel,'include_chans',include_chans);
else
%Note, exclude_chans should be empty if all channels are to
%be shown
plot_wave(p.Results.GNDorGRP,bin,'ydir',p.Results.ydir, ...
'verblevel',p.Results.verblevel,'exclude_chans',exclude_chans);
end
end
return
elseif sum(yes_coord)<length(loaded_chans),
watchit(sprintf('%d channels do not have scalp coordinates. The waveforms for such channels will be visualized but they the will not be represented in the scalp topography.', ...
length(loaded_chans)-sum(yes_coord)));
end
%remove any sets of t-tests peformed on channels that will not be
%included in the GUI
use_tests=[];
for d=1:n_psbl_tests,
if ~isempty(intersect(loaded_chans,dat.t_tests(d).used_chan_ids)),
use_tests=[use_tests d];
end
end
dat.psbl_tests=dat.psbl_tests(use_tests);
dat.t_tests=dat.t_tests(use_tests);
crnt_ttest=find(crnt_ttest==[use_tests n_psbl_tests+1]); % "n_psbl_tests+1" adds the manual/no test option
n_psbl_tests=length(use_tests);
%% attach data to figure
dat.erp=p.Results.GNDorGRP.grands;
dat.t_scores=p.Results.GNDorGRP.grands_t;
dat.stder=p.Results.GNDorGRP.grands_stder;
mn_erp_across_chans=mean(dat.erp,1);
dat.gfp=squeeze(sqrt(mean( (dat.erp-repmat(mn_erp_across_chans,[n_chan 1 1])).^2,1)));
%t-scores of data that will be shown
if (crnt_ttest<=n_psbl_tests) && (dat.t_tests(crnt_ttest).null_mean),
%The mean of the null hypothesis is non-zero
dat.showing_t=squeeze( (p.Results.GNDorGRP.grands(loaded_chans,:,bin)- ...
dat.t_tests(crnt_ttest).null_mean)./p.Results.GNDorGRP.grands_stder(loaded_chans,:,bin) );
else
dat.showing_t=squeeze(p.Results.GNDorGRP.grands_t(loaded_chans,:,bin));
end
%data that will be shown
if isinf(dat.t_scores(1,1,bin)) || isnan(dat.t_scores(1,1,bin)) || strcmpi(p.Results.stat,'gfp'),
%default to global field power if there's only one subject in the
%bin (and standard deviation isn't defined). For within-subject
%t-scores, stdev will bin Inf/-Inf when there's only one subject.
%For between-subject t-scores, stdev will bin NaN when there are
%insufficient subjects in one or both groups.
dat.showingB=dat.gfp(:,bin)';
elseif strcmpi(p.Results.stat,'t'),
dat.showingB=dat.showing_t;
else
%standard error
dat.showingB=squeeze(p.Results.GNDorGRP.grands_stder(loaded_chans,:,bin));
end
dat.showingA=squeeze(p.Results.GNDorGRP.grands(loaded_chans,:,bin)); %always show ERPs in top axis
n_bin=length(p.Results.GNDorGRP.bin_info);
dat.bindesc=cell(1,n_bin);
for b=1:n_bin,
dat.bindesc{b}=p.Results.GNDorGRP.bin_info(b).bindesc;
end
dat.times=p.Results.GNDorGRP.time_pts;
if isempty(p.Results.show_wind),
dat.plt_times=[p.Results.GNDorGRP.time_pts(1) p.Results.GNDorGRP.time_pts(end)];
else
dat.plt_times=p.Results.show_wind;
end
dat.chanlocs=p.Results.GNDorGRP.chanlocs;
dat.loaded_chans=loaded_chans;
dat.showing_chans=loaded_chans;
critical_t=dat.critical_t;
ydir=p.Results.ydir;
if length(critical_t)>2,
critical_t=critical_t(1:2);
end
dat.critical_t=critical_t;
%
%%%%%%%%%%%%%%%%%%%%%% GUI Metaparameters %%%%%%%%%%%%%%%%%%%%%%%%
%
topo_ax_dim=[0.1 .09 .85 .85];
frm_col=[1 1 1]*.702;
fontsize_topo_ui=18;
fontsize_bottom_ui=14;
fontsize_time_ax=14;
cbar_title_fontsize=14;
cbar_fontsize=12;
%
%%%%%%%%%%%%%%%%%%%%%% AXIS A: Time x ERP Axes %%%%%%%%%%%%%%%%%%%%%%%%
%
uipan=uipanel(dat.fig_id,...
'Units','normalized', ...
'Position',[ 0 0.59 .72 0.42 ],...
'shadowcolor','k', ...
'highlightcolor',frm_col, ...
'foregroundcolor',frm_col, ...
'backgroundcolor',frm_col);
dat.h_timeA=axes('position',[0.1 .1 .85 .8],'parent',uipan);
dat.start_pt=find_tpt(dat.plt_times(1),dat.times);
dat.end_pt=find_tpt(dat.plt_times(2),dat.times);
plotted_pts=dat.start_pt:dat.end_pt;
plotted_times=dat.times(dat.start_pt:dat.end_pt);
[dat.absmxA, mx_tpt]=max(max(abs(dat.showingA(:,dat.start_pt:dat.end_pt))));
stat_mx=max(max(dat.showingA(:,dat.start_pt:dat.end_pt)));
stat_mn=min(min(dat.showingA(:,dat.start_pt:dat.end_pt)));
stat_rng=stat_mx-stat_mn;
stat_plt_rng=[stat_mn-stat_rng*.02 stat_mx+stat_rng*.02];
stat_plt_rng=round(stat_plt_rng*100)/100;
plot([p.Results.GNDorGRP.time_pts(1) p.Results.GNDorGRP.time_pts(end)],[0 0],'k'); % uV/t=0 line
hold on;
set(dat.h_timeA,'fontsize',fontsize_time_ax-2);
dat.h_t0lineA=plot([0 0],stat_plt_rng,'k'); % time=0 line
set(dat.h_timeA,'ygrid','on');
if ydir<0,
set(dat.h_timeA,'ydir','reverse');
end
if size(dat.showingA,1)==1,
%only one channel being plot
dat.h_showingA=plot(dat.times,dat.showingA);
else
dat.h_showingA=plot(dat.times,dat.showingA');
end
axis tight;
axis([plotted_times(1) plotted_times(end) stat_plt_rng]);
vA=axis;
dat.h_lineA=plot([1 1]*plotted_times(mx_tpt),vA(3:4),'k');
set(dat.h_lineA,'linewidth',2);
% Dashed vertical lines marking test window
dat.n_wind=size(test_wind,1);
if dat.n_wind
for nw=1:dat.n_wind,
dat.h_wind1A(nw)=plot([1 1]*test_wind(nw,1),vA(3:4),'k--');
set(dat.h_wind1A(nw),'linewidth',2);
dat.h_wind2A(nw)=plot([1 1]*test_wind(nw,2),vA(3:4),'k--');
set(dat.h_wind2A(nw),'linewidth',2);
end
else
dat.h_wind1A=[];
dat.h_wind2A=[];
end
%y-axis
h=ylabel('\muV (ERP)');
dat.h_time_ylabA=h;
set(h,'fontsize',fontsize_time_ax,'fontunits','normalized');
%Title
new_title=['Bin ' int2str(bin) ': ' dat.bindesc{bin}];
title_max_char=43; %prevents title from spilling over into topography axis
if length(new_title)>title_max_char,
new_title=new_title(1:title_max_char);
end
dat.h_time_title=title(new_title);
set(dat.h_time_title,'fontsize',fontsize_time_ax,'fontunits','normalized');
bdf_code = [ 'tmppos = get(gca, ''currentpoint'');' ...
'dat=get(gcbf, ''userdata'');' ...
'new_tpt=find_tpt(tmppos(1,1),dat.times);' ...
'set(dat.h_lineA,''XData'',[1 1]*dat.times(new_tpt));' ...
'set(dat.h_lineB,''XData'',[1 1]*dat.times(new_tpt));' ...
'set(dat.h_topo_time,''string'',num2str(dat.times(new_tpt)));' ...
'set(dat.fig_id,''userdata'',dat);' ...
'gui_erp(''redraw topo'');' ...
'drawnow;' ...
'clear latpoint dattmp tmppos;' ...
];
set(dat.h_timeA,'ButtonDownFcn',bdf_code);
set(dat.h_showingA,'ButtonDownFcn',bdf_code);
%
%%%%%%%%%%%%%%%%%%%%%% AXIS B: Time x t-score/stderr/GFP Axes %%%%%%%%%%%%%%%%%%%%%%%%
%
frm_col=[1 1 1]*.702; %background color (gray) differs from EEGLAB blue background color
uipan=uipanel(dat.fig_id,...
'Units','normalized', ...
'Position',[ 0 0.175 .72 0.42 ],...
'shadowcolor','k', ...
'highlightcolor',frm_col, ...
'foregroundcolor',frm_col, ...
'backgroundcolor',frm_col);
dat.h_timeB=axes('position',[0.1 .18 .85 .8],'Parent',uipan);
dat.absmxB=max(max(abs(dat.showingB(:,dat.start_pt:dat.end_pt))));
stat_mx=max(max(dat.showingB(:,dat.start_pt:dat.end_pt)));
stat_mn=min(min(dat.showingB(:,dat.start_pt:dat.end_pt)));
stat_rng=stat_mx-stat_mn;
stat_plt_rng=[stat_mn-stat_rng*.02 stat_mx+stat_rng*.02];
stat_plt_rng=round(stat_plt_rng*100)/100;
plot([p.Results.GNDorGRP.time_pts(1) p.Results.GNDorGRP.time_pts(end)],[0 0],'k'); % uV/t=0 line
hold on;
set(dat.h_timeB,'fontsize',fontsize_time_ax-2);
dat.h_t0lineB=plot([0 0],stat_plt_rng,'k'); % time=0 line
set(dat.h_timeB,'ygrid','on');
if ydir<0,
set(dat.h_timeB,'ydir','reverse');
end
if size(dat.showingB,1)==1,
%only one channel being plot
dat.h_showingB=plot(dat.times,dat.showingB);
else
dat.h_showingB=plot(dat.times,dat.showingB');
end
axis tight;
axis([plotted_times(1) plotted_times(end) stat_plt_rng]);
vB=axis;
dat.h_lineB=plot([1 1]*plotted_times(mx_tpt),vB(3:4),'k');
set(dat.h_lineB,'linewidth',2);
% Dashed vertical lines marking test window
if dat.n_wind
for nw=1:dat.n_wind,
dat.h_wind1B(nw)=plot([1 1]*test_wind(nw,1),vB(3:4),'k--');
set(dat.h_wind1B(nw),'linewidth',2);
dat.h_wind2B(nw)=plot([1 1]*test_wind(nw,2),vB(3:4),'k--');
set(dat.h_wind2B(nw),'linewidth',2);
end
else
dat.h_wind1B=[];
dat.h_wind2B=[];
end
% Dashed lines marking critical t-score(s)
dat.h_crit1=[];
dat.h_crit2=[];
dat.h_alph1=[];
dat.h_alph2=[];
if ~isempty(critical_t) && ~isempty(test_wind),
if strcmpi(p.Results.stat,'t'),
if isempty(dat.alpha),
watchit('You did not specify an alpha level via optional input argument ''alpha''. Alpha level will not be displayed.');
else
for nw=1:dat.n_wind,
dat.h_crit1(nw)=plot(test_wind(nw,:),[1 1]*critical_t(1),'r--');
set(dat.h_crit1(nw),'linewidth',3);
if nw==1,
tm_rng=double(p.Results.GNDorGRP.time_pts(end)-p.Results.GNDorGRP.time_pts(1));
if strcmpi(dat.mltplcmp_crct,'fdr')
dat.h_alph1=text(test_wind(nw,1)-tm_rng*.02,critical_t(1), ...
['q=' num2str(rnd_orderofmag(dat.alpha))]);
else
dat.h_alph1=text(test_wind(nw,1)-tm_rng*.02,critical_t(1), ...
['\alpha=' num2str(rnd_orderofmag(dat.alpha))]);
end
set(dat.h_alph1,'color','r','fontweight','normal','fontsize',12, ...
'horizontalalignment','right','backgroundcolor',[1 1 1], ...
'edgecolor',[1 1 1]*.3,'clipping','on','fontname','fixedwidth');
end
end
end
if length(critical_t)>1,
for nw=1:dat.n_wind,
dat.h_crit2(nw)=plot(test_wind(nw,:),[1 1]*critical_t(2),'r--');
set(dat.h_crit2(nw),'linewidth',3);
if nw==1,
if strcmpi(dat.mltplcmp_crct,'fdr')
dat.h_alph2=text(test_wind(nw,1)-tm_rng*.02,critical_t(2), ...
['q=' num2str(rnd_orderofmag(dat.alpha))]);
else
dat.h_alph2=text(test_wind(nw,1)-tm_rng*.02,critical_t(2), ...
['\alpha=' num2str(rnd_orderofmag(dat.alpha))]);
end
set(dat.h_alph2,'color','r','fontweight','normal','fontsize',12, ...
'horizontalalignment','right','backgroundcolor',[1 1 1], ...
'edgecolor',[1 1 1]*.3,'clipping','on','fontname','fixedwidth');
end
end
end
end
end
%x-axis label
h=xlabel('Time (msec)');
set(h,'fontsize',fontsize_time_ax,'fontunits','normalized');
%y-axis label
if strcmpi(p.Results.stat,'gfp') || isinf(dat.t_scores(1,1,bin)) || isnan(dat.t_scores(1,1,bin)),
h=ylabel('\muV (GFP)');
elseif strcmpi(p.Results.stat,'t'),
h=ylabel('t-score');
else
h=ylabel('\muV (StdEr)');
end
dat.h_time_ylabB=h;
set(h,'fontsize',fontsize_time_ax,'fontunits','normalized');
bdf_code = [ 'tmppos = get(gca, ''currentpoint'');' ...
'dat=get(gcbf, ''userdata'');' ...
'new_tpt=find_tpt(tmppos(1,1),dat.times);' ...
'set(dat.h_lineA,''XData'',[1 1]*dat.times(new_tpt));' ...
'set(dat.h_lineB,''XData'',[1 1]*dat.times(new_tpt));' ...
'set(dat.h_topo_time,''string'',num2str(dat.times(new_tpt)));' ...
'set(dat.fig_id,''userdata'',dat);' ...
'gui_erp(''redraw topo'');' ...
'drawnow;' ...
'clear latpoint dattmp tmppos;' ...
];
set(dat.h_timeB,'ButtonDownFcn',bdf_code);
set(dat.h_showingB,'ButtonDownFcn',bdf_code);
%
%%%%%%%%%%%%%%%%%%%%%% AXIS C: ERP Topography %%%%%%%%%%%%%%%%%%%%%%%%
%
% PANEL
uipan=uipanel(dat.fig_id,...
'Units','normalized', ...
'Position',[ 0.719 0.59 0.281 0.42 ],...
'shadowcolor','k', ...
'highlightcolor',frm_col, ...
'foregroundcolor',frm_col, ...
'backgroundcolor',frm_col);
% TOPOGRAPHY
dat.h_topoA=axes('position',topo_ax_dim,'box','off','Parent',uipan);
sig_chans=[];
if ~isempty(test_wind) && ~isempty(critical_t),
%if current time point is in a test window look for channels with
%sig effects
for nw=1:dat.n_wind,
if (dat.times(plotted_pts(mx_tpt))>=test_wind(nw,1)) && (dat.times(plotted_pts(mx_tpt))<=test_wind(nw,2)),
if isnan(critical_t)
%cluster based test
mx_tpt_in_ms=plotted_times(mx_tpt);
mx_tpt_epoch_id=find(dat.times==mx_tpt_in_ms);
use_test_id=find(dat.psbl_tests==p.Results.t_test);
pval_tpt_id=find(dat.t_tests(use_test_id).used_tpt_ids==mx_tpt_epoch_id);
if ~isempty(pval_tpt_id)
sig_chans_temp=find(dat.t_tests(use_test_id).adj_pval(:,pval_tpt_id)<dat.t_tests(use_test_id).desired_alphaORq);
sig_chans_temp=dat.t_tests(use_test_id).used_chan_ids(sig_chans_temp); %convert sig channel indices into channel indices in the original GND/GRP variable
n_showing_chans=length(dat.showing_chans);
sig_chans=zeros(1,n_showing_chans);
for a=1:n_showing_chans,
if ismember(dat.showing_chans(a),sig_chans_temp)
sig_chans(a)=1;
end
end
sig_chans=find(sig_chans);
else
sig_chans=[];
end
else
if length(critical_t)==2,
sig_chans=find(dat.showing_t(:,plotted_pts(mx_tpt))>max(critical_t));
sig_chans=[sig_chans; find(dat.showing_t(:,plotted_pts(mx_tpt))<min(critical_t))];
else
if critical_t>0,
sig_chans=find(dat.showing_t(:,plotted_pts(mx_tpt))>critical_t);
else
sig_chans=find(dat.showing_t(:,plotted_pts(mx_tpt))<critical_t);
end
end
end
break; %Visualized time point is in this window. Break out of for loop since there's no need to look at additional time windows
end
end
end
if size(dat.showingA,1)<=2,
%two or fewer channels, we can only plot electrode locations
topoplotMK(dat.showingA(:,plotted_pts(mx_tpt)),dat.chanlocs(dat.showing_chans), ...
'style','blank','plain_blank',1,'emarker2',{sig_chans,'o',[1 1 1],4});
cbar_title='Not Applicable';
cbar_title_fontsize=10; %for some reason a fontsize of 14 cuts off last later for topoB axis
else
topoplotMK(dat.showingA(:,plotted_pts(mx_tpt)),dat.chanlocs(dat.showing_chans), ...
'maplimits',[-1 1]*dat.absmxA,'emarker2',{sig_chans,'o',[1 1 1],4});
set(findobj(gca,'type','patch'),'facecolor',[1 1 1]*.702);
cbar_title='\muV';
end
% COLOR BAR
dat.h_cbarA=axes('position',[0.13 .88 .77 .02],'Parent',uipan);
cbarDG(dat.h_cbarA);
absmx=round(dat.absmxA*100)/100;
set(gca,'xticklabel',[-absmx 0 absmx],'fontsize',cbar_fontsize);
h_cbar_title=title(cbar_title);
set(h_cbar_title,'fontsize',cbar_title_fontsize);
%%% TIME POINT TEXT BOX