-
Notifications
You must be signed in to change notification settings - Fork 16
/
conn_displayroi.m
4581 lines (4485 loc) · 311 KB
/
conn_displayroi.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 hfig=conn_displayroi(option,varargin)
% internal function ROI-to-ROI results display
%
global CONN_x CONN_gui;
if ~nargin, option='init'; end
hfig=[];
if ~ischar(option), % gui-callback
if ishandle(option)&&isequal(get(option,'type'),'figure'), hfig=option;
else hfig=gcbf;
end
if isempty(hfig), hfig=gcf; end
option=varargin{2};
varargin=varargin(3:end);
margin=nargin-2;
else
margin=nargin;
if isempty(regexpi(option,'^init')), hfig=gcf; end
end
init=false;
initxy=false;
DOSCALEF=true;
switch(lower(option)),
case {'init','initfile','initspm'}
init=true;
ncon=1;
if isempty(CONN_gui)||~isfield(CONN_gui,'font_offset'), conn_font_init; end
if margin>1,
data.source=0; %if numel(varargin)>=2, data.source=varargin{2}; else data.source=[]; end
data.thres=1;
data.side=3;
data.initfile='';
if strcmpi(option,'initfile')
if conn_fileutils('isdir',varargin{1})
if conn_existfile(fullfile(varargin{1},'ROI.mat')), varargin{1}=fullfile(varargin{1},'ROI.mat');
elseif conn_existfile(fullfile(varargin{1},'SPM.mat')), varargin{1}=fullfile(varargin{1},'SPM.mat');
else error('unable to find ROI.mat or SPM.mat file in results directory %s',varargin{1});
end
end
[fpath,fname,fext]=fileparts(varargin{1});
if strcmp([fname,fext],'SPM.mat'), option='initspm'; end
end
%h=conn_msgbox('computing ROI-level results, please wait...','conn_displayroi');
if strcmpi(option,'initfile'),
data.initfile=varargin{1};
results=conn_loadmatfile(varargin{1});
results=results.ROI;
filepath=fileparts(varargin{1});
if isempty(data.source), data.source=0; end
if numel(varargin)>=2, ncon=varargin{2}; end
if numel(varargin)>=3, data.thres=varargin{3}; end
if numel(varargin)>=4, data.side=varargin{4}; end
elseif strcmpi(option,'initspm'),
data.initfile=varargin{1};
filepath=fileparts(varargin{1});
if isempty(filepath), filepath=pwd; end
if isempty(data.source), data.source=0; end
SPM=struct; conn_loadmatfile(varargin{1},'SPM');
SPM_h=permute(SPM.xX_multivariate.h,[3,4,1,2]);
if size(SPM_h,3)>1||size(SPM_h,4)>1, SPM_h=sqrt(sum(abs(SPM_h(:,:,:)).^2,3)); end
SPM_F=permute(SPM.xX_multivariate.F,[3,4,1,2]);
if isfield(SPM.xX_multivariate,'p'), SPM_p=SPM.xX_multivariate.p;
else
SPM_p=nan(size(SPM_F));
idxvalid=~(isnan(SPM_F)|SPM_F==0);
switch(SPM.xX_multivariate.statsname)
case 'T', SPM_p(idxvalid)=spm_Tcdf(-SPM_F(idxvalid),SPM.xX_multivariate.dof);
case 'F', SPM_p(idxvalid)=1-spm_Fcdf(SPM_F(idxvalid),SPM.xX_multivariate.dof(1),SPM.xX_multivariate.dof(2));
case 'X', SPM_p(idxvalid)=1-spm_Xcdf(SPM_F(idxvalid),SPM.xX_multivariate.dof);
end
end
SPM_F(SPM_F==0)=nan;
nrois=size(SPM_F,1);
[fpath,fname,fext]=fileparts(SPM.xY.VY(1).fname);
if isempty(fpath), fpath=filepath; end
info=[];
try, info=conn_jsonread(fullfile(fpath,[fname,fext])); end
if isempty(info)
info.names=arrayfun(@(n)sprintf('ROI#%04d',n),1:nrois,'uni',0);
info.coords=repmat({[0 0 0]},nrois,1);
end
if ~iscell(info.coords), info.coords=num2cell(info.coords,2); end % [nroisx3]
%z=permute(randn([nrois,nrois,size(SPM.xX_multivariate.Zfiles)]),[3,2,4,1]);
vol=conn_fileutils('spm_vol',char(SPM.xX_multivariate.Zfiles));
z=conn_fileutils('spm_read_vols',vol);
z=permute(reshape(z,[nrois,nrois,size(SPM.xX_multivariate.Zfiles)]),[3,2,4,1]); % subjects x rois (targets) x conditions x rois (seeds)
% subjects x rois x conditions
validrois=any(all(all(~isnan(z),1),3),4); % note: eliminates ROIs that have no valid connectivity data with any other ROI
if ~all(validrois)
fprintf('warning: disregarding the following ROIs from this group-level analysis due to missing-data %s\n',sprintf('%s ',info.names{~validrois}));
z=z(:,validrois,:,validrois);
SPM_h=SPM_h(validrois,validrois,:,:);
SPM_F=SPM_F(validrois,validrois,:,:);
SPM_p=SPM_p(validrois,validrois,:,:);
info.names=info.names(validrois);
info.coords=info.coords(validrois);
end
results=struct(...
'xX', struct('isSurface',SPM.xX.isSurface,'isMtx',SPM.xX.isMtx,'SelectedSubjects',SPM.xX.SelectedSubjects,'name',{SPM.xX_multivariate.Xnames},'X',SPM.xX_multivariate.X), ...
'data',z,...
'h', SPM_h,...
'F', SPM_F,...
'p', SPM_p,...
'dof', SPM.xX_multivariate.dof,...
'statsname',SPM.xX_multivariate.statsname,...
'c', SPM.xX_multivariate.C,...
'c2', SPM.xX_multivariate.M,...
'ynames',{SPM.xX_multivariate.Ynames}, ...
'names',{info.names},...
'names2',{info.names},...
'xyz', {info.coords},...
'xyz2',{info.coords} ...
);
if numel(varargin)>=2, ncon=varargin{2}; end
if numel(varargin)>=3, data.thres=varargin{3}; end
else
[results,filepath]=conn_process(varargin{:});
end
if isempty(filepath), data.defaultfilepath=pwd;
else data.defaultfilepath=filepath;
end
if ~isempty(data.initfile)&&isempty(fileparts(data.initfile)), data.initfile=fullfile(data.defaultfilepath,data.initfile); end
%close(h);
else
data.thres=1;
data.side=3;
[filename,filepath]=conn_fileutils('uigetfile','*ROI*.mat');
if ~ischar(filename), return; end
results=conn_loadmatfile(fullfile(filepath,filename));results=results.ROI;
data.initfile=fullfile(filepath,filename);
data.source=0;
if isempty(filepath), data.defaultfilepath=pwd;
else data.defaultfilepath=filepath;
end
end
hmsginit=conn_msgbox('Initializing. Please wait...','conn_displayroi',-1);
data.roifile=fullfile(data.defaultfilepath,'ROI.mat');
if isempty(data.initfile), data.initfile=data.roifile; end
if ~isfield(results(1),'data')||numel(results)>1
if 1 % note: disregard any pre-computed mvpa stats for consistency
data.MVPAh=[];
data.MVPAF=[];
data.MVPAp=[];
data.MVPAdof=[];
data.MVPAstatsname=[];
else
data.MVPAh=cat(1,results.MVPAh);
data.MVPAF=cat(1,results.MVPAF);
data.MVPAp=cat(1,results.MVPAp);
temp={results.MVPAdof};
if any(cellfun('length',temp)>1), temp=cellfun(@(x)[ones(1,max(0,2-length(x))),x(:)'],temp,'uni',0); end
data.MVPAdof=cell2mat(temp(:));
data.MVPAstatsname=results(1).MVPAstatsname;
end
data.h=cat(1,results.h);
data.F=cat(1,results.F);
data.p=cat(1,results.p);
data.dof=cat(1,results.dof);
data.statsname=results(1).statsname;
temp=cat(4,results.y); % subjects x rois (targets) x nconditions x rois (seeds)
data.results=results(1);
data.results.data=temp;
clear temp;
else
data.MVPAh=[];
data.MVPAF=[];
data.MVPAp=[];
data.MVPAdof=[];
data.MVPAstatsname=[];
data.h=results.h;
data.F=results.F;
data.p=results.p;
data.dof=repmat(results.dof,numel(data.F),1);
data.statsname=results.statsname;
data.results=results;
end
if isempty(data.MVPAdof), data.MVPAdofstr={};
elseif ~any(any(diff(data.MVPAdof,1,1),1),2),
if size(data.MVPAdof,2)==1, data.MVPAdofstr=repmat({['(',num2str(data.MVPAdof(1)),')']},numel(data.MVPAdof),1);
else data.MVPAdofstr=repmat({['(',num2str(data.MVPAdof(1,1)),',',num2str(data.MVPAdof(1,2)),')']},size(data.MVPAdof,1),1);
end
else
if size(data.MVPAdof,2)==1, data.MVPAdofstr=arrayfun(@(dof)['(',num2str(dof(1)),')'],data.MVPAdof,'uni',0);
else data.MVPAdofstr=cellfun(@(dof)['(',num2str(dof(1)),',',num2str(dof(2)),')'],num2cell(data.MVPAdof,2),'uni',0);
end
end
if size(data.F,2)>=size(data.F,1)&&max(max(abs(data.F(:,1:size(data.F,1))-data.F(:,1:size(data.F,1))')))<1e-10, data.issymmetric=true; else data.issymmetric=false; end
if strcmp(data.statsname,'T')&&all(data.dof(:)==data.dof(1)), data.p2=nan(size(data.p));data.p2(~isnan(data.F))=spm_Tcdf(data.F(~isnan(data.F)),data.dof(1));
else data.p2=1-data.p;
end
%if size(data.dof,2)>1&&~any(diff(data.dof(:,1))), data.statsname=[data.statsname,'(',num2str(data.dof(1)),')']; end
if ~any(any(diff(data.dof,1,1),1),2),
if size(data.dof,2)==1, data.dofstr=repmat({['(',num2str(data.dof(1)),')']},numel(data.dof),1);
else data.dofstr=repmat({['(',num2str(data.dof(1,1)),',',num2str(data.dof(1,2)),')']},size(data.dof,1),1);
end
else
if size(data.dof,2)==1, data.dofstr=arrayfun(@(dof)['(',num2str(dof(1)),')'],data.dof,'uni',0);
else data.dofstr=cellfun(@(dof)['(',num2str(dof(1)),',',num2str(dof(2)),')'],num2cell(data.dof,2),'uni',0);
end
end
data.names=results(1).names;
data.names=regexprep(data.names,{'_1_1$','^rs\.','^rsREL\.','^aal\.'},'');
data.namesreduced=regexprep(data.names,{'^BA\.(\d+) \(([LR])\)\. .*','^\((-?\d+),(-?\d+),(-?\d+)\)$','^SLrois\.|^aal\.|^atlas\.|^networks\.','\s\(([LlRr])\)','([^\(\)]*[^\.])\s*\(.+\)\s*$'},{'$1$2','($1 $2 $3)','',' ${lower($1)}','$1'});
data.names2=results(1).names2;
data.names2=regexprep(data.names2,{'_1_1$','^rs\.','^rsREL\.','^aal\.'},'');
data.names2reduced=regexprep(data.names2,{'^BA\.(\d+) \(([LR])\)\. .*','^\((-?\d+),(-?\d+),(-?\d+)\)$','^SLrois\.|^aal\.|^atlas\.|^networks\.','\s\(([LlRr])\)','([^\(\)]*[^\.])\s*\(.+\)\s*$'},{'$1$2','($1 $2 $3)','',' ${lower($1)}','$1'});
data.xyz=cat(1,results(1).xyz{:});
data.xyz2=cat(1,results(1).xyz2{:});
data.displaytheserois=1:length(data.names);
data.tfceZ=[];
data.tfceZpeaks=[];
data.tfceZd=[];
data.cMVPAh=[];
data.cMVPAF=[];
data.cMVPAp=[];
data.thr=.01;
data.thrtype=1;
data.mvpathr=.05;
data.mvpathrtype=6;
data.thres_defaults={ {.05,1,.05,32}, {.01,1,.05,6}, {.05,4,0,1}, {.05,2,0,1}, {.01,1,.05,30}, {.001,1,.05,15} };
if ~isempty(data.thres),
if iscell(data.thres)
[data.thr,data.thrtype,data.mvpathr,data.mvpathrtype]=deal(data.thres{:});
data.thres=numel(data.thres_defaults)+1;
else
[data.thr,data.thrtype,data.mvpathr,data.mvpathrtype]=deal(data.thres_defaults{data.thres}{:});
data.side=3;
end
end
data.mvpasortresultsby=2;
data.mvpathrtype_all={'none',...
'cluster-level p-uncorrected (SPC TFCE score)', 'cluster-level p-FDR corrected (SPC TFCE score)', 'cluster-level p-FWE corrected (SPC TFCE score)',...
'cluster-level p-uncorrected (SPC mass/intensity)', 'cluster-level p-FDR corrected (SPC mass/intensity)', 'cluster-level p-FWE corrected (SPC mass/intensity)',...
'cluster-level p-uncorrected (SPC size)', 'cluster-level p-FDR corrected (SPC size)', 'cluster-level p-FWE corrected (SPC size)',...
'network-level p-uncorrected (NBS TFCE score)', 'network-level p-FDR corrected (NBS TFCE score)', 'network-level p-FWE corrected (NBS TFCE score)',...
'network-level p-uncorrected (NBS mass/intensity)', 'network-level p-FDR corrected (NBS mass/intensity)', 'network-level p-FWE corrected (NBS mass/intensity)',...
'network-level p-uncorrected (NBS size)', 'network-level p-FDR corrected (NBS size)', 'network-level p-FWE corrected (NBS size)',...
'ROI-level p-uncorrected (ROI TFCE score)', 'ROI-level p-FDR corrected (ROI TFCE score)', 'ROI-level p-FWE corrected (ROI TFCE score)',...
'ROI-level p-uncorrected (ROI mass/intensity)', 'ROI-level p-FDR corrected (ROI mass/intensity)', 'ROI-level p-FWE corrected (ROI mass/intensity)',...
'ROI-level p-uncorrected (ROI size)', 'ROI-level p-FDR corrected (ROI size)', 'ROI-level p-FWE corrected (ROI size)',...
'ROI-level p-uncorrected (MVPA omnibus test)', 'ROI-level p-FDR corrected (MVPA omnibus test)',...
'cluster-level p-uncorrected (MVPA omnibus test)', 'cluster-level p-FDR corrected (MVPA omnibus test)'};
data.mvpathrtype_isnonparam=ismember(1:numel(data.mvpathrtype_all),[2:28]);
data.mvpathrtype_iscluster=ismember(1:numel(data.mvpathrtype_all),[2:10,31:32]);
data.mvpathrtype_isnetwork=ismember(1:numel(data.mvpathrtype_all),11:19);
data.mvpathrtype_isroi=ismember(1:numel(data.mvpathrtype_all),[20:28,29:30]);
data.mvpathrtype_isce=ismember(1:numel(data.mvpathrtype_all),[2:4,11:13,20:22]);
data.mvpathrtype_ismass=ismember(1:numel(data.mvpathrtype_all),[5:7,14:16,23:25]);
data.mvpathrtype_issize=ismember(1:numel(data.mvpathrtype_all),[8:10,17:19,26:28]);
data.mvpathrtype_isftest=ismember(1:numel(data.mvpathrtype_all),[29:30,31:32]);
data.mvpathrtype_shown=[14:16,31:32,5:7,29:30,23:25,1]; %[15,24,6,1];
%data.mvpaside=3;
data.PERM=[];
data.iPERM=[];
data.clusters=[];
data.view=0;
data.proj=[];
data.x=[];
data.y=[];
data.z=[];
data.bgz=0;
data.maxz=[];
data.display='connectivity';
%data.displayreduced=0;
%data.displaytheserois=1:length(data.names2);
data.displayreduced=1;
data.displaylabels=1;
data.displaybrains=1;
data.display3d=0;
data.displaygui=1;
data.pausegui=1;
data.mvpaenablethr=1;
data.enablethr=1;
data.displayconnectionstats=0;
data.displayroilabelsinstats=0;
data.displayallmeasures=0;
data.visible='on';
data.plotposition={[.01,.27,.53,.60],[.01,.05,.88,.9]};
data.plotconnoptions.menubar=false;
data.plotconnoptions.LINEWIDTH=2;
data.plotconnoptions.LINESTYLEMTX=0;
data.plotconnoptions.DOFFSET=.35;
data.plotconnoptions.BSCALE=.25;
data.plotconnoptions.BTRANS=.10;
data.plotconnoptions.LTRANS=1;
data.plotconnoptions.RSCALE=.75;
data.plotconnoptions.LCOLOR=3;
data.plotconnoptions.LCOLORSCALE=1;
data.plotconnoptions.LCURVE=2;
data.plotconnoptions.LBUNDL=.5;
data.plotconnoptions.FONTSIZE=max(4,[0,1]+4+CONN_gui.font_offset);
data.plotconnoptions.FONTANGLE=0;
if 1, data.plotconnoptions.BCOLOR=.975*[1,1,1];
elseif isfield(CONN_gui,'backgroundcolor'), data.plotconnoptions.BCOLOR=CONN_gui.backgroundcolor;
else data.plotconnoptions.BCOLOR=[0.12 0.126 0.132];
end
data.plotconnoptions.NPLOTS=12;
data.plotconnoptions.Projections={[0,-1,0;0,0,1;-1,0,0],[1,0,0;0,0,1;0,1,0],[1,0,0;0,1,0;0,0,1]};
data.plotconnoptions.nprojection=1;
data.plotconnoptions.Projections_axes={{'y','z'},{'x','z'},{'x','y'}};
FSfolder=fullfile(fileparts(which('conn')),'utils','surf');
rend(1)=reducepatch(conn_surf_readsurf(fullfile(FSfolder,'lh.pial.surf')),.02,'fast');
rend(2)=reducepatch(conn_surf_readsurf(fullfile(FSfolder,'rh.pial.surf')),.02,'fast');
%[xyz,faces]=read_surf(fullfile(FSfolder,'lh.cortex.surf'));
%rend(1)=reducepatch(struct('vertices',xyz,'faces',faces+1),.02,'fast');
%[xyz,faces]=read_surf(fullfile(FSfolder,'rh.cortex.surf'));
%rend(2)=reducepatch(struct('vertices',xyz,'faces',faces+1),.02,'fast');
data.plotconnoptions.rende=struct('vertices',cat(1,rend.vertices),'faces',[rend(1).faces; size(rend(1).vertices,1)+rend(2).faces]);
data.xy2=200*[cos(2*pi*(0:numel(data.displaytheserois)-1)'/numel(data.displaytheserois)),sin(2*pi*(0:numel(data.displaytheserois)-1)'/numel(data.displaytheserois))];
data.xy2_clusters=[];
if isfield(CONN_gui,'refs')&&isfield(CONN_gui.refs,'canonical')&&isfield(CONN_gui.refs.canonical,'filename')&&~isempty(CONN_gui.refs.canonical.filename)
filename=CONN_gui.refs.canonical.filename;
else
filename=fullfile(fileparts(which('spm')),'canonical','avg152T1.nii');
end
data.ref=spm_vol(filename);
color1=data.plotconnoptions.BCOLOR;
color2=color1; %.975*[1 1 1];
color3=color2+(.5-color2)*.15; %.9*[1 1 1];
foregroundcolor=.5*.8+.2*(1-round(color1));
%if all(data.plotconnoptions.BCOLOR>.8), color2=data.plotconnoptions.BCOLOR;
%else color2=.94*[1,1,1];
%end
%color1=[.5/6,1/6,2/6];
%color2=[.5/6,1/6,2/6];
hmsg=[];%figure('units','norm','position',[.01,.1,.98,.8],'numbertitle','off','name','ROI second-level results. Initializing...','color',color1,'colormap',gray,'menubar','none','toolbar','none','interruptible','off');
h0=get(0,'screensize');
hfig=figure('visible','off','renderer','opengl','units','pixels','position',[h0(3)-.75*h0(3)+2,h0(4)-.9*h0(4)-48,.75*h0(3)-2*2,.9*h0(4)]);
%h0=get(0,'screensize'); h0=h0(1,3:4)-h0(1,1:2)+1; h0=h0/max(1,max(abs(h0))/2000);
%minheight=500;
%hfig=figure('visible','off','renderer','opengl','units','pixels','position',[0*72+1,h0(2)-max(minheight,.5*h0(1))-48,h0(1)-0*72-1,max(minheight,.5*h0(1))]);
data.hfig=hfig;
set(hfig,'units','norm','numbertitle','off','name',['ROI second-level results explorer ',data.defaultfilepath],'color',color1,'colormap',gray,'menubar','none','toolbar','none','interruptible','off','tag','conn_displayroi','keypressfcn',@conn_displayroi_keypress,'windowbuttondownfcn',@(varargin)conn_display_windowbuttonmotionfcn('down'),'windowbuttonupfcn',@(varargin)conn_display_windowbuttonmotionfcn('up'),'visible','on');
%uicontrol('style','frame','units','norm','position',[.0,.95,.5,.05],'backgroundcolor',color2,'foregroundcolor',color2);
hframe1=uicontrol('style','frame','units','norm','position',[0,0,1,.27],'backgroundcolor',color2,'foregroundcolor',color2,'parent',data.hfig);
hframe2=uicontrol('style','frame','units','norm','position',[0,.87,1,.13],'backgroundcolor',color3,'foregroundcolor',color3,'parent',data.hfig);
hframe3=0;%uicontrol('style','frame','units','norm','position',[.62,.35,.33,.45],'backgroundcolor',1*[1 1 1],'foregroundcolor',.85*[1,1,1],'parent',data.hfig);
huicontrol_cthr=uicontrol('style','popupmenu','units','norm','position',[.20,.965,.605,.03],'string',{...
'standard settings for cluster-based inferences #1: Functional Network Connectivity',...
'standard settings for cluster-based inferences #2: Spatial Pairwise Clustering',...
'standard settings for cluster-based inferences #3: Threshold Free Cluster Enhancement',...
'alternative settings for connection-based inferences: parametric univariate statistics ',...
'alternative settings for ROI-based inferences: parametric multivariate statistics',...
'alternative settings for network-based inferences: Network Based Statistics',...
'<HTML><i>customize (advanced Family-Wise Error control settings)</i></HTML>'},'tag','highlight','fontname','arial','fontsize',8+CONN_gui.font_offset,'callback',{@conn_displayroi,'fwec.option'},'value',data.thres,'tooltipstring','Select false-positive control method','backgroundcolor',.9*[1,1,1]);
huicontrol_cthr0=uicontrol('style','text','units','norm','position',[.03,.925,.17,.03],'fontsize',8+CONN_gui.font_offset,'string','connection threshold: p < ','horizontalalignment','right','fontweight','bold','foregroundcolor',1-color3,'backgroundcolor',color3,'interruptible','off','parent',data.hfig);
huicontrol_cthr1=uicontrol('style','edit','units','norm','position',[.20,.925,.10,.03],'fontsize',8+CONN_gui.font_offset,'string',num2str(data.thr),'foregroundcolor',1-color3,'backgroundcolor',color3,'interruptible','off','callback',{@conn_displayroi,'fwec.connectionlevel.value'},'tooltipstring','Connection-level threshold value (false-positive threshold value for individual connections)','parent',data.hfig);
huicontrol_cthr2=uicontrol('style','popupmenu','units','norm','position',[.325,.915,.25,.04],'fontsize',8+CONN_gui.font_offset,'string',{'p-uncorrected','p-FDR corrected','p-FDR corrected (TFCE)','p-FWE corrected (TFCE)','F/T/X stat'},'foregroundcolor',1-color3,'backgroundcolor',color3,'tooltipstring','<HTML>False-positive control type for individual connections</HTML>','interruptible','off','callback',{@conn_displayroi,'fwec.connectionlevel.type'},'value',max(1,min(5, data.thrtype)),'parent',data.hfig);
huicontrol_cthr3=uicontrol('style','popupmenu','units','norm','position',[.605,.915,.20,.04],'fontsize',8+CONN_gui.font_offset,'string',{'positive contrast (one-sided)','negative contrast (one-sided)','two-sided'},'foregroundcolor',1-color3,'backgroundcolor',color3,'tooltipstring','Analysis results directionality','interruptible','off','callback',{@conn_displayroi,'fwec.connectionlevel.side'},'value',data.side,'parent',data.hfig);
huicontrol_ccthr0=uicontrol('style','text','units','norm','position',[.03,.885,.17,.03],'fontsize',8+CONN_gui.font_offset,'string','cluster threshold: p < ','horizontalalignment','right','fontweight','bold','foregroundcolor',1-color3,'backgroundcolor',color3,'fontweight','bold','interruptible','off','parent',data.hfig);
huicontrol_ccthr1=uicontrol('style','edit','units','norm','position',[.20,.885,.10,.03],'fontsize',8+CONN_gui.font_offset,'string',num2str(data.mvpathr),'foregroundcolor',1-color3,'backgroundcolor',color3,'interruptible','off','callback',{@conn_displayroi,'fwec.clusterlevel.value'},'tooltipstring','<HTML>Cluster-level threshold value (false-positive threshold value for individual clusters/groups of connections)','parent',data.hfig);
huicontrol_ccthr2=uicontrol('style','popupmenu','units','norm','position',[.325,.875,.48,.04],'fontsize',8+CONN_gui.font_offset,'string',data.mvpathrtype_all(data.mvpathrtype_shown),'value',find(data.mvpathrtype_shown==data.mvpathrtype),'foregroundcolor',1-color3,'backgroundcolor',color3,'tooltipstring',...
['<HTML>Type of cluster- or ROI- level false-positive control',...
'<br/> <br/> - choose <i>network</i> measures for <b>non-parametric network-level inferences</b> (NBS: Network Based Statistics, Zalesky et al. 2010)<br/> Networks represent maximal subgraphs of suprathreshold-connected ROIs (groups of ROIs and suprathreshold effects/connections among them)<br/> Network size and Network mass measures both represent measures of degree/cost of these subgraphs (i.e. number and strength of suprathreshold effects/connections within each graph) <br/> Network TFCE scores represent a combined measure of network size and mass, defined as the Threshold Free Cluster Enhancement score for the chosen support section (Smith and Nichols 2009) <br/> Multiple comparison correction is implemented at the network-level (FWE/FDR across multiple networks). Network-level inferences remain valid when used in combination with arbitrary (e.g. p-uncorrected) connection thresholds<br/> e.g. <b>connection-level threshold p < 0.01 (p-uncorrected) & cluster-threshold p < 0.05 (network p-FDR corrected)</b>',...
'<br/> <br/> - choose <i>cluster</i> measures for <b>parametric cluster-level inferences</b> (FNC: Functional Network Connetivity, Jafri et al. 2008)<br/> Clusters represent groups of effects/connections within- or between- networks (networks here refers to groups of ROIs)<br/> MVPA omnibus-test represents a multivariate measure characterizing the strength of all effects/connections within a network or between two networks<br/> Multiple comparison correction is implemented at the cluster-level (FWE/FDR across multiple clusters). Cluster-level inferences remain valid when used in combination with arbitrary (e.g. p-uncorrected) connection thresholds<br/> e.g. <b>connection-level threshold p < 0.05 (p-uncorrected) & cluster-threshold p < 0.05 (cluster p-FDR corrected)</b>',...
'<br/> <br/> - choose <i>cluster</i> measures for <b>non-parametric cluster-level inferences</b> (SPC: Spatial Pairwise Clustering, Zalesky et al. 2012)<br/> Clusters represent groups of suprathreshold effects/connections<br/> Cluster size and cluster mass measures both represent measures of degree/cost of these clusters (i.e. number and strength of suprathreshold effects/connections within each cluster)<br/> Cluster TFCE scores represent a combined measure of cluster size and mass, defined as the Threshold Free Cluster Enhancement score for the chosen support section (Smith and Nichols 2009) <br/> Multiple comparison correction is implemented at the cluster-level (FWE/FDR across multiple clusters). Cluster-level inferences remain valid when used in combination with arbitrary (e.g. p-uncorrected) connection thresholds<br/> e.g. <b>connection-level threshold p < 0.01 (p-uncorrected) & cluster-threshold p < 0.05 (cluster p-FDR corrected)</b>',...
'<br/> <br/> - choose <i>ROI</i> for <b>parametric or non-parametric ROI-level inferences</b><br/> MVPA omnibus-test represents a multivariate measure characterizing the strength of all effects/connections from each ROI<br/> ROI size and ROI mass measures both represent measures of degree/cost of each ROI (i.e. number and strength of suprathreshold effects/connections from each ROI)<br/> ROI TFCE scores represent a combined measure of ROI size and mass, defined as the Threshold Free Cluster Enhancement score for the chosen support section (Smith and Nichols 2009) <br/> Multiple comparison correction is implemented at the ROI-level (FWE/FDR across multiple ROIs). ROI-level inferences are invariant to the choice of connection-level threshold<br/> e.g. <b>connection-level threshold p < 0.01 (p-uncorrected) & cluster-threshold p < 0.05 (ROI p-FDR corrected)</b>',...
'<br/> <br/> - choose <i>none</i> for <b>parametric connection-level inferences</b> <br/> This option is only appropriately corrected for multiple comparisons when used in combination with p-FDR corrected connection thresholds (but not with p-uncorrected connection thresholds)<br/> e.g. <b>connection-level threshold p < 0.05 (p-FDR corrected) & cluster-threshold none</b><br/></HTML>'],...
'interruptible','off','callback',{@conn_displayroi,'fwec.clusterlevel.type'},'value',max([1,find(data.mvpathrtype_shown==data.mvpathrtype,1)]),'parent',data.hfig);
huicontrol_cthr4=uicontrol('style','checkbox','units','norm','position',[.88,.87,.12,.03],'string','show details','tag','highlight','value',0,'fontsize',8+CONN_gui.font_offset,'horizontalalignment','right','foregroundcolor',1-color3,'backgroundcolor',color3,'callback',{@conn_displayroi,'advancedthr'},'tooltipstring','Displays advanced thresholding options');
hhelp=uicontrol('style','pushbutton','units','norm','position',[.81,.965,.02,.03],'fontsize',7+CONN_gui.font_offset,'foregroundcolor',foregroundcolor,'backgroundcolor',color2,'string','?','tag','highlight','tooltipstring','<HTML>Documentation about available methods of statistical inference</HTML>','interruptible','off','callback',@(varargin)conn('gui_help','url','http://www.conn-toolbox.org/fmri-methods/cluster-level-inferences'),'parent',data.hfig);
%huicontrol_ccthr3=uicontrol('style','popupmenu','units','norm','position',[.66,.35,.33,.04],'fontsize',8+CONN_gui.font_offset,'string',{'threshold seed ROIs (F-test)','threshold seed ROIs (NBS; by intensity)','threshold seed ROIs (NBS; by size)','threshold networks (NBS; by intensity)','threshold networks (NBS; by size)'},'foregroundcolor',1-color2,'backgroundcolor',color2,'fontweight','bold','horizontalalignment','right','value',data.mvpathrmeasure,'tooltipstring','Threshold individual seed ROIs or individual networks (subsets of connected ROIs)','interruptible','off','callback',{@conn_displayroi,'mvpathrmeasure'},'parent',data.hfig);
data.handles=[...
huicontrol_cthr,...
huicontrol_cthr1,...
huicontrol_cthr2,...
huicontrol_cthr3,...
uicontrol('style','text','units','norm','position',[.15,.875,.70,.07],'fontsize',7+CONN_gui.font_offset,'string','','foregroundcolor',.5*[1 1 1],'backgroundcolor',color3,'horizontalalignment','center','parent',data.hfig),...
huicontrol_cthr4, ... %0, ...%uicontrol('style','listbox','units','norm','position',[.57,.31,.41,.39],'fontsize',8+CONN_gui.font_offset,'string',' ','max',2,'foregroundcolor',.9-.8*color2,'backgroundcolor',color2,'tooltipstring','Selecting one or several seed ROIs limits the analyses only to the connectivity between the selected seeds and all of the ROIs in the network','interruptible','off','callback',{@conn_displayroi,'list1'},'keypressfcn',@conn_menu_search,'visible','off','parent',data.hfig),...
uicontrol('style','text','units','norm','position',[.05,.22,.90,.03],'fontsize',7+CONN_gui.font_offset,'string',sprintf('%-24s %-20s %+12s %+12s %+12s','Analysis Unit','Statistic','p-unc','p-FDR','p-FWE'),'foregroundcolor',.5*[1 1 1],'backgroundcolor',color2,'fontname','monospaced','horizontalalignment','left','parent',data.hfig),...
uicontrol('style','listbox','units','norm','position',[.05,.07,.90,.15],'fontsize',7+CONN_gui.font_offset,'string',' ','tag','highlight','fontname','monospaced','foregroundcolor',round(1-color2),'backgroundcolor',color2,'tooltipstring','Statistics for each connection, ROI, or cluster. Right-click to export table to .txt file','max',2,'interruptible','off','callback',{@conn_displayroi,'list2'},'keypressfcn',@conn_menu_search,'parent',data.hfig),...
uicontrol('style','checkbox','units','norm','position',[.05,.04,.20,.03],'fontsize',8+CONN_gui.font_offset,'string','display extended stats','tag','highlight','foregroundcolor',1-color2,'backgroundcolor',color2,'interruptible','off','callback',{@conn_displayroi,'displayconnectionstats'},'value',data.displayconnectionstats,'tooltipstring','Check to display additional and post-hoc statistics for all suprathreshold units','parent',data.hfig),... %uicontrol('style','text','units','norm','position',[.61,.50,.38,.04],'fontsize',8+CONN_gui.font_offset,'string','Define thresholds:','foregroundcolor',color2,'backgroundcolor',1-.5*color2,'fontweight','bold','horizontalalignment','left','parent',data.hfig),...
uicontrol('style','text','units','norm','position',[.64,.76,.14,.03],'string','Display&Print','horizontalalignment','center','fontweight','bold','fontname','arial','fontsize',9+CONN_gui.font_offset,'foregroundcolor',foregroundcolor,'backgroundcolor',color2,'parent',data.hfig),... %uicontrol('style','pushbutton','units','norm','position',[.84,.05,.14,.04],'fontsize',8+CONN_gui.font_offset,'string','non-parametric stats','callback',{@conn_displayroi,'enableperm'},'tooltipstring','Enables permutation-test based statistics (Cluster and ROI size/mass statistics)','parent',data.hfig),...
uicontrol('style','text','units','norm','position',[.80,.76,.14,.03],'string','Tools','horizontalalignment','center','fontweight','bold','fontname','arial','fontsize',9+CONN_gui.font_offset,'foregroundcolor',foregroundcolor,'backgroundcolor',color2,'parent',data.hfig),... %uicontrol('style','text','units','norm','position',[.61,.95,.38,.04],'fontsize',8+CONN_gui.font_offset,'string','Define connectivity matrix:','foregroundcolor',color2,'backgroundcolor',1-.5*color2,'fontweight','bold','horizontalalignment','left','parent',data.hfig),...
uicontrol('style','pushbutton','units','norm','position',[.64,.40,.29,.04],'fontsize',7+CONN_gui.font_offset,'foregroundcolor',foregroundcolor,'backgroundcolor',color2,'string',sprintf('Analysis of %d connections among %d ROIs',numel(data.names)*(numel(data.names)-1)/2*(1+~data.issymmetric),numel(data.names)),'tag','highlight','tooltipstring','<HTML>Defines subset of ROIs to include in these analyses (among all the sources selected in the first-level analysis definition)<br/>note: this choice affects all inferences</HTML>','interruptible','off','callback',{@conn_displayroi,'roi.select'},'parent',data.hfig),...
uicontrol('style','checkbox','units','norm','position',[.25,.04,.20,.03],'fontsize',8+CONN_gui.font_offset,'string','display extended roi labels','tag','highlight','foregroundcolor',1-color2,'backgroundcolor',color2,'interruptible','off','callback',{@conn_displayroi,'displayroilabelstats'},'value',data.displayroilabelsinstats,'visible','off','tooltipstring','Check to include complete labels when describing ROIs','parent',data.hfig),... %uicontrol('style','pushbutton','units','norm','position',[.61,.10,.38,.04],'fontsize',8+CONN_gui.font_offset,'string','Select all','tooltipstring','Looks at the connectivity between all ROIs in the network','interruptible','off','callback',{@conn_displayroi,'selectall'},'parent',data.hfig),...
uicontrol('style','pushbutton','units','norm','position',[.64,.36,.29,.04],'fontsize',7+CONN_gui.font_offset,'foregroundcolor',foregroundcolor,'backgroundcolor',color2,'string','ROIs sorted using hierarchical clustering','tag','highlight','tooltipstring','<HTML>Defines ROIs order and clusters<br/>note: this choice affects all cluster-based inferences (but not connection- ROI- or network-based inferences)</HTML>','interruptible','off','callback',{@conn_displayroi,'roi.order'},'parent',data.hfig),...
huicontrol_ccthr1,...
huicontrol_ccthr2,...
uicontrol('style','pushbutton','units','norm','position',[.80,.68,.13,.04],'fontsize',8+CONN_gui.font_offset,'string','Export mask','tag','highlight','foregroundcolor',foregroundcolor,'backgroundcolor',color2,'callback',{@conn_displayroi,'export_mask'},'tooltipstring','Exports list of suprathreshold connections in ROI-to-ROI connectivity matrix','parent',data.hfig),... %0,...%uicontrol('style','popupmenu','units','norm','position',[.68,.34,.15,.04],'fontsize',8+CONN_gui.font_offset,'string',{'connection-level results','seed-level results','network-level results'},'foregroundcolor',1-color2,'backgroundcolor',color2,'tooltipstring','Criteria for sorting results in statistics table','interruptible','off','callback',{@conn_displayroi,'mvpasort'},'value',data.mvpasortresultsby),...
uicontrol('style','pushbutton','units','norm','position',[.80,.72,.13,.04],'fontsize',8+CONN_gui.font_offset,'string','Import values','tag','highlight','foregroundcolor',foregroundcolor,'backgroundcolor',color2,'callback',{@conn_displayroi,'import_values'},'tooltipstring','Imports individual connectivity values for each suprathreshold connection and for each subject into CONN toolbox as second-level covariates','parent',data.hfig),... %uicontrol('style','checkbox','units','norm','position',[.61,.36,.03,.03],'fontsize',8+CONN_gui.font_offset,'foregroundcolor',1-color2,'backgroundcolor',color2,'interruptible','off','callback',{@conn_displayroi,'mvpaenablethr'},'value',data.mvpaenablethr,'tooltipstring','Enable Seed/Network threshold','parent',data.hfig)...
uicontrol('style','pushbutton','units','norm','position',[.80,.64,.13,.04],'fontsize',8+CONN_gui.font_offset,'string','Export data','tag','highlight','foregroundcolor',foregroundcolor,'backgroundcolor',color2,'callback',{@conn_displayroi,'export_data'},'tooltipstring','Exports all connectvity values (entire ROI-to-ROI matrix) for each individual subject and condition to matrix NIFTI file','parent',data.hfig),...
hframe1,...%uicontrol('style','pushbutton','units','norm','position',[0,0,.10,.025],'fontsize',8+CONN_gui.font_offset,'backgroundcolor',get(hfig,'color'),'string','display options','tooltipstring','Controls the way functional results are displayed (right-click on figure to get this same menu and remove this button)','callback','set(findobj(gcbf,''type'',''uicontextmenu'',''tag'',''conn_displayroi_plot''),''visible'',''on'')'),...
uicontrol('style','text','units','norm','position',[.05,0,.90,.03],'string','','foregroundcolor',1-color2,'backgroundcolor',color2,'parent',data.hfig),...
huicontrol_cthr0,...
huicontrol_ccthr0,...
hframe2,...
hframe3, ...
uicontrol('style','pushbutton','units','norm','position',[.71,.695,.06,.05],'string','Ring Print','tag','highlight','fontname','arial','fontweight','bold','fontsize',8+CONN_gui.font_offset,'callback',{@conn_displayroi,'ring_print'},'tooltipstring','<HTML><b>Ring print</b><br/>Prints current results on ROI-ring display</HTML>','parent',data.hfig), ...
uicontrol('style','pushbutton','units','norm','position',[.64,.530,.06,.05],'string','Glass display','tag','highlight','fontname','arial','fontweight','bold','fontsize',8+CONN_gui.font_offset,'callback',{@conn_displayroi,'glass_view'},'tooltipstring','<HTML><b>Glass display</b><br/>Displays current results on 3d glass-brain</HTML>','parent',data.hfig), ...
uicontrol('style','pushbutton','units','norm','position',[.71,.530,.06,.05],'string','Glass print','tag','highlight','fontname','arial','fontweight','bold','fontsize',8+CONN_gui.font_offset,'callback',{@conn_displayroi,'glass_print'},'tooltipstring','<HTML><b>Glass print</b><br/>Prints current results on 3d glass-brain</HTML>','parent',data.hfig), ...
uicontrol('style','pushbutton','units','norm','position',[.64,.475,.06,.05],'string','Plot effects','tag','highlight','fontname','arial','fontsize',8+CONN_gui.font_offset,'callback',{@conn_displayroi,'cluster_view'},'tooltipstring','<HTML><b>Plot effects</b><br/>Explores/displays average effect sizes within each suprathreshold cluster or connection</HTML>'),...
uicontrol('style','pushbutton','units','norm','position',[.71,.475,.06,.05],'string','Plot design','tag','highlight','fontname','arial','fontsize',8+CONN_gui.font_offset,'callback',{@conn_displayroi,'plot_design'},'tooltipstring','<HTML><b>Plot design</b><br/>Displays General Linear Model design matrix and additional details</HTML>'), ...
uicontrol('style','pushbutton','units','norm','position',[.80,.58,.13,.04],'string','Bookmark','tag','highlight','foregroundcolor',foregroundcolor,'backgroundcolor',color2,'fontname','arial','fontsize',8+CONN_gui.font_offset,'callback',{@conn_displayroi,'bookmark'},'tooltipstring','Bookmark this second-level results explorer view'),...
uicontrol('style','pushbutton','units','norm','position',[.80,.54,.13,.04],'string','Open folder','tag','highlight','foregroundcolor',foregroundcolor,'backgroundcolor',color2,'fontname','arial','fontsize',8+CONN_gui.font_offset,'callback',{@conn_displayroi,'openfolder'},'tooltipstring','Open folder containing current second-level results files'), ...
uicontrol('style','pushbutton','units','norm','position',[.80,.50,.13,.04],'string','Graphic options','tag','highlight','foregroundcolor',foregroundcolor,'backgroundcolor',color2,'fontname','arial','fontsize',8+CONN_gui.font_offset,'callback',{@conn_displayroi,'menubar'},'tooltipstring','Show/hide menubar for advanced display/graphic options'), ...
uicontrol('style','pushbutton','units','norm','position',[.64,.640,.06,.05],'string','Matrix display','tag','highlight','fontname','arial','fontweight','bold','fontsize',8+CONN_gui.font_offset,'callback',{@conn_displayroi,'matrix_view'},'tooltipstring','<HTML><b>Matrix display</b><br/>Displays current results on ROI-to-ROI matrix display</HTML>','parent',data.hfig), ...
uicontrol('style','pushbutton','units','norm','position',[.71,.640,.06,.05],'string','Matrix print','tag','highlight','fontname','arial','fontweight','bold','fontsize',8+CONN_gui.font_offset,'callback',{@conn_displayroi,'matrix_print'},'tooltipstring','<HTML><b>Matrix print</b><br/>Prints current results on ROI-to-ROI matrix display</HTML>','parent',data.hfig), ...
uicontrol('style','pushbutton','units','norm','position',[.64,.695,.06,.05],'string','Ring Display','tag','highlight','fontname','arial','fontweight','bold','fontsize',8+CONN_gui.font_offset,'callback',{@conn_displayroi,'ring_view'},'tooltipstring','<HTML><b>Ring display</b><br/>Displays current results on ROI-ring display</HTML>','parent',data.hfig), ...
uicontrol('style','pushbutton','units','norm','position',[.64,.585,.06,.05],'string','Lines display','tag','highlight','fontname','arial','fontweight','bold','fontsize',8+CONN_gui.font_offset,'callback',{@conn_displayroi,'lines_view'},'tooltipstring','<HTML><b>Connections display</b><br/>Displays current results on ROI-to-ROI connections display</HTML>','parent',data.hfig), ...
uicontrol('style','pushbutton','units','norm','position',[.71,.585,.06,.05],'string','Lines print','tag','highlight','fontname','arial','fontweight','bold','fontsize',8+CONN_gui.font_offset,'callback',{@conn_displayroi,'lines_print'},'tooltipstring','<HTML><b>Connections print</b><br/>Prints current results on ROI-to-ROI connections display</HTML>','parent',data.hfig) ...
];
uiwrap(hhelp);
uiwrap(data.handles([8, 12,14, 17,18,19,31,32,33]));
bp=[36 26 27 28 34 35 29 30 37 38 ];
bp_isprint=[0 1 0 1 0 1 0 0 0 1];
temp=imread(fullfile(fileparts(which(mfilename)),sprintf('conn_vproject_icon%02d.jpg',0))); temp=double(temp); printmask=round(temp/255);
for n1=1:numel(bp),
set(data.handles(bp(n1)),'units','pixel'); pt=get(data.handles(bp(n1)),'position'); set(data.handles(bp(n1)),'units','norm');
temp=imread(fullfile(fileparts(which(mfilename)),sprintf('conn_displayroi_icon%02d.jpg',n1))); temp=double(temp); temp=temp/255; temp=max(0,min(1,(temp).^.5)); ft=min(size(temp,1)/ceil(pt(4)),size(temp,2)/ceil(pt(3))); if any(n1==[1,2]), ft=0.95*ft; elseif any(n1==[9,10]), ft=.90*ft; else ft=.70*ft; end;
maxtemp=1;%mode(round(temp(:)*100))/100;
if maxtemp<.5, temp=1-temp; maxtemp=1-maxtemp; end
temp=max(0,min(.95, .75*temp+.25*temp/maxtemp.*repmat(shiftdim(color1,-1),[size(temp,1),size(temp,2),1,size(temp,4)]) ));
if bp_isprint(n1)
if ismember(n1,[2,4,6,10]), tempprintmask=printmask(ceil(size(printmask,1)/4)+(1:ceil(size(printmask,1)/2)),ceil(size(printmask,2)/4)+(1:ceil(size(printmask,2)/2))); else tempprintmask=printmask; end
temp=.75*mean(color1)+.25*temp;
if size(temp,1)>size(temp,2), temp=temp(1:size(temp,2),:,:); end
temp(:,ceil(size(temp,2)/2+(1:size(temp,1))-size(temp,1)/2),:)=max(0,temp(:,ceil(size(temp,2)/2+(1:size(temp,1))-size(temp,1)/2),:)+(1-2*mean(color1))*repmat(.5*tempprintmask(round(linspace(1,size(tempprintmask,1),size(temp,1))),round(linspace(1,size(tempprintmask,2),size(temp,1)))),[1,1,3]));
end
tempr1=round(1:ft/10:size(temp,1)); tempr1=tempr1(1:floor(numel(tempr1)/10)*10);
tempr2=round(1:ft/10:size(temp,2)); tempr2=tempr2(1:floor(numel(tempr2)/10)*10);
temp=permute(mean(mean(reshape(temp(tempr1,tempr2,:),[10,numel(tempr1)/10,10,numel(tempr2)/10,size(temp,3)]),1),3),[2,4,5,1,3]);
str=get(data.handles(bp(n1)),'string'); set(data.handles(bp(n1)),'cdata',temp,'string','');
end
if data.thrtype==5, set(data.handles(22),'string',['connection threshold: ',data.statsname,' > ']);
elseif data.mvpathr==1, set(data.handles(22),'string','connection threshold: ');
else set(data.handles(22),'string','connection threshold: p < ');
end
set(data.handles([2,3,4,15,16,22,23]),'visible','off');
hc1=uicontextmenu('parent',hfig);
uimenu(hc1,'Label','Export table','callback',@(varargin)conn_exportlist(data.handles(8),'',get(data.handles(7),'string')),'tag','donotdelete');
%hc2=uimenu(hc1,'Label','Sort rows by','tag','donotdelete');
%uimenu(hc2,'Label','Connections','callback',@(varargin)conn_displayroi('mvpasort',1),'tag','donotdelete');
%uimenu(hc2,'Label','Seeds','callback',@(varargin)conn_displayroi('mvpasort',2),'tag','donotdelete');
%uimenu(hc2,'Label','Clusters','callback',@(varargin)conn_displayroi('mvpasort',3),'tag','donotdelete');
set(data.handles(8),'uicontextmenu',hc1);
%set(data.handles(7),'string',sprintf('%-6s %-6s %6s %6s %4s %8s %8s','Seed','Target','beta',[data.MVPAstatsname,'/',data.statsname],'dof','p-unc','p-FDR'));
%uicontrol('style','text','units','norm','position',[.53,.50,.45,.04],'string','second-level analysis results','foregroundcolor','b','backgroundcolor',color2,'fontname','monospaced','fontweight','bold','horizontalalignment','center');
%uicontrol('style','text','units','norm','position',[.03,.01,.05,.04],'string','view: ','foregroundcolor',1-color1,'backgroundcolor',color1,'fontweight','bold','horizontalalignment','right');
%uicontrol('style','text','units','norm','position',[.35,.01,.02,.04],'string','q','fontname','symbol','horizontalalignment','right','foregroundcolor',1-color1,'backgroundcolor',color1,'fontweight','bold','horizontalalignment','right');
%uicontrol('style','text','units','norm','position',[.20,.01,.02,.04],'string','z','horizontalalignment','right','foregroundcolor',1-color1,'backgroundcolor',color1,'fontweight','bold','horizontalalignment','right');
rcircle=sign([sin(linspace(0,2*pi,64)'),cos(linspace(0,2*pi,64))'])*diag([5,5]);
data.plotaxes=[];%axes('units','norm','position',[.01,.08,.58,.84],'visible','off','parent',data.hfig);
data.legendaxes=axes('parent',data.hfig);set(data.legendaxes,'units','norm','position',[.90,.82,.09,.05],'xtick',[],'ytick',[],'box','on','xcolor',.5*[1,1,1],'ycolor',.5*[1,1,1]);axis(data.legendaxes,'equal');set(data.legendaxes,'xlim',[95-20,200]);axis(data.legendaxes,'off');
cmap=jet(256);%cmap=cmap(32:224,:)*.8;
%cmap=cmap.^repmat(.1+.9*abs(linspace(1,-1,size(cmap,1)))',1,size(cmap,2));
data.legend=[patch(100+rcircle(:,1),0+rcircle(:,2),'w','edgecolor','none','facecolor',[1,.5,.5],'parent',data.legendaxes),...
patch(150+rcircle(:,1),0+rcircle(:,2),'w','edgecolor','none','facecolor',[.5,.5,1],'parent',data.legendaxes),...
text(0,0,'','horizontalalignment','left','fontsize',6+CONN_gui.font_offset,'color',.5*[1,1,1],'parent',data.legendaxes),... % ROI-to-ROI effects:
text(100+10,0,'Positive','horizontalalignment','left','fontsize',6+CONN_gui.font_offset,'color',.5*[1,1,1],'parent',data.legendaxes),...
text(150+10,0,'Negative','horizontalalignment','left','fontsize',6+CONN_gui.font_offset,'color',.5*[1,1,1],'parent',data.legendaxes),...
text(100-5,0,'Negative','horizontalalignment','left','fontsize',6+CONN_gui.font_offset,'color',.5*[1,1,1],'horizontalalignment','right','parent',data.legendaxes),...
text(150+5,0,'Positive','horizontalalignment','left','fontsize',6+CONN_gui.font_offset,'color',.5*[1,1,1],'horizontalalignment','left','parent',data.legendaxes)];
for n=1:size(cmap,1), data.legend=[data.legend patch(100+(n+[0 0 1 1])*50/size(cmap,1),[-5,5,5,-5],'w','edgecolor','none','facecolor',cmap(n,:),'tag','conn_displayroi_plotlegendcont','parent',data.legendaxes)]; end
set(data.legend,'visible','off');
set(data.legend,'buttondownfcn',@(varargin)conn_displayroi(hfig,[],'display.colorbar.limit'));
set(hfig,'userdata',data);
conn_displayroi(hfig,[],'fwec.option',[],'immediatereturn');
data=get(hfig,'userdata');
if data.displayreduced
conn_displayroi(hfig,[],'displayreduced');
set(hfig,'visible','on');
if ishandle(hmsg), delete(hmsg); end
if ishandle(hmsginit), delete(hmsginit); end
return;
else
set(hfig,'visible','on');
if ishandle(hmsg), delete(hmsg); end
if ishandle(hmsginit), delete(hmsginit); end
end
case 'advancedthr'
data=get(hfig,'userdata');
if margin>1, advanced=varargin{1}; set(data.handles(6),'value',advanced);
else advanced=get(data.handles(6),'value');
end
if advanced
conn_displayroi(hfig,[],'fwec.option',numel(data.thres_defaults)+1,'immediatereturn');
else
ok=false;for method=1:numel(data.thres_defaults), if isequal({data.thr,data.thrtype,data.mvpathr,data.mvpathrtype},data.thres_defaults{method})&&data.side==3, ok=true; break; end; end;
if ~ok,
conn_displayroi(hfig,[],'fwec.option',numel(data.thres_defaults)+1,'immediatereturn');
else
conn_displayroi(hfig,[],'fwec.option',method,'immediatereturn');
data.mvpathrtype=method;
end
end
return
case 'fwec.option'
data=get(hfig,'userdata');
if margin>1&&~isempty(varargin{1}), value=varargin{1}; set(data.handles(1),'value',value);
else value=get(data.handles(1),'value');
end
data.thres=value;
advanced=get(data.handles(6),'value');
if value<=numel(data.thres_defaults)
[data.thr,data.thrtype,data.mvpathr,data.mvpathrtype]=deal(data.thres_defaults{data.thres}{:});
data.side=3;
set(data.handles(2),'string',num2str(data.thr));
set(data.handles(3),'value',data.thrtype);
set(data.handles(15),'string',num2str(data.mvpathr));
set(data.handles(16),'value',find(data.mvpathrtype_shown==data.mvpathrtype));
if data.thrtype==5, set(data.handles(22),'string',['connection threshold: ',data.statsname,' > ']);
elseif data.mvpathr==1, set(data.handles(22),'string','connection threshold: ');
else set(data.handles(22),'string','connection threshold: p < ');
end
switch(value)
case 1, tstr3='parametric multivariate statistics (cluster-level inferences, Functional Network Connectivity, Jafri et al., 2008)';
case 2, tstr3='non-parametric statistics (cluster-level inferences, Spatial Pairwise Clustering, Zalesky et al., 2012)';
case 3, tstr3='non-parametric statistics (cluster-level inferences, Threshold Free Cluster Enhancement, Smith and Nichols 2007)';
case 4, tstr3='parametric univariate statistics (connection-level inferences, FDR corrected, Benjamini & Hochberg, 1995)';
case 5, tstr3='parametric multivariate statistics (ROI-level inferences, FDR corrected, Benjamini & Hochberg, 1995)';
case 6, tstr3='non-parametric statistics (network-level inferences, Network Based Statistics, Zalesky et al., 2010)';
end
tstr1=cellstr(get(data.handles(3),'string'));
tstr2=cellstr(get(data.handles(16),'string'));
tstr4=sprintf('%s %s %s',get(data.handles(22),'string'),get(data.handles(2),'string'),tstr1{get(data.handles(3),'value')});
tstr5=sprintf('%s %s %s',get(data.handles(23),'string'),get(data.handles(15),'string'),tstr2{get(data.handles(16),'value')});
if value==3||value==4, set(data.handles(5),'string',{tstr3,sprintf('%s',tstr4)});
else set(data.handles(5),'string',{tstr3,sprintf('%s; %s',tstr5,tstr4)});
end
if advanced,
set(data.handles(5),'string','','visible','off');
set(data.handles([2,3,4,15,16,22,23]),'visible','on');
if data.thrtype==3||data.thrtype==4, set(data.handles([15,16,23]),'visible','off'); end
else
set(data.handles(5),'visible','on');
set(data.handles([2,3,4,15,16,22,23]),'visible','off');
end
else
set(data.handles(5),'string','','visible','off');
set(data.handles([2,3,4,15,16,22,23]),'visible','on');
if data.thrtype==3||data.thrtype==4, set(data.handles([15,16,23]),'visible','off'); end
set(hfig,'userdata',data); return;
end
if margin>2&&isequal(varargin{2},'immediatereturn'), set(hfig,'userdata',data); return; end
case 'fwec.connectionlevel.value',
data=get(hfig,'userdata');
if margin>1, value=varargin{1}; set(data.handles(2),'string',num2str(value))
else value=str2num(get(data.handles(2),'string'));
end
if ~isempty(value), data.thr=max(0,value); end
data.visible='on';
case 'fwec.connectionlevel.type',
data=get(hfig,'userdata');
if margin>1, value=varargin{1}; set(data.handles(3),'value',value);
else value=max(1,min(5,get(data.handles(3),'value')));
end
docont=true;
if data.thrtype==1&&value==5&&data.side==3, data.thr=spm_invTcdf(1-data.thr/2,data.dof(1)); set(data.handles(2),'string',num2str(data.thr)); docont=false;
elseif data.thrtype==1&&value==5, data.thr=spm_invTcdf(1-data.thr,data.dof(1)); set(data.handles(2),'string',num2str(data.thr)); docont=false;
elseif data.thrtype==5&&value==1&&data.side==3, data.thr=1-spm_Tcdf(data.thr,data.dof(1)); data.thr=2*min(data.thr,1-data.thr); set(data.handles(2),'string',num2str(data.thr)); docont=false;
elseif data.thrtype==5&&value==1, data.thr=1-spm_Tcdf(data.thr,data.dof(1)); set(data.handles(2),'string',num2str(data.thr)); docont=false;
elseif data.thrtype<3&&value==5&&data.thr<1, data.thr=3; set(data.handles(2),'string',num2str(data.thr));
elseif data.thrtype==5&&value==2, data.thr=.05; set(data.handles(2),'string',num2str(data.thr));
elseif data.thrtype==5&&value==1, data.thr=.001; set(data.handles(2),'string',num2str(data.thr));
end
data.thrtype=value;
if data.thrtype==5, set(data.handles(22),'string',['connection threshold: ',data.statsname,' > ']);
elseif data.mvpathr==1, set(data.handles(22),'string','connection threshold: ');
else set(data.handles(22),'string','connection threshold: p < ');
end
if data.thrtype==3||data.thrtype==4, set(data.handles([15,16,23]),'visible','off');
else set(data.handles([15,16,23]),'visible','on');
end
data.visible='on';
if ~docont, set(hfig,'userdata',data); return; end
case 'fwec.connectionlevel.side',
data=get(hfig,'userdata');
if margin>1, value=varargin{1}; set(data.handles(4),'value',value);
else value=get(data.handles(4),'value');
end
data.side=value;
%data.plotconnoptions.LCOLOR=1+(data.side<3);
data.visible='on';
case 'fwec.clusterlevel.value',
data=get(hfig,'userdata');
if margin>1, value=varargin{1}; set(data.handles(15),'string',num2str(value));
else
str=get(data.handles(15),'string');
value=str2num(str);
end
if ~isempty(value),
data.mvpathr=max(0,value);
end
data.visible='on';
case 'fwec.clusterlevel.type',
data=get(hfig,'userdata');
if margin>1, value=varargin{1}; set(data.handles(16),'value',value);
else value=get(data.handles(16),'value');
end
data.mvpathrtype=data.mvpathrtype_shown(value);
data.visible='on';
case 'plot_design'
data=get(hfig,'userdata');
Y=repmat({''},size(data.results(1).xX.X,1),size(data.results(1).c2,2));
idx=find(data.results(1).xX.SelectedSubjects);
if isfield(data.results(1),'ynames'), for n1=1:numel(idx), for n2=1:size(data.results(1).c2,2), Y{n1,n2}=sprintf('subject %d %s',idx(n1),data.results(1).ynames{n2}); end; end
else for n1=1:numel(idx), for n2=1:size(data.results(1).c2,2), Y{n1,n2}=sprintf('subject %d condition %d',idx(n1),n2); end; end
end
conn_displaydesign(data.results(1).xX.X,Y,data.results(1).c,data.results(1).c2,data.results(1).xX.name,true);
return
case {'import_values','cluster_view'}
data=get(hfig,'userdata');
filename={fullfile(data.defaultfilepath,'results.clusters.nii')};
tfilename=conn_displayroi_selectfiles(filename,data.initfile);
if isempty(tfilename), return;
elseif iscell(tfilename), CLUSTERSFROMFILE='';
else CLUSTERSFROMFILE=tfilename;
end
hmsginit=conn_msgbox('Loading data. Please wait...','conn_displayroi',-1);
selectedsubjects=data.results(1).xX.SelectedSubjects;
if isfield(data.results(1),'ynames'), names_conditions=data.results(1).ynames;
else names_conditions={};
end
y={};name={};
y2=[];name2={};
y3=[];name3={};
txt1='';
txt2='';
if ~isempty(CLUSTERSFROMFILE)
[Cdata,Cnames,Ccoords,Csamples] = conn_mtx_read(CLUSTERSFROMFILE);
[ok,Cidx]=ismember(Cnames,data.results(1).names2);
if ~all(ok), fprintf('warning: unable to find ROI %s. Skipping\n',sprintf('%s ',Cnames{~ok})); Cdata(~ok,~ok)=0; end
for value=1:max(Cdata(:))
[isource,itarget]=find(Cdata==value);
if isempty(y3), y2(end+1)=0; else y2(end+1)=size(y3,3); end
if numel(Csamples)>=value, name2{end+1}=Csamples{value}; else name2{end+1}=sprintf('cluster %d',value); end
for ni=1:numel(isource)
ty=permute(data.results(1).data(:,Cidx(itarget(ni)),:,Cidx(isource(ni))),[1,3,2]); % (seed) [subjects x targets x conditions]
if ~isempty(selectedsubjects)&&~rem(size(ty,1),nnz(selectedsubjects)) % fill-in with NaN for missing data
tty=nan(size(ty,1)/nnz(selectedsubjects)*numel(selectedsubjects),size(ty,2));
tty(repmat(logical(selectedsubjects),size(ty,1)/nnz(selectedsubjects),1),:)=ty;
ty=tty;
if isempty(names_conditions), names_conditions=arrayfun(@(n)sprintf('condition %d',n),1:size(ty,2),'uni',0); end
y3=cat(3,y3,ty);
name3{end+1}=sprintf('%s connection between %s and %s',name2{end},Cnames{isource(ni)},Cnames{itarget(ni)});
for n=1:size(ty,2)
y{end+1}=ty(:,n);
name{end+1}=sprintf('%s at %s',name3{end},names_conditions{n});
end
end
end
end
else
for value=1:size(data.list2,1)
isource=[];
itarget=[];
if data.list2(value,2)>0, % connection
txt2=sprintf('connectivity between %s and %s',data.names2{data.list2(value,1)},data.names2{data.list2(value,2)});
isource=data.list2(value,1);
itarget=data.list2(value,2);
elseif data.list2(value,1)>0, % seed
txt1=data.list2txt{value};
if isempty(y3), y2(end+1)=0; else y2(end+1)=size(y3,3); end
name2{end+1}=regexp(txt1,'^(Cluster|Network|ROI) \d+\/\d+','match','once');
else % cluster
txt1=data.list2txt{value};
if isempty(y3), y2(end+1)=0; else y2(end+1)=size(y3,3); end
name2{end+1}=regexp(txt1,'^(Cluster|Network|ROI) \d+\/\d+','match','once');
end
if ~isempty(isource)
ty=permute(data.results(1).data(:,itarget,:,isource),[1,3,2]); % (seed) [subjects x targets x conditions]
if ~isempty(selectedsubjects)&&~rem(size(ty,1),nnz(selectedsubjects)) % fill-in with NaN for missing data
tty=nan(size(ty,1)/nnz(selectedsubjects)*numel(selectedsubjects),size(ty,2));
tty(repmat(logical(selectedsubjects),size(ty,1)/nnz(selectedsubjects),1),:)=ty;
ty=tty;
if isempty(names_conditions), names_conditions=arrayfun(@(n)sprintf('condition %d',n),1:size(ty,2),'uni',0); end
y3=cat(3,y3,ty);
name3{end+1}=sprintf('%s %s',regexp(txt1,'^(Cluster|Network|ROI) \d+\/\d+','match','once'),regexprep(txt2,'\s+',' '));
for n=1:size(ty,2)
y{end+1}=ty(:,n);
name{end+1}=sprintf('%s %s at %s',regexp(txt1,'^(Cluster|Network|ROI) \d+\/\d+','match','once'),regexprep(txt2,'\s+',' '),names_conditions{n});
% name{end+1}=regexprep(sprintf('conn between %s and %s at %s',...
% data.names2reduced{isource},...
% data.names2reduced{itarget},...
% names_conditions{n}),'\s+',' ');
end
end
end
end
end
if isempty(y3)
elseif strcmpi(option,'import_values')
if ~isfield(CONN_x,'filename')||isempty(CONN_x.filename)||~isfield(CONN_x,'Setup')||~isfield(CONN_x.Setup,'nsubjects')||isempty(CONN_x.Setup.nsubjects)||any(rem(cellfun(@numel,y),CONN_x.Setup.nsubjects)), % no conn project loaded
[tfilename,tfilepath]=uiputfile('*.mat','Save data as',fileparts(tfilename));
if ischar(tfilename), conn_savematfile(fullfile(tfilepath,tfilename),'name','y'); fprintf('data saved to file %s\n',fullfile(tfilepath,tfilename)); end
else
conn_importl2covariate(name,y);
end
else
if get(data.handles(9),'value')||isempty(y2), % one plot per connection
conn_rex('test',data.results(1).xX,reshape(y3(selectedsubjects,:,:),[nnz(selectedsubjects)*size(y3,2),size(y3,3)]),data.results(1).c,names_conditions,name3,[],[],true,data.results(1).c2,[],true);
else % one plot per cluster
breaks=[y2,size(y3,3)];
y2=zeros([size(y3,1),size(y3,2),numel(breaks)-1]);
for n=1:numel(breaks)-1,
y2(:,:,n)=mean(y3(:,:,breaks(n)+1:breaks(n+1)),3);
end
conn_rex('test',data.results(1).xX,reshape(y2(selectedsubjects,:,:),[nnz(selectedsubjects)*size(y2,2),size(y2,3)]),data.results(1).c,names_conditions,name2,[],[],true,data.results(1).c2,[],true);
end
end
if ishandle(hmsginit), delete(hmsginit); end
return
case 'export_data'
data=get(hfig,'userdata');
if margin>1, tfilename=varargin{1};
else
[tfilename,tpathname]=uiputfile({'*.nii','NIFTI files (*.nii)'; '*', 'All Files (*)'},'Output data to file:',data.defaultfilepath);
if ischar(tfilename)&&~isempty(tfilename),
tfilename=fullfile(tpathname,tfilename);
else return;
end
end
if isfield(data.results,'data'), Y=permute(data.results(1).data,[1,3,4,2]);
else Y=permute(cat(4,data.results.y),[1,3,4,2]);
end
Y=Y(:,:,data.displaytheserois(data.displaytheserois<=size(Y,3)),data.displaytheserois(data.displaytheserois<=size(Y,3)));
Y=permute(Y,[3,4,1,2]);
ColumnNames=data.names2(data.displaytheserois);
ColumnGroups=data.clusters(data.displaytheserois);
SampleNames=repmat({''},size(Y,3),size(Y,4));
idx=find(data.results(1).xX.SelectedSubjects);
if isfield(data.results(1),'ynames'), for n1=1:numel(idx), for n2=1:size(Y,4), SampleNames{n1,n2}=sprintf('subject %d %s',idx(n1),data.results(1).ynames{n2}); end; end
else for n1=1:numel(idx), for n2=1:size(Y,4), SampleNames{n1,n2}=sprintf('subject %d measure %d',idx(n1),n2); end; end
end
conn_mtx_write(tfilename,Y(:,:,:),ColumnNames, data.xyz2(data.displaytheserois), SampleNames);
conn_disp('fprintf','Connectivity matrix data saved in %s\n',tfilename);
return
case {'export','export_mask'}
data=get(hfig,'userdata');
if margin>1, tfilename=varargin{1};
else
[tfilename,tpathname]=uiputfile({'*.nii','NIFI files (*.nii)'; '*.txt','text files (*.txt)'; '*.csv','CSV-files (*.csv)'; '*.mat','MAT-files (*.mat)'; '*', 'All Files (*)'},'Output mask to file:',fullfile(data.defaultfilepath,'results.nii'));
if ischar(tfilename)&&~isempty(tfilename),
tfilename=fullfile(tpathname,tfilename);
else return
end
end
if ~isempty(tfilename)
[nill,nill,tfileext]=fileparts(tfilename);
z=data.CM_z;
R=z(data.displaytheserois(data.displaytheserois<=size(z,1)),data.displaytheserois);
R(isnan(R))=0;
z=data.CM_z0;
R_unthresholded=z(data.displaytheserois(data.displaytheserois<=size(z,1)),data.displaytheserois);
R_unthresholded(isnan(R))=0;
ColumnNames=data.names2(data.displaytheserois);
ColumnGroups=data.clusters(data.displaytheserois);
R_clusters_unthresholded=data.CLUSTER_labels(data.displaytheserois(data.displaytheserois<=size(z,1)),data.displaytheserois);
R_clusters=R_clusters_unthresholded;R_clusters(R==0)=0;
%R_clusters=R_clusters_unthresholded;R_clusters(~ismember(R_clusters,unique(R_clusters(R~=0))))=0;
if ~isempty(data.CLUSTER_selected)
[ok,idx1]=ismember(R_clusters,data.CLUSTER_selected);
R_clusters(~ok)=0;
R_clusters(ok)=idx1(ok);
R_clusters_names=data.CLUSTER_selected_names;
else R_clusters_names={};
end
switch(tfileext)
case '.nii'
conn_mtx_write(tfilename,R,ColumnNames, data.xyz2(data.displaytheserois));
conn_mtx_write(conn_prepend('',tfilename,'.orig.nii'),R_unthresholded,ColumnNames,data.xyz2(data.displaytheserois));
conn_mtx_write(conn_prepend('',tfilename,'.mask.nii'),double(R~=0),ColumnNames,data.xyz2(data.displaytheserois));
conn_disp('fprintf','Thresholded connectivity matrix saved in %s\n',tfilename);
if ~isempty(R_clusters_names),
for n=1:numel(R_clusters_names)
idx=find(strncmp(data.list2txt(data.list2visible),R_clusters_names{n},numel(R_clusters_names{n})),1);
if ~isempty(idx),R_clusters_names{n}=data.list2txt{data.list2visible(idx)}; end
end
conn_mtx_write(conn_prepend('',tfilename,'.clusters.orig.nii'),R_clusters_unthresholded,ColumnNames,data.xyz2(data.displaytheserois),R_clusters_names);
conn_mtx_write(conn_prepend('',tfilename,'.clusters.nii'),R_clusters,ColumnNames,data.xyz2(data.displaytheserois),R_clusters_names);
conn_disp('fprintf','Suprathreshold connectivity clusters saved in %s\n',conn_prepend('',tfilename,'.clusters.nii'));
end
case '.txt'
%fh=fopen(tfilename,'wt');
fh={};
for nt=1:numel(ColumnNames), fh{end+1}=sprintf('%s\t',ColumnNames{nt}); end; fh{end+1}=sprintf('\n');
for nt=1:numel(ColumnNames), for nt2=1:numel(ColumnNames), fh{end+1}=sprintf('%f\t',R(nt,nt2)); end; fh{end+1}=sprintf('\n'); end
%fclose(fh);
conn_fileutils('filewrite_raw',tfilename, fh);
conn_disp('fprintf','Thresholded connectivity matrix saved in %s\n',tfilename);
case '.csv'
%fh=fopen(tfilename,'wt');
fh={};
for nt=1:numel(ColumnNames), fh{end+1}=sprintf(',%s',ColumnNames{nt}); end; fh{end+1}=sprintf('\n');
for nt=1:numel(ColumnNames),
fh{end+1}=sprintf('%s',ColumnNames{nt});
for nt2=1:numel(ColumnNames), fh{end+1}=sprintf(',%f',R(nt,nt2)); end; fh{end+1}=sprintf('\n');
end
conn_fileutils('filewrite_raw',tfilename, fh);
%fclose(fh);
conn_disp('fprintf','Thresholded connectivity matrix saved in %s\n',tfilename);
case '.mat',
conn_savematfile(tfilename,'R','R_unthresholded','ColumnNames','ColumnGroups');
conn_disp('fprintf','Thresholded connectivity matrix saved in %s\n',tfilename);
end
end
return
case 'openfolder'
data=get(hfig,'userdata');
conn_fileutils('cd',data.defaultfilepath);
try
if ispc, [nill,nill]=system(sprintf('start "%s"',data.defaultfilepath));
else [nill,nill]=system(sprintf('open ''%s''',data.defaultfilepath));
end
end
return
case 'bookmark',
data=get(hfig,'userdata');
tfilename=[];
descr='';
if isfield(CONN_gui,'slice_display_skipbookmarkicons'), SKIPBI=CONN_gui.slice_display_skipbookmarkicons;
else SKIPBI=false;
end
conn_args={'displayroi','initfile',data.initfile};
opts={};%{'forcecd'};
[fullfilename,tfilename,descr]=conn_bookmark('save',...
tfilename,...
descr,...
conn_args,...
opts);
if isempty(fullfilename), return; end
if ~SKIPBI,
tht=conn_msgbox('Printing bookmark icon. Please wait...','',-1);
conn_print(gcbf,conn_prepend('',fullfilename,'.jpg'),'-nogui','-r50','-nopersistent');
if ishandle(tht), delete(tht); end
end
return;
case 'mvpaextend'
data=get(hfig,'userdata');
if margin>1, value=varargin{1}; set(data.handles(16),'value',find(mvpathrtype_shown==value,1));
else value=data.mvpathrtype_shown(get(data.handles(16),'value'));
end
if isequal(data.mvpathrtype_shown,1:numel(data.mvpathrtype_all)), data.mvpathrtype_shown=[14:16,5:7,23:25,29:30,1]; %[15,24,6,1]; %[1,3,9,21];
else data.mvpathrtype_shown=1:numel(data.mvpathrtype_all);
end
docont=false;
if ~any(value==data.mvpathrtype_shown), value=data.mvpathrtype_shown(1); docont=true; end
set(data.handles(16),'string',data.mvpathrtype_all(data.mvpathrtype_shown),'value',find(data.mvpathrtype_shown==value,1));
data.mvpathrtype=value;
if ~docont, set(hfig,'userdata',data); return; end
data.visible='on';
% case 'mvpaside',
% hfig=gcbf;
% data=get(hfig,'userdata');
% value=get(data.handles(17),'value');
% data.mvpaside=value;
% data.visible='on';
case 'mvpasort',
data=get(hfig,'userdata');
data.mvpasortresultsby=varargin{1};
data.visible='on';
case {'displayreduced','roi.select'}
data=get(hfig,'userdata');
if strcmpi(option,'roi.select'), data.displayreduced=2;
elseif margin>1, data.displayreduced=varargin{1};
end
olddisplaytheserois=data.displaytheserois;
oldclusters=data.clusters;
switch(data.displayreduced),
case 0,
data.displaytheserois=1:length(data.names2);
case 1,
data.displaytheserois=1:length(data.names);
case 2,
if margin>2&&~isempty(varargin{2}),
initial=varargin{2};
listrois=[];
for n1=1:length(initial),
idx=strmatch(initial{n1},data.names,'exact');
if isempty(idx),
idx=strmatch(initial{n1},data.names); % allows partial-name matches
end
if isempty(idx), fprintf('warning: unable to find ROI %s. Skipping\n',initial{n1}); end
listrois=[listrois,idx(:)'];
end
if numel(listrois)>1, data.displaytheserois=listrois;
else
if numel(listrois)==1, conn_disp('Please select more than one ROI'); end
return;
end
else
idxresortv=1:numel(data.names);
temp=regexp(data.names,'BA\.(\d*) \(L\)','tokens'); itemp=~cellfun(@isempty,temp); idxresortv(itemp)=-2e6+cellfun(@(x)str2double(x{1}),temp(itemp));
temp=regexp(data.names,'BA\.(\d*) \(R\)','tokens'); itemp=~cellfun(@isempty,temp); idxresortv(itemp)=-1e6+cellfun(@(x)str2double(x{1}),temp(itemp));
[nill,idxresort]=sort(idxresortv);
[nill,tidx]=ismember(data.displaytheserois,idxresort);
answ=listdlg('Promptstring','Select ROIs to include in this group-analysis:','selectionmode','multiple','liststring',data.names2(idxresort),'initialvalue',sort(tidx),'ListSize',[520 300]);
if numel(answ)>1, data.displaytheserois=sort(idxresort(answ));
else
if numel(answ)==1, conn_disp('Please select more than one ROI'); end
return;
end
end
end
new1displaytheserois=olddisplaytheserois(ismember(olddisplaytheserois,data.displaytheserois)); % existing ones
new2displaytheserois=data.displaytheserois(~ismember(data.displaytheserois,olddisplaytheserois)); % new ones
data.displaytheserois=[reshape(new1displaytheserois,1,[]),reshape(new2displaytheserois,1,[])];
data.source=data.source(data.source==0 | data.source<=length(data.displaytheserois));if isempty(data.source),data.source=1;end
%results=conn_process('results_roi',data.displaytheserois);
if margin<=1, h=conn_msgbox('Updating ROI-level results. Please wait...','conn_displayroi',-1);
else h=[];
end
for nresults=1:size(data.results(1).data,4), %numel(data.results) % note: obsolete?
domvpa=data.displaytheserois;
ndims=min(4,ceil(sqrt(size(data.results(1).data,1))/4));
ndims=max(1,min(min(numel(domvpa),size(data.results(1).data,2)), ndims ));
if ndims<numel(domvpa)
y=data.results(1).data(:,domvpa,:,nresults);
y(:,any(any(isnan(y),1),3),:)=[]; % subjects x rois x conditions
sy=[size(y),1,1];
y=reshape(permute(y,[1,3,2]),sy(1)*sy(3),sy(2)); % (subjects x conditions) x rois
[Q,D,R]=svd(y,0);
ndims=max(1,min(size(R,2),ndims));
d=D(1:size(D,1)+1:size(D,1)*min(size(D))).^2;
ndims=min([ndims,find(cumsum(d)/sum(d)>.95,1)]); % 95 percent variance
y=y*R(:,1:ndims);
MVPAy=permute(reshape(y,[sy(1),sy(3),ndims]),[1,3,2]);
%data.results(nresults).MVPApcacov=d(1:ndims)/sum(d);
else
y=data.results(1).data(:,domvpa,:,nresults);
y=y(:,~any(any(isnan(y),1),3),:);
MVPAy=y;
%data.results(nresults).MVPApcacov=[];
end
[dataresults(nresults).MVPAh,dataresults(nresults).MVPAF,dataresults(nresults).MVPAp,dataresults(nresults).MVPAdof,dataresults(nresults).MVPAstatsname]=conn_glm(data.results(1).xX.X,MVPAy(:,:),data.results(1).c,kron(data.results(1).c2,eye(size(MVPAy,2))));
if isequal(dataresults(nresults).MVPAstatsname,'T'),
%data.results(nresults).MVPAstatsname='F'; data.results(nresults).MVPAdof=[1,data.results(nresults).MVPAdof]; data.results(nresults).MVPAF=data.results(nresults).MVPAF.^2;
dataresults(nresults).MVPAp=2*min(dataresults(nresults).MVPAp,1-dataresults(nresults).MVPAp);
end
end
if ishandle(h), close(h); end
data.MVPAF=cat(1,dataresults.MVPAF);
data.MVPAp=cat(1,dataresults.MVPAp);
temp={dataresults.MVPAdof};
if any(cellfun('length',temp)>1), temp=cellfun(@(x)[ones(1,max(0,2-length(x))),x(:)'],temp,'uni',0); end
data.MVPAdof=cell2mat(temp(:));
%data.MVPAdof=cat(1,data.results.MVPAdof);
data.MVPAstatsname=dataresults(1).MVPAstatsname;
%data.MVPApcacov=cat(1,data.results.MVPApcacov);
%if size(data.MVPAdof,2)>1&&~any(diff(data.MVPAdof(:,1))), data.MVPAstatsname=[data.MVPAstatsname,'(',num2str(data.MVPAdof(1)),')']; end
if ~any(any(diff(data.MVPAdof,1,1),1),2),
if size(data.MVPAdof,2)==1, data.MVPAdofstr=repmat({['(',num2str(data.MVPAdof(1)),')']},numel(data.MVPAdof),1);
else data.MVPAdofstr=repmat({['(',num2str(data.MVPAdof(1,1)),',',num2str(data.MVPAdof(1,2)),')']},size(data.MVPAdof,1),1);
end
else
if size(data.MVPAdof,2)==1, data.MVPAdofstr=arrayfun(@(dof)['(',num2str(dof(1)),')'],data.MVPAdof,'uni',0);
else data.MVPAdofstr=cellfun(@(dof)['(',num2str(dof(1)),',',num2str(dof(2)),')'],num2cell(data.MVPAdof,2),'uni',0);
end
end
%set(data.handles(7),'string',sprintf('%-6s %-6s %6s %6s %4s %8s %8s','Seed','Target','beta',[data.MVPAstatsname,'/',data.statsname],'dof','p-unc','p-FDR'));
if ~isequal(olddisplaytheserois,data.displaytheserois)||~isequal(oldclusters,data.clusters), %if ~isempty(new2displaytheserois) % skip recomputing clusters when only removing ROIs?
data.xy2=zeros(length(data.names2),2); data.xy2(data.displaytheserois,:)=200*[cos(2*pi*(0:numel(data.displaytheserois)-1)'/numel(data.displaytheserois)),sin(2*pi*(0:numel(data.displaytheserois)-1)'/numel(data.displaytheserois))];
data.xy2_clusters=[];
data.clusters=[];
data.names_clusters={};
if isfield(data,'clusters_options')&&~isempty(data.clusters_options), data=conn_displayroi_clusters(data); end
end
if ~isequal(olddisplaytheserois,data.displaytheserois)||~isequal(oldclusters,data.clusters),
data.PERM=[];
data.tfceZ=[];
data.cMVPAF=[];
%f=conn_dir(conn_displayroi_simfilename(data.roifile,'all'),'-R','-cell');
%if ~isempty(f), conn_fileutils('spm_unlink',f{:}); end
end
if ishandle(h), close(h); end
data.proj=[];data.x=[];data.y=[];data.z=[];
data.bgz=0;
data.visible='on';
case {'roi.order.export','roi.order.save'}
if margin>1&&~isempty(varargin{1}), answ=varargin{1};
else answ=conn_questdlg('','Save ROI order:','Save ROI order/groups to file','Save ROI order/groups to clipboard','Save ROI order/groups to file');
end
try, answ=regexprep(answ,'order/cluster','order/group'); end
data=get(hfig,'userdata');
ROIconfiguration=struct('xy2',data.xy2,'displaytheserois',data.displaytheserois,'xy2_clusters',data.xy2_clusters,'clusters',data.clusters,'names2',{data.names2},'names_clusters',{data.names_clusters});
if isequal(answ,'Save ROI order/groups to file')
if margin>2&&~isempty(varargin{2}), tfilename=varargin{2};