⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 rest.m

📁 While resting-state fMRI is drawing more and more attention, there has not been a software for its d
💻 M
字号:
function varargout = rest(AOperation, varargin)
%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
% 	<a href="Dawnwei.Song@gmail.com">Mail to Author</a>: Xiaowei Song
%	Version=1.1;
%	Release=20071212;
%-----------------------------------------------------------
 
if isappdata(0, 'Rest_Cfg'),
	Rest_Cfg =getappdata(0, 'Rest_Cfg'); % run-time persistent config
else
	Rest_Cfg =[];
end	

if nargin<1, AOperation='Init'; end	%Revise the Start

switch upper(AOperation),
case 'INIT',		%Init
	if isempty(Rest_Cfg) || ~rest_misc( 'ForceCheckExistFigure' , Rest_Cfg.hFig);,
		% the first time to run this program
		% Initialize the Matlab envionment		
		clear all;
		clc;
		QuitAll;
		% Initialize self				
		Rest_Cfg =[];
		Rest_Cfg =InitControls(Rest_Cfg);
		%rest_misc( 'SetFigViewStyle', gcf);
	end
	if ~isempty(Rest_Cfg) && rest_misc( 'ForceCheckExistFigure' , Rest_Cfg.hFig),
		figure(Rest_Cfg.hFig);
	end
	if nargout>0,
		varargout{1} =Rest_Cfg.hFig;
	end
	setappdata(0, 'Rest_Cfg', Rest_Cfg);
	
	%Forcely delete the last log file to make sure there will be only one log content for one run of REST
	%recycle on;
	if 2==exist(fullfile(rest_misc('WhereIsREST'), 'rest.log'),'file'),
		delete(fullfile(rest_misc('WhereIsREST'), 'rest.log'));
	end
	diary(fullfile(rest_misc('WhereIsREST'), 'rest.log'));
    %Initialize the log file
	diary on;
    
	[theVer, theRelease] =rest_misc( 'GetRestVersion');
	disp(sprintf('Welcome: %s, %s \nREST Version: %s, Release: %s', rest_misc('GetCurrentUser'),rest_misc( 'GetDateTimeStr'), theVer, theRelease));
	
	
case 'RESTART', 	%Restart	
	if nargin~=1, error('Usage: rest(''Restart'');'); end
	clear all;
	clc;	
	QuitAll;
	% Initialize self
	Rest_Cfg =[];
	Rest_Cfg =InitControls(Rest_Cfg);
	figure(Rest_Cfg.hFig);
	if nargout>0,
		varargout{1} =Rest_Cfg.hFig;
	end
	
	setappdata(0, 'Rest_Cfg', Rest_Cfg);
	
case 'QUITALL',		%QuitAll
	if nargin~=1, error('Usage: rest(''QuitAll'');'); end
	QuitAll;
	%At the end, I quit
	if ~isempty(Rest_Cfg) && rest_misc( 'ForceCheckExistFigure' , Rest_Cfg.hFig),
		delete(Rest_Cfg.hFig);
	end
	if isappdata(0, 'Rest_Cfg'),
		rmappdata(0, 'Rest_Cfg');
	end	
	clc;
	[theVer, theRelease] =rest_misc( 'GetRestVersion');
	disp(sprintf('Good Bye: %s, %s \nREST Version: %s, Release: %s', rest_misc('GetCurrentUser'),rest_misc( 'GetDateTimeStr'), theVer, theRelease));
	%Force stop the log file, 20071127
	diary off;
	%recycle off;
	
case 'STARTREHO', 	%StartReHo
	StartReHo;
case 'STARTALFF', 	%StartALFF
	StartALFF;
case 'MAILTOZANG', 	%MailToZang
	MailToZang;
case 'MAILTOSONG', 	%MailToSong
	MailToSong;
case 'OPENHELP', 	%OpenHelp
	OpenHelp;
case 'FUNCTIONALCONNECTIVITYNOTREADY',		%FunctionalConnectivityNotReady
	% msgbox(sprintf('Functional Connectivity analysis is not ready.\n\nIt would be born in the next version.'), ...
					% 'Resting State Toolkit' ,'help');
	StartFunctionalConnectivity;
otherwise	
end

