WebAssembly-ready Rust implementation of preranked Gene Set Enrichment Analysis (GSEA) distilled from GSEApy.
- Rust
- wasm-pack (
cargo install wasm-pack
)
- Clone repo:
git clone https://github.com/wigginno/gsea-rs.git
cd gsea-rs
- Build the WebAssembly module:
wasm-pack build --target web
- Serve the demo
index.html
file e.g. by runningnpx http-server
in the project directory then openhttp://localhost:8080
in your browser.
Options:
- Genes (comma-separated)
- Metric (comma-separated)
- Gene Sets (in JSON format). This could easily be adapted to load .json gene sets from MSigDB.
- Weight
- Min Size
- Max Size
- Number of Permutations
- Random Seed
After filling in the form, click the "Run GSEA" button to perform the analysis. The results will be displayed in a table below the form.
The main function exposed by the WebAssembly module is prerank_rs
:
pub fn prerank_rs(
genes: Vec<String>,
metric: Vec<f64>,
gene_sets: JsValue,
weight: f64,
min_size: usize,
max_size: usize,
nperm: usize,
seed: u64,
) -> Result<JsValue, JsValue>
This function takes the following inputs:
genes
: A vector of gene names (as strings)metric
: A vector of metric values corresponding to the genes (as floating-point numbers)gene_sets
: A JavaScript object representing gene sets, where keys are set names and values are arrays of gene namesweight
: The weight parameter for the GSEA algorithm (as a floating-point number)min_size
: The minimum size of the gene sets to consider (as an integer)max_size
: The maximum size of the gene sets to consider (as an integer)nperm
: The number of permutations to perform for the GSEA algorithm (as an integer)seed
: A random seed for the permutation generation (as an unsigned 64-bit integer)
The function returns a Result
containing a JsValue
on success, which represents an array of summary objects with the following structure:
[
{
term: string,
es: number,
nes: number,
pval: number,
fwerp: number,
fdr: number,
run_es: number[],
hits: number[],
esnull: number[],
index: number | null
},
// ... more summary objects
]
Each summary object in the array contains:
term
: The name of the gene setes
: The enrichment score for the gene setnes
: The normalized enrichment score for the gene setpval
: The p-value for the gene setfwerp
: The family-wise error rate p-value for the gene setfdr
: The false discovery rate for the gene setrun_es
: An array of running enrichment scoreshits
: An array of indices representing the positions of hits in the ranked listesnull
: An array of null enrichment scoresindex
: An optional index value (may be null)
To use this function in JavaScript, you'll need to use a Web Worker to run the WebAssembly module. See gsea-worker.js
and gsea-app.js
for implementation details.