0001 function varargout = rest(AOperation, varargin)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014 if isappdata(0, 'Rest_Cfg'),
0015 Rest_Cfg =getappdata(0, 'Rest_Cfg');
0016 else
0017 Rest_Cfg =[];
0018 end
0019
0020 if nargin<1, AOperation='Init'; end
0021
0022 switch upper(AOperation),
0023 case 'INIT',
0024 if isempty(Rest_Cfg) || ~rest_misc( 'ForceCheckExistFigure' , Rest_Cfg.hFig);,
0025
0026
0027 clear all;
0028 clc;
0029 QuitAll;
0030
0031 Rest_Cfg =[];
0032 Rest_Cfg =InitControls(Rest_Cfg);
0033
0034 end
0035 if ~isempty(Rest_Cfg) && rest_misc( 'ForceCheckExistFigure' , Rest_Cfg.hFig),
0036 figure(Rest_Cfg.hFig);
0037 end
0038 if nargout>0,
0039 varargout{1} =Rest_Cfg.hFig;
0040 end
0041 setappdata(0, 'Rest_Cfg', Rest_Cfg);
0042
0043
0044
0045 if 2==exist(fullfile(rest_misc('WhereIsREST'), 'rest.log'),'file'),
0046 delete(fullfile(rest_misc('WhereIsREST'), 'rest.log'));
0047 end
0048 diary(fullfile(rest_misc('WhereIsREST'), 'rest.log'));
0049
0050 diary on;
0051
0052 [theVer, theRelease] =rest_misc( 'GetRestVersion');
0053 disp(sprintf('Welcome: %s, %s \nREST Version: %s, Release: %s', rest_misc('GetCurrentUser'),rest_misc( 'GetDateTimeStr'), theVer, theRelease));
0054
0055
0056 case 'RESTART',
0057 if nargin~=1, error('Usage: rest(''Restart'');'); end
0058 clear all;
0059 clc;
0060 QuitAll;
0061
0062 Rest_Cfg =[];
0063 Rest_Cfg =InitControls(Rest_Cfg);
0064 figure(Rest_Cfg.hFig);
0065 if nargout>0,
0066 varargout{1} =Rest_Cfg.hFig;
0067 end
0068
0069 setappdata(0, 'Rest_Cfg', Rest_Cfg);
0070
0071 case 'QUITALL',
0072 if nargin~=1, error('Usage: rest(''QuitAll'');'); end
0073 QuitAll;
0074
0075 if ~isempty(Rest_Cfg) && rest_misc( 'ForceCheckExistFigure' , Rest_Cfg.hFig),
0076 delete(Rest_Cfg.hFig);
0077 end
0078 if isappdata(0, 'Rest_Cfg'),
0079 rmappdata(0, 'Rest_Cfg');
0080 end
0081 clc;
0082 [theVer, theRelease] =rest_misc( 'GetRestVersion');
0083 disp(sprintf('Good Bye: %s, %s \nREST Version: %s, Release: %s', rest_misc('GetCurrentUser'),rest_misc( 'GetDateTimeStr'), theVer, theRelease));
0084
0085 diary off;
0086
0087
0088 case 'STARTREHO',
0089 StartReHo;
0090 case 'STARTALFF',
0091 StartALFF;
0092 case 'STARTFALFF',
0093 StartfALFF;
0094 case 'MAILTOZANG',
0095 MailToZang;
0096 case 'MAILTOSONG',
0097 MailToSong;
0098 case 'OPENHELP',
0099 OpenHelp;
0100 case 'FUNCTIONALCONNECTIVITYNOTREADY',
0101
0102
0103 StartFunctionalConnectivity;
0104 otherwise
0105 end
0106
0107 function Result =InitControls(AConfig)
0108 DefaultColorBackground =[1 1 1]*.5;
0109 theFig =figure('Units', 'pixel', 'Toolbar', 'none', 'MenuBar', 'none', ...
0110 'NumberTitle', 'off', 'Visible', 'off', ...
0111 'Name', sprintf('REST %s',rest_misc( 'GetRestVersion')), ...
0112 'Position', [0,0,500, 330], 'Resize','off', ...
0113 'Color', DefaultColorBackground , ...
0114 'DeleteFcn', sprintf('rest(''QuitAll'');') );
0115 movegui(theFig, 'northwest');
0116
0117 uicontrol(theFig,'Style','Text','Position',[0 286 500 36],...
0118 'String','Resting State fMRI Data Analysis Toolkit',...
0119 'FontSize',18, ...
0120 'FontWeight','Bold',...
0121 'ForegroundColor',[1 1 1]*.7,'BackgroundColor', DefaultColorBackground);
0122
0123 logoPos =[10, 135, 0,0];
0124 theLogo = fullfile(rest_misc( 'WhereIsREST'), 'logo.jpg');
0125 if (exist(theLogo,'file')==2),
0126 theLogo = imread(theLogo);
0127 logoPos(3) =size(theLogo, 2);
0128 logoPos(4) =size(theLogo, 1);
0129 for x=1:3,
0130 theLogo(:, :, x) =flipud(theLogo(:, :, x));
0131 end
0132
0133 hAxesLogo =axes('Parent', theFig, 'Box', 'on', ...
0134 'Units', 'pixel', 'DrawMode','normal', ...
0135 'Position', logoPos, ...
0136 'YDir','normal', 'XTickLabel',[],'XTick',[], ...
0137 'YTickLabel',[],'YTick',[], 'DataAspectRatio',[1 1 1]);
0138 hImgLogo =image('Tag','LogoImage', 'Parent', hAxesLogo);
0139 set(hAxesLogo,'YDir','normal','XTickLabel',[],'XTick',[], 'YTickLabel',[],'YTick',[]);
0140
0141 set(hImgLogo, 'CData', theLogo);
0142 set(hAxesLogo, 'XLim', [1 logoPos(3)], 'YLim', [1 logoPos(4)]);
0143 else
0144 error('Please re-install REST');
0145 end
0146
0147
0148 uicontrol(theFig,'Style','Frame','Position', ...
0149 [logoPos(1)+logoPos(3)+2, logoPos(2), 500-logoPos(3)-20 ,logoPos(4)], ...
0150 'BackgroundColor', [1 1 1]*.0);
0151 uicontrol(theFig,'Style','Text','String','REST 2007',...
0152 'ToolTipString',sprintf('\nby the ZangYF neuroimaging methods group of BNU\n'),...
0153 'Position', ...
0154 [logoPos(1)+logoPos(3)+12, logoPos(2)+logoPos(4)-56, 500-logoPos(3)-40 , 36], ...
0155 'BackgroundColor', [1 1 1]*.0, ...
0156 'FontSize',24,'FontWeight','Bold',...
0157 'ForegroundColor','b')
0158
0159
0160
0161
0162
0163
0164
0165
0166 uicontrol(theFig,'Style','Text', 'Position', ...
0167 [logoPos(1)+logoPos(3)+12, logoPos(2)+20*3, 500-logoPos(3)-40 , 20], ...
0168 'String','State Key Laboratory of',...
0169 'BackgroundColor', [1 1 1]*.0, ...
0170 'ToolTipString','', 'ForegroundColor', [1 1 1]*1, ...
0171 'FontSize',12);
0172 uicontrol(theFig,'Style','Text', 'Position',...
0173 [logoPos(1)+logoPos(3)+12, logoPos(2)+20*2, 500-logoPos(3)-40 , 20], ...
0174 'String','Cognitive Neuroscience and Learning',...
0175 'BackgroundColor', [1 1 1]*.0, ...
0176 'ToolTipString','', 'ForegroundColor', 'w', ...
0177 'FontSize',12);
0178 uicontrol(theFig,'Style','Text', 'Position',...
0179 [logoPos(1)+logoPos(3)+12, logoPos(2)+20, 500-logoPos(3)-40 , 20], ...
0180 'BackgroundColor', [1 1 1]*.0, ...
0181 'String','Beijing Normal University', 'ForegroundColor', [1 1 1]*1, ...
0182 'ToolTipString','',...
0183 'FontSize',12);
0184
0185 uicontrol(theFig,'Style','Frame','Position',[10 10 480 115], 'BackgroundColor', [0.9 0.8 0.6]);
0186
0187
0188
0189
0190
0191
0192
0193
0194
0195 uicontrol(theFig,'Style','pushbutton', 'Position',[30 70 100 40],...
0196 'String','ReHo','ToolTipString','Regional homogeneity approach to fMRI data analysis', ...
0197 'Callback', sprintf('rest(''StartReHo'');'), ...
0198 'FontSize',16, 'FontWeight','Bold', 'ForegroundColor','m')
0199 uicontrol(theFig,'Style','pushbutton', 'Position',[140 70 100 40],...
0200 'String','ALFF', 'ToolTipString','Amplitude of low-frequency fluctuation',...
0201 'Callback', sprintf('rest(''StartALFF'');'), ...
0202 'FontSize',16, 'FontWeight','Bold', ...
0203 'ForegroundColor','m')
0204 uicontrol(theFig,'Style','pushbutton', 'Position',[250 70 100 40],...
0205 'String','fALFF', 'ToolTipString','fractional ALFF',...
0206 'Callback', sprintf('rest(''StartfALFF'');'), ...
0207 'FontSize',16, 'FontWeight','Bold', ...
0208 'ForegroundColor','m')
0209
0210 uicontrol(theFig,'Style','pushbutton', 'Position',[370 70 100 40],...
0211 'String','Help',...
0212 'Callback', sprintf('rest(''OpenHelp'');'), ...
0213 'FontSize',16, 'FontWeight','Bold', 'ForegroundColor','g')
0214 uicontrol(theFig,'Style','pushbutton', 'Position',[370 20 100 40],...
0215 'String','Quit',...
0216 'Callback', sprintf('rest(''QuitAll'');'), ...
0217 'FontSize',16, 'FontWeight','Bold', 'ForegroundColor','r')
0218
0219
0220
0221
0222
0223
0224
0225
0226
0227 uicontrol(theFig,'Style','pushbutton', 'Position',[30 20 320 40],...
0228 'String','Functional Connectivity',...
0229 'Callback', sprintf('rest(''FunctionalConnectivityNotReady'');'), ...
0230 'FontSize',16, 'FontWeight','Bold', 'ForegroundColor','m')
0231
0232
0233 AConfig.hFig =theFig;
0234
0235 Result =AConfig;
0236
0237 set(theFig, 'Visible', 'on');
0238
0239 function QuitAll()
0240
0241 delete(gcbf);
0242
0243 rest_waitbar;
0244
0245 rest_sliceviewer('QuitAllSliceViewer');
0246
0247 rest_powerspectrum('QuitAllPowerSpectrum');
0248
0249 theFig =findobj(allchild(0),'flat','Tag','figRehoMain');
0250 if ~isempty(theFig) && rest_misc( 'ForceCheckExistFigure' , theFig),
0251 delete(theFig);
0252 end
0253
0254 theFig =findobj(allchild(0),'flat','Tag','figAlffMain');
0255 if ~isempty(theFig) && rest_misc( 'ForceCheckExistFigure' , theFig),
0256 delete(theFig);
0257 end
0258
0259 theFig =findobj(allchild(0),'flat','Tag','figfAlffMain');
0260 if ~isempty(theFig) && rest_misc( 'ForceCheckExistFigure' , theFig),
0261 delete(theFig);
0262 end
0263
0264 theFig =findobj(allchild(0),'flat','Tag','figFCMain');
0265 if ~isempty(theFig) && rest_misc( 'ForceCheckExistFigure' , theFig),
0266 delete(theFig);
0267 end
0268
0269 rest_misc('UnlockRestFiles');
0270 clear all
0271
0272
0273 rest_misc( 'ClearTempFiles');
0274
0275
0276 function StartReHo()
0277 theFig =findobj(allchild(0),'flat','Tag','figRehoMain');
0278 if ~isempty(theFig) && rest_misc( 'ForceCheckExistFigure' , theFig),
0279 figure(theFig);
0280 else
0281 reho_gui;
0282 end
0283
0284
0285 function StartALFF()
0286 theFig =findobj(allchild(0),'flat','Tag','figAlffMain');
0287 if ~isempty(theFig) && rest_misc( 'ForceCheckExistFigure' , theFig),
0288 figure(theFig);
0289 else
0290 alff_gui;
0291 end
0292
0293 function StartfALFF()
0294 theFig =findobj(allchild(0),'flat','Tag','figfAlffMain');
0295 if ~isempty(theFig) && rest_misc( 'ForceCheckExistFigure' , theFig),
0296 figure(theFig);
0297 else
0298 f_alff_gui;
0299 end
0300
0301 function StartFunctionalConnectivity()
0302 theFig =findobj(allchild(0),'flat','Tag','figFCMain');
0303 if ~isempty(theFig) && rest_misc( 'ForceCheckExistFigure' , theFig),
0304 figure(theFig);
0305 else
0306 fc_gui;
0307 end
0308
0309 function MailToZang()
0310 web('mailto:zangyf@gmail.com');
0311 function MailToSong()
0312 web('mailto:dawnwei.song@gmail.com');
0313
0314 function OpenHelp()
0315 web('http://resting-fmri.sourceforge.net');
0316