Home > rest_20090422 > rest.m

rest

PURPOSE ^

RESTing state fMRI data analysis toolkit by Xiao-Wei Song

SYNOPSIS ^

function varargout = rest(AOperation, varargin)

DESCRIPTION ^

RESTing state fMRI data analysis toolkit by Xiao-Wei 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 to Authors:  <a href="Dawnwei.Song@gmail.com">Xiaowei Song</a>; <a href="ycg.yan@gmail.com">Chaogan Yan</a> 
    Version=1.3;
    Release=20090422;
   Last Revised by YAN Chao-Gan 090321, added the fALFF module. Thank Dr. CHENG Wen-Lian for the helpful work.
-----------------------------------------------------------

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

DOWNLOAD ^

rest.m

SOURCE CODE ^

0001 function varargout = rest(AOperation, varargin)
0002 %RESTing state fMRI data analysis toolkit by Xiao-Wei Song
0003 %-----------------------------------------------------------
0004 %    Copyright(c) 2007~2010
0005 %    State Key Laboratory of Cognitive Neuroscience and Learning in Beijing Normal University
0006 %    Written by Xiao-Wei Song
0007 %    http://resting-fmri.sourceforge.net
0008 %     Mail to Authors:  <a href="Dawnwei.Song@gmail.com">Xiaowei Song</a>; <a href="ycg.yan@gmail.com">Chaogan Yan</a>
0009 %    Version=1.3;
0010 %    Release=20090422;
0011 %   Last Revised by YAN Chao-Gan 090321, added the fALFF module. Thank Dr. CHENG Wen-Lian for the helpful work.
0012 %-----------------------------------------------------------
0013  
0014 if isappdata(0, 'Rest_Cfg'),
0015     Rest_Cfg =getappdata(0, 'Rest_Cfg'); % run-time persistent config
0016 else
0017     Rest_Cfg =[];
0018 end    
0019 
0020 if nargin<1, AOperation='Init'; end    %Revise the Start
0021 
0022 switch upper(AOperation),
0023 case 'INIT',        %Init
0024     if isempty(Rest_Cfg) || ~rest_misc( 'ForceCheckExistFigure' , Rest_Cfg.hFig);,
0025         % the first time to run this program
0026         % Initialize the Matlab envionment
0027         clear all;
0028         clc;
0029         QuitAll;
0030         % Initialize self
0031         Rest_Cfg =[];
0032         Rest_Cfg =InitControls(Rest_Cfg);
0033         %rest_misc( 'SetFigViewStyle', gcf);
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     %Forcely delete the last log file to make sure there will be only one log content for one run of REST
0044     %recycle on;
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     %Initialize the log file
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',     %Restart
0057     if nargin~=1, error('Usage: rest(''Restart'');'); end
0058     clear all;
0059     clc;    
0060     QuitAll;
0061     % Initialize self
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',        %QuitAll
0072     if nargin~=1, error('Usage: rest(''QuitAll'');'); end
0073     QuitAll;
0074     %At the end, I quit
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     %Force stop the log file, 20071127
0085     diary off;
0086     %recycle off;
0087     
0088 case 'STARTREHO',     %StartReHo
0089     StartReHo;
0090 case 'STARTALFF',     %StartALFF
0091     StartALFF;
0092 case 'STARTFALFF',     %StartfALFF  --Revised by YAN Chao-Gan, 090321
0093     StartfALFF;
0094 case 'MAILTOZANG',     %MailToZang
0095     MailToZang;
0096 case 'MAILTOSONG',     %MailToSong
0097     MailToSong;
0098 case 'OPENHELP',     %OpenHelp
0099     OpenHelp;
0100 case 'FUNCTIONALCONNECTIVITYNOTREADY',        %FunctionalConnectivityNotReady
0101     % msgbox(sprintf('Functional Connectivity analysis is not ready.\n\nIt would be born in the next version.'), ...
0102                     % 'Resting State Toolkit' ,'help');
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', ... %'Name', sprintf('REST %s - %s',rest_misc( 'GetRestVersion') ,rest_misc('GetCurrentUser')) , ...                    
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,    %Revise the coordinate to make it same with MATLAB
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     % uicontrol(theFig,'Style','Text','Position',[171+40 260 250 20],...
0159         % 'String','developed by Song Xiaowei, He Yong',...
0160         % 'ToolTipString','', 'BackgroundColor', [1 1 1]*.8, ...
0161         % 'FontSize',10,'FontAngle','Italic')
0162     % uicontrol(theFig,'Style','Text','Position',[40 180 440 80],...
0163         % 'String',sprintf('Ref:\n\tZang YF et.al. Neuroimage. 2004 May;22(1):394-400\n\tZang YF et.al. Brain Dev. 2007 Mar;29(2):83-91. Epub 2006 Aug 17\n\tetc.'),...
0164         % 'HorizontalAlignment', 'left', ...
0165         % 'FontSize',10,'FontAngle','Italic')
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 %     uicontrol(theFig,'Style','pushbutton', 'Position',[30 70 150 40],...
0187 %         'String','ReHo','ToolTipString','Regional homogeneity approach to fMRI data analysis', ...
0188 %         'Callback', sprintf('rest(''StartReHo'');'), ...
0189 %         'FontSize',16, 'FontWeight','Bold', 'ForegroundColor','m')
0190 %     uicontrol(theFig,'Style','pushbutton', 'Position',[200 70 150 40],...
0191 %         'String','ALFF', 'ToolTipString','Amplitude of low-frequency fluctuation',...
0192 %         'Callback', sprintf('rest(''StartALFF'');'), ...
0193 %         'FontSize',16, 'FontWeight','Bold', ...
0194 %         'ForegroundColor','m')
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],...       %Revised by YAN Chao-Gan, 090321
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     % uicontrol(theFig,'Style','pushbutton', 'Position',[30 40 150 20],...
0220         % 'String','Mailto: Zang YuFeng',...
0221         % 'Callback', sprintf('rest(''MailToZang'');'), ...
0222         % 'FontSize',10, 'ForegroundColor','k')
0223     % uicontrol(theFig,'Style','pushbutton', 'Position',[30 20 150 20],...
0224         % 'String','Mailto: Song XiaoWei',...
0225         % 'Callback', sprintf('rest(''MailToSong'');'), ...
0226         % 'FontSize',10, 'ForegroundColor','k')
0227     uicontrol(theFig,'Style','pushbutton', 'Position',[30 20 320 40],...
0228         'String','Functional  Connectivity',...    %'FontName', 'FixedWidth', ...        
0229         'Callback', sprintf('rest(''FunctionalConnectivityNotReady'');'), ...
0230         'FontSize',16, 'FontWeight','Bold', 'ForegroundColor','m')
0231     
0232     %Save Hanldes
0233     AConfig.hFig =theFig;
0234     
0235     Result =AConfig;
0236     
0237     set(theFig, 'Visible', 'on');
0238     
0239 function QuitAll()
0240     %Force stopping current Callback
0241     delete(gcbf);
0242     %Close any progressbar
0243     rest_waitbar;
0244     %Close any SliceViewer
0245     rest_sliceviewer('QuitAllSliceViewer');
0246     %Close any PowerSpectrum
0247     rest_powerspectrum('QuitAllPowerSpectrum');
0248     %Close any ReHo figure
0249     theFig =findobj(allchild(0),'flat','Tag','figRehoMain');
0250     if ~isempty(theFig) && rest_misc( 'ForceCheckExistFigure' , theFig),
0251         delete(theFig);
0252     end
0253     %Close any ALFF figure
0254     theFig =findobj(allchild(0),'flat','Tag','figAlffMain');
0255     if ~isempty(theFig) && rest_misc( 'ForceCheckExistFigure' , theFig),
0256         delete(theFig);
0257     end
0258     %Close any fALFF figure   % Revised by YAN Chao-Gan, 090321
0259     theFig =findobj(allchild(0),'flat','Tag','figfAlffMain');
0260     if ~isempty(theFig) && rest_misc( 'ForceCheckExistFigure' , theFig),
0261         delete(theFig);
0262     end
0263     %Close any functional connectivity figure
0264     theFig =findobj(allchild(0),'flat','Tag','figFCMain');
0265     if ~isempty(theFig) && rest_misc( 'ForceCheckExistFigure' , theFig),
0266         delete(theFig);
0267     end
0268     %Clear mem
0269     rest_misc('UnlockRestFiles');
0270     clear all
0271     
0272     %Clear temp files
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     %web (sprintf('%s/man/English/manual.html', rest_misc( 'WhereIsREST')), '-helpbrowser');

Generated on Wed 29-Apr-2009 01:06:38 by m2html © 2005