function Result =InitControls(AConfig)	
	DefaultColorBackground =[1 1 1]*.5;
	theFig =figure('Units', 'pixel', 'Toolbar', 'none', 'MenuBar', 'none', ...
					'NumberTitle', 'off', 'Visible', 'off', ... %'Name', sprintf('REST %s - %s',rest_misc( 'GetRestVersion') ,rest_misc('GetCurrentUser')) , ...					
					'Name', sprintf('REST %s',rest_misc( 'GetRestVersion')), ...
					'Position', [0,0,500, 330], 'Resize','off', ...
					'Color', DefaultColorBackground , ...
					'DeleteFcn', sprintf('rest(''QuitAll'');')  );
	movegui(theFig, 'northwest'); 
	
	uicontrol(theFig,'Style','Text','Position',[0 286 500 36],...
		'String','Resting State fMRI Data Analysis Toolkit',...
		'FontSize',18, ...		
		'FontWeight','Bold',...
		'ForegroundColor',[1 1 1]*.7,'BackgroundColor', DefaultColorBackground);
		
	logoPos =[10, 135, 0,0];	
	theLogo = fullfile(rest_misc( 'WhereIsREST'), 'logo.jpg');
	if (exist(theLogo,'file')==2),
		theLogo = imread(theLogo);
		logoPos(3) =size(theLogo, 2);
		logoPos(4) =size(theLogo, 1);
		for x=1:3,	%Revise the coordinate to make it same with MATLAB
			theLogo(:, :, x) =flipud(theLogo(:, :, x));
		end
		
		hAxesLogo =axes('Parent', theFig, 'Box', 'on', ...
					  'Units', 'pixel', 'DrawMode','normal', ...
					  'Position', logoPos, ...
					  'YDir','normal', 'XTickLabel',[],'XTick',[], ...
					  'YTickLabel',[],'YTick',[], 'DataAspectRatio',[1 1 1]);
		hImgLogo =image('Tag','LogoImage', 'Parent', hAxesLogo);
		set(hAxesLogo,'YDir','normal','XTickLabel',[],'XTick',[], 'YTickLabel',[],'YTick',[]);
				
		set(hImgLogo, 'CData', theLogo);
		set(hAxesLogo, 'XLim', [1 logoPos(3)], 'YLim', [1 logoPos(4)]);
	else
		error('Please re-install REST');
	end
	
	
	uicontrol(theFig,'Style','Frame','Position', ...
			[logoPos(1)+logoPos(3)+2, logoPos(2), 500-logoPos(3)-20 ,logoPos(4)], ...
			'BackgroundColor', [1 1 1]*.0);
	uicontrol(theFig,'Style','Text','String','REST 2007',...
		'ToolTipString',sprintf('\nby the ZangYF neuroimaging methods group of BNU\n'),...
		'Position', ...
		[logoPos(1)+logoPos(3)+12, logoPos(2)+logoPos(4)-56, 500-logoPos(3)-40 , 36], ...
		'BackgroundColor', [1 1 1]*.0, ...
		'FontSize',24,'FontWeight','Bold',...
		'ForegroundColor','b')
	% uicontrol(theFig,'Style','Text','Position',[171+40 260 250 20],...
		% 'String','developed by Song Xiaowei, He Yong',...
		% 'ToolTipString','', 'BackgroundColor', [1 1 1]*.8, ...
		% 'FontSize',10,'FontAngle','Italic')	
	% uicontrol(theFig,'Style','Text','Position',[40 180 440 80],...
		% '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.'),...
		% 'HorizontalAlignment', 'left', ...
		% 'FontSize',10,'FontAngle','Italic')	
	uicontrol(theFig,'Style','Text', 'Position', ...		
		[logoPos(1)+logoPos(3)+12, logoPos(2)+20*3, 500-logoPos(3)-40 , 20], ...
		'String','State Key Laboratory of',...
		'BackgroundColor', [1 1 1]*.0, ...
		'ToolTipString','', 'ForegroundColor', [1 1 1]*1, ...
		'FontSize',12);	
	uicontrol(theFig,'Style','Text', 'Position',...
		[logoPos(1)+logoPos(3)+12, logoPos(2)+20*2, 500-logoPos(3)-40 , 20], ...
		'String','Cognitive Neuroscience and Learning',...
		'BackgroundColor', [1 1 1]*.0, ...
		'ToolTipString','', 'ForegroundColor', 'w', ...
		'FontSize',12);	
	uicontrol(theFig,'Style','Text', 'Position',...
		[logoPos(1)+logoPos(3)+12, logoPos(2)+20, 500-logoPos(3)-40 , 20], ...
		'BackgroundColor', [1 1 1]*.0, ...
		'String','Beijing Normal University', 'ForegroundColor', [1 1 1]*1, ...
		'ToolTipString','',...
		'FontSize',12);
		
	uicontrol(theFig,'Style','Frame','Position',[10 10 480 115], 'BackgroundColor', [0.9 0.8 0.6]);
	uicontrol(theFig,'Style','pushbutton', 'Position',[30 70 150 40],...
		'String','ReHo','ToolTipString','Regional homogeneity approach to fMRI data analysis', ...
		'Callback', sprintf('rest(''StartReHo'');'), ...
		'FontSize',16, 'FontWeight','Bold', 'ForegroundColor','m')
	uicontrol(theFig,'Style','pushbutton', 'Position',[200 70 150 40],...
		'String','ALFF', 'ToolTipString','Amplitude of low-frequency fluctuation',...		 
		'Callback', sprintf('rest(''StartALFF'');'), ...		
		'FontSize',16, 'FontWeight','Bold', ...		
		'ForegroundColor','m')
	
	uicontrol(theFig,'Style','pushbutton', 'Position',[370 70 100 40],...
		'String','Help',...		
		'Callback', sprintf('rest(''OpenHelp'');'), ...
		'FontSize',16, 'FontWeight','Bold', 'ForegroundColor','g')	
	uicontrol(theFig,'Style','pushbutton', 'Position',[370 20 100 40],...
		'String','Quit',...		
		'Callback', sprintf('rest(''QuitAll'');'), ...
		'FontSize',16, 'FontWeight','Bold', 'ForegroundColor','r')
		
	% uicontrol(theFig,'Style','pushbutton', 'Position',[30 40 150 20],...
		% 'String','Mailto: Zang YuFeng',...		
		% 'Callback', sprintf('rest(''MailToZang'');'), ...
		% 'FontSize',10, 'ForegroundColor','k')
	% uicontrol(theFig,'Style','pushbutton', 'Position',[30 20 150 20],...
		% 'String','Mailto: Song XiaoWei',...
		% 'Callback', sprintf('rest(''MailToSong'');'), ...
		% 'FontSize',10, 'ForegroundColor','k')
	uicontrol(theFig,'Style','pushbutton', 'Position',[30 20 320 40],...
		'String','Functional  Connectivity',...	%'FontName', 'FixedWidth', ...		
		'Callback', sprintf('rest(''FunctionalConnectivityNotReady'');'), ...
		'FontSize',16, 'FontWeight','Bold', 'ForegroundColor','m')
	
	%Save Hanldes
	AConfig.hFig =theFig;
	
	Result =AConfig;
	
	set(theFig, 'Visible', 'on');
	
