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(['   HMMER is only required by getKEGGModelForOrganism() when\n'...
0313             '   using a FASTA file as input. If you do not use this function,\n'...
0314             '   this failure can be ignored.\n'])
0315         % On Windows, HMMER runs through Windows Subsystem for Linux
0316         if ispc
0317             [status,~]=system('where wsl');
0318             if status~=0
0319                 printOrange(['   MATLAB cannot find wsl.exe. On Windows, HMMER runs through WSL.\n'...
0320                     '   Install it with "wsl --install" in a Command Prompt, then restart\n'...
0321                     '   MATLAB (it inherits the system PATH at startup) and rerun checkInstallation\n'])
0322             else
0323                 [status,~]=system('wsl -e true');
0324                 if status~=0
0325                     printOrange(['   MATLAB finds wsl.exe, but cannot start a Linux distribution\n'...
0326                         '   through it. Run "wsl -l -v" in a Command Prompt to check that a\n'...
0327                         '   distribution is installed and set up, then restart MATLAB and\n'...
0328                         '   rerun checkInstallation\n'])
0329                 else
0330                     try
0331                         [status,~]=system(['wsl "' getWSLpath(fullfile(ravenDir,'software','hmmer','hmmsearch')) '" -h']);
0332                     catch
0333                         status=1;
0334                     end
0335                     if status~=0
0336                         printOrange(['   WSL works, but the RAVEN HMMER binary cannot be run in it.\n'...
0337                             '   Check that the files in software/hmmer are present and that\n'...
0338                             '   the drive holding RAVEN is accessible from WSL\n'])
0339                     end
0340                 end
0341             end
0342         end
0343     end
0344 
0345     if developMode
0346         fprintf('\n=== Development binary executables ===\n');
0347         fprintf('NOTE: These binaries are only required when using KEGG FTP dump files in getKEGGModelForOrganism\n');
0348 
0349         fprintf(myStr(' > Checking CD-HIT',40))
0350         [~,res]=evalc("runtests('cdhitTests.m');");
0351         interpretResults(res);
0352 
0353         fprintf(myStr(' > Checking MAFFT',40))
0354         [~,res]=evalc("runtests('mafftTests.m');");
0355         interpretResults(res);
0356     end
0357 end
0358 
0359 fprintf('\n=== Compatibility ===\n');
0360 fprintf(myStr(' > Checking function uniqueness',40))
0361 checkFunctionUniqueness();
0362 
0363 fprintf('\n*** checkInstallation complete ***\n');
0364 end
0365 
0366 function res = interpretResults(results)
0367 if results.Failed==0 && results.Incomplete==0
0368     fprintf('Pass\n');
0369     res=true;
0370 else
0371     printOrange('Fail\n')
0372     fprintf('   Download/compile the binary and rerun checkInstallation\n');
0373     res=false;
0374 end
0375 end
0376 
0377 function str = myStr(InputStr,len)
0378 str=InputStr;
0379 lenDiff = len - length(str);
0380 if lenDiff < 0
0381     warning('String too long');
0382 else
0383     str = [str blanks(lenDiff)];
0384 end
0385 end
0386 
0387 function status = makeBinaryExecutable(ravenDir)
0388 % This function is required to run when RAVEN is downloaded as MATLAB
0389 % Add-On, in which case the file permissions are not correctly set
0390 if ispc
0391     status = 0; % No need to run on Windows
0392     return;
0393 end
0394 binDir = fullfile(ravenDir,'software');
0395 
0396 binList = {fullfile(binDir,'blast+','blastp');                      fullfile(binDir,'blast+','blastp.mac');
0397            fullfile(binDir,'blast+','makeblastdb');                 fullfile(binDir,'blast+','makeblastdb.mac');
0398            fullfile(binDir,'cd-hit','cd-hit');                      fullfile(binDir,'cd-hit','cd-hit.mac');
0399            fullfile(binDir,'diamond','diamond');                    fullfile(binDir,'diamond','diamond.mac');
0400            fullfile(binDir,'hmmer','hmmbuild');                     fullfile(binDir,'hmmer','hmmbuild.mac');
0401            fullfile(binDir,'hmmer','hmmsearch');                    fullfile(binDir,'hmmer','hmmsearch.mac');
0402            fullfile(binDir,'GLPKmex','glpkcc.mexa64');              fullfile(binDir,'GLPKmex','glpkcc.mexglx');                 fullfile(binDir,'GLPKmex','glpkcc.mexmaci64');              fullfile(binDir,'GLPKmex','glpkcc.mexmaca64');
0403            fullfile(binDir,'libSBML','TranslateSBML_RAVEN.mexa64'); fullfile(binDir,'libSBML','TranslateSBML_RAVEN.mexglx');    fullfile(binDir,'libSBML','TranslateSBML_RAVEN.mexmaci64');  fullfile(binDir,'libSBML','TranslateSBML_RAVEN.mexmaca64');
0404            fullfile(binDir,'libSBML','OutputSBML_RAVEN.mexa64');    fullfile(binDir,'libSBML','OutputSBML_RAVEN.mexglx');       fullfile(binDir,'libSBML','OutputSBML_RAVEN.mexmaci64');     fullfile(binDir,'libSBML','OutputSBML_RAVEN.mexmaca64');
0405            fullfile(binDir,'mafft','mafft-linux64','mafft.bat');
0406            fullfile(binDir,'mafft','mafft-mac','mafft.bat');};
0407 
0408 for i=1:numel(binList)
0409     [status,cmdout] = system(['chmod +x "' binList{i} '"']);
0410     if status ~= 0
0411         warning('Failed to make %s executable: %s ',binList{i},strip(cmdout))
0412     end
0413 end
0414 end
0415 
0416 function printOrange(stringToPrint)
0417 % printOrange
0418 %   Duplicate of RAVEN/core/printOrange is also kept here, as this function
0419 %   should be able to run before adding RAVEN to the MATLAB path.
0420 try useDesktop = usejava('desktop'); catch, useDesktop = false; end
0421 if useDesktop
0422     fprintf(['[\b' stringToPrint,']\b'])
0423 else
0424     fprintf(stringToPrint)
0425 end
0426 end

Generated by m2html © 2005