Home > installation > checkInstallation.m

checkInstallation

PURPOSE ^

checkInstallation

SYNOPSIS ^

function [currVer, installType] = checkInstallation(developMode,checkBinaries)

DESCRIPTION ^

 checkInstallation
   The purpose of this function is to check if all necessary functions are
   installed and working. It also checks whether there are any functions
   with overlapping names between RAVEN and other toolboxes or
   user-defined functions, which are accessible from MATLAB pathlist

 Input: 
   developMode     logical indicating development mode, which includes
                   testing of binaries that are required to update KEGG
                   HMMs (optional, default false). If 'versionOnly' is
                   specified, only the version is reported as currVer, no
                   further installation or tests are performed.
   checkBinaries   logical whether non-developMode binaries should be
                   checked for functionality. If false, it overwrites
                   developMode. Default true.

 Output:
   currVer         current RAVEN version
   installType     how RAVEN is installed
                   0:  via git (as .git folder is found)
                   1:  as MATLAB Add-On
                   2:  neither of the above, direct download of ZIP file
                   This matches the installations mentioned in the wiki:
                   https://github.com/SysBioChalmers/RAVEN/wiki/Installation
                   0 = advanced / 1 = easy / 2 = medium

 Usage: [currVer, installType] = checkInstallation(developMode)

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function [currVer, installType] = checkInstallation(developMode,checkBinaries)
0002 % checkInstallation
0003 %   The purpose of this function is to check if all necessary functions are
0004 %   installed and working. It also checks whether there are any functions
0005 %   with overlapping names between RAVEN and other toolboxes or
0006 %   user-defined functions, which are accessible from MATLAB pathlist
0007 %
0008 % Input:
0009 %   developMode     logical indicating development mode, which includes
0010 %                   testing of binaries that are required to update KEGG
0011 %                   HMMs (optional, default false). If 'versionOnly' is
0012 %                   specified, only the version is reported as currVer, no
0013 %                   further installation or tests are performed.
0014 %   checkBinaries   logical whether non-developMode binaries should be
0015 %                   checked for functionality. If false, it overwrites
0016 %                   developMode. Default true.
0017 %
0018 % Output:
0019 %   currVer         current RAVEN version
0020 %   installType     how RAVEN is installed
0021 %                   0:  via git (as .git folder is found)
0022 %                   1:  as MATLAB Add-On
0023 %                   2:  neither of the above, direct download of ZIP file
0024 %                   This matches the installations mentioned in the wiki:
0025 %                   https://github.com/SysBioChalmers/RAVEN/wiki/Installation
0026 %                   0 = advanced / 1 = easy / 2 = medium
0027 %
0028 % Usage: [currVer, installType] = checkInstallation(developMode)
0029 
0030 if nargin<1
0031     developMode=false;
0032 end
0033 if nargin<2
0034     checkBinaries=true;
0035 end
0036 if ischar(developMode) && strcmp(developMode,'versionOnly')
0037     versionOnly = true;
0038 else
0039     versionOnly = false;
0040 end
0041 
0042 %Get the RAVEN path
0043 [ST, I]=dbstack('-completenames');
0044 [ravenDir,~,~]=fileparts(fileparts(ST(I).file));
0045 
0046 installType = 2; % If neither git nor add-on, then ZIP was downloaded
0047 addList = matlab.addons.installedAddons;
0048 if isfolder(fullfile(ravenDir,'.git'))
0049     installType = 0;
0050 elseif any(strcmp(addList.Name,'RAVEN Toolbox'))
0051     installType = 1;
0052 end
0053 
0054 % Do not print first few lines if only version should be reported
0055 if ~versionOnly
0056     fprintf('\n*** THE RAVEN TOOLBOX ***\n\n');
0057     %Print the RAVEN version if it is not the development version
0058     fprintf(myStr(' > Installation type',40));
0059     switch installType
0060         case 0
0061             fprintf('Advanced (via git)\n');
0062         case 1
0063             fprintf('Easy (as MATLAB Add-On)\n');
0064         case 2
0065             fprintf('Medium (as downloaded ZIP file)\n');
0066     end
0067     fprintf(myStr(' > Installing from location',40));
0068     fprintf('%s\n',ravenDir)
0069     fprintf(myStr(' > Checking RAVEN release',40));
0070 end
0071                        
0072 if exist(fullfile(ravenDir,'version.txt'), 'file') == 2
0073     currVer = fgetl(fopen(fullfile(ravenDir,'version.txt')));
0074     fclose('all');
0075     if ~versionOnly
0076         fprintf([currVer '\n']);
0077         try
0078             newVer=strtrim(webread('https://raw.githubusercontent.com/SysBioChalmers/RAVEN/main/version.txt'));
0079             newVerNum=str2double(strsplit(newVer,'.'));
0080             currVerNum=str2double(strsplit(currVer,'.'));
0081             for i=1:3
0082                 if currVerNum(i)<newVerNum(i)
0083                     fprintf(myStr('   > Latest RAVEN release available',40))
0084                     printOrange([newVer,'\n'])
0085                     switch installType
0086                         case 0
0087                             printOrange('     Run git pull in your favourite git client\n')
0088                             printOrange('     to get the latest RAVEN release\n');
0089                         case 1
0090                             printOrange(myStr('     Instructions on how to upgrade',40))
0091                             fprintf('<a href="https://github.com/SysBioChalmers/RAVEN/wiki/Installation#upgrade-raven-after-easy-installation">here</a>\n');
0092                         case 2
0093                             printOrange(myStr('     Instructions on how to upgrade',40))
0094                             fprintf('<a href="https://github.com/SysBioChalmers/RAVEN/wiki/Installation#upgrade-raven-after-medium-installation">here</a>\n');                            
0095                     end
0096                     break
0097                 elseif i==3
0098                     fprintf('   > You are running the latest RAVEN release\n');
0099                 end
0100             end
0101         catch
0102             fprintf(myStr('   > Checking for latest RAVEN release',40))
0103             printOrange('Fail\n');
0104             printOrange('     Cannot reach GitHub for release info\n');
0105         end
0106     end
0107 else
0108     currVer = 'develop';
0109     if ~versionOnly; fprintf('DEVELOPMENT\n'); end
0110 end
0111 if strcmp(developMode,'versionOnly')
0112     return;
0113 end
0114 
0115 fprintf(myStr(' > Checking MATLAB release',40))
0116 fprintf([version('-release') '\n'])
0117 fprintf(myStr(' > Checking system architecture',40))
0118 fprintf([computer('arch'),'\n'])
0119 
0120 fprintf(myStr(' > Set RAVEN in MATLAB path',40))
0121 subpath=regexp(genpath(ravenDir),pathsep,'split'); %List all subdirectories
0122 pathsToKeep=cellfun(@(x) ~contains(x,'.git'),subpath) & cellfun(@(x) ~contains(x,'doc'),subpath);
0123 try
0124     addpath(strjoin(subpath(pathsToKeep),pathsep));
0125     fprintf('Pass\n');
0126     fprintf(myStr(' > Save MATLAB path',40))
0127     try
0128         savepath
0129         fprintf('Pass\n')   
0130     catch
0131         printOrange('Fail\n')
0132         fprintf(['   You might have to rerun checkInstallation again\n'...
0133                  '   next time you start up MATLAB\n'])        
0134     end
0135 catch
0136     printOrange('Fail\n')
0137 end
0138 fprintf(myStr(' > Store RAVEN path as MATLAB pref',40))
0139 try
0140     setpref('RAVEN','ravenPath',ravenDir);
0141     fprintf('Pass\n');
0142 catch
0143     printOrange('Fail\n')
0144 end
0145 
0146 if isunix
0147     fprintf(myStr('   > Make binaries executable',40))
0148     status = makeBinaryExecutable(ravenDir);
0149     if status == 0
0150         fprintf('Pass\n')
0151     else
0152         printOrange('Fail\n')
0153     end
0154 end
0155 
0156 %Check if it is possible to parse an Excel file
0157 fprintf('\n=== Model import and export ===\n');
0158 fprintf(myStr(' > Add Java paths for Excel format',40))
0159 try
0160     %Add the required classes to the static Java path if not already added
0161     addJavaPaths();
0162     fprintf('Pass\n')
0163 catch
0164     printOrange('Fail\n')
0165 end
0166 fprintf(myStr(' > Checking libSBML version',40))
0167 try
0168     evalc('importModel(fullfile(ravenDir,''tutorial'',''empty.xml''))');
0169     try
0170         libSBMLver=OutputSBML_RAVEN; % Only works in libSBML 5.17.0+
0171         fprintf([libSBMLver.libSBML_version_string '\n']);
0172     catch
0173         printOrange('Fail\n')
0174         fprintf('   An older libSBML version was found, update to version 5.17.0 or higher for a significant improvement of model import\n');
0175     end
0176 catch
0177     printOrange('Fail\n')
0178     fprintf('   Download libSBML from http://sbml.org/Software/libSBML/Downloading_libSBML and add to MATLAB path\n');
0179 end
0180 fprintf(' > Checking model import and export\n')
0181 [~,res]=evalc("runtests('importExportTests.m');");
0182 
0183 fprintf(myStr('   > Import Excel format',40))
0184 if res(1).Passed == 1
0185     fprintf('Pass\n')
0186 else
0187     printOrange('Fail\n')
0188     if any(strcmpi(addList.Name,'Text Analytics Toolbox'))
0189         fprintf(['   Excel import/export is incompatible with MATLAB Text Analytics Toolbox.\n' ...
0190                  '   Further instructions => https://github.com/SysBioChalmers/RAVEN/issues/55#issuecomment-1514369299\n'])
0191     end
0192 end
0193 
0194 fprintf(myStr('   > Export Excel format',40))
0195 if res(4).Passed == 1
0196     fprintf('Pass\n')
0197 else
0198     printOrange('Fail\n')
0199 end
0200 
0201 fprintf(myStr('   > Import SBML format',40))
0202 if res(2).Passed == 1
0203     fprintf('Pass\n')
0204 else
0205     printOrange('Fail\n')
0206 end
0207 
0208 fprintf(myStr('   > Export SBML format',40))
0209 if res(5).Passed == 1
0210     fprintf('Pass\n')
0211 else
0212     printOrange('Fail\n')
0213 end
0214 
0215 fprintf(myStr('   > Import YAML format',40))
0216 if res(3).Passed == 1
0217     fprintf('Pass\n')
0218 else
0219     printOrange('Fail\n')
0220 end
0221 
0222 fprintf(myStr('   > Export YAML format',40))
0223 if res(6).Passed == 1
0224     fprintf('Pass\n')
0225 else
0226     printOrange('Fail\n')
0227 end
0228 
0229 fprintf('\n=== Model solvers ===\n');
0230 
0231 %Get current solver. Set it to 'none', if it is not set
0232 fprintf(' > Checking for LP solvers\n')
0233 [~,res]=evalc("runtests('solverTests.m');");
0234 
0235 fprintf(myStr('   > glpk',40))
0236 if res(1).Passed == 1
0237     fprintf('Pass\n')
0238 else
0239     printOrange('Fail\n')
0240 end
0241 
0242 fprintf(myStr('   > gurobi',40))
0243 if res(2).Passed == 1
0244     fprintf('Pass\n')
0245 else
0246     printOrange('Fail\n')
0247 end
0248 
0249 fprintf(myStr('   > scip',40))
0250 if res(3).Passed == 1
0251     fprintf('Pass\n')
0252 else
0253     printOrange('Fail\n')
0254 end
0255 
0256 fprintf(myStr('   > cobra',40))
0257 if res(4).Passed == 1
0258     fprintf('Pass\n')
0259 else
0260     printOrange('Fail\n')
0261 end
0262 fprintf(myStr(' > Set RAVEN solver',40))
0263 try
0264     oldSolver=getpref('RAVEN','solver');
0265     solverIdx=find(strcmp(oldSolver,{'glpk','gurobi','scip','cobra'}));
0266 catch
0267     solverIdx=0;
0268 end
0269 % Do not change old solver if functional
0270 if solverIdx~=0 && res(solverIdx).Passed == 1
0271     fprintf([oldSolver '\n'])
0272 % Order of preference: gurobi > glpk > scip > cobra
0273 elseif res(2).Passed == 1
0274     fprintf('gurobi\n')
0275     setRavenSolver('gurobi');
0276 elseif res(1).Passed == 1
0277     fprintf('glpk\n')
0278     setRavenSolver('glpk');
0279 elseif res(3).Passed == 1
0280     fprintf('scip\n')
0281     setRavenSolver('scip');    
0282 elseif res(4).Passed == 1
0283     fprintf('cobra\n')
0284     setRavenSolver('cobra');
0285 else
0286     fprintf('None, no functional solvers\n')
0287     fprintf('    The glpk should always be working, check your RAVEN installation to make sure all files are present\n')
0288 end
0289 
0290 fprintf('\n=== Essential binary executables ===\n');
0291 if ~checkBinaries
0292     printOrange('    Skipping check of binary executables\n')
0293 else
0294     fprintf(myStr(' > Checking BLAST+',40))
0295     [~,res]=evalc("runtests('blastPlusTests.m');");
0296     res=interpretResults(res);
0297     if res==false
0298         fprintf('   This is essential to run getBlast()\n')
0299     end
0300 
0301     fprintf(myStr(' > Checking DIAMOND',40))
0302     [~,res]=evalc("runtests('diamondTests.m');");
0303     res=interpretResults(res);
0304     if res==false
0305         fprintf('   This is essential to run the getDiamond()\n')
0306     end
0307 
0308     fprintf(myStr(' > Checking HMMER',40))
0309     [~,res]=evalc("runtests('hmmerTests.m')");
0310     res=interpretResults(res);
0311     if res==false
0312         fprintf(['   This is essential to run getKEGGModelFromHomology()\n'...
0313             '   when using a FASTA file as input\n'])
0314     end
0315 
0316     if developMode
0317         fprintf('\n=== Development binary executables ===\n');
0318         fprintf('NOTE: These binaries are only required when using KEGG FTP dump files in getKEGGModelForOrganism\n');
0319 
0320         fprintf(myStr(' > Checking CD-HIT',40))
0321         [~,res]=evalc("runtests('cdhitTests.m');");
0322         interpretResults(res);
0323 
0324         fprintf(myStr(' > Checking MAFFT',40))
0325         [~,res]=evalc("runtests('mafftTests.m');");
0326         interpretResults(res);
0327     end
0328 end
0329 
0330 fprintf('\n=== Compatibility ===\n');
0331 fprintf(myStr(' > Checking function uniqueness',40))
0332 checkFunctionUniqueness();
0333 
0334 fprintf('\n*** checkInstallation complete ***\n');
0335 end
0336 
0337 function res = interpretResults(results)
0338 if results.Failed==0 && results.Incomplete==0
0339     fprintf('Pass\n');
0340     res=true;
0341 else
0342     printOrange('Fail\n')
0343     fprintf('   Download/compile the binary and rerun checkInstallation\n');
0344     res=false;
0345 end
0346 end
0347 
0348 function str = myStr(InputStr,len)
0349 str=InputStr;
0350 lenDiff = len - length(str);
0351 if lenDiff < 0
0352     warning('String too long');
0353 else
0354     str = [str blanks(lenDiff)];
0355 end
0356 end
0357 
0358 function status = makeBinaryExecutable(ravenDir)
0359 % This function is required to run when RAVEN is downloaded as MATLAB
0360 % Add-On, in which case the file permissions are not correctly set
0361 if ispc
0362     status = 0; % No need to run on Windows
0363     return;
0364 end
0365 binDir = fullfile(ravenDir,'software');
0366 
0367 binList = {fullfile(binDir,'blast+','blastp');                      fullfile(binDir,'blast+','blastp.mac');
0368            fullfile(binDir,'blast+','makeblastdb');                 fullfile(binDir,'blast+','makeblastdb.mac');
0369            fullfile(binDir,'cd-hit','cd-hit');                      fullfile(binDir,'cd-hit','cd-hit.mac');
0370            fullfile(binDir,'diamond','diamond');                    fullfile(binDir,'diamond','diamond.mac');
0371            fullfile(binDir,'hmmer','hmmbuild');                     fullfile(binDir,'hmmer','hmmbuild.mac');
0372            fullfile(binDir,'hmmer','hmmsearch');                    fullfile(binDir,'hmmer','hmmsearch.mac');
0373            fullfile(binDir,'GLPKmex','glpkcc.mexa64');              fullfile(binDir,'GLPKmex','glpkcc.mexglx');                 fullfile(binDir,'GLPKmex','glpkcc.mexmaci64');              fullfile(binDir,'GLPKmex','glpkcc.mexmaca64');
0374            fullfile(binDir,'libSBML','TranslateSBML_RAVEN.mexa64'); fullfile(binDir,'libSBML','TranslateSBML_RAVEN.mexglx');    fullfile(binDir,'libSBML','TranslateSBML_RAVEN.mexmaci64');  fullfile(binDir,'libSBML','TranslateSBML_RAVEN.mexmaca64');
0375            fullfile(binDir,'libSBML','OutputSBML_RAVEN.mexa64');    fullfile(binDir,'libSBML','OutputSBML_RAVEN.mexglx');       fullfile(binDir,'libSBML','OutputSBML_RAVEN.mexmaci64');     fullfile(binDir,'libSBML','OutputSBML_RAVEN.mexmaca64');
0376            fullfile(binDir,'mafft','mafft-linux64','mafft.bat');
0377            fullfile(binDir,'mafft','mafft-mac','mafft.bat');};
0378 
0379 for i=1:numel(binList)
0380     [status,cmdout] = system(['chmod +x "' binList{i} '"']);
0381     if status ~= 0
0382         warning('Failed to make %s executable: %s ',binList{i},strip(cmdout))
0383     end
0384 end
0385 end
0386 
0387 function printOrange(stringToPrint)
0388 % printOrange
0389 %   Duplicate of RAVEN/core/printOrange is also kept here, as this function
0390 %   should be able to run before adding RAVEN to the MATLAB path.
0391 try useDesktop = usejava('desktop'); catch, useDesktop = false; end
0392 if useDesktop
0393     fprintf(['[\b' stringToPrint,']\b'])
0394 else
0395     fprintf(stringToPrint)
0396 end
0397 end

Generated by m2html © 2005