forked from Chaogan-Yan/REST
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrest_GRFCorrection_gui.m
executable file
·352 lines (288 loc) · 14.4 KB
/
rest_GRFCorrection_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
function varargout = rest_GRFCorrection_gui(varargin)
% varargout = rest_GRFCorrection_gui(varargin)
% Perform Gaussian Random Field theory multiple comparison correction
% -------------------------------------------------------------------
% GUI by Sandy Wang and ZANG Zhen-Xiang
% State Key Laboratory of Cognitive Neuroscience and Learning in Beijing Normal University
% Center for Cognition and Brain Disorders and The Affiliated Hospital,Hangzhou Normal University
% --------------------------------------------------------------------
% GRF_Function (rest_GRF_Threshold) by YAN Chao-Gan.
% The Nathan Kline Institute for Psychiatric Research, 140 Old Orangeburg Road, Orangeburg, NY 10962, USA
% Child Mind Institute, 445 Park Avenue, New York, NY 10022, USA
% The Phyllis Green and Randolph Cowen Institute for Pediatric
% Neuroscience, New York University Child Study Center, New York, NY 10016, USA
% --------------------------------------------------------------------
% http://www.restfmri.net
% Mail to Authors: <a href="[email protected]">YAN Chao-Gan</a>; <a href="[email protected]">ZANG Zhen-Xiang</a>;
% Version=1.0; Released: 120501
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @rest_GRFCorrection_gui_OpeningFcn, ...
'gui_OutputFcn', @rest_GRFCorrection_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 sandy_GRF_Correction is made visible.
function rest_GRFCorrection_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 sandy_GRF_Correction (see VARARGIN)
% Choose default command line output for sandy_GRF_Correction
handles.output = hObject;
set(handles.output_entry , 'String' , pwd);
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes sandy_GRF_Correction wait for user response (see UIRESUME)
% uiwait(handles.fig_GRF_multi);
% --- Outputs from this function are returned to the command line.
function varargout = rest_GRFCorrection_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;
% --- Executes on selection change in input_listbox.
function input_listbox_Callback(hObject, eventdata, handles)
% hObject handle to input_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 input_listbox contents as cell array
% contents{get(hObject,'Value')} returns selected item from input_listbox
% --- Executes during object creation, after setting all properties.
function input_listbox_CreateFcn(hObject, eventdata, handles)
% hObject handle to input_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 input_pushbutton.
function input_pushbutton_Callback(hObject, eventdata, handles)
% hObject handle to input_pushbutton (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
[input_filename , input_pathname]=uigetfile({'*.img;*.nii;*.nii.gz','Brain Image Files (*.img;*.nii;*.nii.gz)';'*.*', 'All Files (*.*)';}, ...
'Pick statistical maps' , 'MultiSelect' , 'On');
if (ischar(input_filename) || iscell(input_filename)) && ischar(input_pathname)
present_list=get(handles.input_listbox , 'String');
if iscell(input_filename)
for i=1:size(input_filename , 2)
if isempty(present_list)
present_list={[input_pathname , input_filename{i}]};
else
present_list=...
[present_list , {[input_pathname , input_filename{i}]}];
end
end
else
if isempty(present_list)
present_list={[input_pathname , input_filename]};
else
present_list=[present_list , {[input_pathname , input_filename]}];
end
end
set(handles.input_listbox , 'String' , present_list);
set(handles.input_listbox , 'Value' , size(present_list ,2));
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 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.mask_entry , 'String' , mask_entry);
end
function voxel_entry_Callback(hObject, eventdata, handles)
% hObject handle to voxel_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 voxel_entry as text
% str2double(get(hObject,'String')) returns contents of voxel_entry as a double
% --- Executes during object creation, after setting all properties.
function voxel_entry_CreateFcn(hObject, eventdata, handles)
% hObject handle to voxel_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 cluster_entry_Callback(hObject, eventdata, handles)
% hObject handle to voxel_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 voxel_entry as text
% str2double(get(hObject,'String')) returns contents of voxel_entry as a double
% --- Executes during object creation, after setting all properties.
function cluster_entry_CreateFcn(hObject, eventdata, handles)
% hObject handle to voxel_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 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
% --- 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=uigetdir('Please pick a directory');
set(handles.output_entry , 'String' , output_dir);
% --- 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)
check_tag=0;
if isempty(get(handles.input_listbox , 'String'))
check_warning(handles.input_listbox);
check_tag=1;
end
if isempty(get(handles.voxel_entry , 'String'))
check_warning(handles.voxel_entry);
check_tag=1;
end
if isempty(get(handles.voxel_entry , 'String'))
check_warning(handles.voxel_entry);
check_tag=1;
end
if check_tag==1
return;
end
is_two_tag=get(handles.two_tail , 'Value');
mask_file=get(handles.mask_entry , 'String');
voxel_p=str2num(get(handles.voxel_entry , 'String'));
cluster_p=str2num(get(handles.cluster_entry , 'String'));
input=get(handles.input_listbox , 'String');
output_path=get(handles.output_entry , 'String');
try
set(handles.input_listbox , 'Value' , 1);
for i=1:size(input ,2)
[Data VoxelSize Header]=rest_readfile(input{i});
[input_path , input_name , input_ext]=fileparts(input{i});
if isfield(Header,'descrip')
headinfo=Header.descrip;
testDf2=0;
if ~isempty(strfind(headinfo,'{T_['))% dong 100331 begin
testFlag='T';
Tstart=strfind(headinfo,'{T_[')+length('{T_[');
Tend=strfind(headinfo,']}')-1;
testDf = str2num(headinfo(Tstart:Tend));
elseif ~isempty(strfind(headinfo,'{F_['))
testFlag='F';
Tstart=strfind(headinfo,'{F_[')+length('{F_[');
Tend=strfind(headinfo,']}')-1;
F_Df = str2num(headinfo(Tstart:Tend));
testDf=F_Df(1,1);
testDf2=F_Df(1,2);
elseif ~isempty(strfind(headinfo,'{R_['))
testFlag='R';
Tstart=strfind(headinfo,'{R_[')+length('{R_[');
Tend=strfind(headinfo,']}')-1;
testDf = str2num(headinfo(Tstart:Tend));
elseif ~isempty(strfind(headinfo,'{Z_['))
testFlag='Z';
Tstart=strfind(headinfo,'{Z_[')+length('{Z_[');
Tend=strfind(headinfo,']}')-1;
testDf = str2num(headinfo(Tstart:Tend));
end
end
rest_GRF_Threshold(input{i},... %rest_GRF_Threshold(Data,...
voxel_p,...
is_two_tag,...
cluster_p,...
[output_path , filesep , input_name],...
mask_file,...
testFlag,...
testDf,...
testDf2,...
VoxelSize,...
Header); %rest_GRF_Threshold by YAN Chao-Gan
end
catch
rest_misc( 'DisplayLastException');
end
function check_warning(UIcontrol)
set(UIcontrol , 'BackgroundColor' , 'Red');
pause(0.1);
set(UIcontrol , 'BackgroundColor' , 'White');
pause(0.1);
set(UIcontrol , 'BackgroundColor' , 'Red');
pause(0.1);
set(UIcontrol , 'BackgroundColor' , 'White');
pause(0.1);
set(UIcontrol , 'BackgroundColor' , 'Red');
pause(0.1);
set(UIcontrol , 'BackgroundColor' , 'White');
pause(0.1);
function two_tail_Callback(hObject, eventdata, handles)
% --- Executes when selected object is changed in tail_panel.
function tail_panel_SelectionChangeFcn(hObject, eventdata, handles)
% hObject handle to the selected object in tail_panel
% eventdata structure with the following fields (see UIBUTTONGROUP)
% EventName: string 'SelectionChanged' (read only)
% OldValue: handle of the previously selected object or empty if none was selected
% NewValue: handle of the currently selected object
% handles structure with handles and user data (see GUIDATA)
is_two_tag=get(handles.two_tail , 'Value');
if is_two_tag
uiwait(msgbox('The "two-tailed" option is doing as following (e.g., if set VoxelPThreshold = 0.01 and cluster level p<0.05): 1) Get Group A > Group B, set Z>2.576 (two-tailed p <0.01) and cluster level p<0.025 2) Get Group A < Group B, set a Z<-2.576 (two-tailed p <0.01) and cluster level p<0.025. 3) Add 1 and 2 together, which could ensure the total p<0.05.','Two-tailed'));
end