Home > installation > checkInstallation.m

checkInstallation

PURPOSE ^

checkInstallation

SYNOPSIS ^

function [currVer, installType] = checkInstallation(developMode)

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.

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

Generated by m2html © 2005