📄 fc_gui.m
字号:
function ResultLogFileName=GetLogFilename(ALogDirectory, APrefix)
if isempty(ALogDirectory)
[pathstr, name, ext, versn] = fileparts(mfilename('fullpath'));
ALogDirectory =pathstr;
end
if ~strcmp(ALogDirectory(end), filesep)
ALogDirectory =[ALogDirectory filesep];
end
ResultLogFileName=sprintf('%s%s_%s.log', ...
ALogDirectory, ...
APrefix, ...
rest_misc( 'GetDateTimeStr'));
function btnSliceViewer_Callback(hObject, eventdata, handles)
%Display a brain image like MRIcro
theOldColor=get(hObject,'BackgroundColor');
set(hObject,'Enable','off', 'BackgroundColor', 'red');
drawnow;
try
rest_sliceviewer;
% [filename, pathname] = uigetfile({'*.img', 'ANALYZE files (*.img)'}, ...
% 'Pick one brain map');
% if any(filename~=0) && ischar(filename) && length(filename)>4 , % not canceled and legal
% if ~strcmpi(pathname(end), filesep)%revise pathname to remove extension
% pathname = [pathname filesep];
% end
% theBrainMap =[pathname filename];
% rest_sliceviewer('ShowImage', theBrainMap);
% end
catch
rest_misc( 'DisplayLastException');
end
set(hObject,'Enable','on', 'BackgroundColor', theOldColor);
drawnow;
function btnWaveGraph_Callback(hObject, eventdata, handles)
%Display a brain image like MRIcro, and show specific voxel's time course and its freq domain's fluctuation
theOldColor=get(hObject,'BackgroundColor');
set(hObject,'Enable','off', 'BackgroundColor', 'red');
drawnow;
try
[filename, pathname] = uigetfile({'*.img', 'ANALYZE files (*.img)'}, ...
'Pick one functional EPI brain map in the dataset''s directory');
if any(filename~=0) && ischar(filename), % not canceled and legal
if ~strcmpi(pathname(end), filesep)%revise pathname to remove extension
pathname = [pathname filesep];
end
theBrainMap =[pathname filename];
theViewer =rest_sliceviewer('ShowImage', theBrainMap);
%Set the Functional Connectivity figure to show corresponding voxel's time-course and its freq amplitude
theDataSetDir =pathname;
theVoxelPosition=rest_sliceviewer('GetPosition', theViewer);
theSamplePeriod =handles.Filter.SamplePeriod;
theBandRange =[handles.Filter.BandLow, handles.Filter.BandHigh];
rest_powerspectrum('ShowFluctuation', theDataSetDir, theVoxelPosition, ...
theSamplePeriod, theBandRange);
%Update the Callback
theCallback ='';
cmdDataSetDir =sprintf('theDataSetDir= ''%s'';', theDataSetDir);
cmdBrainMap =sprintf('theVoxelPosition=rest_sliceviewer(''GetPosition'', %g);', theViewer);
cmdSamplePeriod =sprintf('theSamplePeriod= %g;', theSamplePeriod);
cmdBandRange =sprintf('theBandRange= [%g, %g];', theBandRange(1), theBandRange(2));
cmdUpdateWaveGraph ='rest_powerspectrum(''ShowFluctuation'', theDataSetDir, theVoxelPosition, theSamplePeriod, theBandRange);';
theCallback =sprintf('%s\n%s\n%s\n%s\n%s\n',cmdDataSetDir, ...
cmdBrainMap, cmdSamplePeriod, cmdBandRange, ...
cmdUpdateWaveGraph);
cmdClearVar ='clear theDataSetDir theVoxelPosition theSamplePeriod theBandRange;';
rest_sliceviewer('UpdateCallback', theViewer, [theCallback cmdClearVar], 'ALFF Analysis');
% Update some Message
theMsg =sprintf('TR( s): %g\nBand( Hz): %g~%g', ...
theSamplePeriod, theBandRange(1), theBandRange(2) );
rest_sliceviewer('SetMessage', theViewer, theMsg);
end
catch
rest_misc( 'DisplayLastException');
end
set(hObject,'Enable','on', 'BackgroundColor', theOldColor);
drawnow;
rest_waitbar;
function ckboxRemoveTrendBefore_Callback(hObject, eventdata, handles)
if get(hObject,'Value')
handles.Detrend.BeforeFilter ='Yes';
else
handles.Detrend.BeforeFilter ='No';
end
guidata(hObject, handles);
UpdateDisplay(handles);
function ckboxRemoveTrendAfter_Callback(hObject, eventdata, handles)
if get(hObject,'Value')
handles.Detrend.AfterFilter ='Yes';
else
handles.Detrend.AfterFilter ='No';
end
guidata(hObject, handles);
UpdateDisplay(handles);
function btnDetrend_Callback(hObject, eventdata, handles)
try
Detrend(hObject,handles);
msgbox('Remove the Linear Trend Over.',...
'Detrend successfully' ,'help');
catch
rest_misc( 'DisplayLastException');
end
rest_waitbar;
function Detrend(hObject,handles)
for x=1:size(handles.Cfg.DataDirs, 1)
%Update display
set(handles.listDataDirs, 'Value', x);
drawnow;
if size(handles.Cfg.DataDirs, 1)>1,
rest_waitbar((x-1)/size(handles.Cfg.DataDirs, 1)+0.01, ...
handles.Cfg.DataDirs{x, 1}, ...
'Removing the Linear Trend','Parent');
end
rest_detrend(handles.Cfg.DataDirs{x, 1}, '_detrend');
%Revise the data directories
handles.Cfg.DataDirs{x, 1}=[handles.Cfg.DataDirs{x, 1} , '_detrend'];
guidata(hObject, handles); % Save Dir names
end
UpdateDisplay(handles);
function BandPass(hObject, handles)
for x=1:size(handles.Cfg.DataDirs, 1)
%Update display
set(handles.listDataDirs, 'Value', x);
drawnow;
if size(handles.Cfg.DataDirs, 1)>1,
rest_waitbar((x-1)/size(handles.Cfg.DataDirs, 1)+0.01, ...
handles.Cfg.DataDirs{x, 1}, ...
'Band Pass filter','Parent');
end
rest_bandpass(handles.Cfg.DataDirs{x, 1}, ...
handles.Filter.SamplePeriod, ...
handles.Filter.BandHigh, ...
handles.Filter.BandLow, ...
handles.Filter.Retrend, ...
handles.Cfg.MaskFile);
%build the postfix for filtering
thePostfix ='_filtered';
%Revise the data directories
handles.Cfg.DataDirs{x, 1}=[handles.Cfg.DataDirs{x, 1} , thePostfix];
guidata(hObject, handles); % Save Dir names
end
UpdateDisplay(handles);
function btnHelp_Callback(hObject, eventdata, handles)
web('http://resting-fmri.sourceforge.net');
%web (sprintf('%s/man/English/ALFF/index.html', rest_misc( 'WhereIsREST')), '-helpbrowser');
function btnROIVoxelWise_Callback(hObject, eventdata, handles)
%msgbox( sprintf('There is two way to define a ROI:\n\n1. Define a ball with its central coordinate and radius. Such as defining a ROI ball which centered at (-2,-36,37) and had a radius 10, you could enter "(-2,-36,37), radius=10".\n\n2. Any other ROI that''s not a ball. This kind of ROI could be defined by MRIcro or other softwares and must be a ANALYZE hdr/img file. Then select this file as ROI definition like selecting a mask.'), ...
% 'ROI Definition method' ,'help');
try
if ~iscell(handles.Cfg.ROIList),
handles.Cfg.ROIList =rest_SetROI('Init', handles.Cfg.ROIList);
else
if prod(size(handles.Cfg.ROIList)),
handles.Cfg.ROIList =rest_SetROI('Init', handles.Cfg.ROIList{1});
else
handles.Cfg.ROIList =rest_SetROI('Init');
end
end
catch
rest_SetROI('Delete');
end
guidata(hObject, handles);
UpdateDisplay(handles);
function btnROIRegionWise_Callback(hObject, eventdata, handles)
if ~iscell(handles.Cfg.ROIList), handles.Cfg.ROIList={handles.Cfg.ROIList}; end
handles.Cfg.ROIList=rest_ROIList_gui(handles.Cfg.ROIList);
% if prod(size(handles.Cfg.ROIList)) && size(handles.Cfg.ROIList, 1)==1,
% handles.Cfg.ROIList =handles.Cfg.ROIList{1};
% end
guidata(hObject, handles);
UpdateDisplay(handles);
function btnComputeFC_Callback(hObject, eventdata, handles)
if (size(handles.Cfg.DataDirs, 1)==0) %check legal parameter set first
errordlg('No Data found! Please re-config');
return;
end
if size(handles.Cfg.ROIList, 1) ==0,
errordlg('No ROI Defined! Please define ROI first');
return;
end
%Remove the blank ROI definition at the end before judging
if iscell(handles.Cfg.ROIList) && all(isspace(handles.Cfg.ROIList{1})),
handles.Cfg.ROIList(1)=[];
end
if iscell(handles.Cfg.ROIList) && size(handles.Cfg.ROIList,1)<2 ,
errordlg('Only one ROI Defined for ROI-wise functional connectivity! Please define ROI first');
return;
end
if (exist('fc.m','file')==2)
%write log 20070830
handles.Log.Filename =GetLogFilename(handles.Cfg.OutputDir, get(handles.edtPrefix, 'String'));
Log2File(handles);
handles.Performance =cputime; %Write down the Start time , 20070903
%start computation
theOldDir =pwd;
theOldColor=get(hObject,'BackgroundColor');
set(hObject,'Enable','off', 'BackgroundColor', 'red');
drawnow;
try
%%Remove the linear trend first, and create a new directory, then do filtering
if strcmpi(handles.Filter.UseFilter, 'Yes') && strcmpi(handles.Detrend.BeforeFilter, 'Yes'),
Detrend(hObject, handles);
%20070614, Bug fix, Update the data structure manually
handles =guidata(hObject); % I have to read it again, because I changed it for further processing
end
%%Filter all the data and create a new directory, then compute the Functional Connectivity value, dawnsong 20070429
%Band pass filter
if strcmpi(handles.Filter.UseFilter, 'Yes')
BandPass(hObject, handles);
%20070614, Bug fix, Update the data structure manually
handles =guidata(hObject); % I have to read it again, because I changed it for further processing
end
%%Remove the linear trend after filtering, and create a new directory, then do ReHo
if strcmpi(handles.Filter.UseFilter, 'Yes') && strcmpi(handles.Detrend.AfterFilter, 'Yes'),
Detrend(hObject, handles);
%20070614, Bug fix, Update the data structure manually
handles =guidata(hObject); % I have to read it again, because I changed it for further processing
end
%compute the Functional Connectivity brain
for x=1:size(handles.Cfg.DataDirs, 1)
%Update display
set(handles.listDataDirs, 'Value', x);
drawnow;
if size(handles.Cfg.DataDirs, 1)>1,
rest_waitbar((x-1)/size(handles.Cfg.DataDirs, 1)+0.01, ...
handles.Cfg.DataDirs{x, 1}, ...
'Functional connectivity Computing','Parent');
end
fprintf('\nFunctional connectivity :"%s"\n', handles.Cfg.DataDirs{x, 1});
theOutputDir=get(handles.edtOutputDir, 'String');
thePrefix =get(handles.edtPrefix, 'String');
theDstFile=fullfile(theOutputDir,[thePrefix '_' ...
GetDirName(handles.Cfg.DataDirs{x, 1}) ] );
ResultMaps =fc( handles.Cfg.DataDirs{x, 1}, ...
handles.Cfg.MaskFile, ...
handles.Cfg.ROIList, ...
theDstFile, ...
handles.Covariables);
%20070504, divide Functional Connectivity brain by the mean within the mask
if strcmpi(handles.Cfg.WantFisherZMap, 'Yes')
if ndims(ResultMaps)>2 && size(ResultMaps, 1)>1 ,
%There are many correlation maps
for y=1:size(ResultMaps, 1),
theOrigFCMap =ResultMaps{y, 1};
[pathstr, name, ext, versn] = fileparts(theOrigFCMap);
theFisherZMap =[pathstr, filesep, 'z', name, ext, versn];
theMaskFile =handles.Cfg.MaskFile;
rest_Corr2FisherZ(theOrigFCMap, theFisherZMap, theMaskFile);
end
elseif size(ResultMaps, 1)==1,
%There is only one correlation map
theOrigFCMap =theDstFile;
[pathstr, name, ext, versn] = fileparts(theOrigFCMap);
theFisherZMap =[pathstr, filesep, 'z', name, ext, versn];
theMaskFile =handles.Cfg.MaskFile;
rest_Corr2FisherZ(theOrigFCMap, theFisherZMap, theMaskFile);
elseif ndims(ResultMaps)==2,
%Time series correlation matrix
theOrigFCMap =theDstFile;
[pathstr, name, ext, versn] = fileparts(theOrigFCMap);
theFisherZMap =[pathstr, filesep, 'z', name, ext, versn];
ResultMaps =0.5 * log((1 +ResultMaps)./(1- ResultMaps));
save([theFisherZMap, '.txt'], 'ResultMaps', '-ASCII', '-DOUBLE','-TABS')
end
end
end
handles.Performance =cputime -handles.Performance; %Write down the End time , 20070903
LogPerformance(handles);
catch
rest_misc( 'DisplayLastException');
errordlg(sprintf('Exception occured: \n\n%s' , lasterr));
end
cd(theOldDir);
set(hObject,'Enable','on', 'BackgroundColor', theOldColor);
drawnow;
rest_waitbar;
else
errordlg('No fc.m ! Please re-install');
end
function edtCovariableFile_Callback(hObject, eventdata, handles)
handles.Covariables.ort_file =get(hObject, 'String');
guidata(hObject,handles);
function edtCovariableFile_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function btnSelectCovariableFile_Callback(hObject, eventdata, handles)
[filename, pathname] = uigetfile({'*.txt; *.1D', 'Covariables'' time course file (*.txt; *.1D)'; ...
'*.txt','text file (*.txt)'; ...
'*.1D', 'AFNI 1D file(*.1D)'}, ...
'Pick Covariables'' time course file');
if ~(filename==0),
handles.Covariables.ort_file =[pathname filename];
guidata(hObject,handles);
end
UpdateDisplay(handles);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -