Home > . > prt.m

prt

PURPOSE ^

Pattern Recognition for Neuroimaging Toolbox, PRoNTo.

SYNOPSIS ^

function varargout = prt(varargin)

DESCRIPTION ^

 Pattern Recognition for Neuroimaging Toolbox, PRoNTo.

 This function initializes things for PRoNTo and provides some low level
 functionalities

_______________________________________________________________________
 Copyright (C) 2011 Machine Learning & Neuroimaging Laboratory

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function varargout = prt(varargin)
0002 % Pattern Recognition for Neuroimaging Toolbox, PRoNTo.
0003 %
0004 % This function initializes things for PRoNTo and provides some low level
0005 % functionalities
0006 %
0007 %_______________________________________________________________________
0008 % Copyright (C) 2011 Machine Learning & Neuroimaging Laboratory
0009 
0010 % Written by Christophe Phillips
0011 % $Id$
0012 
0013 % TODO:
0014 % - fix which subdirectories from all the machines are necessary, and only
0015 %   add these to Matlab path.
0016 
0017 %-Format arguments
0018 %-----------------------------------------------------------------------
0019 global PRT_INIT
0020 if nargin == 0,
0021     Action = 'StartUp';
0022 else
0023     Action = varargin{1};
0024 end
0025 
0026 switch lower(Action)
0027     %==================================================================
0028     case 'startup'                                    % Startup the toolbox
0029         %==================================================================
0030         
0031         % Welcome message
0032         prt('ASCIIwelcome');
0033         
0034         % add appropriate paths, if necessary
0035         %   - batch dir
0036         if ~exist('prt_cfg_batch','file')
0037             addpath(fullfile(prt('Dir'),'batch'));
0038         end
0039         %   - machines
0040         if ~exist('prt_machine','file')
0041             pth_machines = fullfile(prt('Dir'),'machines');
0042             addpath(pth_machines);
0043             % add each machine's sub-directory
0044             % and ALL its subdirectories recursively
0045             ls_machinedir = list_subdir(pth_machines);
0046             for ii=1:numel(ls_machinedir)
0047                 gpath_ii = genpath(fullfile(pth_machines,ls_machinedir{ii}));
0048                 gpath_ii = clean_gpath(gpath_ii);
0049                 addpath(gpath_ii)
0050             end
0051         end
0052         
0053         % utils - dirty check for the moment
0054         if ~exist('prt_checkAlphaNumUnder','file')
0055             addpath(fullfile(prt('Dir'),'utils'));
0056         end
0057         
0058         % check installation of machines and that of SPM8/12
0059         ok = check_installation;
0060         if ~ok
0061             beep
0062             fprintf('INSTALLATION PROBLEM!');
0063             return
0064         end
0065         
0066         % Add SPM's directories: matlabbatch
0067         if ~exist('cfg_util','file')
0068             addpath(fullfile(spm('Dir'),'matlabbatch'));
0069         end
0070         
0071         % intialize the matlabbatch system
0072         cfg_get_defaults('cfg_util.genscript_run', @genscript_run);
0073         cfg_util('initcfg');
0074         clear prt_batch;
0075         
0076         % set path to PRoNTo and SPM dir into 'file select'
0077         spm_select('prevdirs',[spm('Dir') filesep]);
0078         spm_select('prevdirs',[prt('Dir') filesep]);
0079         
0080         % launch the main GUI, if needed
0081         if nargin<2 || ~strcmp(varargin{2},'nogui')
0082             prt_ui_main;
0083         end
0084         
0085         % print present working directory
0086         fprintf('PRoNTo present working directory:\n\t%s\n',pwd)
0087         
0088         % Init flag true
0089         PRT_INIT = true;
0090         
0091         %==================================================================
0092     case 'asciiwelcome'                       %-ASCII PRoNTo banner welcome
0093         %==================================================================
0094         disp( '                                                             ');
0095         disp( '     ____  ____        _   ________              ___    ____ ');
0096         disp( '    / __ \/ __ \____  / | / /_  __/___     _   _|__ \  / __ \');
0097         disp( '   / /_/ / /_/ / __ \/  |/ / / / / __ \   | | / /_/ / / / / /');
0098         disp( '  / ____/ _, _/ /_/ / /|  / / / / /_/ /   | |/ / __/_/ /_/ / ');
0099         disp( ' /_/   /_/ |_|\____/_/ |_/ /_/  \____/    |___/____(_)____/  ');
0100         disp( '                                                             ');
0101         disp( '      PRoNTo v2.0 - http://www.mlnl.cs.ucl.ac.uk/pronto      ');
0102         fprintf('\n');
0103         
0104         %==================================================================
0105     case 'dir'                          %-Identify specific (PRT) directory
0106         %==================================================================
0107         % prt('Dir',Mfile)
0108         %------------------------------------------------------------------
0109         if nargin<2,
0110             Mfile = 'prt';
0111         else
0112             Mfile = varargin{2};
0113         end
0114         PRTdir = which(Mfile);
0115         
0116         if isempty(PRTdir)             %-Not found or full pathname given
0117             if exist(Mfile,'file')==2  %-Full pathname
0118                 PRTdir = Mfile;
0119             else
0120                 error(['Can''t find ',Mfile,' on MATLABPATH']);
0121             end
0122         end
0123         PRTdir    = fileparts(PRTdir);
0124         varargout = {PRTdir};
0125  
0126         %==================================================================
0127     case 'ver'                                             %-PRoNTo version
0128         %==================================================================
0129         % [ver, rel] = prt('Ver',ReDo)
0130         %------------------------------------------------------------------
0131         % NOTE:
0132         % 1/
0133         % This bit of code is largely inspired/copied from SPM8!
0134         % See http://www.fil.ion.ucl.ac.uk/spm for details.
0135         %
0136         % 2/
0137         % NOT usable any more to get the version of an individual file
0138         % since the  switch from SVN to GitHub!
0139         % Git does not update an Id tag inside the files, hence no option
0140         % to check the version automatically...
0141        
0142         if nargin ~= 2,
0143             ReDo = false;
0144         else
0145             ReDo = logical(varargin{3});
0146         end
0147         
0148         v = get_version(ReDo);
0149         varargout = {v.Release v.Version};
0150         
0151         %==================================================================
0152     otherwise                                       %-Unknown action string
0153         %==================================================================
0154         error('Unknown action string');
0155         
0156 end
0157 
0158 return
0159 
0160 %=======================================================================
0161 %% SUBFUNCTIONS
0162 %=======================================================================
0163 
0164 %=======================================================================
0165 function ok = check_installation
0166 %=======================================================================
0167 % Function to check installation state of machines and SPM
0168 
0169 ok = true;
0170 
0171 % Check SPM installation
0172 if exist('spm.m','file')
0173     [SPMver, SPMrel] = spm('Ver');
0174     if (~(strcmpi(SPMver,'spm8') && str2double(SPMrel)>8.5)) && ...
0175             isempty(regexpi(SPMver,'spm12'))
0176         beep
0177         fprintf('\nERROR:\n')
0178         fprintf('\tThe *latest* version of SPM8 or SPM12 should be installed on your computer,\n')
0179         fprintf('\tand be available on MATLABPATH!\n\n')
0180         ok = false;
0181     end
0182 else
0183     beep
0184     fprintf('\nERROR:\n')
0185     fprintf('\tThe *latest* version of SPM8 or SPM12 should be installed on your computer,\n')
0186     fprintf('\tand be available on MATLABPATH!\n\n')
0187     ok = false;
0188 end
0189 
0190 
0191 % Check for compiled routines
0192 %============================
0193 % - svm
0194 dumb = which('svmtrain');
0195 if ~isempty(strfind(dumb,'libsvm'))          % svm found in libsvm folder, OK
0196     disp('SVM path: OK')
0197     flag=1;
0198 elseif ~isempty(strfind(dumb,'biolearning')) % svm found in the Matlab toolbox
0199     flag=0;
0200 else                                         % svm not found at all, so need to compile
0201     flag=2;
0202 end
0203 
0204 % in case PRoNTo was installed with all subfolders under the biostats
0205 if ~flag
0206     pth_machines = fullfile(prt('Dir'),'machines');
0207     addpath(pth_machines);
0208     % add each machine's sub-directory
0209     % and ALL its subdirectories recursively
0210     ls_machinedir = list_subdir(pth_machines);
0211     for ii=1:numel(ls_machinedir)
0212         gpath_ii = genpath(fullfile(pth_machines,ls_machinedir{ii}));
0213         gpath_ii = clean_gpath(gpath_ii);
0214         addpath(gpath_ii)
0215     end
0216     dumb = which('svmtrain');
0217     if isempty(strfind(dumb,'libsvm'))
0218         flag=2; %s till not working, need to recompile
0219     elseif ~isempty(strfind(dumb,'biolearning'))
0220         flag = 2;
0221         disp('PRoNTo was found under the biostats toolbox, please correct path')
0222         disp('SVM path: OK')
0223     else
0224         flag =1;
0225     end
0226 end
0227 
0228 if flag ==2 % need to recompile for the OS
0229     pth_machines = fullfile(prt('Dir'),'machines');
0230     ls_machinedir = list_subdir(pth_machines);
0231     for i=1:length(ls_machinedir)
0232         if ~isempty(strfind(ls_machinedir{i},'libsvm'))
0233             pfn= fullfile(pth_machines,ls_machinedir{i});
0234             dirtorem=cd;
0235             cd(pfn)
0236             cd matlab
0237             make;
0238             cd(dirtorem)
0239         end
0240     end
0241     dumb = which('svmtrain');
0242     if isempty(strfind(dumb,'libsvm'))
0243         %could not recompile
0244         beep
0245         warning('PRoNTo:SVMcompilation', ...
0246         ['SVM path not recognized. Please check that: \n', ...
0247         '- PRoNTo''directory was added *without* all subfolders \n',...
0248         '- PRoNTo is above the biostats Matlab toolbox \n',...
0249         'Otherwise, the routines surely need to be re-compiled for your OS \n',...
0250         'Please look on the web or ask on the mailing list for assistance'])
0251     end
0252 end
0253 
0254 % - GP
0255 dumb = which('solve_chol');
0256 if ~isempty(dumb) && ~isempty(strfind(dumb,'.mex'))
0257     disp('GP path: OK')
0258 else
0259     beep
0260     disp('GP not compiled: routines will work but be slower')
0261 end
0262 
0263 % NOTE:
0264 % Tree-based methods not available in this version.
0265 % So no need to check for it!
0266 % We still plan to have it in a future release.
0267 %
0268 % % - RF
0269 % dumb = which('rtenslearn_c');
0270 % if ~isempty(dumb) || ~isempty(strfind(dumb,'.mex'))
0271 %     disp('RF path: OK')
0272 % else
0273 %     beep
0274 %     warning('PRoNTo:RFcompilation', ...
0275 %         ['RF path not recognized. Please check that \n', ...
0276 %         'PRoNTo was added with all subfolders \n',...
0277 %         'Otherwise, the routines surely need to be re-compiled for your OS \n',...
0278 %         'Please look on the web or ask on the mailing list for assistance'])
0279 % end
0280 
0281 return
0282 
0283 %=======================================================================
0284 function lsdir = list_subdir(pth_dir,rejd)
0285 %=======================================================================
0286 % function that returns the list of subdirectories of a directory,
0287 % rejecting those beginning with some characters ('.', '@' and '_' by
0288 % default)
0289 
0290 if nargin<2
0291     rejd = '.@_';
0292 end
0293 if nargin<1
0294     pth_dir = pwd;
0295 end
0296 
0297 tmp = dir(pth_dir);
0298 ld = find([tmp.isdir]); ld([1 2]) = [];
0299 lsdir = {tmp(ld).name};
0300 if ~isempty(rejd)
0301     for ii=1:numel(rejd)
0302         lrej = find(strncmp(rejd(ii),lsdir,1));
0303         if ~isempty(lrej)
0304             lsdir(lrej) = [];
0305         end
0306     end
0307 end
0308 
0309 return
0310 
0311 %=======================================================================
0312 function v = get_version(ReDo)                 %-Retrieve PRoNTo version
0313 %=======================================================================
0314 persistent PRoNTo_VER;
0315 v = PRoNTo_VER;
0316 if isempty(PRoNTo_VER) || (nargin > 0 && ReDo)
0317     v = struct('Name','','Version','','Release','','Date','');
0318     try
0319         vfile = fullfile(prt('Dir'),'prt_contents.m');
0320         fid = fopen(vfile,'rt');
0321         if fid == -1, error(str); end
0322         l1 = fgetl(fid); l2 = fgetl(fid);
0323         fclose(fid);
0324         l1 = strtrim(l1(2:end)); l2 = strtrim(l2(2:end));
0325         t  = textscan(l2,'%s','delimiter',' '); t = t{1};
0326         v.Name = l1; v.Date = t{4};
0327         v.Version = t{2}; v.Release = t{3}(2:end-1);
0328     catch %#ok<CTCH>
0329         error('PRoNTo:getversion', ...
0330             'Can''t obtain PRoNTo Revision information.');
0331     end
0332     PRoNTo_VER = v;
0333 end
0334 
0335 return
0336 
0337 %=======================================================================
0338 function gpath = clean_gpath(gpath,rejd)
0339 %=======================================================================
0340 % function that "cleans up" a list of pathes to subdirectories,
0341 % i.e. it removes any path containing a set of strings.
0342 % By default, it removes all the '.svn' pathes. Other strings can be passed
0343 % as a cell array
0344 
0345 if nargin<2
0346     rejd = {'.svn'};
0347 end
0348 if nargin<1
0349     return
0350 end
0351 
0352 if numel(rejd)>1
0353     % do it 1 by 1
0354     for ii=1:numel(rejd)
0355         gpath = clean_gpath(gpath,rejd{ii});
0356     end
0357 else
0358     % deal with 1 string
0359     l_col = strfind(gpath,':');
0360     for ii=numel(l_col):-1:1
0361         if ii>1
0362             pth_bit = [l_col(ii-1)+1 l_col(ii)];
0363         else
0364             pth_bit = [1 l_col(ii)];
0365         end
0366         if ~isempty(strfind(gpath(pth_bit(1):pth_bit(2)),rejd{1}))
0367             % remove the bit
0368             gpath(pth_bit(1):pth_bit(2)) = [];
0369         end
0370     end
0371 end
0372 
0373 return

Generated on Tue 10-Feb-2015 18:16:33 by m2html © 2005