Skip to content

Commit

Permalink
use map.collect for rayon too improve performance by 6%
Browse files Browse the repository at this point in the history
  • Loading branch information
iblacksand committed Nov 2, 2023
1 parent e4ac434 commit bdd320d
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 54 deletions.
84 changes: 49 additions & 35 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 2 additions & 3 deletions webgestalt_lib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,11 @@ rust-version = "1.63.0"

[dependencies]
csv = "1.3.0"
serde = { version = "1.0.188", features = ["std", "derive"] }
serde = { version = "1.0.190", features = ["std", "derive"] }
rand = { version = "0.8.5", features = ["small_rng"] }
rayon = "1.8.0"
rustc-hash = "1.1.0"
statrs = "0.16.0"
ahash = "0.8.3"
ahash = "0.8.6"

[dev-dependencies]
pretty_assertions = "1.4.0"
Expand Down
6 changes: 3 additions & 3 deletions webgestalt_lib/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Supported methods include:

## Installation

To use webgestalt_lib in your Rust project, add the following line to your `Cargo.toml`.
To use webgestalt_lib in your Rust project, add the following line to your `Cargo.toml`.

```toml
webgestalt_lib = {git = "https://github.com/bzhanglab/webgestalt_rust.git"}
Expand All @@ -23,8 +23,8 @@ If you are just interested in running an analysis, rather than develop new tools

1. Fast and correct implementations of enrichment methods
2. Full compatibility with the WebGestaltR package
- The R package provides the most reporting functionality, and project was initially created to only assist the R package with the computation aspects
- The R package provides the most reporting functionality, and project was initially created to only assist the R package with the computation aspects
3. Fast compilation times
- Every package install has to build the library from scratch, so the lower number of dependencies, the better
- Every package install has to build the library from scratch, so the lower number of dependencies, the better

This crate does not provide any data formatting, or charts to display the results of the analysis. This work has already been done by the [R package](https://github.com/bzhanglab/webgestaltr), and a limited implementation is provided by the Rust CLI. The focus for this library is purely computational.
28 changes: 15 additions & 13 deletions webgestalt_lib/src/methods/gsea.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,19 +161,21 @@ fn analyte_set_p(
inverse_nr,
false,
);
let mut es_iter = Vec::new(); // Not parallelized because locking is expensive
(0..permutations).for_each(|i| {
// get es for the permutations
let (p_es, _, _) = enrichment_score(
&has_analyte,
&new_ranks,
&permutations_vec[i],
inverse_size_dif,
inverse_nr,
true,
);
es_iter.push(p_es);
});
let es_iter: Vec<f64> = (0..permutations)
.into_par_iter()
.map(|i| {
// get es for the permutations
let (p_es, _, _) = enrichment_score(
&has_analyte,
&new_ranks,
&permutations_vec[i],
inverse_size_dif,
inverse_nr,
true,
);
p_es
})
.collect();
let side: Vec<&f64> = if real_es >= 0_f64 {
// get side of distribution for p value
es_iter.iter().filter(|x| *x >= &0_f64).collect()
Expand Down

0 comments on commit bdd320d

Please sign in to comment.