📄 alff_gui.m
字号:
function varargout = alff_gui(varargin)
%ALFF GUI by Xiaowei Song
%-----------------------------------------------------------
% Copyright(c) 2007~2010
% State Key Laboratory of Cognitive Neuroscience and Learning in Beijing Normal University
% Written by Xiao-Wei Song
% http://resting-fmri.sourceforge.net
% $mail =dawnwei.song@gmail.com
% $Version =1.0;
% $Date =20070421;
%-----------------------------------------------------------
% <a href="Dawnwei.Song@gmail.com">Mail to Author</a>: Xiaowei Song
% Version=1.1;
% Release=20070903;
% Last Modified by GUIDE v2.5 31-May-2007 17:32:29
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @alff_gui_OpeningFcn, ...
'gui_OutputFcn', @alff_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 alff_gui is made visible.
function alff_gui_OpeningFcn(hObject, eventdata, handles, varargin)
%Matlab -Linux compatible, Initialize controls' default properties, dawnsong , 20070507
InitControlProperties(hObject, handles);
%Matlab -v6 compatible, create some frames instead of panels
InitFrames(hObject,handles);
[pathstr, name, ext, versn] = fileparts(mfilename('fullpath'));
%the {hdr/img} directories to be processed , count of volumns(i.e. time series' point number) corresponding to the dir
handles.Cfg.DataDirs ={}; %{[pathstr '\SampleData'], 10} ;
handles.Cfg.MaskFile = 'Default'; %the user defined mask file
handles.Cfg.OutputDir =pwd; % pwd is the default dir for alff map result
handles.Cfg.WantMeanAlffMap ='Yes'; %Calcute the mean alff map default
handles.Filter.BandLow =0.01; %Config about Band pass filter, dawnsong 20070429
handles.Filter.BandHigh =0.08;
handles.Filter.UseFilter ='No';
handles.Filter.Retrend ='Yes'; % by default, always re-trend after linear filtering after removing linear trend 20070614, bug fixes
handles.Filter.SamplePeriod=2; %by default, set TR=2s
handles.Detrend.BeforeFilter ='No';% ZangYF, 20070530 decide
handles.Detrend.AfterFilter ='No';% ZangYF, 20070530 decide
handles.ALFF.BandLow =0.01; % Band Info for ALFF computing
handles.ALFF.BandHigh =0.08; % Band Info for ALFF computing
handles.ALFF.SamplePeriod =2; % Band Info for ALFF computing
handles.Log.SelfPath =pathstr; % 20070507, dawnsong, just for writing log to file for further investigation
handles.Log.Filename =GetLogFilename('','');
%Performance record, use elapsed time to describe it, 20070507
handles.Performance =0;
guidata(hObject, handles);
UpdateDisplay(handles);
movegui(handles.figAlffMain, 'center');
set(handles.figAlffMain,'Name','Amplitude of Low Frequency Fluctuation');
% Choose default command line output for alff_gui
handles.output = hObject;
guidata(hObject, handles);% Update handles structure
% UIWAIT makes alff_gui wait for user response (see UIRESUME)
% uiwait(handles.figAlffMain);
% --- Outputs from this function are returned to the command line.
function varargout = alff_gui_OutputFcn(hObject, eventdata, handles)
% Get default command line output from handles structure
varargout{1} = handles.output;
function edtDataDirectory_Callback(hObject, eventdata, handles)
theDir =get(hObject, 'String');
SetDataDir(hObject, theDir,handles);
function edtDataDirectory_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function btnSelectDataDir_Callback(hObject, eventdata, handles)
if size(handles.Cfg.DataDirs, 1)>0
theDir =handles.Cfg.DataDirs{1,1};
else
theDir =pwd;
end
theDir =uigetdir(theDir, 'Please select the data directory to compute alff map: ');
if ischar(theDir),
SetDataDir(hObject, theDir,handles);
end
function RecursiveAddDataDir(hObject, eventdata, handles)
if prod(size(handles.Cfg.DataDirs))>0 && size(handles.Cfg.DataDirs, 1)>0,
theDir =handles.Cfg.DataDirs{1,1};
else
theDir =pwd;
end
theDir =uigetdir(theDir, 'Please select the parent data directory of many sub-folders containing EPI data to compute ALFF map: ');
if ischar(theDir),%Make the warning dlg off! 20071201
setappdata(0, 'ALFF_DoingRecursiveDir', 1);
theOldColor =get(handles.listDataDirs, 'BackgroundColor');
set(handles.listDataDirs, 'BackgroundColor', [ 0.7373 0.9804 0.4784]);
try
rest_RecursiveDir(theDir, 'alff_gui(''SetDataDir'',gcbo, ''%s'', guidata(gcbo) )');
catch
rest_misc( 'DisplayLastException');
end
set(handles.listDataDirs, 'BackgroundColor', theOldColor);
rmappdata(0, 'ALFF_DoingRecursiveDir');
end
function SetDataDir(hObject, ADir, handles)
if ~ischar(ADir), return; end
theOldWarnings =warning('off', 'all');
% if (~isequal(ADir , 0)) &&( (size(handles.Cfg.DataDirs, 1)==0)||(0==seqmatch({ADir} ,handles.Cfg.DataDirs( : , 1) ) ) )
if rest_misc('GetMatlabVersion')>=7.3,
ADir =strtrim(ADir);
end
if (~isequal(ADir , 0)) &&( (size(handles.Cfg.DataDirs, 1)==0)||(0==length(strmatch(ADir,handles.Cfg.DataDirs( : , 1),'exact' ) ) ))
handles.Cfg.DataDirs =[ {ADir , 0}; handles.Cfg.DataDirs];%update the dir
theVolumnCount =CheckDataDir(handles.Cfg.DataDirs{1,1} );
if (theVolumnCount<=0),
if isappdata(0, 'ALFF_DoingRecursiveDir') && getappdata(0, 'ALFF_DoingRecursiveDir'),
else
fprintf('There is no data or non-data files in this directory:\n%s\nPlease re-select\n\n', ADir);
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} ));
end
handles.Cfg.DataDirs(1,:)=[];
if size(handles.Cfg.DataDirs, 1)==0
handles.Cfg.DataDirs=[];
end %handles.Cfg.DataDirs = handles.Cfg.DataDirs( 2:end, :);%update the dir
else
handles.Cfg.DataDirs{1,2} =theVolumnCount;
end
guidata(hObject, handles);
UpdateDisplay(handles);
end
warning(theOldWarnings);
%% Update All the uiControls' display on the GUI
function UpdateDisplay(handles)
if size(handles.Cfg.DataDirs,1)>0
theOldIndex =get(handles.listDataDirs, 'Value');
%set(handles.listDataDirs, 'String', handles.Cfg.DataDirs(: ,1) , 'Value', 1);
set(handles.listDataDirs, 'String', GetInputDirDisplayList(handles) , 'Value', 1);
theCount =size(handles.Cfg.DataDirs,1);
if (theOldIndex>0) && (theOldIndex<= theCount)
set(handles.listDataDirs, 'Value', theOldIndex);
end
set(handles.edtDataDirectory,'String', handles.Cfg.DataDirs{1,1});
theResultFilename=get(handles.edtPrefix, 'String');
theResultFilename=[theResultFilename '_' GetDirName(handles.Cfg.DataDirs{1,1})];
set(handles.txtResultFilename, 'String', [theResultFilename '.{hdr/img}']);
else
set(handles.listDataDirs, 'String', '' , 'Value', 0);
set(handles.txtResultFilename, 'String', 'Result: Prefix_DirectoryName.{hdr/img}');
end
% set(handles.pnlParametersInput,'Title', ... %show the first dir's Volumn count in the panel's title
% ['Input Parameters (Volumn count= '...
% num2str( cell2mat(handles.Cfg.DataDirs(1,2)) )...
% ' in 'handles.Cfg.DataDirs(1,1) ' )']);
set(handles.edtOutputDir ,'String', handles.Cfg.OutputDir);
if isequal(handles.Cfg.MaskFile, '')
set(handles.edtMaskfile, 'String', 'Don''t use any Mask');
else
set(handles.edtMaskfile, 'String', handles.Cfg.MaskFile);
end
%Set detrend dawnsong 20070820
if strcmpi(handles.Detrend.BeforeFilter, 'Yes')
%Update filter and detrend button's state according to Option: detrend/Filter 20070820
set(handles.btnDetrend, 'Enable', 'on');
else
%Update filter and detrend button's state according to Option: detrend/Filter 20070820
set(handles.btnDetrend, 'Enable', 'off');
end
%Set filter, dawnsong 20070430
if strcmpi(handles.Filter.UseFilter, 'Yes')
set(handles.ckboxFilter, 'Value', 1);
set(handles.ckboxRetrend, 'Enable', 'on');
set(handles.edtBandLow, 'Enable', 'on', 'String', num2str(handles.Filter.BandLow));
set(handles.edtBandHigh, 'Enable', 'on', 'String', num2str(handles.Filter.BandHigh));
set(handles.edtSamplePeriod, 'Enable', 'on', 'String', num2str(handles.Filter.SamplePeriod));
%Update filter and detrend button's state according to Option: detrend/Filter 20070820
set(handles.btnBandPass, 'Enable', 'on');
else
set(handles.ckboxFilter, 'Value', 0);
set(handles.ckboxRetrend,'Enable', 'off');
set(handles.edtBandLow, 'Enable', 'off', 'String', num2str(handles.Filter.BandLow));
set(handles.edtBandHigh, 'Enable', 'off', 'String', num2str(handles.Filter.BandHigh));
set(handles.edtSamplePeriod, 'Enable', 'off', 'String', num2str(handles.Filter.SamplePeriod));
%Update filter and detrend button's state according to Option: detrend/Filter 20070820
set(handles.btnBandPass, 'Enable', 'off');
end
%Set mean calculation, dawnsong 20070504
set(handles.ckboxDivideMean, 'Value', strcmpi(handles.Cfg.WantMeanAlffMap, 'Yes'));
% Set detrend option
set(handles.ckboxRemoveTrendBefore, 'Value', strcmpi(handles.Detrend.BeforeFilter, 'Yes'));
set(handles.ckboxRemoveTrendAfter, 'Value', strcmpi(handles.Detrend.AfterFilter, 'Yes'));
%% check the Data dir to make sure that there are only {hdr,img}
function Result=GetInputDirDisplayList(handles)
Result ={};
for x=size(handles.Cfg.DataDirs, 1):-1:1
Result =[{sprintf('%d# %s',handles.Cfg.DataDirs{x, 2},handles.Cfg.DataDirs{x, 1})} ;Result];
end
% in this dir
function [nVolumn]=CheckDataDir(ADataDir)
theFilenames = dir(ADataDir);
theHdrFiles=dir(fullfile(ADataDir,'*.hdr'));
theImgFiles=dir(fullfile(ADataDir,'*.img'));
% if (length(theFilenames)-length(theHdrFiles)-length(theImgFiles))>2
% nVolumn =-1;
% errordlg(sprintf(['There should not be any file other than *.{hdr,img} .' ...
% 'Please re-examin the DataDir\n\n%s '] ...
% , ADataDir));
% return;
% end
if ~length(theHdrFiles)==length(theImgFiles)
nVolumn =-1;
fprintf('%s, *.{hdr,img} should be pairwise. Please re-examin them.\n', ADataDir);
errordlg('*.{hdr,img} should be pairwise. Please re-examin them.');
return;
end
count = 3; nVolumn = 0;
for count = 3:size(struct2cell(theFilenames),2)
if (length(theFilenames(count).name)>4) && ...
strcmpi(theFilenames(count).name(end-3:end) , '.hdr')
if strcmpi(theFilenames(count).name(1:end-4) ... %hdr
, theFilenames(count+1).name(1:end-4) ) %img
nVolumn = nVolumn + 1;
else
%error('*.{hdr,img} should be pairwise. Please re-examin them.');
nVolumn =-1;
fprintf('%s, *.{hdr,img} should be pairwise. Please re-examin them.\n', ADataDir);
errordlg('*.{hdr,img} should be pairwise. Please re-examin them.');
break;
end
end
end
function btnComputeAlff_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 (exist('alff.m','file')==2)
%write log 20070507
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 change it for further processing
end
%%Filter all the data and create a new directory, then compute the alff 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 change 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 change it for further processing
end
%compute the alff 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}, ...
'ALFF Computing','Parent');
end
fprintf('\nALFF :"%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}) ] );
alff( handles.Cfg.DataDirs{x, 1}, ...
handles.ALFF.SamplePeriod, ...
handles.ALFF.BandHigh, ...
handles.ALFF.BandLow, ...
handles.Cfg.MaskFile, ...
theDstFile);
%20070504, divide alff brain by the mean within the mask
if strcmpi(handles.Cfg.WantMeanAlffMap, 'Yes')
theOrigAlffMap =theDstFile;
theMeanAlffMap =fullfile(theOutputDir,['m' thePrefix '_' ...
GetDirName(handles.Cfg.DataDirs{x, 1}) ] );
theMaskFile =handles.Cfg.MaskFile;
rest_DivideMeanWithinMask(theOrigAlffMap, theMeanAlffMap, theMaskFile);
end
end
handles.Performance =cputime -handles.Performance; %Write down the End time , 20070903
LogPerformance(handles);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -