📄 alff_gui.m
字号:
%% Log options to a log file for further investigation, 20070507
function Log2File(handles)
constLineSep= '-------------------------------------------------------------------------------';
[theVer, theRelease] =rest_misc( 'GetRestVersion');
theMsgVersion = sprintf('REST Version:%s, Release %s\r\n%s\r\n', theVer, theRelease, constLineSep);
theMsgHead = sprintf('ALFF computation log %s\r\n%s\r\n', rest_misc( 'GetDateTimeStr'), constLineSep);
theMsg =sprintf('%s\r\n%s\r\n\r\n%s', theMsgVersion, theMsgHead, constLineSep);
theMsg =sprintf('%s\r\nRemove Linear Trend options:\r\n%s\r\n\r\n%s',theMsg,...
LogRemoveLinearTrend(handles), constLineSep);
theMsg =sprintf('%s\r\nIdeal Band Pass filter options:\r\n%s\r\n\r\n%s',theMsg,...
LogBandPassFilter(handles), constLineSep);
theMsg =sprintf('%s\r\nALFF input parameters:\r\n%s\r\n\r\n%s', theMsg, ...
LogInputParameters(handles), constLineSep);
theMsg =sprintf('%s\r\nALFF Band Config:\r\n%s\r\n\r\n%s',theMsg,...
LogALFFParameters(handles), constLineSep);
theMsg =sprintf('%s\r\nALFF output parameters:\r\n%s\r\n\r\n%s', theMsg, ...
LogOutputParameters(handles), constLineSep);
fid = fopen(handles.Log.Filename,'w');
if fid~=-1
fprintf(fid,'%s',theMsg);
fclose(fid);
else
errordlg(sprintf('Error to open log file:\n\n%s', handles.Log.Filename));
end
function ResultLogString=LogRemoveLinearTrend(handles)
ResultLogString ='';
ResultLogString =sprintf('%s\tremove linear trend BEFORE filter: %s\r\n',ResultLogString, handles.Detrend.BeforeFilter);
ResultLogString =sprintf('%s\tremove linear trend AFTER filter: %s\r\n',ResultLogString, handles.Detrend.AfterFilter);
function ResultLogString=LogBandPassFilter(handles)
ResultLogString ='';
ResultLogString =sprintf('%s\tUse Filter: %s\r\n',ResultLogString, handles.Filter.UseFilter);
ResultLogString =sprintf('%s\tBand Low: %g\r\n', ResultLogString, handles.Filter.BandLow);
ResultLogString =sprintf('%s\tBand High: %g\r\n',ResultLogString, handles.Filter.BandHigh);
ResultLogString =sprintf('%s\tSample Period(i.e. TR): %g\r\n',ResultLogString, handles.Filter.SamplePeriod);
function ResultLogString=LogALFFParameters(handles)
ResultLogString ='';
ResultLogString =sprintf('%s\tBand Low: %g\r\n', ResultLogString, handles.ALFF.BandLow);
ResultLogString =sprintf('%s\tBand High: %g\r\n',ResultLogString, handles.ALFF.BandHigh);
ResultLogString =sprintf('%s\tSample Period(i.e. TR): %g\r\n',ResultLogString, handles.ALFF.SamplePeriod);
function ResultLogString=LogInputParameters(handles)
ResultLogString ='';
constLineSep= '-------------------------------------------------------------------------------';
theDataDirString= '';
theDataDirCells =get(handles.listDataDirs, 'string');
for x=1:length(theDataDirCells)
theDataDirString =sprintf('%s\r\n\t%s', theDataDirString, theDataDirCells{x});
end
theDirType ='';
if strcmpi(handles.Detrend.BeforeFilter, 'Yes')
theDirType =sprintf(' %s after Detrend processing', theDirType);
end
if strcmpi(handles.Detrend.BeforeFilter, 'Yes') && ...
strcmpi(handles.Filter.UseFilter, 'Yes'),
theDirType =sprintf(' %s and ', theDirType);
end
if strcmpi(handles.Filter.UseFilter, 'Yes')
theDirType =sprintf(' %s after Filter processing', theDirType);
end
ResultLogString =sprintf('%s\tInput Data Directories( %s): \r\n\t%s%s\r\n\t%s\r\n',ResultLogString,...
theDirType, ...
constLineSep, ...
theDataDirString, ...
constLineSep);
ResultLogString =sprintf('%s\tMask file: %s\r\n', ResultLogString, handles.Cfg.MaskFile);
function ResultLogString=LogOutputParameters(handles)
ResultLogString ='';
ResultLogString =sprintf('%s\tPrefix to the Data directories: %s\r\n',ResultLogString, get(handles.edtPrefix, 'String'));
ResultLogString =sprintf('%s\tOutput Data Directories: %s\r\n',ResultLogString, handles.Cfg.OutputDir);
ResultLogString =sprintf('%s\tWant mean ReHo map computation: %s \r\n',ResultLogString, handles.Cfg.WantMeanAlffMap);
%Log the total elapsed time by once "Do all"
function LogPerformance(handles)
theMsg =sprintf('\r\n\r\nTotal elapsed time for ALFF Computing: %g seconds\r\n',handles.Performance);
fid = fopen(handles.Log.Filename,'r+');
fseek(fid, 0, 'eof');
if fid~=-1
fprintf(fid,'%s',theMsg);
fclose(fid);
else
errordlg(sprintf('Error to open log file:\n\n%s', handles.Log.Filename));
end
%compose the log filename
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 ALFF figure to show corresponding voxel's time-course and its freq amplitude
theDataSetDir =pathname;
theVoxelPosition=rest_sliceviewer('GetPosition', theViewer);
theSamplePeriod =handles.ALFF.SamplePeriod;
theBandRange =[handles.ALFF.BandLow, handles.ALFF.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)
theOldColor=get(hObject,'BackgroundColor');
set(hObject,'Enable','off', 'BackgroundColor', 'red');
drawnow;
try
Detrend(hObject,handles);
msgbox('Remove the Linear Trend Over.',...
'Detrend successfully' ,'help');
catch
rest_misc( 'DisplayLastException');
end
rest_waitbar;
set(hObject,'Enable','on', 'BackgroundColor', theOldColor);
drawnow;
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 edtAlffBandLow_Callback(hObject, eventdata, handles)
handles.ALFF.BandLow =str2double(get(hObject,'String'));
guidata(hObject, handles);
function edtAlffBandLow_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function edtAlffBandHigh_Callback(hObject, eventdata, handles)
handles.ALFF.BandHigh =str2double(get(hObject,'String'));
guidata(hObject, handles);
function edtAlffBandHigh_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function edtAlffSamplePeriod_Callback(hObject, eventdata, handles)
handles.ALFF.SamplePeriod =str2double(get(hObject,'String'));
guidata(hObject, handles);
function edtAlffSamplePeriod_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function btnAlffBandDetail_Callback(hObject, eventdata, handles)
%Compute the ALFF Band detailed message and show it
sampleLength =inputdlg('Please input sample length: (i.e. the total number of time points)', ...
'ALFF Band Detailed Message');
sampleLength =str2num(sampleLength{1});
sampleFreq =1/handles.ALFF.SamplePeriod;
paddedLength =rest_nextpow2_one35(sampleLength);
freqPrecision =sampleFreq /paddedLength;
BandLowIdx =handles.ALFF.BandLow * paddedLength * handles.ALFF.SamplePeriod;
rBandLowIdx =round(BandLowIdx);
rBandLow =rBandLowIdx /paddedLength /handles.ALFF.SamplePeriod;
BandHighIdx =handles.ALFF.BandHigh * paddedLength * handles.ALFF.SamplePeriod;
rBandHighIdx =round(BandHighIdx);
rBandHigh =rBandHighIdx /paddedLength /handles.ALFF.SamplePeriod;
theWantBandInfo =sprintf('%gHz --> Index=%g, %gHz --> Index=%g', ...
handles.ALFF.BandLow, BandLowIdx, ...
handles.ALFF.BandHigh, BandHighIdx);
theRealBandInfo =sprintf('%gHz --> Index=%g, %gHz --> Index=%g', ...
rBandLow, rBandLowIdx, ...
rBandHigh, rBandHighIdx);
if rBandLowIdx==ceil(BandLowIdx)
rBandLowIdx =floor(BandLowIdx);
else
rBandLowIdx =ceil(BandLowIdx);
end
rBandLow =rBandLowIdx /paddedLength /handles.ALFF.SamplePeriod;
if rBandHighIdx==ceil(BandHighIdx)
rBandHighIdx =floor(BandHighIdx);
else
rBandHighIdx =ceil(BandHighIdx);
end
rBandHigh =rBandHighIdx /paddedLength /handles.ALFF.SamplePeriod;
theAnother2Point =sprintf('%gHz --> Index=%g, %gHz --> Index=%g', ...
rBandLow, rBandLowIdx, ...
rBandHigh, rBandHighIdx);
msgbox( sprintf('The Band you want to use is:\n%s\n\nAdopted ALFF Band is:\n%s\n\n\nAnother 2 points'' Infomation:\n%s\n\nYou can view full information in "Power Spectrum"', theWantBandInfo, theRealBandInfo, theAnother2Point), ...
'Calculated Band Range Hint' ,'help');
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');
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -