-
Notifications
You must be signed in to change notification settings - Fork 5
/
aedes_fmri_gui.m
900 lines (807 loc) · 27.1 KB
/
aedes_fmri_gui.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
function aedes_fmri_gui(DATA,mask)
% fMRI tool GUI
% Check input arguments
if nargin == 0
error('Too few input arguments.')
elseif nargin == 1
mask = [];
elseif nargin > 2
error('Too many input arguments.')
end
% Check data
if isstruct(DATA) && isfield(DATA,'FTDATA')
Dat.data = DATA.FTDATA;
elseif isnumeric(DATA) && ndims(DATA)==4
Dat.data=DATA;
else
error('Input data has to be a 4D numeric matrix or Aedes data structure!')
end
Dat.nVolumes = size(Dat.data,4);
% Check mask
if islogical(mask)
Dat.mask = mask;
else
Dat.mask = [];
end
% Check mask size
if ~isempty(Dat.mask)
sz_mask = [size(Dat.mask,1),size(Dat.mask,2),size(Dat.mask,3)];
sz_data = [size(Dat.data,1),size(Dat.data,2),size(Dat.data,3)];
if ~isequal(sz_mask,sz_data)
warning('Mask size does not match with data volume size. Disabling masking...')
Dat.mask = [];
end
end
% Construct the GUI
H = l_MainGui;
% Build the main GUI -----------------------------------------------------
function H=l_MainGui()
% Load default font and colors
GD=aedes_gui_defaults;
% Overlay controls figure
fig_h = 500;
fig_w = 500;
fig_location = aedes_dialoglocation([fig_w,fig_h]);
fig_left = fig_location(1);
fig_bottom = fig_location(2);
% Main figure
H.fig = figure('units','pixel',...
'position',...
[fig_left fig_bottom ...
fig_w fig_h],...
'Name','Aedes - fMRI Analysis',...
'numbertitle','off',...
'tag','aedes_fmri_analysis_tool_fig',...
'Toolbar','none',...
'Color',GD.col.mainfig,...
'Menubar','none',...
'DockControls','off',...
'renderer','painters',...
'resize','off',...
'CloseRequestFcn',@l_Close,...
'Handlevisibility','off');
if ~GD.HG2graphics
set(H.fig, 'DoubleBuffer','on')
end
% % Data uipanel -----------------------------------
% H.uipanel_data = uipanel('parent',H.fig,...
% 'units','pixel',...
% 'position',[10 fig_h-10-100 fig_w-20 100],...
% 'title','Image data',...
% 'backgroundcolor',GD.col.mainfig);
% Templates uipanel ------------------------------
% pos = get(H.uipanel_data,'position');
% H.uipanel_tmpl = uipanel('parent',H.fig,...
% 'units','pixel',...
% 'position',[pos(1) fig_h-20-pos(4)-60 fig_w-20 60],...
% 'title','Analysis parameter templates',...
% 'backgroundcolor',GD.col.mainfig);
H.uipanel_tmpl = uipanel('parent',H.fig,...
'units','pixel',...
'position',[10 fig_h-10-60 fig_w-20 60],...
'title','Analysis parameter templates',...
'backgroundcolor',GD.col.mainfig);
if ispref('Aedes','fMRIToolTemplates')
tmp = getpref('Aedes','fMRIToolTemplates');
popup_str = {' ',tmp{:,1}};
else
popup_str = ' ';
end
H.popup_tmpl = uicontrol('parent',H.uipanel_tmpl,...
'style','popupmenu','position',[20 10 200 25],...
'string',popup_str);
pos = get(H.popup_tmpl,'position');
btn_w = (fig_w-20-20-pos(3)-4*10)/3;
H.loadbtn_tmpl = uicontrol('parent',H.uipanel_tmpl,...
'style','pushbutton','position',[pos(1)+pos(3)+10 10 btn_w 25],...
'string','Load',...
'callback',@l_LoadTemplate);
H.savebtn_tmpl = uicontrol('parent',H.uipanel_tmpl,...
'style','pushbutton','position',[pos(1)+pos(3)+2*10+btn_w 10 btn_w 25],...
'string','Save',...
'callback',@l_SaveTemplate);
H.deletebtn_tmpl = uicontrol('parent',H.uipanel_tmpl,...
'style','pushbutton','position',[pos(1)+pos(3)+3*10+2*btn_w 10 btn_w 25],...
'string','Delete',...
'callback',@l_DeleteTemplate);
% Parameters buttons ------------------------------
pos = get(H.uipanel_tmpl,'position');
H.preprocessing_toggle = uicontrol('parent',H.fig,...
'style','togglebutton','position',[pos(1) pos(2)-20-30 100 30],...
'string','Preprocessing',...
'value',1,...
'callback',@l_ChangeTab);
pos = get(H.preprocessing_toggle,'position');
H.design_toggle = uicontrol('parent',H.fig,...
'style','togglebutton','position',[pos(1)+pos(3)+15 pos(2) pos(3:4)],...
'string','Design',...
'value',0,...
'callback',@l_ChangeTab);
pos = get(H.design_toggle,'position');
H.results_toggle = uicontrol('parent',H.fig,...
'style','togglebutton','position',[pos(1)+pos(3)+15 pos(2) pos(3:4)],...
'string','Results',...
'value',0,...
'callback',@l_ChangeTab);
% Preprocessing tab -------------------------------
pos = get(H.preprocessing_toggle,'position');
H.uipanel_preprocessing = uipanel('parent',H.fig,...
'units','pixel',...
'position',[10 10+40 fig_w-20 pos(2)-20-40],...
'title','Preprocessing',...
'visible','on',...
'backgroundcolor',GD.col.mainfig);
pos = get(H.uipanel_preprocessing,'position');
H.TR_tx = uicontrol('parent',H.uipanel_preprocessing,...
'style','text',...
'string','Repetition time, TR (sec.):',...
'position',[20 pos(4)-25-25-10 250 25],...
'horizontalalign','left',...
'backgroundcolor',GD.col.mainfig);
pos = get(H.TR_tx,'position');
H.TR_edit = uicontrol('parent',H.uipanel_preprocessing,...
'style','edit',...
'string','',...
'position',[pos(1)+pos(3)+20 pos(2) 100 25],...
'backgroundcolor','w');
H.smooth_checkbox = uicontrol('parent',H.uipanel_preprocessing,...
'style','checkbox',...
'string','Spatial smoothing',...
'value',1,...
'position',[pos(1) pos(2)-35-5 pos(3:4)],...
'backgroundcolor',GD.col.mainfig,...
'callback',@checkbox_callback);
pos = get(H.smooth_checkbox,'position');
H.smooth_tx = uicontrol('parent',H.uipanel_preprocessing,...
'style','text',...
'string','Smoothing kernel FWHM (pixels):',...
'position',[pos(1)+20 pos(2)-25-5 230 25],...
'horizontalalign','left',...
'backgroundcolor',GD.col.mainfig);
pos = get(H.smooth_tx,'position');
H.smooth_edit = uicontrol('parent',H.uipanel_preprocessing,...
'style','edit',...
'string','',...
'position',[pos(1)+pos(3)+20 pos(2) 100 25],...
'backgroundcolor','w');
pos = get(H.smooth_checkbox,'position');
H.hp_checkbox = uicontrol('parent',H.uipanel_preprocessing,...
'style','checkbox',...
'string','Temporal filtering',...
'value',1,...
'position',[pos(1) pos(2)-35-25-10 pos(3:4)],...
'backgroundcolor',GD.col.mainfig,...
'callback',@checkbox_callback);
pos = get(H.hp_checkbox,'position');
H.hp_tx = uicontrol('parent',H.uipanel_preprocessing,...
'style','text',...
'string','High-pass filter cut-off (sec.):',...
'position',[pos(1)+20 pos(2)-25-5 230 25],...
'horizontalalign','left',...
'backgroundcolor',GD.col.mainfig);
pos = get(H.hp_tx,'position');
H.hp_edit = uicontrol('parent',H.uipanel_preprocessing,...
'style','edit',...
'string','',...
'position',[pos(1)+pos(3)+20 pos(2) 100 25],...
'backgroundcolor','w');
set(H.hp_checkbox,'userdata',[H.hp_tx,H.hp_edit])
set(H.smooth_checkbox,'userdata',[H.smooth_tx,H.smooth_edit])
% Design tab --------------------------------------
pos = get(H.uipanel_preprocessing,'position');
H.uipanel_design = uipanel('parent',H.fig,...
'units','pixel',...
'position',pos,...
'title','Design',...
'visible','off',...
'backgroundcolor',GD.col.mainfig);
H.hrf_tx = uicontrol('parent',H.uipanel_design,...
'style','text',...
'string','Hemodynamic response function:',...
'position',[20 pos(4)-25-25-10 250 25],...
'horizontalalign','left',...
'backgroundcolor',GD.col.mainfig);
pos = get(H.hrf_tx,'position');
H.hrf_popup = uicontrol('parent',H.uipanel_design,...
'style','popupmenu',...
'string',{'Human','Rodent'},...
'position',[pos(1)+pos(3)+20 pos(2) 170 25],...
'backgroundcolor','w');
H.omit_volumes_tx = uicontrol('parent',H.uipanel_design,...
'style','text',...
'string','Omit volumes from analysis (indices):',...
'position',[pos(1) pos(2)-25-10 250 25],...
'horizontalalign','left',...
'backgroundcolor',GD.col.mainfig);
pos = get(H.omit_volumes_tx,'position');
H.omit_volumes_edit = uicontrol('parent',H.uipanel_design,...
'style','edit',...
'string','',...
'position',[pos(1)+pos(3)+20 pos(2) 170 25],...
'backgroundcolor','w');
H.conditions_tx = uicontrol('parent',H.uipanel_design,...
'style','text',...
'string','Conditions:',...
'position',[pos(1) pos(2)-15-10 250 15],...
'horizontalalign','left',...
'backgroundcolor',GD.col.mainfig);
pos = get(H.conditions_tx,'position');
H.first_condition_tx = uicontrol('parent',H.uipanel_design,...
'style','text',...
'string','First condition:',...
'position',[pos(1)+20 pos(2)-15-5 230 15],...
'horizontalalign','left',...
'backgroundcolor',GD.col.mainfig);
pos = get(H.first_condition_tx,'position');
H.onsets_tx = uicontrol('parent',H.uipanel_design,...
'style','text',...
'string','Onsets (scans):',...
'position',[pos(1)+20 pos(2)-25-5 210 25],...
'horizontalalign','left',...
'backgroundcolor',GD.col.mainfig);
pos = get(H.onsets_tx,'position');
H.onsets_edit = uicontrol('parent',H.uipanel_design,...
'style','edit',...
'string','',...
'position',[pos(1)+pos(3)+20 pos(2) 170 25],...
'backgroundcolor','w');
H.durations_tx = uicontrol('parent',H.uipanel_design,...
'style','text',...
'string','Durations (scans):',...
'position',[pos(1) pos(2)-25-5 210 25],...
'horizontalalign','left',...
'backgroundcolor',GD.col.mainfig);
pos = get(H.durations_tx,'position');
H.durations_edit = uicontrol('parent',H.uipanel_design,...
'style','edit',...
'string','',...
'position',[pos(1)+pos(3)+20 pos(2) 170 25],...
'backgroundcolor','w');
H.second_condition_cb = uicontrol('parent',H.uipanel_design,...
'style','checkbox',...
'string','Second condition:',...
'position',[pos(1)-20 pos(2)-20-20 230 20],...
'horizontalalign','left',...
'value',0,...
'backgroundcolor',GD.col.mainfig,...
'callback',@checkbox_callback);
pos = get(H.second_condition_cb,'position');
H.onsets2_tx = uicontrol('parent',H.uipanel_design,...
'style','text',...
'string','Onsets (scans):',...
'position',[pos(1)+20 pos(2)-25-5 210 25],...
'horizontalalign','left',...
'enable','off',...
'backgroundcolor',GD.col.mainfig);
pos = get(H.onsets2_tx,'position');
H.onsets2_edit = uicontrol('parent',H.uipanel_design,...
'style','edit',...
'string','',...
'position',[pos(1)+pos(3)+20 pos(2) 170 25],...
'backgroundcolor','w',...
'enable','off');
H.durations2_tx = uicontrol('parent',H.uipanel_design,...
'style','text',...
'string','Durations (scans):',...
'position',[pos(1) pos(2)-25-5 210 25],...
'horizontalalign','left',...
'enable','off',...
'backgroundcolor',GD.col.mainfig);
pos = get(H.durations2_tx,'position');
H.durations2_edit = uicontrol('parent',H.uipanel_design,...
'style','edit',...
'string','',...
'position',[pos(1)+pos(3)+20 pos(2) 170 25],...
'backgroundcolor','w',...
'enable','off');
set(H.second_condition_cb,'userdata',...
[H.onsets2_tx,H.onsets2_edit,H.durations2_tx,H.durations2_edit])
% Results tab -------------------------------------
pos = get(H.uipanel_preprocessing,'position');
H.uipanel_results = uipanel('parent',H.fig,...
'units','pixel',...
'position',pos,...
'title','Results',...
'visible','off',...
'backgroundcolor',GD.col.mainfig);
H.t_contrast_tx = uicontrol('parent',H.uipanel_results,...
'style','text',...
'string','Contrast vector for t-statistics:',...
'position',[20 pos(4)-25-25-10 250 25],...
'horizontalalign','left',...
'backgroundcolor',GD.col.mainfig);
pos = get(H.t_contrast_tx,'position');
H.t_contrast_edit = uicontrol('parent',H.uipanel_results,...
'style','edit',...
'string','',...
'position',[pos(1)+pos(3)+20 pos(2) 170 25],...
'backgroundcolor','w');
H.threshold_tx = uicontrol('parent',H.uipanel_results,...
'style','text',...
'string','Threshold (p < value):',...
'position',[pos(1) pos(2)-25-10 250 25],...
'horizontalalign','left',...
'backgroundcolor',GD.col.mainfig);
pos = get(H.threshold_tx,'position');
H.threshold_edit = uicontrol('parent',H.uipanel_results,...
'style','edit',...
'string','0.05',...
'position',[pos(1)+pos(3)+20 pos(2) 170 25],...
'backgroundcolor','w');
H.th_fdr_radio = uicontrol('parent',H.uipanel_results,...
'style','radio',...
'string','Use FDR-corrected threshold',...
'value',1,...
'position',[pos(1)+20 pos(2)-25-5 230 25],...
'horizontalalign','left',...
'backgroundcolor',GD.col.mainfig,...
'callback',@radiobutton_callback);
pos = get(H.th_fdr_radio,'position');
H.th_uncorr_radio = uicontrol('parent',H.uipanel_results,...
'style','radio',...
'value',0,...
'string','Use uncorrected threshold',...
'position',[pos(1) pos(2)-25-5 230 25],...
'horizontalalign','left',...
'backgroundcolor',GD.col.mainfig,...
'callback',@radiobutton_callback);
pos = get(H.th_uncorr_radio,'position');
H.use_mask_cb = uicontrol('parent',H.uipanel_results,...
'style','checkbox',...
'string','Use brain mask (ROI labeled "mask")',...
'position',[pos(1)-20 pos(2)-20-20 250 20],...
'horizontalalign','left',...
'value',0,...
'backgroundcolor',GD.col.mainfig);
if ~isempty(Dat.mask)
set(H.use_mask_cb,'value',1)
else
set(H.use_mask_cb,'enable','off')
end
pos = get(H.use_mask_cb,'position');
H.save_results_cb = uicontrol('parent',H.uipanel_results,...
'style','checkbox',...
'string','Save results in a MAT-file in folder:',...
'position',[pos(1) pos(2)-20-20 250 20],...
'horizontalalign','left',...
'value',1,...
'backgroundcolor',GD.col.mainfig,...
'callback',@checkbox_callback);
pos = get(H.save_results_cb,'position');
H.save_results_edit = uicontrol('parent',H.uipanel_results,...
'style','edit',...
'string','',...
'position',[pos(1)+20 pos(2)-25-5 340 25],...
'backgroundcolor','w',...
'horizontalalign','left');
pos = get(H.save_results_edit,'position');
H.save_results_browse = uicontrol('parent',H.uipanel_results,...
'style','pushbutton',...
'string','Browse...',...
'position',[pos(1)+pos(3)+10 pos(2) 70 25],...
'callback',@l_BrowserFolder);
pos = get(H.save_results_edit,'position');
H.view_results_cb = uicontrol('parent',H.uipanel_results,...
'style','checkbox',...
'string','View results in Aedes',...
'position',[pos(1)-20 pos(2)-20-20 250 20],...
'horizontalalign','left',...
'value',1,...
'backgroundcolor',GD.col.mainfig,...
'callback',@checkbox_callback);
set(H.save_results_cb,'userdata',...
[H.save_results_edit,H.save_results_browse])
set(H.th_fdr_radio,'userdata',...
[H.th_fdr_radio,H.th_uncorr_radio])
set(H.th_uncorr_radio,'userdata',...
[H.th_fdr_radio,H.th_uncorr_radio])
% Start and Close buttons -------------------------
H.close_btn = uicontrol('parent',H.fig,...
'style','pushbutton','position',[fig_w-10-100 10 100 30],...
'string','Close',...
'callback',@l_Close);
pos = get(H.close_btn,'position');
H.start_btn = uicontrol('parent',H.fig,...
'style','pushbutton','position',[pos(1)-10-pos(3) pos(2:4)],...
'string','Start',...
'callback',@l_Start);
end
% Enable/disable uicontrols
function checkbox_callback(h,evd)
% Make sure that results are either save or viewed or both
val_save = get(H.save_results_cb,'value');
val_view = get(H.view_results_cb,'value');
if ~val_save && ~val_view
if h == H.save_results_cb
set(H.save_results_cb,'value',1)
else
set(H.view_results_cb,'value',1)
end
end
if get(h,'value')
set(get(h,'userdata'),'enable','on')
else
set(get(h,'userdata'),'enable','off')
end
end
function radiobutton_callback(h,evd)
set(get(h,'userdata'),'value',0)
set(h,'value',1)
end
function l_BrowserFolder(h,evd)
d = uigetdir;
if isequal(d,0)
return
end
set(H.save_results_edit,'string',d)
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Change tab
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function l_ChangeTab(h,evd)
panels = [H.uipanel_preprocessing,H.uipanel_design,...
H.uipanel_results];
btns = [H.preprocessing_toggle,H.design_toggle,...
H.results_toggle];
set(btns,'value',0)
ind = find(btns == h);
set(h,'value',1)
set(panels(ind),'visible','on')
set(panels(setdiff([1 2 3],ind)),'visible','off')
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Close GUI
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function l_Close(h,evd)
delete(H.fig)
return
resp = questdlg('Are you sure you want to close the fMRI Analysis Tool?',...
'Close fMRI Analysis Tool',...
'Yes','No','No');
if isempty(resp) || strcmpi(resp,'No')
return
end
delete(H.fig)
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Get all inputted values and selections
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function out = l_GetValues()
out = struct;
% Get preprocessing values
out.prep.TR = str2num(get(H.TR_edit,'string'));
out.prep.smooth.do_smooth = get(H.smooth_checkbox,'value');
out.prep.smooth.kernel = str2num(get(H.smooth_edit,'string'));
out.prep.hp.do_filt = get(H.hp_checkbox,'value');
out.prep.hp.cutoff = str2num(get(H.hp_edit,'string'));
% Get design values
str=get(H.hrf_popup,'string');
out.design.hrf = str{get(H.hrf_popup,'value')};
out.design.omit_volumes = str2num(get(H.omit_volumes_edit,'string'));
out.design.first_condition.onsets =str2num(get(H.onsets_edit,'string'));
out.design.first_condition.durations = str2num(get(H.durations_edit,'string'));
out.design.second_condition.use_second_condition = get(H.second_condition_cb,'value');
out.design.second_condition.onsets =str2num(get(H.onsets2_edit,'string'));
out.design.second_condition.durations = str2num(get(H.durations2_edit,'string'));
% Get results values
out.results.contrast = str2num(get(H.t_contrast_edit,'string'));
out.results.threshold.p_value = str2num(get(H.threshold_edit,'string'));
if get(H.th_fdr_radio,'value')
out.results.threshold.corr = 'FDR';
else
out.results.threshold.corr = 'uncorr';
end
out.results.use_mask = get(H.use_mask_cb,'value');
out.results.save_results = get(H.save_results_cb,'value');
out.results.save_results_folder = get(H.save_results_edit,'string');
out.results.view_in_aedes = get(H.view_results_cb,'value');
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Set all values from a structure
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function l_SetValues(in_struct)
% Set preprocessing values
set(H.TR_edit,'string',num2str(in_struct.prep.TR))
set(H.smooth_checkbox,'value',in_struct.prep.smooth.do_smooth);
set(H.smooth_edit,'string',num2str(in_struct.prep.smooth.kernel));
set(H.hp_checkbox,'value',in_struct.prep.hp.do_filt);
set(H.hp_edit,'string',num2str(in_struct.prep.hp.cutoff))
% Set design values
if strcmpi(in_struct.design.hrf,'human')
set(H.hrf_popup,'value',1);
else
set(H.hrf_popup,'value',2);
end
set(H.omit_volumes_edit,'string',num2str(in_struct.design.omit_volumes))
set(H.onsets_edit,'string',num2str(in_struct.design.first_condition.onsets))
set(H.durations_edit,'string',num2str(in_struct.design.first_condition.durations))
set(H.second_condition_cb,'value',in_struct.design.second_condition.use_second_condition);
set(H.onsets2_edit,'string',num2str(in_struct.design.second_condition.onsets));
set(H.durations2_edit,'string',num2str(in_struct.design.second_condition.durations));
% Set results values
set(H.t_contrast_edit,'string',num2str(in_struct.results.contrast));
set(H.threshold_edit,'string',num2str(in_struct.results.threshold.p_value))
if strcmpi(in_struct.results.threshold.corr,'FDR')
set(H.th_fdr_radio,'value',1)
set(H.th_uncorr_radio,'value',0)
else
set(H.th_uncorr_radio,'value',1)
set(H.th_fdr_radio,'value',0)
end
if strcmpi(get(H.use_mask_cb,'enable'),'on')
set(H.use_mask_cb,'value',in_struct.results.use_mask)
end
set(H.save_results_cb,'value',in_struct.results.save_results);
set(H.save_results_edit,'string',in_struct.results.save_results_folder);
set(H.view_results_cb,'value',in_struct.results.view_in_aedes);
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Do sanity check for input values
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function [ok,msg] = l_SanityCheck(in_struct)
ok = false;
msg = '';
% Check TR
TR = in_struct.prep.TR;
if length(TR) ~= 1
msg = 'TR';
return
end
% Check smoothing
if in_struct.prep.smooth.do_smooth
kr_sz = in_struct.prep.smooth.kernel;
if length(kr_sz) ~= 3
msg = 'smoothing kernel size';
return
end
end
% Check high-pass filtering
if in_struct.prep.hp.do_filt
co = in_struct.prep.hp.cutoff;
if length(co) ~= 1
msg = 'high-pass filter cut-off';
return
end
end
% Check omit volumes
ov = in_struct.design.omit_volumes;
if ~isempty(ov) && any(ov < 1 | ov > Dat.nVolumes)
msg = 'index/indices in omit volumes';
return
end
% Check first condition onsets and durations
onsets = in_struct.design.first_condition.onsets;
durations = in_struct.design.first_condition.durations;
if length(onsets) ~= length(durations) || isempty(onsets) ...
|| any(onsets<1) || any(onsets>Dat.nVolumes) || isempty(durations) ...
|| any(durations<1) || any((onsets+durations)>Dat.nVolumes)
msg = 'first condition onsets or durations';
return
end
% Check 2nd condition onsets and durations
if in_struct.design.second_condition.use_second_condition
onsets = in_struct.design.second_condition.onsets;
durations = in_struct.design.second_condition.durations;
if length(onsets) ~= length(durations) || isempty(onsets) ...
|| any(onsets<1) || any(onsets>Dat.nVolumes) || isempty(durations) ...
|| any(durations<1) || any((onsets+durations)>Dat.nVolumes)
msg = 'second condition onsets or durations';
return
end
end
% Check contrast vector
c=in_struct.results.contrast;
if in_struct.design.second_condition.use_second_condition
cols = 3;
else
cols = 2;
end
if length(c) ~= cols
msg = 'contrast vector length';
return
end
% Check p value
p_val = in_struct.results.threshold.p_value;
if length(p_val) ~= 1 || p_val <= 0 || p_val >= 1
msg = 'threshold p-value';
return
end
% Check save folder
if get(H.save_results_cb,'value')
if ~isdir(get(H.save_results_edit,'string'))
msg = 'save directory'
return
end
end
% All passed
ok = true;
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Save parameter template
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function l_SaveTemplate(h,evd)
% Prompt for a name for the template
popup_str = get(H.popup_tmpl,'string');
popup_val = get(H.popup_tmpl,'value');
save_new = true;
if popup_val ~= 1
% Prompt if current template should be overwritten
qResp = questdlg(['Save a new template or overwrite "',popup_str{popup_val},'"?'],...
'Save a new template or overwrite existing',...
'Save new','Overwrite','Save new');
if strcmp(qResp,'Overwrite')
save_new = false;
end
end
if save_new
done = false;
while ~done
resp=aedes_inputdlg('Please write a name for the template',...
'Template name');
if isempty(resp)
% Canceled
break
elseif any(strcmpi(resp{1},popup_str))
h=errordlg(['A template named "',resp{1},'" already exists. Please select unique name.'],...
'Template already exists','modal');
uiwait(h)
elseif isempty(strtrim(resp{1}))
h=errordlg(['Template name cannot be empty'],...
'Template name cannot be empty','modal');
uiwait(h)
else
done = true;
end
end
if ~done
return
end
resp = resp{1};
else
resp = popup_str{popup_val};
end
% Get current values
vals = l_GetValues;
% Save to preferences
if ispref('Aedes','fMRIToolTemplates')
tmp = getpref('Aedes','fMRIToolTemplates');
else
tmp = {};
end
if ~save_new
ind = find(strcmp(resp,{tmp{:,1}}));
tmp{ind,2} = vals;
else
tmp(end+1,:) = {resp,vals};
% Add template to popup list
if iscell(popup_str)
popup_str{end+1} = resp;
else
popup_str = {popup_str,resp};
end
set(H.popup_tmpl,'string',popup_str,'value',length(popup_str))
end
setpref('Aedes','fMRIToolTemplates',tmp)
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Load parameter template
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function l_LoadTemplate(h,evd)
popup_str = get(H.popup_tmpl,'string');
popup_val = get(H.popup_tmpl,'value');
if popup_val == 1
return
end
load_name = popup_str{popup_val};
tmp = getpref('Aedes','fMRIToolTemplates');
ind = strcmp(load_name,{tmp{:,1}});
tmpl_values = tmp{ind,2};
l_SetValues(tmpl_values)
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Delete parameter template
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function l_DeleteTemplate(h,evd)
popup_str = get(H.popup_tmpl,'string');
popup_val = get(H.popup_tmpl,'value');
if popup_val == 1
return
end
resp = questdlg(['Really delete template "',popup_str{popup_val},'"?'],...
'Confirm template deletion','Yes','No','No');
if isempty(resp) || strcmpi(resp,'No')
return
end
del_name = popup_str{popup_val};
tmp = getpref('Aedes','fMRIToolTemplates');
ind = strcmp(del_name,{tmp{:,1}});
tmp(ind,:)=[];
if isempty(tmp)
rmpref('Aedes','fMRIToolTemplates')
else
setpref('Aedes','fMRIToolTemplates',tmp)
end
popup_str(popup_val)=[];
set(H.popup_tmpl,'string',popup_str,'value',1)
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Start fMRI analysis
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function l_Start(h,evd)
% Get input values
vals = l_GetValues;
% Do sanity check
[ok,msg] = l_SanityCheck(vals);
if ~ok
errordlg(['Input value error. Invalid ',msg,'.'],...
'Input value error','modal');
return
end
% Close GUI
delete(H.fig)
TR = vals.prep.TR;
if vals.design.second_condition.use_second_condition
onset = {vals.design.first_condition.onsets,...
vals.design.second_condition.onsets};
durat = {vals.design.first_condition.durations,...
vals.design.second_condition.durations};
else
onset = vals.design.first_condition.onsets;
durat = vals.design.first_condition.durations;
end
if vals.prep.smooth.do_smooth
smooth_sz = vals.prep.smooth.kernel;
else
smooth_sz = [];
end
qFDR = vals.results.threshold.p_value;
contr = vals.results.contrast;
if vals.prep.hp.do_filt
hipass = vals.prep.hp.cutoff;
else
hipass = [];
end
hrf_type = vals.design.hrf;
omitVols = vals.design.omit_volumes;
if vals.results.use_mask
mask = Dat.mask;
else
mask = [];
end
% Do the fMRI analysis
[maps,th] = aedes_fmri_analysis(Dat.data,'TR',TR,...
'onsets',onset,'durations',durat,...
'contrast',contr,'smooth',smooth_sz,...
'p-value',qFDR,...
'hipass',hipass,'omitvolumes',omitVols,...
'mask',mask,'hrf',hrf_type,...
'multicomp',vals.results.threshold.corr);
% Save results to MAT-file
if vals.results.save_results
opts = vals;
fname = ['results_',datestr(now,'YYYY_mm_dd_HHMMSS.FFF'),'.mat'];
save(fullfile(vals.results.save_results_folder,fname),'maps','th','opts')
end
% View results in Aedes
if vals.results.view_in_aedes
overlay.FTDATA = maps.tmap;
overlay.ImageOverlayCmapStr = 'hot';
overlay.ImageOverlayTholdDirPos = 1;
overlay.ImageOverlayAlpha = 1;
if iscell(onset)
overlay.fMRIonsets = onset{1};
overlay.fMRIdurats = durat{1};
else
overlay.fMRIonsets = onset;
overlay.fMRIdurats = durat;
end
if ~isempty(th)
overlay.ImageOverlayThold = th;
overlay.ImOverlayMin = 0;
else
overlay.ImageOverlayAlpha = 0;
end
aedes(DATA,[],overlay);
end
end
end