-
Notifications
You must be signed in to change notification settings - Fork 0
/
tfce_list.m
1002 lines (883 loc) · 40 KB
/
tfce_list.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 = tfce_list(varargin)
% Display an analysis of SPM{.}
% FORMAT TabDat = tfce_list('List',xSPM,hReg,[Num,Dis,Str])
% Summary list of local maxima for entire volume of interest
% FORMAT TabDat = tfce_list('ListCluster',xSPM,hReg,[Num,Dis,Str])
% List of local maxima for a single suprathreshold cluster
%
% xSPM - structure containing SPM, distribution & filtering details
% - required fields are:
% .Z - minimum of n Statistics {filtered on u and k}
% .n - number of conjoint tests
% .STAT - distribution {Z, T, X or F}
% .df - degrees of freedom [df{interest}, df{residual}]
% .u - height threshold
% .k - extent threshold {voxels}
% .XYZ - location of voxels {voxel coords}
% .S - search Volume {voxels}
% .R - search Volume {resels}
% .FWHM - smoothness {voxels}
% .M - voxels - > mm matrix
% .VOX - voxel dimensions {mm}
% .DIM - image dimensions {voxels}
% .units - space units
% .VRpv - filehandle - Resels per voxel
% .Ps - uncorrected P values in searched volume (for voxel FDR)
% .Pp - uncorrected P values of peaks (for peak FDR)
% .Pc - uncorrected P values of cluster extents (for cluster FDR)
% .uc - 0.05 critical thresholds for FWEp, FDRp, FWEc, FDRc
% .thresDesc - description of height threshold (string)
%
% (see spm_getSPM.m for further details of xSPM structures)
%
% hReg - Handle of results section XYZ registry (see spm_results_ui.m)
%
% Num - number of maxima per cluster [3]
% Dis - distance among clusters {mm} [8]
% Str - header string
%
% TabDat - Structure containing table data
% - fields are
% .tit - table title (string)
% .hdr - table header (2x12 cell array)
% .fmt - fprintf format strings for table data (1x12 cell array)
% .str - table filtering note (string)
% .ftr - table footnote information (5x2 cell array)
% .dat - table data (Nx12 cell array)
%
% ----------------
%
% FORMAT tfce_list('TxtList',TabDat,c)
% Prints a tab-delimited text version of the table
% TabDat - Structure containing table data (format as above)
% c - Column of table data to start text table at
% (E.g. c=3 doesn't print set-level results contained in columns 1 & 2)
% ----------------
%
% FORMAT tfce_list('SetCoords',xyz,hAx,hReg)
% Highlighting of table co-ordinates (used by results section registry)
% xyz - 3-vector of new co-ordinate
% hAx - table axis (the registry object for tables)
% hReg - Handle of caller (not used)
%__________________________________________________________________________
%
% tfce_list characterizes SPMs (thresholded at u and k) in terms of
% excursion sets (a collection of face, edge and vertex connected subsets
% or clusters). The corrected significance of the results are based on
% set, cluster and voxel-level inferences using distributional
% approximations from the Theory of Gaussian Fields. These distributions
% assume that the SPM is a reasonable lattice approximation of a
% continuous random field with known component field smoothness.
%
% The p values are based on the probability of obtaining c, or more,
% clusters of k, or more, resels above u, in the volume S analysed =
% P(u,k,c). For specified thresholds u, k, the set-level inference is
% based on the observed number of clusters C, = P(u,k,C). For each
% cluster of size K the cluster-level inference is based on P(u,K,1)
% and for each voxel (or selected maxima) of height U, in that cluster,
% the voxel-level inference is based on P(U,0,1). All three levels of
% inference are supported with a tabular presentation of the p values
% and the underlying statistic:
%
% Set-level - c = number of suprathreshold clusters
% - P = prob(c or more clusters in the search volume)
%
% Cluster-level - k = number of voxels in this cluster
% - Pc = prob(k or more voxels in the search volume)
% - Pu = prob(k or more voxels in a cluster)
% - Qc = lowest FDR bound for which this cluster would be
% declared positive
%
% Peak-level - T/F = Statistic upon which the SPM is based
% - Ze = The equivalent Z score - prob(Z > Ze) = prob(t > T)
% - Pc = prob(Ze or higher in the search volume)
% - Qp = lowest FDR bound for which this peak would be
% declared positive
% - Pu = prob(Ze or higher at that voxel)
%
% Voxel-level - Qu = Expd(Prop of false positives among voxels >= Ze)
%
% x,y,z (mm) - Coordinates of the voxel
%
% The table is grouped by regions and sorted on the Ze-variate of the
% primary maxima. Ze-variates (based on the uncorrected p value) are the
% Z score equivalent of the statistic. Volumes are expressed in voxels.
%
% Clicking on values in the table returns the value to the MATLAB
% workspace. In addition, clicking on the co-ordinates jumps the
% results section cursor to that location. The table has a context menu
% (obtained by right-clicking in the background of the table),
% providing options to print the current table as a text table, or to
% extract the table data to the MATLAB workspace.
%
%__________________________________________________________________________
% Copyright (C) 1999-2015 Wellcome Trust Centre for Neuroimaging
%
% modified version of
% Karl Friston, Andrew Holmes, Guillaume Flandin
% ______________________________________________________________________
%
% Christian Gaser
% Structural Brain Mapping Group (https://neuro-jena.github.io)
% Departments of Neurology and Psychiatry
% Jena University Hospital
% ______________________________________________________________________
% $Id$
%==========================================================================
switch lower(varargin{1}), case 'list' %-List
%==========================================================================
% FORMAT TabDat = tfce_list('List',xSPM,hReg,[Num,Dis,Str])
%-Parse arguments
%----------------------------------------------------------------------
if nargin < 2, error('Not enough input arguments.'); end
if nargin < 3, hReg = []; else hReg = varargin{3}; end
xSPM = varargin{2};
if isempty(xSPM), varargout = {{}}; return; end
%-Extract results table and display it
%----------------------------------------------------------------------
spm('Pointer','Watch')
TabDat = tfce_list('Table',xSPM,varargin{4:end});
tfce_list('Display',TabDat,hReg,xSPM);
spm('Pointer','Arrow')
%-Return TabDat structure
%----------------------------------------------------------------------
varargout = { TabDat };
%==========================================================================
case 'table' %-Table
%==========================================================================
% FORMAT TabDat = tfce_list('table',xSPM,[Num,Dis,Str])
%-Parse arguments
%----------------------------------------------------------------------
if nargin < 2, error('Not enough input arguments.'); end
xSPM = varargin{2};
%-Get number of maxima per cluster to be reported
%----------------------------------------------------------------------
if length(varargin) > 2, Num = varargin{3};
else Num = spm_get_defaults('stats.results.volume.nbmax'); end
%-Get minimum distance among clusters (mm) to be reported
%----------------------------------------------------------------------
if length(varargin) > 3, Dis = varargin{4};
else Dis = spm_get_defaults('stats.results.volume.distmin'); end
%-Get header string
%----------------------------------------------------------------------
if length(varargin) > 4 && ~isempty(varargin{5})
Title = varargin{5};
else
if xSPM.STAT ~= 'P'
Title = 'nonparametric p-values adjusted for search volume';
else
Title = 'P = Log Odds';
end
end
%-Extract data from xSPM
%----------------------------------------------------------------------
S = xSPM.S;
VOX = xSPM.VOX;
DIM = xSPM.DIM;
M = xSPM.M;
XYZ = xSPM.XYZ;
XYZmm = xSPM.XYZmm;
Z = xSPM.Z;
VRpv = xSPM.VRpv;
n = xSPM.n;
STAT = xSPM.STAT;
df = xSPM.df;
u = xSPM.u;
k = xSPM.k;
n_perm = xSPM.n_perm;
try, uc = xSPM.uc; end
try, QPs = xSPM.Ps; end
try, QPp = xSPM.Pp; end
try, QPc = xSPM.Pc; end
try
units = xSPM.units;
catch
units = {'mm' 'mm' 'mm'};
end
units{1} = [units{1} ' '];
units{2} = [units{2} ' '];
if ~spm_mesh_detect(xSPM.Vspm)
DIM = DIM > 1; % non-empty dimensions
else
DIM = true(1,3);
end
VOX = VOX(DIM); % scaling
if STAT ~= 'P'
R = full(xSPM.R); % Resel counts
FWHM = full(xSPM.FWHM); % Full width at half max
FWHM = FWHM(DIM);
FWmm = FWHM.*VOX; % FWHM {units}
V2R = 1/prod(FWHM); % voxels to resels
k = k*V2R; % extent threshold in resels
R = R(1:find(R~=0,1,'last')); % eliminate null resel counts
try, QPs = sort(QPs(:)); end % Needed for voxel FDR
try, QPp = sort(QPp(:)); end % Needed for peak FDR
try, QPc = sort(QPc(:)); end % Needed for cluster FDR
end
%-Tolerance for p-value underflow, when computing equivalent Z's
%----------------------------------------------------------------------
tol = eps*10;
%-Table Headers
%----------------------------------------------------------------------
TabDat.tit = Title;
TabDat.hdr = {...
'set', 'p', '\itp';...
'set', 'c', '\itc';...
'cluster', 'p(FWE-corr)', '\itp\rm_{FWE-corr}';...
'cluster', 'p(FDR-corr)', '\itq\rm_{FDR-corr}';...
'cluster', 'equivk', '\itk\rm_E';...
'cluster', 'p(unc)', '\itp\rm_{uncorr}';...
'peak', 'p(FWE-corr)', '\itp\rm_{FWE-corr}';...
'peak', 'p(FDR-corr)', '\itq\rm_{FDR-corr}';...
'peak', STAT, sprintf('\\it%s',STAT);...
'peak', 'equivZ', '(\itZ\rm_\equiv)';...
'peak', 'p(unc)', '\itp\rm_{uncorr}';...
'', 'x,y,z {mm}', [units{:}]}';...
%-Coordinate Precisions
%----------------------------------------------------------------------
if isempty(XYZmm) % empty results
xyzfmt = '%3.0f %3.0f %3.0f';
voxfmt = repmat('%0.1f ',1,nnz(DIM));
elseif ~any(strcmp(units{3},{'mm',''})) % 2D data
xyzfmt = '%3.0f %3.0f %3.0f';
voxfmt = repmat('%0.1f ',1,nnz(DIM));
else % 3D data, work out best precision based on voxel sizes and FOV
xyzsgn = min(XYZmm(DIM,:),[],2) < 0;
xyzexp = max(floor(log10(max(abs(XYZmm(DIM,:)),[],2)))+(max(abs(XYZmm(DIM,:)),[],2) >= 1),0);
voxexp = floor(log10(abs(VOX')))+(abs(VOX') >= 1);
xyzdec = max(-voxexp,0);
voxdec = max(-voxexp,1);
xyzwdt = xyzsgn+xyzexp+(xyzdec>0)+xyzdec;
voxwdt = max(voxexp,0)+(voxdec>0)+voxdec;
tmpfmt = cell(size(xyzwdt));
for i = 1:numel(xyzwdt)
tmpfmt{i} = sprintf('%%%d.%df ', xyzwdt(i), xyzdec(i));
end
xyzfmt = [tmpfmt{:}];
tmpfmt = cell(size(voxwdt));
for i = 1:numel(voxwdt)
tmpfmt{i} = sprintf('%%%d.%df ', voxwdt(i), voxdec(i));
end
voxfmt = [tmpfmt{:}];
end
TabDat.fmt = { '%-0.3f','%g',... %-Set
'%0.3f', '%0.3f','%0.0f', '%0.3f',... %-Cluster
'%0.3f', '%0.3f', '%6.2f', '%5.2f', '%0.3f',... %-Peak
xyzfmt}; %-XYZ
%-Table filtering note
%----------------------------------------------------------------------
if isinf(Num)
TabDat.str = sprintf('table shows all local maxima more than %.1fmm apart',Dis);
else
TabDat.str = sprintf(['table shows %d local maxima ',...
'more than %.1fmm apart'],Num,Dis);
end
%-Footnote with SPM parameters
%----------------------------------------------------------------------
if STAT ~= 'P'
if spm_mesh_detect(xSPM.Vspm), vx = 'vertices';
else vx = 'voxels'; end
TabDat.ftr = cell(5,2);
TabDat.ftr{1,1} = 'Degrees of freedom = [%0.1f, %0.1f]';
TabDat.ftr{1,2} = df;
if spm_mesh_detect(xSPM.Vspm)
TabDat.ftr{2,1} = ...
['FWHM = ' voxfmt '{' vx '}'];
TabDat.ftr{2,2} = FWHM;
TabDat.ftr{3,1} = ['Volume: %0.0f ' vx ' = %0.1f resels'];
TabDat.ftr{3,2} = [S,R(end)];
TabDat.ftr{4,1} = ['(resel = %0.2f ' vx ')'];
TabDat.ftr{4,2} = prod(FWHM);
else
TabDat.ftr{2,1} = ...
['FWHM = ' voxfmt units{:} '; ' voxfmt '{' vx '}'];
TabDat.ftr{2,2} = [FWmm FWHM];
TabDat.ftr{3,1} = ...
['Volume: %0.0f = %0.0f ' vx ' = %0.1f resels'];
TabDat.ftr{3,2} = [S*prod(VOX),S,R(end)];
TabDat.ftr{4,1} = ...
['Voxel size: ' voxfmt units{:} '; (resel = %0.2f ' vx ')'];
TabDat.ftr{4,2} = [VOX,prod(FWHM)];
end
TabDat.ftr{5,1} = sprintf('Permutations = %d',n_perm);
else
TabDat.ftr = {};
end
%-Characterize excursion set in terms of maxima
% (sorted on Z values and grouped by regions)
%----------------------------------------------------------------------
if isempty(Z)
TabDat.dat = cell(0,12);
varargout = {TabDat};
return
end
%-Workaround in spm_max for conjunctions with negative thresholds
%----------------------------------------------------------------------
minz = abs(min(min(Z)));
Z = 1 + minz + Z;
if ~spm_mesh_detect(xSPM.Vspm)
[N,Z,XYZ,A,L] = spm_max(Z,XYZ);
else
[N,Z,XYZ,A,L] = tfce_surf_max(Z,XYZ,xSPM.G);
end
Z = Z - minz - 1;
% find corresponding p-values for Z
Qu = spm_data_read(xSPM.VQu,'xyz',XYZ);
Pz = spm_data_read(xSPM.VPz,'xyz',XYZ);
Pu = spm_data_read(xSPM.VPu,'xyz',XYZ);
if xSPM.invResult
Qu = -Qu;
Pu = -Pu;
Pz = -Pz;
end
Qu(find(Qu<0)) = 0;
Pz(find(Pz<0)) = 0;
Pu(find(Pu<0)) = 0;
% convert from -log10
Qu = 10.^-Qu;
Pu = 10.^-Pu;
Pz = 10.^-Pz;
%-Convert maxima locations from voxels to mm
%----------------------------------------------------------------------
if spm_mesh_detect(xSPM.Vspm)
XYZmm = xSPM.G.vertices(XYZ(1,:),:)';
else
XYZmm = M(1:3,:)*[XYZ; ones(1,size(XYZ,2))];
end
TabLin = 1;
%-Cluster and local maxima p-values & statistics
%----------------------------------------------------------------------
while numel(find(isfinite(Z)))
%-Find largest remaining local maximum
%------------------------------------------------------------------
[U,i] = max(Z); %-largest maxima
j = find(A == A(i)); %-maxima in cluster
%-Compute cluster {k} and peak-level {u} p-values for this cluster
%------------------------------------------------------------------
if STAT ~= 'P'
Pk = [];
Pn = [];
Qc = [];
Qp = [];
% Equivalent Z-variate
%--------------------------------------------------------------
if Pz < tol
Ze = Inf;
else
Ze = spm_invNcdf(1 - Pz);
end
else
Pz = [];
Pu = [];
Qu = [];
Pk = [];
Pn = [];
Qc = [];
Qp = [];
ws = warning('off','SPM:outOfRangeNormal');
Ze = spm_invNcdf(U);
warning(ws);
end
[TabDat.dat{TabLin,3:12}] = deal(Pk,Qc,N(i),Pn,Pu(i),Qu(i),U,Ze(i),Pz(i),XYZmm(:,i));
TabLin = TabLin + 1;
%-Print Num secondary maxima (> Dis mm apart)
%------------------------------------------------------------------
[l,q] = sort(-Z(j)); % sort on Z value
D = i;
for i = 1:length(q)
d = j(q(i));
if min(sqrt(sum((XYZmm(:,D)-repmat(XYZmm(:,d),1,size(D,2))).^2)))>Dis
if length(D) < Num
% voxel-level p values {Z}
%------------------------------------------------------
if STAT ~= 'P'
Qp = [];
if Pz < tol
Ze = Inf;
else
Ze = spm_invNcdf(1 - Pz);
end
else
Pz = [];
Pu = [];
Qu = [];
Qp = [];
ws = warning('off','SPM:outOfRangeNormal');
Ze_tmp = 1./(1+exp(-Z(d)));
Ze = spm_invNcdf(Ze_tmp);
%Ze = spm_invNcdf(Z(d));
warning(ws);
end
D = [D d];
[TabDat.dat{TabLin,7:12}] = deal(Pu(d),Qu(d),Z(d),Ze(d),Pz(d),XYZmm(:,d));
TabLin = TabLin+1;
end
end
end
Z(j) = NaN; % Set local maxima to NaN
end
varargout = {TabDat};
%======================================================================
case 'display' %-Display table in Graphics window
%======================================================================
% FORMAT tfce_list('display',TabDat,hReg,xSPM)
%-Parse arguments
%----------------------------------------------------------------------
if nargin < 2, error('Not enough input arguments.');
else TabDat = varargin{2}; end
if nargin < 3, hReg = []; else hReg = varargin{3}; end
if nargin < 4, xSPM = []; else xSPM = varargin{4}; end
%-Get current location (to highlight selected voxel in table)
%----------------------------------------------------------------------
xyzmm = spm_results_ui('GetCoords');
%-Setup Graphics panel
%----------------------------------------------------------------------
Fgraph = spm_figure('FindWin','Satellite');
if ~isempty(Fgraph)
spm_figure('Focus',Fgraph);
ht = 0.85; bot = 0.14;
else
Fgraph = spm_figure('GetWin','Graphics');
ht = 0.4; bot = 0.1;
end
spm_results_ui('Clear',Fgraph)
FS = spm('FontSizes'); %-Scaled font sizes
PF = spm_platform('fonts'); %-Font names (for this platform)
%-Table axes & Title
%----------------------------------------------------------------------
hAx = axes('Parent',Fgraph,...
'Position',[0.025 bot 0.9 ht],...
'DefaultTextFontSize',FS(8),...
'DefaultTextInterpreter','Tex',...
'DefaultTextVerticalAlignment','Baseline',...
'Tag','SPMList',...
'Units','points',...
'Visible','off');
AxPos = get(hAx,'Position'); set(hAx,'YLim',[0,AxPos(4)])
dy = FS(9);
y = floor(AxPos(4)) - dy;
if xSPM.invResult
text(0,y,['Statistics (inverse contrast): \it\fontsize{',num2str(FS(9)),'}',TabDat.tit],...
'FontSize',FS(11),'FontWeight','Bold'); y = y - dy/2;
else
text(0,y,['Statistics: \it\fontsize{',num2str(FS(9)),'}',TabDat.tit],...
'FontSize',FS(11),'FontWeight','Bold'); y = y - dy/2;
end
line([0 1],[y y],'LineWidth',3,'Color','r'), y = y - 9*dy/8;
%-Display table header
%----------------------------------------------------------------------
set(hAx,'DefaultTextFontName',PF.helvetica,'DefaultTextFontSize',FS(8))
Hs = []; Hc = []; Hp = [];
h = text(0.40,y-9*dy/8, TabDat.hdr{3,5}); Hc = [Hc,h];
if xSPM.STAT=='TFCE'
h = text(0.55,y, 'combined peak-cluster-level','FontSize',FS(9));
else
h = text(0.55,y, 'peak-level','FontSize',FS(9));
end
Hp = [Hp,h];
h = line([0.38,0.88],[1,1]*(y-dy/4),'LineWidth',0.5,'Color','r'); Hp = [Hp,h];
h = text(0.49,y-9*dy/8, TabDat.hdr{3,7}); Hp = [Hp,h];
h = text(0.58,y-9*dy/8, TabDat.hdr{3,8}); Hp = [Hp,h];
h = text(0.67,y-9*dy/8, TabDat.hdr{3,9}); Hp = [Hp,h];
h = text(0.82,y-9*dy/8, TabDat.hdr{3,11}); Hp = [Hp,h];
text(0.92,y - dy/2,TabDat.hdr{3,12},'Fontsize',FS(8));
%-Move to next vertical position marker
%----------------------------------------------------------------------
y = y - 7*dy/4;
line([0 1],[y y],'LineWidth',1,'Color','r')
y = y - 5*dy/4;
y0 = y;
%-Table filtering note
%----------------------------------------------------------------------
text(0.5,4,TabDat.str,'HorizontalAlignment','Center',...
'FontName',PF.helvetica,'FontSize',FS(8),'FontAngle','Italic')
%-Footnote with SPM parameters (if classical inference)
%----------------------------------------------------------------------
line([0 1],[0.01 0.01],'LineWidth',1,'Color','r')
if ~isempty(TabDat.ftr)
set(gca,'DefaultTextFontName',PF.helvetica,...
'DefaultTextInterpreter','None','DefaultTextFontSize',FS(8))
fx = repmat([0 0.5],ceil(size(TabDat.ftr,1)/2),1);
fy = repmat((1:ceil(size(TabDat.ftr,1)/2))',1,2);
for i=1:size(TabDat.ftr,1)
text(fx(i),-fy(i)*dy,sprintf(TabDat.ftr{i,1},TabDat.ftr{i,2}),...
'UserData',TabDat.ftr{i,2},...
'ButtonDownFcn','get(gcbo,''UserData'')');
end
end
%-Characterize excursion set in terms of maxima
% (sorted on Z values and grouped by regions)
%======================================================================
if isempty(TabDat.dat)
text(0.5,y-6*dy,'no suprathreshold clusters',...
'HorizontalAlignment','Center',...
'FontAngle','Italic','FontWeight','Bold',...
'FontSize',FS(16),'Color',[1,1,1]*.5);
return
end
%-Table proper
%======================================================================
%-Column Locations
%----------------------------------------------------------------------
tCol = [ 0.01 0.08 ... %-Set
0.15 0.24 0.40 0.39 ... %-Cluster
0.49 0.58 0.65 0.74 0.83 ... %-Peak
0.92]; %-XYZ
%-Pagination variables
%----------------------------------------------------------------------
hPage = [];
set(gca,'DefaultTextFontName',PF.courier,'DefaultTextFontSize',FS(7));
%-Set-level p values {c} - do not display if reporting a single cluster
%----------------------------------------------------------------------
if isempty(TabDat.dat{1,1}) % Pc
set(Hs,'Visible','off');
end
%-Cluster and local maxima p-values & statistics
%----------------------------------------------------------------------
HlistXYZ = [];
HlistClust = [];
for i=1:size(TabDat.dat,1)
%-Paginate if necessary
%------------------------------------------------------------------
if y < dy
h = text(0.5,-5*dy,...
sprintf('Page %d',spm_figure('#page',Fgraph)),...
'FontName',PF.helvetica,'FontAngle','Italic',...
'FontSize',FS(8));
spm_figure('NewPage',[hPage,h])
hPage = [];
y = y0;
end
%-Print cluster and maximum peak-level p values
%------------------------------------------------------------------
if ~isempty(TabDat.dat{i,5}), fw = 'Bold'; else fw = 'Normal'; end
for k=[3:9 11]
h = text(tCol(k),y,sprintf(TabDat.fmt{k},TabDat.dat{i,k}),...
'FontWeight',fw,...
'UserData',TabDat.dat{i,k},...
'ButtonDownFcn','get(gcbo,''UserData'')');
hPage = [hPage, h];
if k == 5
HlistClust = [HlistClust, h];
set(h,'UserData',struct('k',TabDat.dat{i,k},'XYZmm',TabDat.dat{i,12}));
set(h,'ButtonDownFcn','getfield(get(gcbo,''UserData''),''k'')');
end
end
% Specifically changed so it properly finds hMIPax
%------------------------------------------------------------------
tXYZmm = TabDat.dat{i,12};
BDFcn = [...
'spm_mip_ui(''SetCoords'',get(gcbo,''UserData''),',...
'findobj(''tag'',''hMIPax''));'];
BDFcn = 'spm_XYZreg(''SetCoords'',get(gcbo,''UserData''),hReg,1);';
h = text(tCol(12),y,sprintf(TabDat.fmt{12},tXYZmm),...
'FontWeight',fw,...
'Tag','ListXYZ',...
'ButtonDownFcn',BDFcn,...
'Interruptible','off',...
'BusyAction','Cancel',...
'UserData',tXYZmm);
HlistXYZ = [HlistXYZ, h];
if spm_XYZreg('Edist',xyzmm,tXYZmm)<eps && ~isempty(hReg)
set(h,'Color','r')
end
hPage = [hPage, h];
y = y - dy;
end
%-Number and register last page (if paginated)
%----------------------------------------------------------------------
if spm_figure('#page',Fgraph)>1
h = text(0.5,-5*dy,sprintf('Page %d/%d',spm_figure('#page',Fgraph)*[1,1]),...
'FontName',PF.helvetica,'FontSize',FS(8),'FontAngle','Italic');
spm_figure('NewPage',[hPage,h])
end
%-End: Store TabDat in UserData of context menu
%======================================================================
h = uicontextmenu('Tag','TabDat','UserData',TabDat);
set(hAx,'UIContextMenu',h,...
'Visible','on',...
'XTick',[],'YTick',[],...
'XColor','w','YColor','w')
uimenu(h,'Label','Print text table',...
'CallBack',...
'tfce_list(''txtlist'',get(get(gcbo,''Parent''),''UserData''),3)',...
'Interruptible','off','BusyAction','Cancel');
uimenu(h,'Label','Extract table data structure',...
'CallBack','TabDat=get(get(gcbo,''Parent''),''UserData'')',...
'Interruptible','off','BusyAction','Cancel');
if ispc
uimenu(h,'Label','Export to Excel',...
'CallBack',...
'tfce_list(''xlslist'',get(get(gcbo,''Parent''),''UserData''));',...
'Interruptible','off','BusyAction','Cancel');
end
uimenu(h,'Label','Export to CSV file',...
'CallBack',...
'tfce_list(''csvlist'',get(get(gcbo,''Parent''),''UserData''));',...
'Interruptible','off','BusyAction','Cancel');
% Export to NIDM-Results using xSPM/TabDat from base workspace
h1 = uimenu(h,'Label','Export to NIDM-Results');
uimenu(h1,'Label','Locally',...
'CallBack',...
'fprintf(''Exporting results in:\n %s\n'',spm_results_nidm(SPM,xSPM,TabDat));',...
'Interruptible','off','BusyAction','Cancel');
% uimenu(h1,'Label','Upload to NeuroVault',...
% 'CallBack',...
% 'spm_results_nidm(''upload'',spm_results_nidm(SPM,xSPM,TabDat));',...
% 'Interruptible','off','BusyAction','Cancel');
%-Setup registry
%----------------------------------------------------------------------
set(hAx,'UserData',struct('hReg',hReg,'HlistXYZ',HlistXYZ,'HlistClust',HlistClust))
spm_XYZreg('Add2Reg',hReg,hAx,'tfce_list');
varargout = {};
%======================================================================
case 'listcluster' %-List for current cluster only
%======================================================================
% FORMAT TabDat = tfce_list('ListCluster',xSPM,hReg,[Num,Dis,Str])
%-Parse arguments
%------------------------------------------------------------------
if nargin < 2, error('Not enough input arguments.'); end
if nargin < 3, hReg = []; else hReg = varargin{3}; end
xSPM = varargin{2};
%-Get number of maxima per cluster to be reported
%------------------------------------------------------------------
if nargin < 4, Num = spm_get_defaults('stats.results.svc.nbmax');
else Num = varargin{4}; end
%-Get minimum distance among clusters (mm) to be reported
%------------------------------------------------------------------
if nargin < 5, Dis = spm_get_defaults('stats.results.svc.distmin');
else Dis = varargin{5}; end
%-Get header string
%------------------------------------------------------------------
if nargin < 6, Str = ''; else Str = varargin{6}; end
%-If there are suprathreshold voxels, filter out all but current cluster
%------------------------------------------------------------------
if ~isempty(xSPM.Z)
%-Jump to voxel nearest current location
%--------------------------------------------------------------
[xyzmm,i] = spm_XYZreg('NearestXYZ',...
spm_results_ui('GetCoords'),xSPM.XYZmm);
warning off
spm_results_ui('SetCoords',xSPM.XYZmm(:,i));
if isfield(xSPM,'G')
C = NaN(1,size(xSPM.G.vertices,1));
C(xSPM.XYZ(1,:)) = ones(size(xSPM.Z));
j = spm_mesh_clusters(xSPM.G,C);
j = j==j(xSPM.XYZ(1,i));
j = j(xSPM.XYZ(1,:));
xSPM.Z = xSPM.Z(j);
xSPM.Qu = xSPM.Qu(j);
xSPM.Pu = xSPM.Pu(j);
xSPM.Pz = xSPM.Pz(j);
xSPM.XYZ = xSPM.XYZ(:,j);
xSPM.XYZmm = xSPM.XYZmm(:,j);
else
%-Find selected cluster
%--------------------------------------------------------------
A = spm_clusters(xSPM.XYZ);
j = find(A == A(i));
xSPM.Z = xSPM.Z(j);
xSPM.Qu = xSPM.Qu(j);
xSPM.Pu = xSPM.Pu(j);
xSPM.Pz = xSPM.Pz(j);
xSPM.XYZ = xSPM.XYZ(:,j);
xSPM.XYZmm = xSPM.XYZmm(:,j);
end
end
%-Call 'list' functionality to produce table
%------------------------------------------------------------------
varargout = { tfce_list('list',xSPM,hReg,Num,Dis,Str) };
%======================================================================
case 'txtlist' %-Print ASCII text table
%======================================================================
% FORMAT tfce_list('TxtList',TabDat,c)
if nargin<2, error('Not enough input arguments.'); end
if nargin<3, c = 1; else c = varargin{3}; end
TabDat = varargin{2};
%-Table Title
%------------------------------------------------------------------
fprintf('\n\nStatistics: %s\n',TabDat.tit)
fprintf('%c',repmat('=',1,80)), fprintf('\n')
%-Table header
%------------------------------------------------------------------
fprintf('%s\t',TabDat.hdr{1,c:end-1}), fprintf('%s\n',TabDat.hdr{1,end})
fprintf('%s\t',TabDat.hdr{2,c:end-1}), fprintf('%s\n',TabDat.hdr{2,end})
fprintf('%c',repmat('-',1,80)), fprintf('\n')
%-Table data
%------------------------------------------------------------------
for i = 1:size(TabDat.dat,1)
for j=c:size(TabDat.dat,2)
fprintf(TabDat.fmt{j},TabDat.dat{i,j});
fprintf('\t')
end
fprintf('\n')
end
for i=1:max(1,12-size(TabDat.dat,1)), fprintf('\n'), end
fprintf('%s\n',TabDat.str)
fprintf('%c',repmat('-',1,80)), fprintf('\n')
%-Table footer
%------------------------------------------------------------------
for i=1:size(TabDat.ftr,1)
fprintf([TabDat.ftr{i,1} '\n'],TabDat.ftr{i,2});
end
fprintf('%c',repmat('=',1,80)), fprintf('\n\n')
%======================================================================
case 'xlslist' %-Export table to Excel
%======================================================================
% FORMAT tfce_list('XLSList',TabDat,ofile)
if nargin<2, error('Not enough input arguments.'); end
TabDat = varargin{2};
if nargin == 3, ofile = varargin{3};
else ofile = [tempname '.xls']; end
d = [TabDat.hdr(1:2,:);TabDat.dat];
xyz = d(3:end,end);
xyz = num2cell([xyz{:}]');
d(:,end+1) = d(:,end);
d(:,end+1) = d(:,end);
d(3:end,end-2:end) = xyz;
xlswrite(ofile, d);
if nargin == 2, winopen(ofile); end
%======================================================================
case 'csvlist' %-Export table to comma-separated values file
%======================================================================
% FORMAT tfce_list('CSVList',TabDat,ofile)
if nargin<2, error('Not enough input arguments.'); end
TabDat = varargin{2};
if nargin == 3, ofile = varargin{3};
else ofile = [tempname '.csv']; end
fid = fopen(ofile,'wt');
ncol = size(TabDat.hdr,2);
fmt = repmat('%s,',1,ncol);
c = repmat(',',1,nnz([TabDat.hdr{2,:}]==','));
fprintf(fid,[fmt(1:end-1) c '\n'],TabDat.hdr{1,:});
fprintf(fid,[fmt(1:end-1) '\n'],TabDat.hdr{2,:});
fmt = strtrim(TabDat.fmt);
[fmt{2,:}] = deal(','); fmt = [fmt{:}];
fmt = [fmt(1:end-1) '\n']; fmt = strrep(fmt,' ',',');
for i=1:size(TabDat.dat,1)
fprintf(fid,fmt,TabDat.dat{i,:});
end
fclose(fid);
if nargin == 2, open(ofile); end
%======================================================================
case 'setcoords' %-Coordinate change
%======================================================================
% FORMAT tfce_list('SetCoords',xyz,hAx,hReg)
if nargin<3, error('Not enough input arguments.'); end
hAx = varargin{3};
xyz = varargin{2};
UD = get(hAx,'UserData');
HlistXYZ = UD.HlistXYZ(ishandle(UD.HlistXYZ));
%-Set all co-ord strings to black
%------------------------------------------------------------------
set(HlistXYZ,'Color','k');
%-If co-ord matches a string, highlight it in red
%------------------------------------------------------------------
XYZ = get(HlistXYZ,'UserData');
if iscell(XYZ), XYZ = cat(2,XYZ{:}); end
[tmp,i,d] = spm_XYZreg('NearestXYZ',xyz,XYZ);
if d<eps
set(HlistXYZ(i),'Color','r');
end
%======================================================================
case 'label' %-Display atlas labels
%======================================================================
% FORMAT tfce_list('label',atlas)
%-Use atlas to label suprathreshold features
fprintf('*** Use atlas labelling with great caution ***\n');
spm('Pointer','Watch')
xA = spm_atlas('load',varargin{2:end});
% F = spm_figure('GetWin','Satellite');
% spm_figure('Focus',F);
% spm_results_ui('Clear',F);
%
% %-Display activation labels
% %----------------------------------------------------------------------
% FS = spm('FontSizes');
% PF = spm_platform('fonts');
%
% hAx = axes('Parent',F,...
% 'Position',[0.025 0.05 0.95 0.9],...
% 'DefaultTextFontSize',FS(8),...
% 'DefaultTextInterpreter','Tex',...
% 'DefaultTextVerticalAlignment','Baseline',...
% 'Tag','XXXXXXXXXXXXXXX',...
% 'Units','points',...
% 'Visible','off');
%
% AxPos = get(hAx,'Position'); set(hAx,'YLim',[0,AxPos(4)])
% dy = FS(9);
% y = floor(AxPos(4)) - dy;
%
% text(0,y,['Atlas: \it\fontsize{',num2str(FS(9)),'}',xA.info.name],...
% 'FontSize',FS(11),'FontWeight','Bold'); y = y - dy/2;
% line([0 1],[y y],'LineWidth',3,'Color','r'), y = y - 9*dy/8;
%
% set(hAx,'DefaultTextFontName',PF.helvetica,'DefaultTextFontSize',FS(8))
%
% text(0.01,y,'mm mm mm','Fontsize',FS(8));
% text(0.15,y,'label','Fontsize',FS(8));
%
% y = y - dy/2;
% line([0 1],[y y],'LineWidth',1,'Color','r')
% y = y - dy;
% y0 = y;
%
% TabDat = evalin('base','TabDat');
%
% for i=1:size(TabDat.dat,1)
% XYZmm = TabDat.dat{i,12};
% if ~isempty(TabDat.dat{i,5}), fw = 'Bold'; else fw = 'Normal'; end
% h = text(0.01,y,sprintf(TabDat.fmt{12},XYZmm),...
% 'FontWeight',fw);
% lab = spm_atlas('query',xA,XYZmm);
% h = text(0.1,y,strrep(lab,'_','\_'),'FontWeight',fw);
% y = y - dy;
% end
hAx = findobj('Tag','SPMList');
for a=1:numel(hAx)
UD = get(hAx(a),'UserData');
if isempty(UD), continue; end
HlistXYZ = UD.HlistXYZ(ishandle(UD.HlistXYZ));
%-Add contextual menus to coordinates
%------------------------------------------------------------------
for i=1:numel(HlistXYZ)
h = uicontextmenu('Parent',ancestor(hAx(a),'figure'));
XYZmm = get(HlistXYZ(i),'UserData');
%-Consider peak only
%--------------------------------------------------------------
labk = spm_atlas('query',xA,XYZmm);
if ~ischar(labk), warning('Probabilistic atlases not handled yet.'); return; end
hi = uimenu(h,'Label',['<html><b>' labk '</b></html>']);
%-Consider a 10mm sphere around the peak
%--------------------------------------------------------------
[labk,P] = spm_atlas('query',xA,...
struct('def','sphere','spec',10,'xyz',XYZmm));
for j=1:numel(labk)
hj = uimenu(hi,'Label',sprintf('<html><b>%s</b> (%.1f%%)</html>',labk{j},P(j)));
%'Callback',['web(''' spm_atlas('weblink',XYZmm,'') ''',''-notoolbar'');']);
end
set(HlistXYZ(i),'UIContextMenu',h);
end
%-Add contextual menus to clusters
%------------------------------------------------------------------
HlistClust = UD.HlistClust(ishandle(UD.HlistClust));
xSPM = evalin('base','xSPM');
A = spm_clusters(xSPM.XYZ);
for i=1:numel(HlistClust)
hi = uicontextmenu('Parent',ancestor(hAx(a),'figure'));
XYZmm = getfield(get(HlistClust(i),'UserData'),'XYZmm');
[unused,j] = spm_XYZreg('NearestXYZ',XYZmm,xSPM.XYZmm);
[labk, P] = spm_atlas('query',xA,xSPM.XYZmm(:,A==A(j)));
for k=1:numel(labk)
hj = uimenu(hi,'Label',sprintf('<html><b>%s</b> (%.1f%%)</html>',labk{k},P(k)));
end
set(HlistClust(i),'UIContextMenu',hi);
end
end
spm('Pointer','Arrow')
%======================================================================
otherwise %-Unknown action string
%======================================================================