Skip to content

Commit

Permalink
Enable preloading files
Browse files Browse the repository at this point in the history
  • Loading branch information
jeyabbalas committed Aug 27, 2023
1 parent 0745ff7 commit f8ed194
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 5 deletions.
28 changes: 24 additions & 4 deletions dist/wasm-icare.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@ class WasmICARE {
*/
constructor() {
// Wasm-iCARE version.
this.version = '1.0.0';
this.version = '1.1.0';
// Version of the iCARE Python package to load from PyPI.
this.pyICareVersion = '1.0.0';
// Version of Pyodide to load from the CDN.
this.pyodideVersion = '0.23.2';
// Files that are pre-loaded to the Pyodide file system.
this.preloadedFiles = [];
}

/**
Expand Down Expand Up @@ -82,6 +84,24 @@ class WasmICARE {
return await Promise.all(fileURLs.map(fetchAndWriteFile));
}

/**
* Method to load files from a list of URLs and write them to the Pyodide file system. This utility allows you to
* save time from network latencies when making several calls to computing absolute risk. When files are loaded
* using this option, they will not be re-loaded when computing absolute risk.
* @param fileURLs
* @returns {Promise<Awaited<*>[]>}
*/
async preloadFiles(fileURLs) {
if (!this.pyodide) {
throw new Error('Please instantiate this class using the WasmICARE.initialize() method.');
}

const fileLoadAndWritePromises = await this.fetchFilesAndWriteToPyodideFS(fileURLs);
this.preloadedFiles = fileURLs;

return fileLoadAndWritePromises;
}

/**
* Method to convert the Wasm-iCARE output to JSON.
* @param obj
Expand Down Expand Up @@ -227,7 +247,7 @@ class WasmICARE {
modelSnpInfoUrl,
applyCovariateProfileUrl,
applySnpProfileUrl,
].filter(url => url !== undefined);
].filter(url => url !== undefined).filter(url => !this.preloadedFiles.includes(url));

await this.fetchFilesAndWriteToPyodideFS(fileURLs);

Expand Down Expand Up @@ -446,7 +466,7 @@ result
applyCovariateProfileBeforeCutpointUrl,
applyCovariateProfileAfterCutpointUrl,
applySnpProfileUrl,
].filter(url => url !== undefined);
].filter(url => url !== undefined).filter(url => !this.preloadedFiles.includes(url));

await this.fetchFilesAndWriteToPyodideFS(fileURLs);

Expand Down Expand Up @@ -707,7 +727,7 @@ result
icareModelParameters.modelSnpInfoUrl,
icareModelParameters.applyCovariateProfileUrl,
icareModelParameters.applySnpProfileUrl,
].filter(url => url !== undefined);
].filter(url => url !== undefined).filter(url => !this.preloadedFiles.includes(url));

await this.fetchFilesAndWriteToPyodideFS(fileURLs);

Expand Down
2 changes: 1 addition & 1 deletion wasm-icare.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class WasmICARE {
*/
constructor() {
// Wasm-iCARE version.
this.version = '1.0.0';
this.version = '1.1.0';
// Version of the iCARE Python package to load from PyPI.
this.pyICareVersion = '1.0.0';
// Version of Pyodide to load from the CDN.
Expand Down

0 comments on commit f8ed194

Please sign in to comment.