0001 function varargout = fc_gui(varargin)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021 gui_Singleton = 1;
0022 gui_State = struct('gui_Name', mfilename, ...
0023 'gui_Singleton', gui_Singleton, ...
0024 'gui_OpeningFcn', @fc_gui_OpeningFcn, ...
0025 'gui_OutputFcn', @fc_gui_OutputFcn, ...
0026 'gui_LayoutFcn', [] , ...
0027 'gui_Callback', []);
0028 if nargin && ischar(varargin{1})
0029 gui_State.gui_Callback = str2func(varargin{1});
0030 end
0031
0032 if nargout
0033 [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
0034 else
0035 gui_mainfcn(gui_State, varargin{:});
0036 end
0037
0038
0039
0040
0041 function fc_gui_OpeningFcn(hObject, eventdata, handles, varargin)
0042
0043 InitControlProperties(hObject, handles);
0044
0045 InitFrames(hObject,handles);
0046
0047 [pathstr, name, ext, versn] = fileparts(mfilename('fullpath'));
0048
0049 handles.Cfg.DataDirs ={};
0050 handles.Cfg.MaskFile = 'Default';
0051 handles.Cfg.OutputDir =pwd;
0052 handles.Cfg.WantFisherZMap ='Yes';
0053 handles.Cfg.ROIList ='';
0054
0055
0056 handles.Covariables.ort_file ='';
0057 handles.Covariables.polort =1;
0058
0059 handles.Filter.BandLow =0.01;
0060 handles.Filter.BandHigh =0.08;
0061 handles.Filter.UseFilter ='No';
0062 handles.Filter.Retrend ='Yes';
0063 handles.Filter.SamplePeriod=2;
0064 handles.Detrend.BeforeFilter ='No';
0065 handles.Detrend.AfterFilter ='No';
0066
0067 handles.Log.SelfPath =pathstr;
0068 handles.Log.Filename =GetLogFilename('','');
0069
0070 handles.Performance =0;
0071
0072 guidata(hObject, handles);
0073 UpdateDisplay(handles);
0074 movegui(handles.figFCMain, 'center');
0075 set(handles.figFCMain,'Name','Functional Connectivity');
0076
0077
0078 handles.output = hObject;
0079 guidata(hObject, handles);
0080
0081
0082
0083
0084
0085 function varargout = fc_gui_OutputFcn(hObject, eventdata, handles)
0086
0087 varargout{1} = handles.output;
0088
0089
0090
0091
0092 function edtDataDirectory_Callback(hObject, eventdata, handles)
0093 theDir =get(hObject, 'String');
0094 SetDataDir(hObject, theDir,handles);
0095
0096 function edtDataDirectory_CreateFcn(hObject, eventdata, handles)
0097 if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
0098 set(hObject,'BackgroundColor','white');
0099 end
0100
0101
0102 function btnSelectDataDir_Callback(hObject, eventdata, handles)
0103 if size(handles.Cfg.DataDirs, 1)>0
0104 theDir =handles.Cfg.DataDirs{1,1};
0105 else
0106 theDir =pwd;
0107 end
0108 theDir =uigetdir(theDir, 'Please select the data directory to compute functional connectivity map: ');
0109 if ischar(theDir),
0110 SetDataDir(hObject, theDir,handles);
0111 end
0112
0113 function RecursiveAddDataDir(hObject, eventdata, handles)
0114 if prod(size(handles.Cfg.DataDirs))>0 && size(handles.Cfg.DataDirs, 1)>0,
0115 theDir =handles.Cfg.DataDirs{1,1};
0116 else
0117 theDir =pwd;
0118 end
0119 theDir =uigetdir(theDir, 'Please select the parent data directory of many sub-folders containing EPI data to compute functional connectivity map: ');
0120 if ischar(theDir),
0121
0122 setappdata(0, 'FC_DoingRecursiveDir', 1);
0123 theOldColor =get(handles.listDataDirs, 'BackgroundColor');
0124 set(handles.listDataDirs, 'BackgroundColor', [ 0.7373 0.9804 0.4784]);
0125 try
0126 rest_RecursiveDir(theDir, 'fc_gui(''SetDataDir'',gcbo, ''%s'', guidata(gcbo) )');
0127 catch
0128 rest_misc( 'DisplayLastException');
0129 end
0130 set(handles.listDataDirs, 'BackgroundColor', theOldColor);
0131 rmappdata(0, 'FC_DoingRecursiveDir');
0132 end
0133
0134 function SetDataDir(hObject, ADir,handles)
0135 if ~ischar(ADir), return; end
0136 theOldWarnings =warning('off', 'all');
0137
0138 if rest_misc('GetMatlabVersion')>=7.3,
0139 ADir =strtrim(ADir);
0140 end
0141 if (~isequal(ADir , 0)) &&( (size(handles.Cfg.DataDirs, 1)==0)||(0==length(strmatch(ADir,handles.Cfg.DataDirs( : , 1),'exact' ) ) ))
0142 handles.Cfg.DataDirs =[ {ADir , 0}; handles.Cfg.DataDirs];
0143 theVolumnCount =CheckDataDir(handles.Cfg.DataDirs{1,1} );
0144 if (theVolumnCount<=0),
0145 if isappdata(0, 'FC_DoingRecursiveDir') && getappdata(0, 'FC_DoingRecursiveDir'),
0146 else
0147 fprintf('There is no data or non-data files in this directory:\n%s\nPlease re-select\n\n', ADir);
0148 errordlg( sprintf('There is no data or non-data files in this directory:\n\n%s\n\nPlease re-select', handles.Cfg.DataDirs{1,1} ));
0149 end
0150 handles.Cfg.DataDirs(1,:)=[];
0151 if size(handles.Cfg.DataDirs, 1)==0
0152 handles.Cfg.DataDirs=[];
0153 end
0154 else
0155 handles.Cfg.DataDirs{1,2} =theVolumnCount;
0156 end
0157
0158 guidata(hObject, handles);
0159 UpdateDisplay(handles);
0160 end
0161 warning(theOldWarnings);
0162
0163
0164 function UpdateDisplay(handles)
0165 if size(handles.Cfg.DataDirs,1)>0
0166 theOldIndex =get(handles.listDataDirs, 'Value');
0167
0168 set(handles.listDataDirs, 'String', GetInputDirDisplayList(handles) , 'Value', 1);
0169 theCount =size(handles.Cfg.DataDirs,1);
0170 if (theOldIndex>0) && (theOldIndex<= theCount)
0171 set(handles.listDataDirs, 'Value', theOldIndex);
0172 end
0173 set(handles.edtDataDirectory,'String', handles.Cfg.DataDirs{1,1});
0174 theResultFilename=get(handles.edtPrefix, 'String');
0175 theResultFilename=[theResultFilename '_' GetDirName(handles.Cfg.DataDirs{1,1})];
0176 set(handles.txtResultFilename, 'String', [theResultFilename '.{hdr/img}']);
0177 else
0178 set(handles.listDataDirs, 'String', '' , 'Value', 0);
0179 set(handles.txtResultFilename, 'String', 'Result: Prefix_DirectoryName.{hdr/img}');
0180 end
0181
0182
0183
0184
0185 set(handles.edtOutputDir ,'String', handles.Cfg.OutputDir);
0186 if isequal(handles.Cfg.MaskFile, '')
0187 set(handles.edtMaskfile, 'String', 'Don''t use any Mask');
0188 else
0189 set(handles.edtMaskfile, 'String', handles.Cfg.MaskFile);
0190 end
0191
0192
0193 if strcmpi(handles.Detrend.BeforeFilter, 'Yes')
0194
0195 set(handles.btnDetrend, 'Enable', 'on');
0196 else
0197
0198 set(handles.btnDetrend, 'Enable', 'off');
0199 end
0200
0201 if strcmpi(handles.Filter.UseFilter, 'Yes')
0202 set(handles.ckboxFilter, 'Value', 1);
0203 set(handles.ckboxRetrend, 'Enable', 'on');
0204 set(handles.edtBandLow, 'Enable', 'on', 'String', num2str(handles.Filter.BandLow));
0205 set(handles.edtBandHigh, 'Enable', 'on', 'String', num2str(handles.Filter.BandHigh));
0206 set(handles.edtSamplePeriod, 'Enable', 'on', 'String', num2str(handles.Filter.SamplePeriod));
0207
0208 set(handles.btnBandPass, 'Enable', 'on');
0209 else
0210 set(handles.ckboxFilter, 'Value', 0);
0211 set(handles.ckboxRetrend,'Enable', 'off');
0212 set(handles.edtBandLow, 'Enable', 'off', 'String', num2str(handles.Filter.BandLow));
0213 set(handles.edtBandHigh, 'Enable', 'off', 'String', num2str(handles.Filter.BandHigh));
0214 set(handles.edtSamplePeriod, 'Enable', 'off', 'String', num2str(handles.Filter.SamplePeriod));
0215
0216 set(handles.btnBandPass, 'Enable', 'off');
0217 end
0218
0219
0220 set(handles.ckboxFisherZ, 'Value', strcmpi(handles.Cfg.WantFisherZMap, 'Yes'));
0221
0222
0223 set(handles.ckboxRemoveTrendBefore, 'Value', strcmpi(handles.Detrend.BeforeFilter, 'Yes'));
0224 set(handles.ckboxRemoveTrendAfter, 'Value', strcmpi(handles.Detrend.AfterFilter, 'Yes'));
0225
0226
0227 if isempty(handles.Cfg.ROIList) || prod(size(handles.Cfg.ROIList)) ==0,
0228
0229 set(handles.btnROIVoxelWise, 'ForegroundColor', 'red', 'FontWeight', 'normal');
0230 set(handles.btnROIRegionWise, 'ForegroundColor', 'red', 'FontWeight', 'normal');
0231 else
0232
0233
0234 if ~iscell(handles.Cfg.ROIList) || 0 ...
0235
0236
0237 set(handles.btnROIVoxelWise, 'ForegroundColor', 'red', 'FontWeight', 'bold');
0238 set(handles.btnROIRegionWise, 'ForegroundColor', 'red', 'FontWeight', 'normal');
0239
0240 elseif size(handles.Cfg.ROIList,1)>=1,
0241
0242 set(handles.btnROIVoxelWise, 'ForegroundColor', 'red', 'FontWeight', 'normal');
0243 set(handles.btnROIRegionWise, 'ForegroundColor', 'red', 'FontWeight', 'bold');
0244 end
0245 end
0246
0247
0248 set(handles.edtCovariableFile, 'String', handles.Covariables.ort_file);
0249
0250
0251
0252 function Result=GetInputDirDisplayList(handles)
0253 Result ={};
0254 for x=size(handles.Cfg.DataDirs, 1):-1:1
0255 Result =[{sprintf('%d# %s',handles.Cfg.DataDirs{x, 2},handles.Cfg.DataDirs{x, 1})} ;Result];
0256 end
0257
0258
0259 function [nVolumn]=CheckDataDir(ADataDir)
0260 theFilenames = dir(ADataDir);
0261 theHdrFiles=dir(fullfile(ADataDir,'*.hdr'));
0262 theImgFiles=dir(fullfile(ADataDir,'*.img'));
0263
0264
0265
0266
0267
0268
0269
0270 if ~length(theHdrFiles)==length(theImgFiles)
0271 nVolumn =-1;
0272 fprintf('%s, *.{hdr,img} should be pairwise. Please re-examin them.\n', ADataDir);
0273 errordlg('*.{hdr,img} should be pairwise. Please re-examin them.');
0274 return;
0275 end
0276 count = 3; nVolumn = 0;
0277 for count = 3:size(struct2cell(theFilenames),2)
0278 if (length(theFilenames(count).name)>4) && ...
0279 strcmpi(theFilenames(count).name(end-3:end) , '.hdr')
0280 if strcmpi(theFilenames(count).name(1:end-4) ...
0281 , theFilenames(count+1).name(1:end-4) )
0282 nVolumn = nVolumn + 1;
0283 else
0284
0285 nVolumn =-1;
0286 fprintf('%s, *.{hdr,img} should be pairwise. Please re-examin them.\n', ADataDir);
0287 errordlg('*.{hdr,img} should be pairwise. Please re-examin them.');
0288 break;
0289 end
0290 end
0291 end
0292
0293
0294
0295
0296
0297 function edtMaskfile_Callback(hObject, eventdata, handles)
0298 theMaskfile =get(hObject, 'String');
0299 if rest_misc('GetMatlabVersion')>=7.3,
0300 theMaskfile =strtrim(theMaskfile);
0301 end
0302 if exist(theMaskfile, 'file')
0303 handles.Cfg.MaskFile =theMaskfile;
0304 guidata(hObject, handles);
0305 else
0306 errordlg(sprintf('The mask file "%s" does not exist!\n Please re-check it.', theMaskfile));
0307 end
0308
0309 function edtMaskfile_CreateFcn(hObject, eventdata, handles)
0310 if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
0311 set(hObject,'BackgroundColor','white');
0312 end
0313
0314
0315 function btnSelectMask_Callback(hObject, eventdata, handles)
0316 [filename, pathname] = uigetfile({'*.img;*.mat', 'All Mask files (*.img; *.mat)'; ...
0317 '*.mat','MAT masks (*.mat)'; ...
0318 '*.img', 'ANALYZE or NIFTI masks(*.img)'}, ...
0319 'Pick a user''s mask');
0320 if ~(filename==0)
0321 handles.Cfg.MaskFile =[pathname filename];
0322 guidata(hObject,handles);
0323 elseif ~( exist(handles.Cfg.MaskFile, 'file')==2)
0324 set(handles.rbtnDefaultMask, 'Value',[1]);
0325 set(handles.rbtnUserMask, 'Value',[0]);
0326 set(handles.edtMaskfile, 'Enable','off');
0327 set(handles.btnSelectMask, 'Enable','off');
0328 handles.Cfg.MaskFile ='Default';
0329 guidata(hObject, handles);
0330 end
0331 UpdateDisplay(handles);
0332
0333
0334
0335
0336
0337 function rbtnDefaultMask_Callback(hObject, eventdata, handles)
0338 set(handles.edtMaskfile, 'Enable','off', 'String','Use Default Mask');
0339 set(handles.btnSelectMask, 'Enable','off');
0340 drawnow;
0341 handles.Cfg.MaskFile ='Default';
0342 guidata(hObject, handles);
0343 set(handles.rbtnDefaultMask,'Value',1);
0344 set(handles.rbtnNullMask,'Value',0);
0345 set(handles.rbtnUserMask,'Value',0);
0346
0347 function rbtnUserMask_Callback(hObject, eventdata, handles)
0348 set(handles.edtMaskfile,'Enable','on', 'String',handles.Cfg.MaskFile);
0349 set(handles.btnSelectMask, 'Enable','on');
0350 set(handles.rbtnDefaultMask,'Value',0);
0351 set(handles.rbtnNullMask,'Value',0);
0352 set(handles.rbtnUserMask,'Value',1);
0353 drawnow;
0354
0355 function rbtnNullMask_Callback(hObject, eventdata, handles)
0356 set(handles.edtMaskfile, 'Enable','off', 'String','Don''t use any Mask');
0357 set(handles.btnSelectMask, 'Enable','off');
0358 drawnow;
0359 handles.Cfg.MaskFile ='';
0360 guidata(hObject, handles);
0361 set(handles.rbtnDefaultMask,'Value',0);
0362 set(handles.rbtnNullMask,'Value',1);
0363 set(handles.rbtnUserMask,'Value',0);
0364
0365
0366
0367
0368
0369 function listDataDirs_Callback(hObject, eventdata, handles)
0370 theIndex =get(hObject, 'Value');
0371 if isempty(theIndex) || theIndex<1,
0372 msgbox(sprintf('Nothing added.\n\nYou must add some diretories containing only paired {hdr/img} files first'), ...
0373 'REST' ,'help');
0374 return;
0375 end
0376
0377 if strcmp(get(handles.figFCMain, 'SelectionType'), 'open')
0378 msgbox(sprintf('%s \t\nhas\t %d\t volumes\n\nTotal: %d Data Directories' , ...
0379 handles.Cfg.DataDirs{theIndex, 1} , ...
0380 handles.Cfg.DataDirs{theIndex, 2} , ...
0381 size(handles.Cfg.DataDirs,1)), ...
0382 'Volume count in selected dir' ,'help');
0383 end
0384
0385 function listDataDirs_KeyPressFcn(hObject, eventdata, handles)
0386
0387 key =get(handles.figFCMain, 'currentkey');
0388 if seqmatch({key},{'delete', 'backspace'})
0389 DeleteSelectedDataDir(hObject, eventdata,handles);
0390 end
0391
0392 function DeleteSelectedDataDir(hObject, eventdata, handles)
0393 theIndex =get(handles.listDataDirs, 'Value');
0394 if prod(size(handles.Cfg.DataDirs))==0 ...
0395 || size(handles.Cfg.DataDirs, 1)==0 ...
0396 || theIndex>size(handles.Cfg.DataDirs, 1),
0397 return;
0398 end
0399 theDir =handles.Cfg.DataDirs{theIndex, 1};
0400 theVolumnCount=handles.Cfg.DataDirs{theIndex, 2};
0401 tmpMsg=sprintf('Delete\n\n "%s" \nVolumn Count :%d ?', theDir, theVolumnCount);
0402 if strcmp(questdlg(tmpMsg, 'Delete confirmation'), 'Yes')
0403 if theIndex>1,
0404 set(handles.listDataDirs, 'Value', theIndex-1);
0405 end
0406 handles.Cfg.DataDirs(theIndex, :)=[];
0407 if size(handles.Cfg.DataDirs, 1)==0
0408 handles.Cfg.DataDirs={};
0409 end
0410 guidata(hObject, handles);
0411 UpdateDisplay(handles);
0412 end
0413
0414 function ClearDataDirectories(hObject, eventdata, handles)
0415 if prod(size(handles.Cfg.DataDirs))==0 ...
0416 || size(handles.Cfg.DataDirs, 1)==0,
0417 return;
0418 end
0419 tmpMsg=sprintf('Attention!\n\n\nDelete all data directories?');
0420 if strcmpi(questdlg(tmpMsg, 'Clear confirmation'), 'Yes'),
0421 handles.Cfg.DataDirs(:)=[];
0422 if prod(size(handles.Cfg.DataDirs))==0,
0423 handles.Cfg.DataDirs={};
0424 end
0425 guidata(hObject, handles);
0426 UpdateDisplay(handles);
0427 end
0428
0429
0430 function listDataDirs_CreateFcn(hObject, eventdata, handles)
0431 if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
0432 set(hObject,'BackgroundColor','white');
0433 end
0434
0435
0436 function edtPrefix_Callback(hObject, eventdata, handles)
0437
0438
0439 function edtPrefix_CreateFcn(hObject, eventdata, handles)
0440 if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
0441 set(hObject,'BackgroundColor','white');
0442 end
0443
0444
0445
0446
0447 function edtOutputDir_Callback(hObject, eventdata, handles)
0448 theDir =get(hObject, 'String');
0449 SetOutputDir(hObject,handles, theDir);
0450
0451 function edtOutputDir_CreateFcn(hObject, eventdata, handles)
0452 if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
0453 set(hObject,'BackgroundColor','white');
0454 end
0455
0456
0457 function btnSelectOutputDir_Callback(hObject, eventdata, handles)
0458 theDir =handles.Cfg.OutputDir;
0459 theDir =uigetdir(theDir, 'Please select the data directory to compute functional connectivity map: ');
0460 if ~isequal(theDir, 0)
0461 SetOutputDir(hObject,handles, theDir);
0462 end
0463
0464 function SetOutputDir(hObject, handles, ADir)
0465 if 7==exist(ADir,'dir')
0466 handles.Cfg.OutputDir =ADir;
0467 guidata(hObject, handles);
0468 UpdateDisplay(handles);
0469 end
0470
0471 function Result=GetDirName(ADir)
0472 if isempty(ADir), Result=ADir; return; end
0473 theDir =ADir;
0474 if strcmp(theDir(end),filesep)==1
0475 theDir=theDir(1:end-1);
0476 end
0477 [tmp,Result]=fileparts(theDir);
0478
0479
0480 function ckboxFilter_Callback(hObject, eventdata, handles)
0481 if get(hObject,'Value')
0482 handles.Filter.UseFilter ='Yes';
0483 else
0484 handles.Filter.UseFilter ='No';
0485 end
0486 guidata(hObject, handles);
0487 UpdateDisplay(handles);
0488
0489 function edtBandLow_Callback(hObject, eventdata, handles)
0490 handles.Filter.BandLow =str2double(get(hObject,'String'));
0491 guidata(hObject, handles);
0492
0493 function edtBandLow_CreateFcn(hObject, eventdata, handles)
0494 if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
0495 set(hObject,'BackgroundColor','white');
0496 end
0497
0498
0499 function edtBandHigh_Callback(hObject, eventdata, handles)
0500 handles.Filter.BandHigh =str2double(get(hObject,'String'));
0501 guidata(hObject, handles);
0502
0503 function edtBandHigh_CreateFcn(hObject, eventdata, handles)
0504 if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
0505 set(hObject,'BackgroundColor','white');
0506 end
0507
0508
0509
0510 function ckboxRetrend_Callback(hObject, eventdata, handles)
0511 if get(hObject,'Value')
0512 handles.Filter.Retrend ='Yes';
0513 else
0514 handles.Filter.Retrend ='No';
0515 end
0516 guidata(hObject, handles);
0517 UpdateDisplay(handles);
0518
0519 function edtSamplePeriod_Callback(hObject, eventdata, handles)
0520 handles.Filter.SamplePeriod =str2double(get(hObject,'String'));
0521 guidata(hObject, handles);
0522
0523 function edtSamplePeriod_CreateFcn(hObject, eventdata, handles)
0524 if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
0525 set(hObject,'BackgroundColor','white');
0526 end
0527
0528
0529 function ckboxFisherZ_Callback(hObject, eventdata, handles)
0530 if get(hObject,'Value')
0531 handles.Cfg.WantFisherZMap ='Yes';
0532 else
0533 handles.Cfg.WantFisherZMap ='No';
0534 end
0535 guidata(hObject, handles);
0536 UpdateDisplay(handles);
0537
0538 function btnFisherZ_Callback(hObject, eventdata, handles)
0539 theOldColor=get(hObject,'BackgroundColor');
0540 set(hObject,'Enable','off', 'BackgroundColor', 'red');
0541 drawnow;
0542 try
0543 [filename, pathname] = uigetfile({'*.img', 'functional connectivity files (*.img)'}, ...
0544 'Pick one functional connectivity map');
0545 if (filename~=0)
0546 if strcmpi(filename(end-3:end), '.img')
0547 filename = filename(1:end-4);
0548 end
0549 if ~strcmpi(pathname(end), filesep)
0550 pathname = [pathname filesep];
0551 end
0552 theOrigFCMap =[pathname filename];
0553 theFisherZMap =[pathname 'z' filename];
0554 theMaskFile =handles.Cfg.MaskFile;
0555 rest_Corr2FisherZ(theOrigFCMap, theFisherZMap, theMaskFile);
0556
0557 msgbox(sprintf('functional connectivity brain "%s.{hdr/img}" \nhas been transformed to Fisher Z-score map in the specified mask.\t\n\nSave to "%s.{hdr/img}"\n' , ...
0558 theOrigFCMap, theFisherZMap), ...
0559 'Fisher Z-score transformation within mask successfully' ,'help');
0560 end
0561 catch
0562 rest_misc( 'DisplayLastException');
0563 end
0564 set(hObject,'Enable','on', 'BackgroundColor', theOldColor);
0565 drawnow;
0566
0567 function btnBandPass_Callback(hObject, eventdata, handles)
0568 theOldColor=get(hObject,'BackgroundColor');
0569 set(hObject,'Enable','off', 'BackgroundColor', 'red');
0570 drawnow;
0571 try
0572
0573 if strcmpi(handles.Filter.UseFilter, 'Yes')
0574 BandPass(hObject, handles);
0575 msgbox('Ideal Band Pass filter Over.',...
0576 'Filter successfully' ,'help');
0577 else
0578 errordlg(sprintf('You didn''t select option "Band Pass". \n\nPlease slect first.'));
0579 end
0580 UpdateDisplay(handles);
0581 catch
0582 rest_misc( 'DisplayLastException');
0583 end
0584 rest_waitbar;
0585 set(hObject,'Enable','on', 'BackgroundColor', theOldColor);
0586 drawnow;
0587
0588 function InitFrames(hObject,handles)
0589 offsetY =83+50;
0590
0591
0592
0593 uicontrol(handles.figFCMain, 'Style','Frame','Position',[2 offsetY+92 433 1]);
0594 uicontrol(handles.figFCMain, 'Style','Frame','Position',[2 offsetY+136 433 1]);
0595
0596 uicontrol(handles.figFCMain, 'Style','Frame','Position',[2 offsetY+227 433 1]);
0597 uicontrol(handles.figFCMain, 'Style','Frame','Position',[90 offsetY+137 1 90]);
0598 uicontrol(handles.figFCMain, 'Style','Frame','Position',[2 offsetY+92 1 290]);
0599 uicontrol(handles.figFCMain, 'Style','Frame','Position',[435 offsetY+92 1 290]);
0600 uicontrol(handles.figFCMain, 'Style','Frame','Position',[2 offsetY+382 433 1]);
0601 uicontrol(handles.figFCMain,'Style','Text','Position',[142 offsetY+378 180 14],...
0602 'String','Input Parameters');
0603 uicontrol(handles.figFCMain,'Style','Text','Position',[208 offsetY+222 40 14],...
0604 'String','Mask');
0605 uicontrol(handles.figFCMain,'Style','Text','Position',[20 offsetY+222 50 14],...
0606 'String','Set ROI', 'FontWeight', 'normal','FontSize', 10,'ForegroundColor', 'red');
0607
0608
0609 uicontrol(handles.figFCMain, 'Style','Frame','Position',[2 offsetY+393 433 1]);
0610 uicontrol(handles.figFCMain, 'Style','Frame','Position',[435 offsetY+393 1 50]);
0611 uicontrol(handles.figFCMain, 'Style','Frame','Position',[2 offsetY+393 1 50]);
0612 uicontrol(handles.figFCMain, 'Style','Frame','Position',[2 offsetY+443 433 1]);
0613 uicontrol(handles.figFCMain,'Style','Text','Position',[142 offsetY+438 180 14],...
0614 'String','Option: Ideal Band Pass Filter');
0615
0616 uicontrol(handles.figFCMain, 'Style','Frame','Position',[2 offsetY+458 433 1]);
0617 uicontrol(handles.figFCMain, 'Style','Frame','Position',[435 offsetY+458 1 50]);
0618 uicontrol(handles.figFCMain, 'Style','Frame','Position',[2 offsetY+458 1 50]);
0619 uicontrol(handles.figFCMain, 'Style','Frame','Position',[2 offsetY+508 433 1]);
0620 uicontrol(handles.figFCMain,'Style','Text','Position',[142 offsetY+498 180 14],...
0621 'String','Option: Remove Linear Trend');
0622
0623
0624 offsetY = offsetY -50;
0625 uicontrol(handles.figFCMain, 'Style','Frame','Position',[2 offsetY+94 433 1]);
0626 uicontrol(handles.figFCMain, 'Style','Frame','Position',[2 offsetY-8 433 1]);
0627 uicontrol(handles.figFCMain, 'Style','Frame','Position',[2 offsetY-8 1 102]);
0628 uicontrol(handles.figFCMain, 'Style','Frame','Position',[435 offsetY-8 1 102]);
0629 uicontrol(handles.figFCMain,'Style','Text','Position',[142 offsetY+88 180 14],...
0630 'String','Output Parameters');
0631
0632
0633 uicontrol(handles.figFCMain, 'Style','Frame','Position',[2 offsetY-25 433 1]);
0634 uicontrol(handles.figFCMain,'Style','Text','Position',[152 offsetY-30 140 14],...
0635 'String','Manual Operations');
0636
0637
0638 function InitControlProperties(hObject, handles)
0639
0640
0641 set(handles.figFCMain,...
0642 'Units', 'pixels', ...
0643 'Position', [20 5 440 645], ...
0644 'Name', 'fc_gui', ...
0645 'MenuBar', 'none', ...
0646 'NumberTitle', 'off', ...
0647 'Color', get(0,'DefaultUicontrolBackgroundColor'));
0648
0649
0650 set(handles.txtLogo, ...
0651 'Style', 'text', ...
0652 'Units', 'pixels', ...
0653 'Position', [16 186 260 30], ...
0654 'FontSize', 16, ...
0655 'FontWeight', 'bold', ...
0656 'String', 'Functional Connectivity');
0657 set(handles.txtLongName, ...
0658 'Style', 'text', ...
0659 'Units', 'pixels', ...
0660 'Position', [10 400 65 30], ...
0661 'FontSize', 10, ...
0662 'FontWeight', 'bold', ...
0663 'Enable', 'on', ...
0664 'Visible', 'off', ...
0665 'String', sprintf('ROI Definition'));
0666
0667 set(handles.txtOutputDir, ...
0668 'Style', 'text', ...
0669 'Units', 'pixels', ...
0670 'Position', [8 109 80 21], ...
0671 'String', 'Directory:');
0672
0673 set(handles.txtInputDir, ...
0674 'Style', 'text', ...
0675 'Units', 'pixels', ...
0676 'Position', [7 370 80 21], ...
0677 'String', 'Data Directory:');
0678
0679 set(handles.txtPrefix, ...
0680 'Style', 'text', ...
0681 'Units', 'pixels', ...
0682 'Position', [9 140 80 21], ...
0683 'String', 'Prefix:');
0684
0685 set(handles.txtResultFilename, ...
0686 'Style', 'text', ...
0687 'Units', 'pixels', ...
0688 'Position', [227 148 200 16], ...
0689 'HorizontalAlignment','left' , ...
0690 'String', 'Result: Prefix_DirectoryName.{hdr/img}');
0691
0692 set(handles.txtBandSep, ...
0693 'Style', 'text', ...
0694 'Units', 'pixels', ...
0695 'Position', [146 516 25 51], ...
0696 'FontSize', 28, ...
0697 'String', '~');
0698
0699 set(handles.txtTR, ...
0700 'Style', 'text', ...
0701 'Units', 'pixels', ...
0702 'Position', [230 530 40 16], ...
0703 'String', 'TR: (s)');
0704
0705
0706 set(handles.btnSelectOutputDir, ...
0707 'Style', 'pushbutton', ...
0708 'Units', 'pixels', ...
0709 'Position', [396 107 30 25], ...
0710 'FontSize', 18, ...
0711 'String', '...');
0712
0713 set(handles.btnSelectDataDir, ...
0714 'Style', 'pushbutton', ...
0715 'Units', 'pixels', ...
0716 'Position', [396 372 30 25], ...
0717 'FontSize', 18, ...
0718 'String', '...', ...
0719 'CData', zeros(1,0));
0720
0721 set(handles.btnSelectMask, ...
0722 'Style', 'pushbutton', ...
0723 'Units', 'pixels', ...
0724 'Position', [396 275 30 25], ...
0725 'FontSize', 18, ...
0726 'String', '...', ...
0727 'Enable', 'off', ...
0728 'CData', zeros(1,0));
0729
0730 set(handles.btnComputeFC, ...
0731 'Style', 'pushbutton', ...
0732 'Units', 'pixels', ...
0733 'Position', [320 186 107 33], ...
0734 'FontSize', 12, ...
0735 'FontWeight', 'bold', ...
0736 'String', 'Do all');
0737
0738
0739 set(handles.btnDetrend , ...
0740 'Style', 'pushbutton', ...
0741 'Units', 'pixels', ...
0742 'Position', [337 593 90 25], ...
0743 'FontSize', 10, ...
0744 'String', 'Detrend');
0745 set(handles.btnBandPass , ...
0746 'Style', 'pushbutton', ...
0747 'Units', 'pixels', ...
0748 'Position', [337 530 90 25], ...
0749 'FontSize', 10, ...
0750 'String', 'Filter');
0751
0752
0753 set(handles.btnROIVoxelWise , ...
0754 'Style', 'pushbutton', ...
0755 'Units', 'pixels', ...
0756 'Position', [5 315 85 25], ...
0757 'ForegroundColor', 'red', ...
0758 'TooltipString', 'Functional Connectivity with whole brain', ...
0759 'String', 'Voxel wise');
0760 set(handles.btnROIRegionWise , ...
0761 'Style', 'pushbutton', ...
0762 'Units', 'pixels', ...
0763 'Position', [5 275 85 25], ...
0764 'ForegroundColor', 'red', ...
0765 'TooltipString', 'Functional Connectivity between defined regions', ...
0766 'String', 'ROI wise');
0767
0768 set(handles.btnCovariable, ...
0769 'Style', 'text', ...
0770 'Units', 'pixels', ...
0771 'Position', [5 234 85 25], ...
0772 'FontSize', 10, ...
0773 'ForegroundColor', 'blue', ...
0774 'Visible', 'on', ...
0775 'String', 'Covariables:');
0776
0777 set(handles.btnSelectCovariableFile , ...
0778 'Style', 'pushbutton', ...
0779 'Units', 'pixels', ...
0780 'Position', [396 234 30 25], ...
0781 'FontSize', 18, ...
0782 'ForegroundColor', 'blue', ...
0783 'String', '...');
0784
0785
0786 set(handles.btnHelp, ...
0787 'Style', 'pushbutton', ...
0788 'Units', 'pixels', ...
0789 'Position', [10 10 90 33], ...
0790 'FontSize', 10, ...
0791 'String', 'Help');
0792 set(handles.btnFisherZ, ...
0793 'Style', 'pushbutton', ...
0794 'Units', 'pixels', ...
0795 'Position', [110 10 90 33], ...
0796 'FontSize', 10, ...
0797 'String', 'Fisher Z');
0798 set(handles.btnSliceViewer, ...
0799 'Style', 'pushbutton', ...
0800 'Units', 'pixels', ...
0801 'Position', [210 10 90 33], ...
0802 'FontSize', 10, ...
0803 'String', 'Slice Viewer');
0804 set(handles.btnWaveGraph, ...
0805 'Style', 'pushbutton', ...
0806 'Units', 'pixels', ...
0807 'Position', [314 10 110 33], ...
0808 'FontSize', 10, ...
0809 'String', 'Power Spectrum');
0810
0811
0812
0813 set(handles.rbtnDefaultMask, ...
0814 'Style', 'radiobutton', ...
0815 'Units', 'pixels', ...
0816 'Position', [110 335 158 16], ...
0817 'String', 'Default mask');
0818
0819 set(handles.rbtnUserMask, ...
0820 'Style', 'radiobutton', ...
0821 'Units', 'pixels', ...
0822 'Position', [110 305 148 16], ...
0823 'String', 'User''s defined mask');
0824
0825 set(handles.rbtnNullMask, ...
0826 'Style', 'radiobutton', ...
0827 'Units', 'pixels', ...
0828 'Position', [277 335 82 16], ...
0829 'String', 'No mask');
0830
0831
0832 set(handles.ckboxFilter, ...
0833 'Style', 'checkbox', ...
0834 'Units', 'pixels', ...
0835 'Position', [14 530 80 22], ...
0836 'String', 'Band (Hz)');
0837
0838 set(handles.ckboxFisherZ, ...
0839 'Style', 'checkbox', ...
0840 'Units', 'pixels', ...
0841 'Position', [12 82 430 19], ...
0842 'String', 'Fisher Z-score transformation within the mask (zPrefix_DirectoryName.{hdr/img})');
0843
0844 set(handles.ckboxRetrend, ...
0845 'Style', 'checkbox', ...
0846 'Units', 'pixels', ...
0847 'Position', [366 530 60 22], ...
0848 'Enable', 'Off', ...
0849 'String', 'Retrend');
0850
0851 set(handles.ckboxRemoveTrendBefore, ...
0852 'Style', 'checkbox', ...
0853 'Units', 'pixels', ...
0854 'Position', [13 595 160 21],...
0855 'String', 'detrend');
0856 set(handles.ckboxRemoveTrendAfter, ...
0857 'Style', 'checkbox', ...
0858 'Units', 'pixels', ...
0859 'Position', [171 595 140 21],...
0860 'Visible', 'off', ...
0861 'String', 'detrend AFTER Filter');
0862
0863
0864 set(handles.edtOutputDir, ...
0865 'Style', 'edit', ...
0866 'Units', 'pixels', ...
0867 'Position', [94 109 300 23], ...
0868 'BackgroundColor', [1 1 1], ...
0869 'String', 'Edit Text');
0870
0871 set(handles.edtDataDirectory, ...
0872 'Style', 'edit', ...
0873 'Units', 'pixels', ...
0874 'Position', [94 373 300 22], ...
0875 'BackgroundColor', [1 1 1], ...
0876 'String', '');
0877
0878 set(handles.edtMaskfile, ...
0879 'Style', 'edit', ...
0880 'Units', 'pixels', ...
0881 'Position', [94 275 300 23], ...
0882 'BackgroundColor', [1 1 1], ...
0883 'String', 'Default', ...
0884 'Enable', 'off');
0885
0886 set(handles.edtPrefix, ...
0887 'Style', 'edit', ...
0888 'Units', 'pixels', ...
0889 'Position', [94 142 115 22], ...
0890 'BackgroundColor', [1 1 1], ...
0891 'String', 'FCMap');
0892
0893 set(handles.edtBandLow, ...
0894 'Style', 'edit', ...
0895 'Units', 'pixels', ...
0896 'Position', [94 531 50 22], ...
0897 'BackgroundColor', [1 1 1], ...
0898 'String', '0.01', ...
0899 'Enable', 'off');
0900
0901 set(handles.edtBandHigh, ...
0902 'Style', 'edit', ...
0903 'Units', 'pixels', ...
0904 'Position', [171 531 50 22], ...
0905 'BackgroundColor', [1 1 1], ...
0906 'String', '0.08', ...
0907 'Enable', 'off');
0908
0909 set(handles.edtSamplePeriod, ...
0910 'Style', 'edit', ...
0911 'Units', 'pixels', ...
0912 'Position', [276 531 50 22], ...
0913 'BackgroundColor', [1 1 1], ...
0914 'String', '2', ...
0915 'Enable', 'off');
0916
0917
0918 set(handles.edtCovariableFile, ...
0919 'Style', 'edit', ...
0920 'Units', 'pixels', ...
0921 'Position', [94 235 300 23], ...
0922 'BackgroundColor', [1 1 1], ...
0923 'String', '', ...
0924 'ForegroundColor', 'blue', ...
0925 'Enable', 'on');
0926
0927
0928 set(handles.listDataDirs, ...
0929 'Style', 'listbox', ...
0930 'Units', 'pixels', ...
0931 'Position', [14 400 413 108], ...
0932 'BackgroundColor', [1 1 1], ...
0933 'String', '');
0934
0935
0936 handles.hContextMenu =uicontextmenu;
0937 set(handles.listDataDirs, 'UIContextMenu', handles.hContextMenu);
0938 uimenu(handles.hContextMenu, 'Label', 'Add a directory', 'Callback', get(handles.btnSelectDataDir, 'Callback'));
0939 uimenu(handles.hContextMenu, 'Label', 'Remove selected directory', 'Callback', 'fc_gui(''DeleteSelectedDataDir'',gcbo,[], guidata(gcbo))');
0940 uimenu(handles.hContextMenu, 'Label', 'Add recursively all sub-folders of a directory', 'Callback', 'fc_gui(''RecursiveAddDataDir'',gcbo,[], guidata(gcbo))');
0941 uimenu(handles.hContextMenu, 'Label', '=============================');
0942 uimenu(handles.hContextMenu, 'Label', 'Clear all data directories', 'Callback', 'fc_gui(''ClearDataDirectories'',gcbo,[], guidata(gcbo))');
0943
0944
0945
0946 guidata(hObject,handles);
0947
0948
0949 function Log2File(handles)
0950 constLineSep= '-------------------------------------------------------------------------------';
0951 [theVer, theRelease] =rest_misc( 'GetRestVersion');
0952 theMsgVersion = sprintf('REST Version:%s, Release %s\r\n%s\r\n', theVer, theRelease, constLineSep);
0953 theMsgHead = sprintf('Functional Connectivity computation log %s\r\n%s\r\n', rest_misc( 'GetDateTimeStr'), constLineSep);
0954 theMsg =sprintf('%s\r\n%s\r\n\r\n%s', theMsgVersion, theMsgHead, constLineSep);
0955 theMsg =sprintf('%s\r\nRemove Linear Trend options:\r\n%s\r\n\r\n%s',theMsg,...
0956 LogRemoveLinearTrend(handles), constLineSep);
0957 theMsg =sprintf('%s\r\nIdeal Band Pass filter options:\r\n%s\r\n\r\n%s',theMsg,...
0958 LogBandPassFilter(handles), constLineSep);
0959 theMsg =sprintf('%s\r\nFunctional Connectivity input parameters:\r\n%s\r\n\r\n%s', theMsg, ...
0960 LogInputParameters(handles), constLineSep);
0961 theMsg =sprintf('%s\r\nFunctional Connectivity output parameters:\r\n%s\r\n\r\n%s', theMsg, ...
0962 LogOutputParameters(handles), constLineSep);
0963
0964 fid = fopen(handles.Log.Filename,'w');
0965 if fid~=-1
0966 fprintf(fid,'%s',theMsg);
0967 fclose(fid);
0968 else
0969 errordlg(sprintf('Error to open log file:\n\n%s', handles.Log.Filename));
0970 end
0971
0972
0973 function LogPerformance(handles)
0974 theMsg =sprintf('\r\n\r\nTotal elapsed time for Functional Connectivity Computing: %g seconds\r\n',handles.Performance);
0975 fid = fopen(handles.Log.Filename,'r+');
0976 fseek(fid, 0, 'eof');
0977 if fid~=-1
0978 fprintf(fid,'%s',theMsg);
0979 fclose(fid);
0980 else
0981 errordlg(sprintf('Error to open log file:\n\n%s', handles.Log.Filename));
0982 end
0983
0984
0985 function ResultLogString=LogRemoveLinearTrend(handles)
0986 ResultLogString ='';
0987 ResultLogString =sprintf('%s\tremove linear trend BEFORE filter: %s\r\n',ResultLogString, handles.Detrend.BeforeFilter);
0988
0989
0990 function ResultLogString=LogBandPassFilter(handles)
0991 ResultLogString ='';
0992 ResultLogString =sprintf('%s\tUse Filter: %s\r\n',ResultLogString, handles.Filter.UseFilter);
0993 ResultLogString =sprintf('%s\tBand Low: %g\r\n', ResultLogString, handles.Filter.BandLow);
0994 ResultLogString =sprintf('%s\tBand High: %g\r\n',ResultLogString, handles.Filter.BandHigh);
0995 ResultLogString =sprintf('%s\tSample Period(i.e. TR): %g\r\n',ResultLogString, handles.Filter.SamplePeriod);
0996
0997 function ResultLogString=LogInputParameters(handles)
0998 ResultLogString ='';
0999 constLineSep= '-------------------------------------------------------------------------------';
1000 theDataDirString= '';
1001 theDataDirCells =get(handles.listDataDirs, 'string');
1002 for x=1:length(theDataDirCells)
1003 theDataDirString =sprintf('%s\r\n\t%s', theDataDirString, theDataDirCells{x});
1004 end
1005 theDirType ='';
1006 if strcmpi(handles.Detrend.BeforeFilter, 'Yes')
1007 theDirType =sprintf(' %s after Detrend processing', theDirType);
1008 end
1009 if strcmpi(handles.Detrend.BeforeFilter, 'Yes') && ...
1010 strcmpi(handles.Filter.UseFilter, 'Yes'),
1011 theDirType =sprintf(' %s and ', theDirType);
1012 end
1013 if strcmpi(handles.Filter.UseFilter, 'Yes')
1014 theDirType =sprintf(' %s after Filter processing', theDirType);
1015 end
1016 ResultLogString =sprintf('%s\tInput Data Directories( %s): \r\n\t%s%s\r\n\t%s\r\n',ResultLogString,...
1017 theDirType, ...
1018 constLineSep, ...
1019 theDataDirString, ...
1020 constLineSep);
1021 ResultLogString =sprintf('%s\tMask file: %s\r\n', ResultLogString, handles.Cfg.MaskFile);
1022
1023
1024 ResultLogString =sprintf('%s\n\n\tFunctional Connectivity Parameters\r\n', ResultLogString);
1025
1026 if iscell(handles.Cfg.ROIList),
1027 for x=1:size(handles.Cfg.ROIList, 1),
1028 ResultLogString =sprintf('%s\tROI Definition: \n\t\t%s\r\n', ResultLogString, handles.Cfg.ROIList{x});
1029 end
1030 else
1031 ResultLogString =sprintf('%s\tROI Definition: \n\t\t%s\r\n', ResultLogString, handles.Cfg.ROIList);
1032 end
1033
1034 ResultLogString =sprintf('%s\tCovariables Definition File: \n\t\t%s\r\n', ResultLogString, handles.Covariables.ort_file);
1035 ResultLogString =sprintf('%s\tCovariables Polort (Polynomial Orthogonal Degree): \n\t\t%d\r\n', ResultLogString, handles.Covariables.polort);
1036
1037 function ResultLogString=LogOutputParameters(handles)
1038 ResultLogString ='';
1039 ResultLogString =sprintf('%s\tPrefix to the Data directories: %s\r\n',ResultLogString, get(handles.edtPrefix, 'String'));
1040 ResultLogString =sprintf('%s\tOutput Data Directories: %s\r\n',ResultLogString, handles.Cfg.OutputDir);
1041 ResultLogString =sprintf('%s\tWant Fisher Z-score map transformation: %s \r\n',ResultLogString, handles.Cfg.WantFisherZMap);
1042
1043
1044
1045 function ResultLogFileName=GetLogFilename(ALogDirectory, APrefix)
1046 if isempty(ALogDirectory)
1047 [pathstr, name, ext, versn] = fileparts(mfilename('fullpath'));
1048 ALogDirectory =pathstr;
1049 end
1050 if ~strcmp(ALogDirectory(end), filesep)
1051 ALogDirectory =[ALogDirectory filesep];
1052 end
1053 ResultLogFileName=sprintf('%s%s_%s.log', ...
1054 ALogDirectory, ...
1055 APrefix, ...
1056 rest_misc( 'GetDateTimeStr'));
1057
1058
1059 function btnSliceViewer_Callback(hObject, eventdata, handles)
1060
1061 theOldColor=get(hObject,'BackgroundColor');
1062 set(hObject,'Enable','off', 'BackgroundColor', 'red');
1063 drawnow;
1064 try
1065 rest_sliceviewer;
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075 catch
1076 rest_misc( 'DisplayLastException');
1077 end
1078 set(hObject,'Enable','on', 'BackgroundColor', theOldColor);
1079 drawnow;
1080
1081
1082
1083 function btnWaveGraph_Callback(hObject, eventdata, handles)
1084
1085 theOldColor=get(hObject,'BackgroundColor');
1086 set(hObject,'Enable','off', 'BackgroundColor', 'red');
1087 drawnow;
1088 try
1089 [filename, pathname] = uigetfile({'*.img', 'ANALYZE or NIFTI files (*.img)'}, ...
1090 'Pick one functional EPI brain map in the dataset''s directory');
1091 if any(filename~=0) && ischar(filename),
1092 if ~strcmpi(pathname(end), filesep)
1093 pathname = [pathname filesep];
1094 end
1095 theBrainMap =[pathname filename];
1096 theViewer =rest_sliceviewer('ShowImage', theBrainMap);
1097
1098
1099 theDataSetDir =pathname;
1100 theVoxelPosition=rest_sliceviewer('GetPosition', theViewer);
1101 theSamplePeriod =handles.Filter.SamplePeriod;
1102 theBandRange =[handles.Filter.BandLow, handles.Filter.BandHigh];
1103 rest_powerspectrum('ShowFluctuation', theDataSetDir, theVoxelPosition, ...
1104 theSamplePeriod, theBandRange);
1105
1106
1107 theCallback ='';
1108 cmdDataSetDir =sprintf('theDataSetDir= ''%s'';', theDataSetDir);
1109 cmdBrainMap =sprintf('theVoxelPosition=rest_sliceviewer(''GetPosition'', %g);', theViewer);
1110 cmdSamplePeriod =sprintf('theSamplePeriod= %g;', theSamplePeriod);
1111 cmdBandRange =sprintf('theBandRange= [%g, %g];', theBandRange(1), theBandRange(2));
1112 cmdUpdateWaveGraph ='rest_powerspectrum(''ShowFluctuation'', theDataSetDir, theVoxelPosition, theSamplePeriod, theBandRange);';
1113 theCallback =sprintf('%s\n%s\n%s\n%s\n%s\n',cmdDataSetDir, ...
1114 cmdBrainMap, cmdSamplePeriod, cmdBandRange, ...
1115 cmdUpdateWaveGraph);
1116 cmdClearVar ='clear theDataSetDir theVoxelPosition theSamplePeriod theBandRange;';
1117 rest_sliceviewer('UpdateCallback', theViewer, [theCallback cmdClearVar], 'ALFF Analysis');
1118
1119
1120 theMsg =sprintf('TR( s): %g\nBand( Hz): %g~%g', ...
1121 theSamplePeriod, theBandRange(1), theBandRange(2) );
1122 rest_sliceviewer('SetMessage', theViewer, theMsg);
1123 end
1124 catch
1125 rest_misc( 'DisplayLastException');
1126 end
1127 set(hObject,'Enable','on', 'BackgroundColor', theOldColor);
1128 drawnow;
1129 rest_waitbar;
1130
1131
1132 function ckboxRemoveTrendBefore_Callback(hObject, eventdata, handles)
1133 if get(hObject,'Value')
1134 handles.Detrend.BeforeFilter ='Yes';
1135 else
1136 handles.Detrend.BeforeFilter ='No';
1137 end
1138 guidata(hObject, handles);
1139 UpdateDisplay(handles);
1140
1141 function ckboxRemoveTrendAfter_Callback(hObject, eventdata, handles)
1142 if get(hObject,'Value')
1143 handles.Detrend.AfterFilter ='Yes';
1144 else
1145 handles.Detrend.AfterFilter ='No';
1146 end
1147 guidata(hObject, handles);
1148 UpdateDisplay(handles);
1149
1150 function btnDetrend_Callback(hObject, eventdata, handles)
1151 try
1152 Detrend(hObject,handles);
1153 msgbox('Remove the Linear Trend Over.',...
1154 'Detrend successfully' ,'help');
1155 catch
1156 rest_misc( 'DisplayLastException');
1157 end
1158 rest_waitbar;
1159
1160 function Detrend(hObject,handles)
1161 for x=1:size(handles.Cfg.DataDirs, 1)
1162
1163 set(handles.listDataDirs, 'Value', x);
1164 drawnow;
1165 if size(handles.Cfg.DataDirs, 1)>1,
1166 rest_waitbar((x-1)/size(handles.Cfg.DataDirs, 1)+0.01, ...
1167 handles.Cfg.DataDirs{x, 1}, ...
1168 'Removing the Linear Trend','Parent');
1169 end
1170 rest_detrend(handles.Cfg.DataDirs{x, 1}, '_detrend');
1171
1172
1173 handles.Cfg.DataDirs{x, 1}=[handles.Cfg.DataDirs{x, 1} , '_detrend'];
1174 guidata(hObject, handles);
1175 end
1176 UpdateDisplay(handles);
1177
1178
1179 function BandPass(hObject, handles)
1180 for x=1:size(handles.Cfg.DataDirs, 1)
1181
1182 set(handles.listDataDirs, 'Value', x);
1183 drawnow;
1184 if size(handles.Cfg.DataDirs, 1)>1,
1185 rest_waitbar((x-1)/size(handles.Cfg.DataDirs, 1)+0.01, ...
1186 handles.Cfg.DataDirs{x, 1}, ...
1187 'Band Pass filter','Parent');
1188 end
1189
1190 rest_bandpass(handles.Cfg.DataDirs{x, 1}, ...
1191 handles.Filter.SamplePeriod, ...
1192 handles.Filter.BandHigh, ...
1193 handles.Filter.BandLow, ...
1194 handles.Filter.Retrend, ...
1195 handles.Cfg.MaskFile);
1196
1197 thePostfix ='_filtered';
1198
1199 handles.Cfg.DataDirs{x, 1}=[handles.Cfg.DataDirs{x, 1} , thePostfix];
1200 guidata(hObject, handles);
1201 end
1202 UpdateDisplay(handles);
1203
1204 function btnHelp_Callback(hObject, eventdata, handles)
1205 web('http://resting-fmri.sourceforge.net');
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217 function btnROIVoxelWise_Callback(hObject, eventdata, handles)
1218
1219
1220 try
1221 if ~iscell(handles.Cfg.ROIList),
1222 handles.Cfg.ROIList =rest_SetROI('Init', handles.Cfg.ROIList);
1223 else
1224 if prod(size(handles.Cfg.ROIList)),
1225 handles.Cfg.ROIList =rest_SetROI('Init', handles.Cfg.ROIList{1});
1226 else
1227 handles.Cfg.ROIList =rest_SetROI('Init');
1228 end
1229 end
1230 catch
1231 rest_SetROI('Delete');
1232 end
1233 guidata(hObject, handles);
1234 UpdateDisplay(handles);
1235
1236
1237 function btnROIRegionWise_Callback(hObject, eventdata, handles)
1238 if ~iscell(handles.Cfg.ROIList), handles.Cfg.ROIList={handles.Cfg.ROIList}; end
1239 handles.Cfg.ROIList=rest_ROIList_gui(handles.Cfg.ROIList);
1240
1241
1242
1243 guidata(hObject, handles);
1244 UpdateDisplay(handles);
1245
1246
1247 function btnComputeFC_Callback(hObject, eventdata, handles)
1248 if (size(handles.Cfg.DataDirs, 1)==0)
1249 errordlg('No Data found! Please re-config');
1250 return;
1251 end
1252 if size(handles.Cfg.ROIList, 1) ==0,
1253 errordlg('No ROI Defined! Please define ROI first');
1254 return;
1255 end
1256
1257 if iscell(handles.Cfg.ROIList) && all(isspace(handles.Cfg.ROIList{1})),
1258 handles.Cfg.ROIList(1)=[];
1259 end
1260 if iscell(handles.Cfg.ROIList) && size(handles.Cfg.ROIList,1)<2 ,
1261 errordlg('Only one ROI Defined for ROI-wise functional connectivity! Please define ROI first');
1262 return;
1263 end
1264
1265 if (exist('fc.m','file')==2)
1266
1267 handles.Log.Filename =GetLogFilename(handles.Cfg.OutputDir, get(handles.edtPrefix, 'String'));
1268 Log2File(handles);
1269 handles.Performance =cputime;
1270
1271 theOldDir =pwd;
1272 theOldColor=get(hObject,'BackgroundColor');
1273 set(hObject,'Enable','off', 'BackgroundColor', 'red');
1274 drawnow;
1275 try
1276
1277 if strcmpi(handles.Filter.UseFilter, 'Yes') && strcmpi(handles.Detrend.BeforeFilter, 'Yes'),
1278 Detrend(hObject, handles);
1279
1280 handles =guidata(hObject);
1281 end
1282
1283
1284
1285 if strcmpi(handles.Filter.UseFilter, 'Yes')
1286 BandPass(hObject, handles);
1287
1288 handles =guidata(hObject);
1289 end
1290
1291
1292 if strcmpi(handles.Filter.UseFilter, 'Yes') && strcmpi(handles.Detrend.AfterFilter, 'Yes'),
1293 Detrend(hObject, handles);
1294
1295 handles =guidata(hObject);
1296 end
1297
1298
1299 for x=1:size(handles.Cfg.DataDirs, 1)
1300
1301 set(handles.listDataDirs, 'Value', x);
1302 drawnow;
1303 if size(handles.Cfg.DataDirs, 1)>1,
1304 rest_waitbar((x-1)/size(handles.Cfg.DataDirs, 1)+0.01, ...
1305 handles.Cfg.DataDirs{x, 1}, ...
1306 'Functional connectivity Computing','Parent');
1307 end
1308 fprintf('\nFunctional connectivity :"%s"\n', handles.Cfg.DataDirs{x, 1});
1309
1310 theOutputDir=get(handles.edtOutputDir, 'String');
1311 thePrefix =get(handles.edtPrefix, 'String');
1312 theDstFile=fullfile(theOutputDir,[thePrefix '_' ...
1313 GetDirName(handles.Cfg.DataDirs{x, 1}) ] );
1314
1315 Subject_Covariables = handles.Covariables;
1316 if ~isempty(handles.Covariables.ort_file)
1317 CovariablesList=textread(handles.Covariables.ort_file,'%s')
1318 if strcmp(CovariablesList{1},'Covariables_List:')
1319 Subject_Covariables.ort_file=CovariablesList{x+1};
1320 end
1321 end
1322
1323 ResultMaps =fc( handles.Cfg.DataDirs{x, 1}, ...
1324 handles.Cfg.MaskFile, ...
1325 handles.Cfg.ROIList, ...
1326 theDstFile, ...
1327 Subject_Covariables);
1328
1329
1330 if strcmpi(handles.Cfg.WantFisherZMap, 'Yes')
1331 if ndims(ResultMaps)>2 && size(ResultMaps, 1)>1 ,
1332
1333 for y=1:size(ResultMaps, 1),
1334 theOrigFCMap =ResultMaps{y, 1};
1335 [pathstr, name, ext, versn] = fileparts(theOrigFCMap);
1336 theFisherZMap =[pathstr, filesep, 'z', name, ext, versn];
1337 theMaskFile =handles.Cfg.MaskFile;
1338 rest_Corr2FisherZ(theOrigFCMap, theFisherZMap, theMaskFile);
1339 end
1340 elseif size(ResultMaps, 1)==1,
1341
1342 theOrigFCMap =theDstFile;
1343 [pathstr, name, ext, versn] = fileparts(theOrigFCMap);
1344 theFisherZMap =[pathstr, filesep, 'z', name, ext, versn];
1345 theMaskFile =handles.Cfg.MaskFile;
1346 rest_Corr2FisherZ(theOrigFCMap, theFisherZMap, theMaskFile);
1347 elseif ndims(ResultMaps)==2,
1348
1349 theOrigFCMap =theDstFile;
1350 [pathstr, name, ext, versn] = fileparts(theOrigFCMap);
1351 theFisherZMap =[pathstr, filesep, 'z', name, ext, versn];
1352 ResultMaps =0.5 * log((1 +ResultMaps)./(1- ResultMaps));
1353 save([theFisherZMap, '.txt'], 'ResultMaps', '-ASCII', '-DOUBLE','-TABS')
1354 end
1355 end
1356 end
1357 handles.Performance =cputime -handles.Performance;
1358 LogPerformance(handles);
1359 catch
1360 rest_misc( 'DisplayLastException');
1361 errordlg(sprintf('Exception occured: \n\n%s' , lasterr));
1362 end
1363 cd(theOldDir);
1364 set(hObject,'Enable','on', 'BackgroundColor', theOldColor);
1365 drawnow;
1366 rest_waitbar;
1367 else
1368 errordlg('No fc.m ! Please re-install');
1369 end
1370
1371
1372
1373
1374
1375
1376
1377 function edtCovariableFile_Callback(hObject, eventdata, handles)
1378 handles.Covariables.ort_file =get(hObject, 'String');
1379 guidata(hObject,handles);
1380
1381 function edtCovariableFile_CreateFcn(hObject, eventdata, handles)
1382 if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
1383 set(hObject,'BackgroundColor','white');
1384 end
1385
1386
1387 function btnSelectCovariableFile_Callback(hObject, eventdata, handles)
1388 [filename, pathname] = uigetfile({'*.txt; *.1D', 'Covariables'' time course file (*.txt; *.1D)'; ...
1389 '*.txt','text file (*.txt)'; ...
1390 '*.1D', 'AFNI 1D file(*.1D)'}, ...
1391 'Pick Covariables'' time course file');
1392 if ~(filename==0),
1393 handles.Covariables.ort_file =[pathname filename];
1394 guidata(hObject,handles);
1395 end
1396 UpdateDisplay(handles);