function QuitAll()
	%Force stopping current Callback
	delete(gcbf);
	%Close any progressbar
	rest_waitbar;
	%Close any SliceViewer
	rest_sliceviewer('QuitAllSliceViewer');
	%Close any PowerSpectrum
	rest_powerspectrum('QuitAllPowerSpectrum');
	%Close any ReHo figure
	theFig =findobj(allchild(0),'flat','Tag','figRehoMain');
	if ~isempty(theFig) && rest_misc( 'ForceCheckExistFigure' , theFig),
		delete(theFig);
	end
	%Close any ALFF figure
	theFig =findobj(allchild(0),'flat','Tag','figAlffMain');
	if ~isempty(theFig) && rest_misc( 'ForceCheckExistFigure' , theFig),
		delete(theFig);
	end
	%Close any functional connectivity figure
	theFig =findobj(allchild(0),'flat','Tag','figFCMain');
	if ~isempty(theFig) && rest_misc( 'ForceCheckExistFigure' , theFig),
		delete(theFig);
	end
	%Clear mem
	rest_misc('UnlockRestFiles');
	clear all
	
	%Clear temp files
	rest_misc( 'ClearTempFiles');
	
	
function StartReHo()
	theFig =findobj(allchild(0),'flat','Tag','figRehoMain');
	if ~isempty(theFig) && rest_misc( 'ForceCheckExistFigure' , theFig),
		figure(theFig);
	else
		reho_gui;
	end
	
	
function StartALFF()
	theFig =findobj(allchild(0),'flat','Tag','figAlffMain');
	if ~isempty(theFig) && rest_misc( 'ForceCheckExistFigure' , theFig),
		figure(theFig);
	else
		alff_gui;
	end
	
function StartFunctionalConnectivity()
	theFig =findobj(allchild(0),'flat','Tag','figFCMain');
	if ~isempty(theFig) && rest_misc( 'ForceCheckExistFigure' , theFig),
		figure(theFig);
	else
		fc_gui;
	end
	
function MailToZang()
	web('mailto:zangyf@gmail.com');
function MailToSong()
	web('mailto:dawnwei.song@gmail.com');
	
function OpenHelp()
	web('http://resting-fmri.sourceforge.net');
	%web (sprintf('%s/man/English/manual.html', rest_misc( 'WhereIsREST')), '-helpbrowser');

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -