forked from Chaogan-Yan/REST
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rest_VMHC_gui.m
executable file
·1113 lines (957 loc) · 44.3 KB
/
rest_VMHC_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
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
function varargout = rest_VMHC_gui(varargin)
% REST_VMHC_GUI MATLAB code for rest_VMHC_gui.fig
% REST_VMHC_GUI, by itself, creates a new REST_VMHC_GUI or raises the existing
% singleton*.
%
% H = REST_VMHC_GUI returns the handle to a new REST_VMHC_GUI or the handle to
% the existing singleton*.
%
% REST_VMHC_GUI('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in REST_VMHC_GUI.M with the given input arguments.
%
% REST_VMHC_GUI('Property','Value',...) creates a new REST_VMHC_GUI or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before rest_VMHC_gui_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to rest_VMHC_gui_OpeningFcn via varargin.
%
% *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one
% instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES
% Edit the above text to modify the response to help rest_VMHC_gui
% Last Modified by GUIDE v2.5 19-Aug-2012 22:35:00
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @rest_VMHC_gui_OpeningFcn, ...
'gui_OutputFcn', @rest_VMHC_gui_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end
if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT
% --- Executes just before rest_VMHC_gui is made visible.
function rest_VMHC_gui_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% varargin command line arguments to rest_VMHC_gui (see VARARGIN)
%Create image
%if ~isfield(handles , 'brain_icon')
% set(handles.image_axes,...
% 'Box' , 'On',...
% 'Units' , 'Pixel',...
% 'YDir' , 'normal',...
% 'XTickLabel' , [],...
% 'XTick' , [],...
% 'YTickLabel' , [],...
% 'YTick' , [],...
% 'DataAspectRatio' , [1,1,1]);%
%
% handles.brain_icon=image('Tag' , 'brain_icon' , 'Parent' , handles.image_axes);
%
% dc_icon=imread(fullfile(rest_misc('WhereIsREST') , 'DegreeCentrality.jpg'));
% %dc_icon=imresize(dc_icon,[200 500]);
%
% set(handles.image_axes , 'XLim' , [1 size(dc_icon , 2)],...
% 'YLim' , [1 size(dc_icon ,1)]);
%
% set(handles.brain_icon , 'CData' , (dc_icon) , 'HitTest' , 'Off');
%end
if ~isfield(handles , 'data_list')
handles.data_list='';
end
%if ~isfield(handles , 'logo_icon')
% set(handles.power_axes,...
% 'Box' , 'On',...
% 'Units' , 'Pixel',...
% 'YDir' , 'normal',...
% 'XTickLabel' , [],...
% 'XTick' , [],...
% 'YTickLabel' , [],...
% 'YTick' , [],...
% 'DataAspectRatio' , [1,1,1]);
%
% handles.logo_icon=image('Tag' , 'logo_icon' , 'Parent' , handles.power_axes);
%
% logo_icon=imread(fullfile(rest_misc('WhereIsREST') , 'rest_web.jpg'));
% logo_icon = flipdim(logo_icon,1);
% %logo_icon = flipdim(logo_icon,2);
% logo_icon=imresize(logo_icon,[460 600]);
%
% set(handles.power_axes , 'XLim' , [1 size(dc_icon , 2)],...
% 'YLim' , [1 size(dc_icon ,1)]);
%
% set(handles.logo_icon , 'CData' , (logo_icon) , 'HitTest' , 'Off');
%end
if ~isfield(handles , 'data_list')
handles.data_list='';
end
% Choose default command line output for rest_VMHC_gui
handles.output = hObject;
%Create list box menu
handles.hContextMenu=uicontextmenu;
set(handles.dir_listbox , 'UIContextMenu' , handles.hContextMenu);
uimenu(handles.hContextMenu , 'Label' , 'Add a directory' ,...
'Callback' , get(handles.dir_pushbutton, 'Callback'));
uimenu(handles.hContextMenu , 'Label' , 'Remove selected directory',...
'Callback' , 'rest_VMHC_gui(''delete_selecteddata'',gcbo,[], guidata(gcbo))');
uimenu(handles.hContextMenu , 'Label' , 'Add recursively all sub-folders of a directory',...
'Callback', 'rest_VMHC_gui(''recursive_add_directory'',gcbo,[], guidata(gcbo))');
uimenu(handles.hContextMenu , 'Label' , '==========================');
uimenu(handles.hContextMenu , 'Label' , 'Remove all data directories',...
'Callback', 'rest_VMHC_gui(''clear_datalist'',gcbo,[], guidata(gcbo))');
uimenu(handles.hContextMenu , 'Label' , '==========================');
uimenu(handles.hContextMenu , 'Label' , sprintf('Power Spectrum'),...
'Callback' , get(handles.timecourse_pushbutton , 'Callback'));
%'Callback', 'rest_VMHC_gui(''power_spectrum'',gcbo,[], guidata(gcbo))');
%Create Utilities Menu
set(handles.utilities_popupmenu , 'String',...
{'VMHC',...
'Amplitude of Low Frequency Fluctuation',...
'Fractional Amplitude of Low Frequency Fluctuation',...
'Regional Homogeneity',...
'Functional Connectivity',...
'Degree Centrality',...
'=================================',...
'Slice Viewer'},...
'Value' , 1 ,...
'Callback' , get(handles.utilities_popupmenu, 'Callback'));
set(handles.output_entry , 'String' , pwd);
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes rest_VMHC_gui wait for user response (see UIRESUME)
% uiwait(handles.fig_VMHC);
% --- Outputs from this function are returned to the command line.
function varargout = rest_VMHC_gui_OutputFcn(hObject, eventdata, handles)
% varargout cell array for returning output args (see VARARGOUT);
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Get default command line output from handles structure
varargout{1} = handles.output;
varargout{2} = handles;
% --- Executes on button press in detrend_checkbox.
function detrend_checkbox_Callback(hObject, eventdata, handles)
% hObject handle to detrend_checkbox (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
if get(handles.detrend_checkbox , 'Value')
if ~get(handles.bandpass_checkbox , 'Value')
set(handles.save_checkbox , 'Enable' , 'On');
end
else
if ~get(handles.bandpass_checkbox , 'Value')
set(handles.save_checkbox , 'Enable' , 'Off');
end
end
if isfield(handles , 'position')
create_timecourse(hObject , [] , handles);
end
% Hint: get(hObject,'Value') returns toggle state of detrend_checkbox
% --- Executes on button press in bandpass_checkbox.
function bandpass_checkbox_Callback(hObject, eventdata, handles)
% hObject handle to bandpass_checkbox (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
%Judge whether dataset need be filtered or not Sandy 120814
if get(handles.bandpass_checkbox , 'Value')
set(handles.TR_entry , 'Enable' , 'On');
set(handles.lowpass_entry , 'Enable' , 'On');
set(handles.highpass_entry , 'Enable' , 'On');
if ~get(handles.detrend_checkbox , 'Value')
set(handles.save_checkbox , 'Enable' , 'On');
end
else
set(handles.TR_entry , 'Enable' , 'Off');
set(handles.lowpass_entry , 'Enable' , 'Off');
set(handles.highpass_entry , 'Enable' , 'Off');
if ~get(handles.detrend_checkbox , 'Value')
set(handles.save_checkbox , 'Enable' , 'Off');
end
end
% Hint: get(hObject,'Value') returns toggle state of bandpass_checkbox
function TR_entry_Callback(hObject, eventdata, handles)
% hObject handle to TR_entry (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
if isfield(handles , 'position')
create_timecourse(hObject , [] , handles);
end
% Hints: get(hObject,'String') returns contents of TR_entry as text
% str2double(get(hObject,'String')) returns contents of TR_entry as a double
% --- Executes during object creation, after setting all properties.
function TR_entry_CreateFcn(hObject, eventdata, handles)
% hObject handle to TR_entry (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function lowpass_entry_Callback(hObject, eventdata, handles)
% hObject handle to lowpass_entry (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
if isfield(handles , 'position')
create_timecourse(hObject , [] , handles);
end
% Hints: get(hObject,'String') returns contents of lowpass_entry as text
% str2double(get(hObject,'String')) returns contents of lowpass_entry as a double
% --- Executes during object creation, after setting all properties.
function lowpass_entry_CreateFcn(hObject, eventdata, handles)
% hObject handle to lowpass_entry (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function highpass_entry_Callback(hObject, eventdata, handles)
% hObject handle to highpass_entry (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
if isfield(handles , 'position')
create_timecourse(hObject , [] , handles);
end
% Hints: get(hObject,'String') returns contents of highpass_entry as text
% str2double(get(hObject,'String')) returns contents of highpass_entry as a double
% --- Executes during object creation, after setting all properties.
function highpass_entry_CreateFcn(hObject, eventdata, handles)
% hObject handle to highpass_entry (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% --- Executes on button press in save_checkbox.
function save_checkbox_Callback(hObject, eventdata, handles)
% hObject handle to save_checkbox (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hint: get(hObject,'Value') returns toggle state of save_checkbox
% --- Executes on button press in Default_radiobutton.
function Default_radiobutton_Callback(hObject, eventdata, handles)
% hObject handle to Default_radiobutton (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
if get(handles.Default_radiobutton , 'Value')
set(handles.nomask_radiobutton , 'Enable' , 'On' ,'Value' , 0);
set(handles.Default_radiobutton, 'Enable', 'inactive');
set(handles.mask_entry , 'Enable' , 'Off' , 'String' , 'Default Mask');
end
% Hint: get(hObject,'Value') returns toggle state of Default_radiobutton
% --- Executes on button press in nomask_radiobutton.
function nomask_radiobutton_Callback(hObject, eventdata, handles)
% hObject handle to nomask_radiobutton (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
if get(handles.nomask_radiobutton , 'Value')
set(handles.Default_radiobutton , 'Enable' , 'On' , 'Value' , 0);
set(handles.nomask_radiobutton , 'Enable', 'inactive');
set(handles.mask_entry , 'Enable' , 'Off' , 'String' , 'Don''t use any mask');
end
% Hint: get(hObject,'Value') returns toggle state of nomask_radiobutton
% --- Executes on button press in mask_pushbutton.
function mask_pushbutton_Callback(hObject, eventdata, handles)
% hObject handle to mask_pushbutton (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
[RESTPath , Filename , extn]=fileparts(which('rest.m'));
RESTMask=[RESTPath , filesep , 'mask'];
current_directory=pwd;
cd(RESTMask);
[mask_filename , mask_pathname]=uigetfile({'*.img;*.nii;*.nii.gz','Brain Image Files (*.img;*.nii;*.nii.gz)';'*.*', 'All Files (*.*)';}, ...
'Pick one mask file');
cd(current_directory);
mask_entry=[mask_pathname,mask_filename];
if ischar(mask_entry)
set(handles.Default_radiobutton , 'Enable' , 'On' , 'Value' , 0);
set(handles.nomask_radiobutton , 'Enable' , 'On' , 'Value' , 0);
set(handles.mask_entry , 'String' , mask_entry);
if strcmp(upper(get(handles.mask_entry , 'Enable')) , 'OFF')
set(handles.mask_entry , 'Enable' , 'On');
end
end
function mask_entry_Callback(hObject, eventdata, handles)
% hObject handle to mask_entry (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of mask_entry as text
% str2double(get(hObject,'String')) returns contents of mask_entry as a double
% --- Executes during object creation, after setting all properties.
function mask_entry_CreateFcn(hObject, eventdata, handles)
% hObject handle to mask_entry (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% --- Executes on button press in output_pushbutton.
function output_pushbutton_Callback(hObject, eventdata, handles)
% hObject handle to output_pushbutton (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
output_dir=pwd;
vmhc_output_dir=uigetdir(output_dir ,'Select a directory to save VMHC maps');
if ischar(vmhc_output_dir)
set(handles.output_entry , 'String' , vmhc_output_dir);
end
function output_entry_Callback(hObject, eventdata, handles)
% hObject handle to output_entry (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of output_entry as text
% str2double(get(hObject,'String')) returns contents of output_entry as a double
% --- Executes during object creation, after setting all properties.
function output_entry_CreateFcn(hObject, eventdata, handles)
% hObject handle to output_entry (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function prefix_entry_Callback(hObject, eventdata, handles)
% hObject handle to prefix_entry (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of prefix_entry as text
% str2double(get(hObject,'String')) returns contents of prefix_entry as a double
% --- Executes during object creation, after setting all properties.
function prefix_entry_CreateFcn(hObject, eventdata, handles)
% hObject handle to prefix_entry (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% --- Executes on selection change in dir_listbox.
function dir_listbox_Callback(hObject, eventdata, handles)
% hObject handle to dir_listbox (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: contents = cellstr(get(hObject,'String')) returns dir_listbox contents as cell array
% contents{get(hObject,'Value')} returns selected item from dir_listbox
% --- Executes during object creation, after setting all properties.
function dir_listbox_CreateFcn(hObject, eventdata, handles)
% hObject handle to dir_listbox (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: listbox controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% --- Executes on button press in fisherz_checkbox.
function fisherz_checkbox_Callback(hObject, eventdata, handles)
% hObject handle to fisherz_checkbox (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hint: get(hObject,'Value') returns toggle state of fisherz_checkbox
% --- Executes on button press in dir_pushbutton.
function dir_pushbutton_Callback(hObject, eventdata, handles)
% hObject handle to dir_pushbutton (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
data_dir=uigetdir(pwd , 'Please select the data diretory to compute VMHC map');
handles=select_directory(handles,data_dir);
guidata(hObject,handles);
function result=select_directory(AHandle,data_dir)
if ischar(data_dir)
if rest_misc('GetMatlabVersion')>=7.3
data_dir=strtrim(data_dir);
end
%if ~isfield(AHandle,'data_list')
% AHandle.data_list='';
%end
AHandle.data_list=[AHandle.data_list ; {0 , data_dir}];
DirList_count=size(AHandle.data_list,1);
theVolumnCount=rest_CheckDataDir(AHandle.data_list{DirList_count , 2});
if theVolumnCount<=0
fprintf('There is no data or non-data files in this directory:\n%s\nPlease re-select\n',data_dir);
errordlg(sprintf('There is no data or non-data files in this directory:\n%s\nPlease re-select\n',data_dir));
AHandle.data_list(DirList_count,:)=[];
else
AHandle.data_list{DirList_count,1}=theVolumnCount;
end
if size(AHandle.data_list,1)
data_listtext=GetInputDirDisplayList(AHandle);
set(AHandle.dir_listbox , 'String' , data_listtext ,...
'Value' , DirList_count);
end
result=AHandle;
else
result=AHandle;
end
% --- Executes on button press in timecourse_pushbutton.
function timecourse_pushbutton_Callback(hObject, eventdata, handles)
% hObject handle to timecourse_pushbutton (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
show_timecourse(hObject , [] , handles);
%guidata(hObject , handles);
%%
%%
function disable_button(handles , tag)
tag=upper(tag);
if strcmp(tag , 'OFF')
set(handles.load_tag , 'Visible' , 'ON');
else
set(handles.load_tag , 'Visible' , 'OFF');
end
set(handles.detrend_checkbox , 'enable' , tag);
set(handles.bandpass_checkbox , 'enable' , tag);
if get(handles.bandpass_checkbox , 'Value' )
set(handles.TR_entry , 'enable' , tag);
set(handles.lowpass_entry , 'enable' , tag);
set(handles.highpass_entry , 'enable' , tag);
end
if get(handles.detrend_checkbox , 'Value') ...
|| get(handles.bandpass_checkbox , 'Value')
set(handles.save_checkbox , 'enable' , tag);
end
set(handles.mask_pushbutton , 'enable' , tag);
set(handles.Default_radiobutton , 'enable' , tag);
set(handles.nomask_radiobutton , 'enable' , tag);
if ~strcmp( get(handles.mask_entry , 'String') , 'Default Mask')...
&& ~strcmp( get(handles.mask_entry , 'String') , 'Don''t use any mask')
set(handles.mask_entry, 'enable' , tag);
end
set(handles.output_pushbutton , 'enable' , tag);
set(handles.output_entry , 'enable' , tag);
if strcmp(tag , 'OFF')
set(handles.dir_listbox , 'enable' , 'inactive');
else
set(handles.dir_listbox , 'enable' , 'ON');
end
set(handles.timecourse_pushbutton , 'enable' , tag);
set(handles.dir_pushbutton , 'enable' , tag);
set(handles.utilities_popupmenu , 'enable' , tag);
set(handles.fisherz_checkbox , 'enable' , tag);
set(handles.run_pushbutton , 'enable' , tag);
function recursive_add_directory(hObject , eventdata , handles)
if prod(size(handles.data_list))>0 && size(handles.data_list,1)>0
theDir = handles.data_list{1,1};
else
theDir = pwd;
end
theDir = uigetdir(pwd ,...
['Please select the parent data directory of many sub-folders ',...
'containing EPI data to compute VMHC map: ']);
if ischar(theDir)
set(handles.dir_listbox , 'BackgroundColor' , 'Green');
theFileList = dir(theDir);
disable_button(handles , 'Off')
for x=1:size(theFileList,1)
if theFileList(x).isdir && ~strcmp(theFileList(x).name,'.')...
&& ~strcmp(theFileList(x).name,'..')
handles=select_directory(handles ,...
[theDir , filesep , theFileList(x).name]);
pause(0.01);
end
end
disable_button(handles , 'On');
set(handles.dir_listbox , 'BackgroundColor' , 'White');
end
guidata(hObject, handles);
%% check the Data dir to make sure that there are only {hdr,img}, nii, nii.gz
function Result=GetInputDirDisplayList(handles)
Result ={};
for x=1:size(handles.data_list, 1)
Result =[Result ,...
{sprintf('%d# %s',handles.data_list{x, 1},handles.data_list{x, 2})}];
end
function delete_selecteddata(hObject , eventdata , handles)
theIndex = get(handles.dir_listbox , 'Value');
if prod(size(handles.data_list))==0 || size(handles.data_list ,1 )==0 ...
|| theIndex > size(handles.data_list , 1)
return;
end
theDir=handles.data_list{theIndex , 2};
theVolumnCount=handles.data_list{theIndex , 1};
tmpMsg=sprintf('Delete\n\t %s \nVolumn Count : %d ?' , theDir , theVolumnCount);
if strcmp(questdlg(tmpMsg , 'Delete confirmation') , 'Yes')
if theIndex>1
set(handles.dir_listbox , 'Value' , theIndex-1);
end
handles.data_list(theIndex , :)=[];
if size(handles.data_list , 1)==0
handles.data_list={};
end
data_listtext=GetInputDirDisplayList(handles);
set(handles.dir_listbox , 'String' , data_listtext);
guidata(hObject , handles);
end
function clear_datalist(hObject , eventdata , handles)
if prod(size(handles.data_list))==0 || size(handles.data_list , 1)==0
return
end
tmpMsg=sprintf('Attention!\nDelete all data directories?');
if strcmpi(questdlg(tmpMsg , 'Clear confirmation') , 'Yes')
handles.data_list='';
set(handles.dir_listbox , 'String' , handles.data_list);
guidata(hObject , handles);
end
function show_timecourse(hObject , eventdata , handles)
if prod(size(handles.data_list))==0 || size(handles.data_list , 1)==0
%Check Input Directory
warndlg('Please select a data directory to show!');
check_warning(handles.dir_listbox);
return;
end
%Check band and TR
if ~get(handles.bandpass_checkbox , 'Value')
warndlg('Please set TR and Band');
set(handles.bandpass_checkbox , 'Value' , 1);
set(handles.TR_entry , 'String' , '2' , 'Enable' , 'On');
set(handles.lowpass_entry , 'String' , '0.01' , 'Enable' , 'On');
set(handles.highpass_entry , 'String' , '0.08' , 'Enable' , 'On');
return;
end
if isempty(get(handles.TR_entry , 'String'))
check_warning(handles.TR_entry);
return;
end
if isempty(get(handles.lowpass_entry , 'String'))
check_warning(handles.lowpass_entry);
return;
end
if isempty(get(handles.highpass_entry , 'String'))
check_warning(handles.highpass_entry);
return;
end
selected_value=get(handles.dir_listbox , 'Value');
selected_dir=handles.data_list{selected_value,2};
dir_struct=dir(selected_dir);
disable_button(handles , 'Off');
pause(0.01);
[AllVolume VoxelSize FileList Header]=rest_to4d(selected_dir);
disable_button(handles , 'On');
handles.Volume=AllVolume;
guidata(hObject , handles);
try
Viewer=rest_sliceviewer('ShowImage' , [selected_dir , filesep, dir_struct(3).name]);
voxel_position=rest_sliceviewer('GetPosition' , Viewer);
handles.position=voxel_position;
create_timecourse(hObject , [] , handles);
%Update the Callback
theCallback = '';
cmdBrainMap = sprintf('voxel_position=rest_sliceviewer(''GetPosition'' , %g);' , Viewer);
cmdHandle = sprintf('[AObject , Ahandle ]=rest_VMHC_gui;');
cmdPosition = sprintf('Ahandle.position=voxel_position;');
cmdUpdateTimeCourse = 'rest_VMHC_gui(''create_timecourse'', AObject , [], Ahandle);';
theCallback = sprintf('%s\n%s\n%s\n%s\n' , cmdBrainMap , cmdHandle , cmdPosition ,...
cmdUpdateTimeCourse);
cmdClearVar = 'clear voxel_position Ahandle';
rest_sliceviewer('UpdateCallback' , Viewer , [theCallback cmdClearVar] , 'Time Course');
catch
rest_misc('DisplayLastException');
end
function create_timecourse( hObject , eventdata , handles)
TR=str2num( get(handles.TR_entry , 'String') );
lowband=str2num( get(handles.lowpass_entry , 'String') );
highband=str2num( get(handles.highpass_entry , 'String') );
%Plot time course
axes(handles.image_axes); cla
timecourse=squeeze(handles.Volume(handles.position(1) , handles.position(2) , handles.position(3),:));
timepoint=size(handles.Volume,4);
plot((1:timepoint) * TR , timecourse ,'blue');
xlim([1 , timepoint] * TR);
theYLim = [min(timecourse) , max(timecourse)];
if ~isfinite(theYLim(1)), theYLim(1)=0; end
if ~isfinite(theYLim(2)), theYLim(2)=0; end
if theYLim(2)>theYLim(1), ylim(theYLim); end
set(gca, 'Title',text('String','Time Course', 'Color', 'magenta'));
xlabel('Time (seconds)');
ylabel('Intensity');
%Plot the amlitude in Freq domain
%pow
padded_len = rest_nextpow2_one35( timepoint );
if get(handles.detrend_checkbox , 'Value')
timecourse_notrend=detrend(double (timecourse));
axes(handles.image_axes); hold on;
timecourse_plot=timecourse_notrend + repmat( mean(double(timecourse)) , [timepoint , 1]);
plot( (1:timepoint) * TR , timecourse_plot, 'r:');
theYLim=[min(theYLim(1),min(timecourse_plot)) , max(theYLim(2) , max(timecourse_plot))];
if ~isfinite(theYLim(1)), theYLim(1)=0; end
if ~isfinite(theYLim(2)), theYLim(2)=0; end
if theYLim(2)>theYLim(1), ylim(theYLim); end
set(gca, 'Title',text('String','Time Course(Red dot line is after removing linear trend)', 'Color', 'magenta'));
power_title ='Power Spectrum after removing linear trend';
freq_series =fft(timecourse_notrend, padded_len);
else
%FFT
power_title ='Power Spectrum';
freq_series =fft( double(timecourse) , padded_len);
end
sample_rate=1/TR;
freq_precision=sample_rate/padded_len;
freq_limit= freq_precision : freq_precision : sample_rate/2 ;
x_limit=[2 , (padded_len/2+1)];
freq_series = abs( freq_series( x_limit(1):x_limit(2) ) );
freq_series(1:end) = freq_series(1:end).^2/timepoint;
freq_series(1:end-1) = freq_series(1:end-1) * 2;
axes(handles.power_axes); cla;
plot(freq_limit , freq_series , 'Color' , 'blue');
xlim([freq_limit(1) , freq_limit(end)]);
theYLim = [min(freq_series(1:end)) , max(freq_series(1:end))];
if ~isfinite(theYLim(1)), theYLim(1)=0; end
if ~isfinite(theYLim(2)), theYLim(2)=0; end
if theYLim(2)>theYLim(1), ylim(theYLim); end
set(gca, 'Title', text('String',power_title, 'Color', 'magenta'));
xlabel(sprintf('Frequency( Hz), Sample Period( TR)=%g seconds', TR));
ylabel('Amplitude');
%hDataCursor = datacursormode(handles.fig_VMHC);
%set(hDataCursor,'DisplayStyle','datatip', 'SnapToDataVertex','on','Enable','on')
%set(hDataCursor,'UpdateFcn', @SetDataTip);
hold on;
plot([1 ,1] * lowband , get(gca , 'Ylim') , 'r:');
text(lowband , theYLim(2)-theYLim(2)/10 , ...
sprintf('\\leftarrow %g Hz', lowband),...
'HorizontalAlignment','left', 'Color', 'red');
plot([1, 1]* highband, get(gca,'Ylim'), 'r:');
text(highband , theYLim(2)-theYLim(2)/10, ...
sprintf('\\leftarrow %g Hz', highband),...
'HorizontalAlignment','left', 'Color', 'red');
%set(handles.image_axes,...
% 'Units' , 'Pixel',...
% 'YDir' , 'normal',...
% 'XTickLabel' , [],...
% 'XTick' , [],...
% 'YTickLabel' , [],...
% 'YTick' , [],...
% 'DataAspectRatio' , [1,1,1]);
fig_size=get(handles.fig_VMHC , 'Position');
fig_size(1 ,3)=158;
set(handles.fig_VMHC , 'Position' , fig_size);
guidata(hObject,handles)
%%
% --- Executes on selection change in utilities_popupmenu.
%%
function utilities_popupmenu_Callback(hObject, eventdata, handles)
% hObject handle to utilities_popupmenu (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
switch get(handles.utilities_popupmenu , 'Value')
case 1 %Uitility
return;
case 2 %ALFF
alff_gui;
set(handles.utilities_popupmenu , 'Value' , 1);
case 3 %fALFF
f_alff_gui;
set(handles.utilities_popupmenu , 'Value' , 1);
case 4 %ReHo
reho_gui;
set(handles.utilities_popupmenu , 'Value' , 1);
case 5 %FC
fc_gui;
set(handles.utilities_popupmenu , 'Value' , 1);
case 6 %Degree Centrality
rest_DegreeCentrality_gui;
set(handles.utilities_popupmenu , 'Value' , 1);
case 7 %========
set(handles.utilities_popupmenu , 'Value' , 1);
case 8 %SliceViewer
rest_sliceviewer;
set(handles.utilities_popupmenu , 'Value' , 1);
otherwise
end
guidata(hObject , handles);
% Hints: contents = cellstr(get(hObject,'String')) returns utilities_popupmenu contents as cell array
% contents{get(hObject,'Value')} returns selected item from utilities_popupmenu
% --- Executes during object creation, after setting all properties.
function utilities_popupmenu_CreateFcn(hObject, eventdata, handles)
% hObject handle to utilities_popupmenu (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: popupmenu controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% --------------------------------------------------------------------
function help_menu_Callback(hObject, eventdata, handles)
% hObject handle to help_menu (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --------------------------------------------------------------------
function web_menu_Callback(hObject, eventdata, handles)
% hObject handle to web_menu (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
web('http://restfmri.net');
% --------------------------------------------------------------------
function about_DC_menu_Callback(hObject, eventdata, handles)
% hObject handle to about_DC_menu (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --------------------------------------------------------------------
function file_menu_Callback(hObject, eventdata, handles)
% hObject handle to file_menu (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --------------------------------------------------------------------
function save_menu_Callback(hObject, eventdata, handles)
% hObject handle to save_menu (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
[FileName , PathName]=uiputfile('*.mat', 'Save a configure mat for VMHC' , 'VMHC.mat' );
save_name=[PathName, FileName];
if ischar(save_name)
Configure='';
Configure.detrend_checkbox=get(handles.detrend_checkbox , 'Value');
Configure.bandpass_checkbox=get(handles.bandpass_checkbox , 'Value');
if Configure.bandpass_checkbox
Configure.TR=get(handles.TR_entry , 'String');
Configure.lowpass=get(handles.lowpass_entry , 'String');
Configure.highpass=get(handles.highpass_entry , 'String');
end
Configure.save_checkbox=get(handles.save_checkbox , 'Value');
Configure.dir_listbox=get(handles.dir_listbox , 'String');
Configure.data_list=handles.data_list;
Configure.mask_entry=get(handles.mask_entry , 'String');
Configure.output_entry=get(handles.output_entry , 'String');
Configure.prefix_entry=get(handles.prefix_entry , 'String');
Configure.fisherz_checkbox=get(handles.fisherz_checkbox , 'Value');
save(save_name , 'Configure');
end
% --------------------------------------------------------------------
function load_menu_Callback(hObject, eventdata, handles)
% hObject handle to load_menu (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
[FileName , PathName] = uigetfile('*.mat' , 'Pick a configure mat for VMHC');
load_name=[PathName , FileName];
if ischar(load_name)
load(load_name);
else
return;
end
set(handles.detrend_checkbox , 'Value' , Configure.detrend_checkbox);
set(handles.bandpass_checkbox , 'Value', Configure.bandpass_checkbox);
if Configure.bandpass_checkbox
set(handles.TR_entry , 'String' , Configure.TR);
set(handles.lowpass_entry , 'String' , Configure.lowpass);
set(handles.highpass_entry , 'String' , Configure.highpass);
set(handles.TR_entry , 'Enable' , 'On');
set(handles.lowpass_entry , 'Enable' , 'On');
set(handles.highpass_entry , 'Enable' , 'On');
else
set(handles.TR_entry , 'Enable' , 'Off');
set(handles.lowpass_entry , 'Enable' , 'Off');
set(handles.highpass_entry , 'Enable' , 'Off');
end
if Configure.detrend_checkbox || Configure.bandpass_checkbox
set(handles.save_checkbox , 'Enable' , 'On');
else
set(handles.save_checkbox , 'Enable' , 'Off');
end
set(handles.save_checkbox , 'Value' , Configure.save_checkbox);
set(handles.dir_listbox , 'String', Configure.dir_listbox);
handles.data_list=Configure.data_list;
if strcmp(Configure.mask_entry , 'Default Mask')
set(handles.Default_radiobutton , 'Value' , 1);
set(handles.nomask_radiobutton , 'Value' , 0);
set(handles.mask_entry , 'String', Configure.mask_entry);
set(handles.mask_entry , 'Enable' , 'Off');
elseif strcmp(Configure.mask_entry , 'Don''t use any mask')
set(handles.Default_radiobutton , 'Value' , 0);
set(handles.nomask_radiobutton , 'Value' , 1);
set(handles.mask_entry , 'String', Configure.mask_entry);
set(handles.mask_entry , 'Enable' , 'Off');
else
set(handles.Default_radiobutton , 'Value' , 0);
set(handles.nomask_radiobutton , 'Value' , 0);
set(handles.mask_entry , 'String', Configure.mask_entry);
set(handles.mask_entry , 'Enable' , 'On');
end
set(handles.output_entry , 'String', Configure.output_entry);
set(handles.prefix_entry , 'String' , Configure.prefix_entry);
set(handles.fisherz_checkbox , 'Value' , Configure.fisherz_checkbox);
guidata(hObject , handles);
% --------------------------------------------------------------------
function quit_menu_Callback(hObject, eventdata, handles)
% hObject handle to quit_menu (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
delete(handles.fig_VMHC);
%%
% --- Executes on button press in run_pushbutton.
function run_pushbutton_Callback(hObject, eventdata, handles)
% hObject handle to run_pushbutton (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
set(handles.dir_listbox , 'Value' , 1);
if strcmp( get(handles.mask_entry , 'String') , 'Default Mask' )
[RESTPath , Filename , extn]=fileparts(which('rest.m'));
mask_file=[RESTPath , filesep , 'mask' , filesep , 'BrainMask_05_61x73x61.img'];
elseif strcmp( get(handles.mask_entry , 'String') , 'Don''t use any mask' )
mask_file='';
else
mask_file=get(handles.mask_entry , 'String');
end
%Check Input Directory
if size(handles.data_list, 1)==0
check_warning(handles.dir_listbox);
return;
end
PF_output=get(handles.output_entry , 'String');
if isempty(PF_output)
disable_button(handles.output_entry);
return;
end
%Init TR, LOWPASS, HIGHPASS
if get(handles.bandpass_checkbox , 'Value')
PF_TR=str2num( get(handles.TR_entry , 'String') );
PF_Lp=str2num( get(handles.lowpass_entry , 'String') );
PF_Hp=str2num( get(handles.highpass_entry , 'String') );
else
PF_TR='';
end
output_prefix=get(handles.prefix_entry , 'String');
fisherz_tag=get(handles.fisherz_checkbox , 'Value');
try
set(handles.run_pushbutton , 'BackgroundColor' , 'Red');
CUTNUMBER=10;
disable_button(handles , 'Off');
pause(0.01);
%RUN!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!11
if get(handles.save_checkbox , 'Value')
%Detrend
if get(handles.detrend_checkbox , 'Value')
suffix='_detrend';
%Change Dir Name
PF_inputdata=handles.data_list(: , 2);
for i=1:size(handles.data_list , 1)
handles.data_list{i ,2}=[handles.data_list{i ,2} , suffix];
end
%Calculate
parfor i=1:size(PF_inputdata ,1)
rest_detrend (PF_inputdata{i}, suffix , CUTNUMBER);
end