|
71 | 71 |
|
72 | 72 | ravenPath=findRAVENroot(); |
73 | 73 | genesFile=fullfile(ravenPath,'external','kegg','keggGenes.mat'); |
| 74 | +if ~exist(genesFile, 'file') |
| 75 | + try |
| 76 | + downloadKEGGgenes(); |
| 77 | + catch |
| 78 | + %Download failed; fall through to local regeneration below |
| 79 | + end |
| 80 | +end |
74 | 81 | if exist(genesFile, 'file') |
75 | 82 | fprintf(['Importing KEGG genes from ' strrep(genesFile,'\','/') '... ']); |
76 | 83 | load(genesFile); |
|
338 | 345 | end |
339 | 346 | allKOs=unique(allKOs); |
340 | 347 | end |
| 348 | + |
| 349 | +function downloadKEGGgenes() |
| 350 | +% downloadKEGGgenes |
| 351 | +% Downloads keggGenes.mat from the RAVEN GitHub release into |
| 352 | +% external/kegg/. This file is distributed as a release asset rather |
| 353 | +% than shipped in the repository because it exceeds GitHub's 100 MB |
| 354 | +% file-size limit. |
| 355 | +% |
| 356 | +% The following asset is expected on the release tag defined below: |
| 357 | +% keggGenes.zip containing keggGenes.mat |
| 358 | +% |
| 359 | +% To force a refresh (for example, after a new KEGG snapshot has been |
| 360 | +% published with a new RAVEN release), delete |
| 361 | +% external/kegg/keggGenes.mat and call getGenesFromKEGG again. |
| 362 | +% |
| 363 | +% Usage: downloadKEGGgenes() |
| 364 | + |
| 365 | +% Release tag that hosts the data archive. Bump this for any RAVEN |
| 366 | +% release that ships an updated keggGenes.mat. |
| 367 | +releaseTag = 'v2.11.1'; |
| 368 | + |
| 369 | +archiveName = 'keggGenes.zip'; |
| 370 | +targetDir = fullfile(findRAVENroot(),'external','kegg'); |
| 371 | +targetFile = fullfile(targetDir,'keggGenes.mat'); |
| 372 | +url = ['https://github.com/SysBioChalmers/RAVEN/releases/download/',... |
| 373 | + releaseTag,'/',archiveName]; |
| 374 | +zipPath = fullfile(targetDir,archiveName); |
| 375 | + |
| 376 | +fprintf(['Downloading ' archiveName ' from RAVEN ' releaseTag ' release... ']); |
| 377 | +try |
| 378 | + websave(zipPath,url); |
| 379 | +catch ME |
| 380 | + if strcmp(ME.identifier,'MATLAB:webservices:HTTP404StatusCodeError') |
| 381 | + error(['Failed to download ' archiveName ': the server returned ' ... |
| 382 | + 'a 404 error. If this persists, please report it at ' ... |
| 383 | + 'https://github.com/SysBioChalmers/RAVEN/issues']); |
| 384 | + else |
| 385 | + rethrow(ME); |
| 386 | + end |
| 387 | +end |
| 388 | +fprintf('COMPLETE\n'); |
| 389 | + |
| 390 | +fprintf(['Extracting ' archiveName ' to ' strrep(targetDir,'\','/') '... ']); |
| 391 | +try |
| 392 | + unzip(zipPath,targetDir); |
| 393 | +catch ME |
| 394 | + if isfile(zipPath); delete(zipPath); end |
| 395 | + error(['Failed to extract ' archiveName '. The downloaded archive ' ... |
| 396 | + 'may be corrupted.\nOriginal error: %s'],ME.message); |
| 397 | +end |
| 398 | +fprintf('COMPLETE\n'); |
| 399 | + |
| 400 | +if isfile(zipPath); delete(zipPath); end |
| 401 | + |
| 402 | +if ~isfile(targetFile) |
| 403 | + error(['keggGenes.mat was not found in ' archiveName ... |
| 404 | + '. Please verify the release asset contents.']); |
| 405 | +end |
| 406 | +end |
0 commit comments