-
Notifications
You must be signed in to change notification settings - Fork 0
/
cat_spm_results_ui.m
2130 lines (1892 loc) · 88 KB
/
cat_spm_results_ui.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
function varargout = cat_spm_results_ui(varargin)
% User interface for SPM/PPM results: Display and analysis of regional effects
% FORMAT [hReg,xSPM,SPM] = cat_spm_results_ui('Setup',[xSPM])
%
% hReg - handle of MIP XYZ registry object
% (see spm_XYZreg.m for details)
% xSPM - structure containing specific SPM, distribution & filtering details
% (see spm_getSPM.m for contents)
% SPM - SPM structure containing generic parameters
% (see spm_spm.m for contents)
%
% NB: Results section GUI CallBacks use these data structures by name,
% which therefore *must* be assigned to the correctly named variables.
%__________________________________________________________________________
%
% The SPM results section is for the interactive exploration and
% characterisation of the results of a statistical analysis.
%
% The user is prompted to select a SPM{T} or SPM{F}, that is thresholded at
% user specified levels. The specification of the contrasts to use and the
% height and size thresholds are described in spm_getSPM.m. The resulting
% SPM is then displayed in the Graphics window as a maximum intensity
% projection, alongside the design matrix and contrasts employed.
%
% The cursors in the MIP can be moved (dragged) to select a particular
% voxel. The three mouse buttons give different drag and drop behaviour:
% Button 1 - point & drop; Button 2 - "dynamic" drag & drop with
% co-ordinate & SPM value updating; Button 3 - "magnetic" drag & drop,
% where the cursor jumps to the nearest suprathreshold voxel in the MIP,
% and shows the value there.
% See spm_mip_ui.m, the MIP GUI handling function for further details.
%
% The design matrix and contrast pictures are "surfable": Click and drag
% over the images to report associated data. Clicking with different
% buttons produces different results. Double-clicking extracts the
% underlying data into the base workspace.
% See spm_DesRep.m for further details.
%
% The current voxel specifies the voxel, suprathreshold cluster, or
% orthogonal planes (planes passing through that voxel) for subsequent
% localised utilities.
%
% A control panel in the Interactive window enables interactive exploration
% of the results.
%
% p-values buttons:
% (i) volume - Tabulates p-values and statistics for entire volume.
% - see spm_list.m
% (ii) cluster - Tabulates p-values and statistics for nearest cluster.
% - Note that the cursor will jump to the nearest
% suprathreshold voxel, if it is not already at a
% location with suprathreshold statistic.
% - see spm_list.m
% (iii) S.V.C - Small Volume Correction:
% Tabulates p-values corrected for a small specified
% volume of interest. (Tabulation by spm_list.m)
% - see spm_VOI.m
%
% Data extraction buttons:
% Eigenvariate/CVA
% - Extracts the principal eigenvariate for small volumes
% of interest; or CVA of data within a specified volume
% - Data can be adjusted or not for eigenvariate summaries
% - If temporal filtering was specified (fMRI), then it is
% the filtered data that is returned.
% - Choose a VOI of radius 0 to extract the (filtered &)
% adjusted data for a single voxel. Note that this vector
% will be scaled to have a 2-norm of 1. (See spm_regions.m
% for further details.)
% - The plot button also returns fitted and adjusted
% (after any filtering) data for the voxel being plotted.)
% - Note that the cursor will jump to the nearest voxel for
% which raw data was saved.
% - see spm_regions.m
%
% Visualisation buttons:
% (i) plot - Graphs of adjusted and fitted activity against
% various ordinates.
% - Note that the cursor will jump to the nearest
% suprathreshold voxel, if it is not already at a
% location with suprathreshold statistic.
% - Additionally, returns fitted and adjusted data to the
% MATLAB base workspace.
% - see spm_graph.m
% (ii) overlays - Popup menu: Overlays of filtered SPM on a structural image
% - slices - Slices of the thresholded statistic image overlaid
% on a secondary image chosen by the user. Three
% transverse slices are shown, being those at the
% level of the cursor in the z-axis and the two
% adjacent to it. - see spm_transverse.m
% - sections - Orthogonal sections of the thresholded statistic
% image overlaid on a secondary image chosen by the user.
% The sections are through the cursor position.
% - see spm_sections.m
% - render - Render blobs on previously extracted cortical surface
% - see spm_render.m
% (iii) save - Write out thresholded SPM as image
% - see spm_write_filtered.m
%
% The current cursor location can be set by editing the co-ordinate widgets
% at the bottom of the Interactive window. (Note that many of the results
% section facilities are "linked" and can update co-ordinates. E.g.
% clicking on the co-ordinates in a p-value listing jumps to that location.)
%
% Graphics appear in the bottom half of the Graphics window, additional
% controls and questions appearing in the Interactive window.
%
% ----------------
%
% The MIP uses a template outline in MNI space. Consequently for the
% results section to display properly the input images to the statistics
% section should be in MNI space.
%
% Similarly, secondary images should be aligned with the input images used
% for the statistical analysis.
%
% ----------------
%
% In addition to setting up the results section, cat_spm_results_ui.m sets
% up the results section GUI and services the CallBacks. FORMAT
% specifications for embedded CallBack functions are given in the main
% body of the code.
%__________________________________________________________________________
% Copyright (C) 1996-2018 Wellcome Trust Centre for Neuroimaging
% Karl Friston & Andrew Holmes
% ______________________________________________________________________
%
% Christian Gaser, Robert Dahnke
% Structural Brain Mapping Group (https://neuro-jena.github.io)
% Departments of Neurology and Psychiatry
% Jena University Hospital
% ______________________________________________________________________
% $Id$
%==========================================================================
% - FORMAT specifications for embedded CallBack functions
%==========================================================================
%( This is a multi function function, the first argument is an action )
%( string, specifying the particular action function to take. )
%
% cat_spm_results_ui sets up and handles the SPM results graphical user
% interface, initialising an XYZ registry (see spm_XYZreg.m) to co-ordinate
% locations between various location controls.
%
%__________________________________________________________________________
%
% FORMAT [hreg,xSPM,SPM] = cat_spm_results_ui('Setup')
% Query SPM and setup GUI.
%
% FORMAT [hreg,xSPM,SPM] = cat_spm_results_ui('Setup',xSPM)
% Query SPM and setup GUI using a xSPM input structure. This allows to run
% results setup without user interaction. See spm_getSPM for details of
% allowed fields.
%
% FORMAT hReg = cat_spm_results_ui('SetupGUI',M,DIM,xSPM,Finter)
% Setup results GUI in Interactive window
% M - 4x4 transformation matrix relating voxel to "real" co-ordinates
% DIM - 3 vector of image X, Y & Z dimensions
% xSPM - structure containing xSPM. Required fields are:
% .Z - minimum of n Statistics {filtered on u and k}
% .XYZmm - location of voxels {mm}
% Finter - handle (or 'Tag') of Interactive window (default 'Interactive')
% hReg - handle of XYZ registry object
%
% FORMAT cat_spm_results_ui('DrawButts',hReg,DIM,xSPM,Finter,WS,FS)
% Draw GUI buttons
% hReg - handle of XYZ registry object
% DIM - 3 vector of image X, Y & Z dimensions
% xSPM - structure containing xSPM. Required fields are:
% Finter - handle of Interactive window
% WS - WinScale [Default spm('WinScale') ]
% FS - FontSizes [Default spm('FontSizes')]
%
% FORMAT hFxyz = cat_spm_results_ui('DrawXYZgui',M,DIM,xSPM,xyz,hReg)
% Setup editable XYZ control widgets at foot of Interactive window
% M - 4x4 transformation matrix relating voxel to "real" co-ordinates
% DIM - 3 vector of image X, Y & Z dimensions
% xSPM - structure containing SPM; Required fields are:
% .Z - minimum of n Statistics {filtered on u and k}
% .XYZmm - location of voxels {mm}
% xyz - Initial xyz location {mm}
% hReg - handle of XYZ registry object
% hFxyz - handle of XYZ control - the frame containing the edit widgets
%
% FORMAT cat_spm_results_ui('EdWidCB')
% Callback for editable XYZ control widgets
%
% FORMAT cat_spm_results_ui('UpdateSPMval',hFxyz)
% FORMAT cat_spm_results_ui('UpdateSPMval',UD)
% Updates SPM value string in Results GUI (using data from UserData of hFxyz)
% hFxyz - handle of frame enclosing widgets - the Tag object for this control
% UD - XYZ data structure (UserData of hFxyz).
%
% FORMAT xyz = cat_spm_results_ui('GetCoords',hFxyz)
% Get current co-ordinates from editable XYZ control
% hFxyz - handle of frame enclosing widgets - the Tag object for this control
% xyz - current co-ordinates {mm}
% NB: When using the results section, should use XYZregistry to get/set location
%
% FORMAT [xyz,d] = cat_spm_results_ui('SetCoords',xyz,hFxyz,hC)
% Set co-ordinates to XYZ widget
% xyz - (Input) desired co-ordinates {mm}
% hFxyz - handle of XYZ control - the frame containing the edit widgets
% hC - handle of calling object, if used as a callback. [Default 0]
% xyz - (Output) Desired co-ordinates are rounded to nearest voxel if hC
% is not specified, or is zero. Otherwise, caller is assumed to
% have checked verity of desired xyz co-ordinates. Output xyz returns
% co-ordinates actually set {mm}.
% d - Euclidean distance between desired and set co-ordinates.
% NB: When using the results section, should use XYZregistry to get/set location
%
% FORMAT hFxyz = cat_spm_results_ui('FindXYZframe',h)
% Find/check XYZ edit widgets frame handle, 'Tag'ged 'hFxyz'
% h - handle of frame enclosing widgets, or containing figure [default gcf]
% If ischar(h), then uses spm_figure('FindWin',h) to locate named figures
% hFxyz - handle of confirmed XYZ editable widgets control
% Errors if hFxyz is not an XYZ widget control, or a figure containing
% a unique such control
%
% FORMAT cat_spm_results_ui('PlotUi',hAx)
% GUI for adjusting plot attributes - Sets up controls just above results GUI
% hAx - handle of axes to work with
%
% FORMAT cat_spm_results_ui('PlotUiCB')
% CallBack handler for Plot attribute GUI
%
% FORMAT Fgraph = cat_spm_results_ui('Clear',F,mode)
% Clears results subpane of Graphics window, deleting all but semi-permanent
% results section stuff
% F - handle of Graphics window [Default spm_figure('FindWin','Graphics')]
% mode - 1 [default] - clear results subpane
% - 0 - clear results subpane and hide results stuff
% - 2 - clear, but respect 'NextPlot' 'add' axes
% (which is set by `hold on`)
% Fgraph - handle of Graphics window
%
% FORMAT hMP = cat_spm_results_ui('LaunchMP',M,DIM,hReg,hBmp)
% Prototype callback handler for integrating MultiPlanar toolbox
%
% FORMAT cat_spm_results_ui('Delete',h)
% deletes HandleGraphics objects, but only if they're valid, thus avoiding
% warning statements from MATLAB.
%
% modified version of
% spm_results_ui.m r7388
%__________________________________________________________________________
%-Condition arguments
%--------------------------------------------------------------------------
if nargin == 0
Action='Setup';
elseif nargin == 1 && isstruct(varargin{1})
cat_spm_run_results(varargin{1});
varargout = {[],[],[]};
return
else
Action=varargin{1};
end
useCAT = 2; % 0-like SPM, 1-surface handling, 2-cat_surf_renderer
global result_ui_varargout use_tfce mesh_detect
% prevent that TFCE is called if not yet installed
if ~exist(fullfile(fileparts(fileparts(mfilename('fullpath'))),'TFCE'),'dir')
use_tfce = 0;
end
%==========================================================================
switch lower(Action), case 'setup' %-Set up results
%==========================================================================
%-Initialise
%----------------------------------------------------------------------
spm('FnBanner',mfilename);
try
dcm = datacursormode(spm_figure('FindWin','Graphics'));
set(dcm,'Enable','off','UpdateFcn',[]);
spm_figure('Clear',spm_figure('FindWin','Graphics'));
end
[Finter,Fgraph,CmdLine] = spm('FnUIsetup','Stats: Results');
spm_clf('Satellite');
%-Get thresholded xSPM data and parameters of design
%======================================================================
if nargin > 1
if use_tfce
[SPM,xSPM] = tfce_getSPM(varargin{2});
else
[SPM,xSPM] = spm_getSPM(varargin{2});
end
else
if exist(fullfile(fileparts(fileparts(mfilename('fullpath'))),'TFCE'),'dir')
[spmmatfile, sts] = spm_select(1,'^SPM\.mat$','Select SPM.mat');
swd = spm_file(spmmatfile,'fpath');
cd(swd)
warning off
load('SPM.mat','SPM','xSPM');
warning on
[Ic,xCon] = spm_conman(SPM,'T&F',Inf,' Select contrast(s)...','',1);
if ~isempty(xCon(Ic).Vspm)
[pth,nam,xt] = fileparts(xCon(Ic).Vspm.fname);
xCon(Ic).Vspm = spm_data_hdr_read(fullfile(swd,[nam xt]));
end
SPM.Ic = Ic; SPM.xCon = xCon;
SPM.swd = swd;
% data or analysis moved or data are on a different computer?
if isfield(SPM.xVol,'G') && ischar(SPM.xVol.G)
if ~exist(SPM.xVol.G,'file')
[pp2,ff2,xx2] = spm_fileparts(SPM.xVol.G);
if ~isempty(strfind(ff2,'.central.freesurfer')) || (exist('cat_get_defaults','file')) && (~isempty(strfind(ff2,['.central.' cat_get_defaults('extopts.shootingsurf')])))
if strfind(pp2,'templates_surfaces_32k')
SPM.xVol.G = fullfile(fileparts(mfilename('fullpath')),'templates_surfaces_32k',[ff2 xx2]);
else
SPM.xVol.G = fullfile(fileparts(mfilename('fullpath')),'templates_surfaces',[ff2 xx2]);
end
end
% modified SPM.mat hast to be saved
fmt = spm_get_defaults('mat.format');
s = whos('SPM');
if s.bytes > 2147483647, fmt = '-v7.3'; end
save(fullfile(swd,'SPM.mat'),'SPM',fmt);
end
end
% check for existing TFCE results for this contrast
if numel(Ic)==1 && (exist(fullfile(swd,sprintf('%s_log_p_%04d.nii',xCon(Ic).STAT,Ic))) || ...
exist(fullfile(swd,sprintf('%s_log_p_%04d.gii',xCon(Ic).STAT,Ic))))
stat_str = {'TFCE',xCon(Ic).STAT};
statType = spm_input('Type of statistic',1,'m',...
sprintf('TFCE (non-parametric)|%s (non-parametric)|%s (SPM parametric)',...
xCon(Ic).STAT,xCon(Ic).STAT),[],1);
if statType < 3
use_tfce = 1;
SPM.statType = stat_str{statType};
[SPM,xSPM] = tfce_getSPM(SPM);
xSPM.statType = stat_str{statType};
else
use_tfce = 0;
[SPM,xSPM] = spm_getSPM(SPM);
xSPM.statType = xCon(Ic).STAT;
end
else
use_tfce = 0;
[SPM,xSPM] = spm_getSPM(SPM);
xSPM.statType = xCon(Ic).STAT;
end
else
if nargin > 1
[SPM,xSPM] = spm_getSPM(varargin{2});
else
[SPM,xSPM] = spm_getSPM;
end
end
end
if isempty(xSPM)
varargout = {[],[],[]};
return;
end
if ~use_tfce
xSPM.invResult = 0;
end
if spm_mesh_detect(xSPM.Vspm)
mesh_detect = 1;
else
mesh_detect = 0;
end
%-Ensure pwd = swd so that relative filenames are valid
%----------------------------------------------------------------------
cd(SPM.swd)
%-Get space information
%======================================================================
M = SPM.xVol.M;
DIM = SPM.xVol.DIM;
%-Space units
%----------------------------------------------------------------------
try
try
units = SPM.xVol.units;
catch
units = xSPM.units;
end
catch
try
Modality = spm('CheckModality');
catch
Modality = {'PET','FMRI','EEG'};
selected = spm_input('Modality: ','+1','m',Modality);
Modality = Modality{selected};
spm('ChMod',Modality);
end
if strcmp(Modality,'EEG')
datatype = {...
'Volumetric (2D/3D)',...
'Scalp-Time',...
'Scalp-Frequency',...
'Time-Frequency',...
'Frequency-Frequency'};
selected = spm_input('Data Type: ','+1','m',datatype);
datatype = datatype{selected};
else
datatype = 'Volumetric (2D/3D)';
end
switch datatype
case 'Volumetric (2D/3D)'
units = {'mm' 'mm' 'mm'};
case 'Scalp-Time'
units = {'mm' 'mm' 'ms'};
case 'Scalp-Frequency'
units = {'mm' 'mm' 'Hz'};
case 'Time-Frequency'
units = {'Hz' 'ms' ''};
case 'Frequency-Frequency'
units = {'Hz' 'Hz' ''};
otherwise
error('Unknown data type.');
end
end
% CAT.begin
% -------------------------------------------------------------------------
% ToDo:
% * add batch call with render settings > cat_conf_stools
% * add atlas data coursor > cat_surf_render
% * add colorbar > cat_surf_render
% * fix contrast box boundaries
% * full atlas integration > spm_atlas, spm_XYZreg, spm_list (lot of work)
% -------------------------------------------------------------------------
if useCAT
[pp,ff,ee] = spm_fileparts(xSPM.Vspm.fname);
if strcmp(ee,'.gii')
datatype = 'Surface (3D)';
% units = {'mm' 'mm'};
end
% change surface ?
% - first we have to use the Shooting Surface for the statistic to
% obtain more meaningful MNI coordinates
% - here we have to change to the used surface (FSaverage)
if spm_mesh_detect(xSPM.Vspm) && exist('spm_cat12') && exist('cat_get_defaults','file')
FSavg = '.freesurfer.gii';
GSavg = ['.' cat_get_defaults('extopts.shootingsurf') '.gii'];
if ischar(SPM.xVol.G)
SPM.xVol.G = strrep(SPM.xVol.G,GSavg,FSavg);
end
end
% change coordinates to spherial ??
%XYZmmFS = xSPM.
end
% -------------------------------------------------------------------------
% CAT.end
if spm_mesh_detect(xSPM.Vspm)
DIM(3) = Inf; % force 3D coordinates
elseif DIM(3) == 1
units{3} = '';
if DIM(2) == 1
units{2} = '';
end
end
xSPM.units = units;
SPM.xVol.units = units;
%-Setup Results User Interface; Display MIP, design matrix & parameters
%======================================================================
%-Setup results GUI
%----------------------------------------------------------------------
spm_clf(Finter);
spm('FigName',['SPM{',xSPM.STAT,'}: Results'],Finter,CmdLine);
hReg = cat_spm_results_ui('SetupGUI',M,DIM,xSPM,Finter);
%-Setup design interrogation menu
%----------------------------------------------------------------------
hDesRepUI = spm_DesRep('DesRepUI',SPM);
%-Setup contrast menu
%----------------------------------------------------------------------
hConUI = cat_spm_results_ui('SetupConMenu',xSPM,SPM,Finter);
%-Atlas menu
%----------------------------------------------------------------------
if ~spm_mesh_detect(xSPM.Vspm) && exist('cat_get_defaults','file')
hAtlasUI = cat_spm_results_ui('SetupAtlasMenu',Finter);
end
%-Setup Maximum intensity projection (MIP) & register
%----------------------------------------------------------------------
FS = spm('FontSizes');
hMIPax = axes('Parent',Fgraph,'Position',[0.05 0.60 0.55 0.36],'Visible','off');
if spm_mesh_detect(xSPM.Vspm)
tmp = zeros(1,prod(xSPM.DIM));
tmp(xSPM.XYZ(1,:)) = xSPM.Z;
% block to call cat_surf_render rather than spm_mesh_render
if useCAT>1 & exist('cat_surf_render')
hMax = cat_surf_render('Disp',SPM.xVol.G,'Parent',hMIPax,'Results',1);
hMax = cat_surf_render('Overlay',hMax,tmp);
hMax = cat_surf_render('ColourMap',hMax,jet);
hMax = cat_surf_render('Register',hMax,hReg);
else
hMax = spm_mesh_render('Disp',SPM.xVol.G,'Parent',hMIPax);
hMax = spm_mesh_render('Overlay',hMax,tmp);
hMax = spm_mesh_render('Register',hMax,hReg);
hMax = spm_mesh_render('ColourMap',hMax,jet);
hMax = spm_mesh_render('View',hMax,'top');
end
elseif isequal(units(2:3),{'' ''})
set(hMIPax, 'Position',[0.05 0.65 0.55 0.25]);
[allS,allXYZmm] = spm_read_vols(xSPM.Vspm);
plot(hMIPax,allXYZmm(1,:),allS,'Color',[0.6 0.6 0.6]);
set(hMIPax,'NextPlot','add');
MIP = NaN(1,xSPM.DIM(1));
MIP(xSPM.XYZ(1,:)) = xSPM.Z;
XYZmm = xSPM.M(1,:)*[1:xSPM.DIM(1);zeros(2,xSPM.DIM(1));ones(1,xSPM.DIM(1))];
plot(hMIPax,XYZmm,MIP,'b-+','LineWidth',2);
plot(hMIPax,[XYZmm(1) XYZmm(end)],[xSPM.u xSPM.u],'r');
clim = get(hMIPax,'YLim');
axis(hMIPax,[sort([XYZmm(1) XYZmm(end)]) 0 clim(2)]);
%set(hMIPax,'XTick',[],'YTick',[]);
else
hMIPax = spm_mip_ui(xSPM.Z,xSPM.XYZmm,M,DIM,hMIPax,units);
spm_XYZreg('XReg',hReg,hMIPax,'spm_mip_ui');
end
if xSPM.STAT == 'P'
str = xSPM.STATstr;
else
str = ['SPM\{',xSPM.STATstr,'\}'];
end
text(240,260,str,...
'Interpreter','TeX',...
'FontSize',FS(14),'Fontweight','Bold',...
'Parent',hMIPax)
%-Print comparison title
%----------------------------------------------------------------------
hTitAx = axes('Parent',Fgraph,...
'Position',[0.02 0.96 0.96 0.04],...
'Visible','off');
text(0.5,0.5,xSPM.title,'Parent',hTitAx,...
'HorizontalAlignment','center',...
'VerticalAlignment','top',...
'FontWeight','Bold','FontSize',FS(14))
%-Print SPMresults: Results directory & thresholding info
%----------------------------------------------------------------------
hResAx = axes('Parent',Fgraph,...
'Position',[0.05 0.55 0.45 0.05],...
'DefaultTextVerticalAlignment','baseline',...
'DefaultTextFontSize',FS(9),...
'DefaultTextColor',[1,1,1]*.7,...
'Units','Pixel',...
'Visible','off');
AxPos = get(hResAx,'Position'); set(hResAx,'YLim',[0,AxPos(4)])
h = text(0,24,'SPMresults:','Parent',hResAx,...
'FontWeight','Bold','FontSize',FS(14));
text(get(h,'Extent')*[0;0;1;0],24,spm_file(SPM.swd,'short30'),'Parent',hResAx)
try
thresDesc = xSPM.thresDesc;
if use_tfce
text(0,12,sprintf('Height threshold %s',thresDesc),'Parent',hResAx)
else
if strcmp(xSPM.STAT,'P')
text(0,12,sprintf('Height threshold %s',thresDesc),'Parent',hResAx)
else
text(0,12,sprintf('Height threshold %c = %0.6f {%s}',xSPM.STAT,xSPM.u,thresDesc),'Parent',hResAx)
end
end
catch
text(0,12,sprintf('Height threshold %c = %0.6f',xSPM.STAT,xSPM.u),'Parent',hResAx)
end
if spm_mesh_detect(xSPM.Vspm), str = 'vertices'; else str = 'voxels'; end
text(0,00,sprintf('Extent threshold k = %0.0f %s',xSPM.k,str), 'Parent',hResAx)
%-Plot design matrix
%----------------------------------------------------------------------
hDesMtx = axes('Parent',Fgraph,'Position',[0.65 0.55 0.25 0.25]);
hDesMtxIm = image((SPM.xX.nKX + 1)*32,'Parent',hDesMtx);
xlabel(hDesMtx,'Design matrix','FontSize',FS(10))
set(hDesMtxIm,'ButtonDownFcn','spm_DesRep(''SurfDesMtx_CB'')',...
'UserData',struct(...
'X', SPM.xX.xKXs.X,...
'fnames', {reshape({SPM.xY.VY.fname},size(SPM.xY.VY))},...
'Xnames', {SPM.xX.name}))
%-Plot contrasts
%----------------------------------------------------------------------
nPar = size(SPM.xX.X,2);
xx = [repmat([0:nPar-1],2,1);repmat([1:nPar],2,1)];
nCon = length(xSPM.Ic);
xCon = SPM.xCon;
if nCon
dy = 0.15/max(nCon,2);
hConAx = axes('Parent',Fgraph, 'Position',[0.65 (0.80 + dy*.1) 0.25 dy*(nCon-.1)],...
'Tag','ConGrphAx','Visible','off');
if use_tfce & xSPM.invResult
str = 'inverse contrast';
else
str = 'contrast';
end
if nCon > 1, str = [str 's']; end
title(hConAx,str)
htxt = get(hConAx,'title');
set(htxt,'FontSize',FS(10),'FontWeight','normal','Visible','on','HandleVisibility','on')
end
for ii = nCon:-1:1
hCon = axes('Parent',Fgraph, 'Position',[0.65 (0.80 + dy*(nCon - ii +.1)) 0.25 dy*.9]);
if xCon(xSPM.Ic(ii)).STAT == 'T' && size(xCon(xSPM.Ic(ii)).c,2) == 1
%-Single vector contrast for SPM{t} - bar
%--------------------------------------------------------------
yy = [zeros(1,nPar);repmat(xCon(xSPM.Ic(ii)).c',2,1);zeros(1,nPar)];
if use_tfce & xSPM.invResult, yy = -yy; end
h = patch(xx,yy,[1,1,1]*.5,'Parent',hCon);
set(hCon,'Tag','ConGrphAx',...
'Box','off','TickDir','out',...
'XTick',spm_DesRep('ScanTick',nPar,10) - 0.5,'XTickLabel','',...
'XLim', [0,nPar],...
'YTick',[-1,0,+1],'YTickLabel','',...
'YLim',[min(xCon(xSPM.Ic(ii)).c),max(xCon(xSPM.Ic(ii)).c)] +...
[-1 +1] * max(abs(xCon(xSPM.Ic(ii)).c))/10 )
else
%-F-contrast - image
%--------------------------------------------------------------
h = image((xCon(xSPM.Ic(ii)).c'/max(abs(xCon(xSPM.Ic(ii)).c(:)))+1)*32,...
'Parent',hCon);
set(hCon,'Tag','ConGrphAx',...
'Box','on','TickDir','out',...
'XTick',spm_DesRep('ScanTick',nPar,10),'XTickLabel','',...
'XLim', [0,nPar]+0.5,...
'YTick',[0:size(SPM.xCon(xSPM.Ic(ii)).c,2)]+0.5,...
'YTickLabel','',...
'YLim', [0,size(xCon(xSPM.Ic(ii)).c,2)]+0.5 )
end
ylabel(hCon,num2str(xSPM.Ic(ii)),'FontSize',FS(10),'FontWeight','normal')
set(h,'ButtonDownFcn','spm_DesRep(''SurfCon_CB'')',...
'UserData', struct( 'i', xSPM.Ic(ii),...
'h', htxt,...
'xCon', xCon(xSPM.Ic(ii))))
end
%-Store handles of results section Graphics window objects
%----------------------------------------------------------------------
H = get(Fgraph,'Children');
H = findobj(H,'flat','HandleVisibility','on');
H = findobj(H);
Hv = get(H,'Visible');
set(hResAx,'Tag','PermRes','UserData',struct('H',H,'Hv',{Hv}))
TabDat = call_list('List',xSPM,hReg);
%-Finished results setup
%----------------------------------------------------------------------
varargout = {hReg,xSPM,SPM,TabDat};
spm('Pointer','Arrow')
% -------------------------------------------------------------------------
% This block is required for postprocessing the SPM result figure.
% It include fixes to avoid rotation of non 3D elements and some other tiny
% changes to the contrast & design matrix.
if isfield(xSPM,'G')
% create SPM result table and fix elements to avoid rotation of tables
if use_tfce
tfce_list('List',xSPM,hReg);
else
spm_list_cleanup;
end
% corrections for top elements
hRes.Fgraph = spm_figure('GetWin','Graphics');
hRes.FgraphC = get( hRes.Fgraph ,'children');
hRes.FgraphAx = findobj( hRes.FgraphC,'Type','Axes');
hRes.FgraphAxPos = cell2mat(get( hRes.FgraphAx , 'Position'));
hRes.Ftext = findobj(hRes.Fgraph,'Type','Text');
% fine red lines of the SPM result table
hRes.Fline = findobj(hRes.Fgraph,'Type','Line','Tag','');% ,'UIcontextMenu',[]);
hRes.FlineAx = get(hRes.Fline,'parent');
% find the SPM result texts to fix them against rotation
hres.Ftext = findobj(hRes.Fgraph,'Type','Text','Color',[0.7 0.7 0.7]);
hRes.Ftext3dres = get( hres.Ftext ,'parent');
% for axi=1:numel(hRes.Ftext), set( hRes.Ftext(axi),'Color',[0.2 0.2 0.2]); end
for axi = 1:numel(hRes.Ftext3dres), set( hRes.Ftext3dres{axi},'HitTest','off'); end
for axi = 1:numel(hRes.FlineAx ), set( hRes.FlineAx{axi},'visible','off'); end
% make nice contrast box that is a bit larger than the original boxes
hRes.Fcons = hRes.FgraphAx( hRes.FgraphAxPos(:,1) == 0.65 & hRes.FgraphAxPos(:,2) > 0.6 ) ;
for axi = 1:numel( hRes.Fcons ), l = get( hRes.Fcons(axi) , 'ylim'); set(hRes.Fcons(axi) , 'box','on','ylim', round(l) + [-0.015 0.015]); end
% remove non integer values
hRes.Fdesm = hRes.FgraphAx( hRes.FgraphAxPos(:,1) == 0.65 & hRes.FgraphAxPos(:,2) < 0.6 ) ;
xt = get(hRes.Fdesm,'xtick'); xt(round(xt)~=xt) = []; set(hRes.Fdesm,'xtick',xt);
%
hRes.Fval = hRes.FgraphAx( hRes.FgraphAxPos(:,1) > 10);
hRes.Fsurf = hRes.FgraphAx( hRes.FgraphAxPos(:,1) == 0.05);
hRes.Flabels = [ hRes.FgraphAx( hRes.FgraphAxPos(:,1) == 0.65); hRes.FgraphAx( hRes.FgraphAxPos(:,1) == 0.02)];
for axi = 1:numel( hRes.Flabels ), set(hRes.Flabels(axi),'HitTest','off'); end
if nargout==0,
fprintf( ...
['\n' ...
'========================================================================\n' ...
' You have to call cat_spm_results_ui with all output parameters: \n' ...
' [hReg,xSPM,SPM] = cat_spm_results_ui; \n\n' ...
' Otherwise, the menu and tables will not work properly! Call now: \n %s\n'...
'========================================================================\n\n'], ...
spm_file('[hReg,xSPM,SPM] = cat_spm_results_ui(''Output'');',...
'link','[hReg,xSPM,SPM] = cat_spm_results_ui(''Output'');'));
result_ui_varargout = varargout;
clear varargout;
end
end
% -------------------------------------------------------------------------
%======================================================================
case 'output' %-Set up results section GUI
%======================================================================
fprintf('Updated result_ui output.\n');
varargout = result_ui_varargout;
%======================================================================
case 'setupgui' %-Set up results section GUI
%======================================================================
% hReg = cat_spm_results_ui('SetupGUI',M,DIM,xSPM,Finter)
if nargin < 5, Finter='Interactive'; else Finter = varargin{5}; end
if nargin < 4, error('Insufficient arguments'), end
M = varargin{2};
DIM = varargin{3};
xSPM = varargin{4};
Finter = spm_figure('GetWin',Finter);
WS = spm('WinScale');
FS = spm('FontSizes');
%-Create frame for Results GUI objects
%------------------------------------------------------------------
hPan = uipanel('Parent',Finter,'Title','','Units','Pixels',...
'Position',[001 001 400 190].*WS,...
'BorderType','Line', 'HighlightColor',[0 0 0],...
'BackgroundColor',spm('Colour'));
hReg = uipanel('Parent',hPan,'Title','','Units','Pixels',...
'BorderType','Etchedin', ...
'Position',[005 005 390 180].*WS,...
'BackgroundColor',[179 179 179]/255);
%-Initialise registry in hReg frame object
%------------------------------------------------------------------
[hReg,xyz] = spm_XYZreg('InitReg',hReg,M,DIM,[0;0;0]);
%-Setup editable XYZ widgets & cross register with registry
%------------------------------------------------------------------
hFxyz = cat_spm_results_ui('DrawXYZgui',M,DIM,varargin{4},xyz,hReg);
spm_XYZreg('XReg',hReg,hFxyz,'cat_spm_results_ui');
%-Set up buttons for results functions
%------------------------------------------------------------------
cat_spm_results_ui('DrawButts',hReg,DIM,xSPM,Finter,WS,FS);
if spm_check_version('matlab','7.11') ~= 0
drawnow; % required to force "ratio locking"
set(findobj(hPan),'Units','Normalized','FontUnits','Normalized');
end
varargout = {hReg};
%======================================================================
case 'drawbutts' %-Draw results section buttons in Interactive window
%======================================================================
% cat_spm_results_ui('DrawButts',hReg,DIM,xSPM,Finter,WS,FS)
%
if nargin < 4, error('Insufficient arguments'), end
hReg = varargin{2};
DIM = varargin{3};
xSPM = varargin{4};
if nargin < 5, Finter = spm_figure('FindWin','Interactive');
else Finter = varargin{5}; end
if nargin < 6, WS = spm('WinScale'); else WS = varargin{6}; end
if nargin < 7, FS = spm('FontSizes'); else FS = varargin{7}; end
%-p-values
%------------------------------------------------------------------
hPan = uipanel('Parent',hReg,'Title','p-values','Units','Pixels',...
'Position',[005 085 110 092].*WS,...
'BorderType','Beveledout', ...
'ShadowColor',[0.5 0.5 0.5],...
'FontAngle','Italic',...
'FontSize',FS(10),...
'ForegroundColor',[1 1 1],...
'BackgroundColor',[179 179 179]/255);
if use_tfce
callback = 'TabDat = tfce_list(''List'',xSPM,hReg);cat_spm_results_ui(''spm_list_cleanup'',hReg);';
else
callback = 'TabDat = spm_list(''List'',xSPM,hReg);cat_spm_results_ui(''spm_list_cleanup'',hReg);';
end
uicontrol('Parent',hPan,'Style','PushButton','String','whole brain',...
'Units','Pixels',...
'FontSize',FS(10),...
'ToolTipString',...
'Tabulate summary of local maxima, p-values & statistics',...
'Callback',callback,...
'Interruptible','on','Enable','on',...
'Position',[005 055 100 020].*WS);
if use_tfce
callback = 'TabDat = tfce_list(''ListCluster'',xSPM,hReg);cat_spm_results_ui(''spm_list_cleanup'',hReg);';
else
callback = 'TabDat = spm_list(''ListCluster'',xSPM,hReg);cat_spm_results_ui(''spm_list_cleanup'',hReg);';
end
uicontrol('Parent',hPan,'Style','PushButton','String','current cluster',...
'Units','Pixels',...
'FontSize',FS(10),...
'ToolTipString',...
'Tabulate p-values & statistics for local maxima of nearest cluster',...
'Callback',callback,...
'Interruptible','off','Enable','on',...
'Position',[005 030 100 020].*WS);
%-SPM area - used for Volume of Interest analyses
%------------------------------------------------------------------
if spm_mesh_detect(xSPM.Vspm)
Enable = 'off';
else
Enable = 'on';
end
if ~use_tfce
uicontrol('Parent',hPan,'Style','PushButton','String','small volume',...
'Units','Pixels',...
'FontSize',FS(10),...
'ToolTipString',['Small Volume Correction - corrected p-values ',...
'for a small search region'],...
'Callback','TabDat = spm_VOI(SPM,xSPM,hReg);',...
'Interruptible','off','Enable',Enable,...
'Position',[005 005 100 020].*WS);
end
hPan = uipanel('Parent',hReg,'Title','Multivariate','Units','Pixels',...
'Position',[120 085 150 092].*WS,...
'BorderType','Beveledout', ...
'ShadowColor',[0.5 0.5 0.5],...
'FontAngle','Italic',...
'FontSize',FS(10),...
'ForegroundColor',[1 1 1],...
'BackgroundColor',[179 179 179]/255);
uicontrol('Parent',hPan,'Style','PushButton','String','eigenvariate',...
'Position',[005 055 069 020].*WS,...
'ToolTipString',...
'Responses (principal eigenvariate) in volume of interest',...
'Callback','[Y,xY] = spm_regions(xSPM,SPM,hReg)',...
'Interruptible','on','Enable',Enable,...
'FontSize',FS(10));
uicontrol('Parent',hPan,'Style','PushButton','String','CVA',...
'Position',[076 055 069 020].*WS,...
'ToolTipString',...
'Canonical variates analysis for the current contrast and VOI',...
'Callback','CVA = spm_cva_ui('''',xSPM,SPM)',...
'Interruptible','off','Enable',Enable,...
'FontSize',FS(10));
%-Visualisation
%------------------------------------------------------------------
hPan = uipanel('Parent',hReg,'Title','Display','Units','Pixels',...
'Position',[275 085 110 092].*WS,...
'BorderType','Beveledout',...
'ShadowColor',[0.5 0.5 0.5],...
'FontAngle','Italic',...
'FontSize',FS(10),...
'ForegroundColor',[1 1 1],...
'BackgroundColor',[179 179 179]/255);
uicontrol('Parent',hPan,'Style','PushButton','String','plot',...
'FontSize',FS(10),...
'ToolTipString','plot data & contrasts at current voxel',...
'Callback','[Y,y,beta,Bcov] = spm_graph_ui(xSPM,SPM,hReg);',...
'Interruptible','on','Enable','on',...
'Position',[005 055 100 020].*WS,...
'Tag','plotButton');
str0 = {'overlays...',...
'slices', ...
'sections', ...
'CAT-T1 (IXI555 GS)', ...
'montage',...
'render',...
'previous sections',...
'previous render'};
tstr0 = { 'overlay filtered SPM on another image: ',...
'3 slices / ',...
'slice overlay /', ...
'T1 avg slice overlay /', ...
'ortho sections / ', ...
'render /', ...
'previous ortho sections /', ...
'previous surface rendering'};
if exist('cat_get_defaults','file')
str4 = ['spm_sections(xSPM,hReg,char(cat_get_defaults(''extopts.shootingT1'')));',...
'cat_spm_results_ui(''spm_list_cleanup'');',];
else
str4 = '';
end
tmp0 = {'spm_transverse(''set'',xSPM,hReg)',...
'spm_sections(xSPM,hReg);',...
str4,...
{@myslover},...
['spm_render( struct( ''XYZ'', xSPM.XYZ,',...
'''t'', xSPM.Z'',',...
'''mat'', xSPM.M,',...
'''dim'', xSPM.DIM))'],...
['global prevsect;','spm_sections(xSPM,hReg,prevsect);'],...
['global prevrend;','if ~isstruct(prevrend)',...
'prevrend = struct(''rendfile'','''',''brt'',[],''col'',[]); end;',...
'spm_render( struct( ''XYZ'', xSPM.XYZ,',...
'''t'', xSPM.Z'',',...
'''mat'', xSPM.M,',...
'''dim'', xSPM.DIM),prevrend.brt,prevrend.rendfile)']};
if spm_mesh_detect(xSPM.Vspm)
ind = [1 3 7];
else
ind = [1:3 5:numel(str0)];
end
% add average image only if cat12 exists
if exist('spm_cat12')
ind = sort([ind 4]);
end
% select entries
str = str0(ind);
tstr = tstr0(ind);
tmp = tmp0(ind(2:end)-1);
uicontrol('Parent',hPan,'Style','popupmenu','String',str,...
'FontSize',FS(10),...
'ToolTipString',cat(2,tstr{:}),...
'Callback','spm(''PopUpCB'',gcbo)',...
'UserData',tmp,...
'Interruptible','on','Enable','on',...
'Position',[005 030 100 020].*WS);
str = {'save...',...
'thresholded SPM',...
'all clusters (binary)',...
'all clusters (n-ary)',...
'current cluster'};
tmp = {{@mysavespm, 'thresh' },...
{@mysavespm, 'binary' },...
{@mysavespm, 'n-ary' },...
{@mysavespm, 'current'}};
uicontrol('Parent',hPan,'Style','popupmenu','String',str,...
'FontSize',FS(10),...
'ToolTipString','Save as image',...
'Callback','spm(''PopUpCB'',gcbo)',...
'UserData',tmp,...
'Interruptible','on','Enable','on',...
'Position',[005 005 100 020].*WS);
%-ResultsUI controls
%------------------------------------------------------------------
uicontrol('Parent',hReg,'Style','PushButton','String','clear',...
'ToolTipString','Clear results subpane',...
'FontSize',FS(9),'ForegroundColor','r',...
'Callback',['cat_spm_results_ui(''Clear''); ',...
'spm_input(''!DeleteInputObj''),',...
'spm_clf(''Satellite'')'],...
'Interruptible','on','Enable','on',...
'DeleteFcn','spm_clf(''Graphics'')',...
'Position',[280 050 048 020].*WS);