Home > installation > checkInstallation.m

checkInstallation

PURPOSE ^

checkInstallation

SYNOPSIS ^

function currVer = 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 (opt, 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

   Usage: currVer = checkInstallation(developMode)

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

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

Generated by m2html © 2005