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 bf849df commit 0745ff7
Showing 1 changed file with 23 additions and 3 deletions.
26 changes: 23 additions & 3 deletions wasm-icare.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ class WasmICARE {
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

0 comments on commit 0745ff7

Please sign in to comment.