Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use par_iter for sums, improve speed by 15% #15

Merged
merged 1 commit into from
Nov 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ edition = "2021"
[dependencies]
bincode = "1.3.3"
clap = { version = "4.4.6", features = ["derive"] }
owo-colors = {version = "3.5.0", features = ["supports-colors"]}
serde = {version="1.0.188", features=["std", "derive"]}
webgestalt_lib = {path = "webgestalt_lib"}
owo-colors = { version = "3.5.0", features = ["supports-colors"] }
serde = { version = "1.0.188", features = ["std", "derive"] }
webgestalt_lib = { path = "webgestalt_lib" }

[profile.release]
opt-level = 3
5 changes: 2 additions & 3 deletions webgestalt_lib/src/methods/gsea.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ use ahash::AHashSet;
use rand::prelude::SliceRandom;
use rand::SeedableRng;
use rayon::prelude::*;
use std::sync::{Arc, Mutex};

/// Parameters for GSEA
#[derive(Clone)]
Expand Down Expand Up @@ -202,8 +201,8 @@ fn analyte_set_p(
.collect();
let up_len = up.len();
let down_len = down.len();
let up_avg: f64 = up.iter().sum::<f64>() / (up_len as f64 + 0.000001) + 0.000001; // up average
let down_avg: f64 = down.iter().sum::<f64>() / (down_len as f64 + 0.000001) - 0.000001; // down average
let up_avg: f64 = up.par_iter().sum::<f64>() / (up_len as f64 + 0.000001) + 0.000001; // up average
let down_avg: f64 = down.par_iter().sum::<f64>() / (down_len as f64 + 0.000001) - 0.000001; // down average
let mut nes_es: Vec<f64> = up.par_iter().map(|x| x / up_avg).collect(); // get all normalized scores for up
nes_es.extend(down.par_iter().map(|x| -x / down_avg).collect::<Vec<f64>>()); // extend with down scores
let norm_es: f64 = if real_es >= 0_f64 {
Expand Down
6 changes: 3 additions & 3 deletions webgestalt_lib/src/methods/multiomics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ pub enum MetaAnalysisMethod {
}

pub enum AnalysisType {
/// Gene Set Enrichment Analysips
/// Gene Set Enrichment Analysis
GSEA,
/// Over-representation Analysis
ORA,
Expand All @@ -49,12 +49,12 @@ pub enum NormalizationMethod {
None,
}

/// Run a multiomics analysis, using iehter the max/mean median ratio or a typical meta analysis
/// Run a multiomics analysis, using either the max/mean median ratio or a typical meta analysis
/// method
///
/// # Parameters
///
/// - `jobs` - A [`Vec<GSEAJob>`] containing all of the seperates 'jobs' or analysis to combine
/// - `jobs` - A [`Vec<GSEAJob>`] containing all of the separates 'jobs' or analysis to combine
/// - `method` - A [`MultiOmicsMethod`] enum detailing the analysis method to combine the runs together (meta-analysis, mean median ration, or max median ratio).
///
/// # Returns
Expand Down
1 change: 0 additions & 1 deletion webgestalt_lib/src/methods/ora.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ use crate::{readers::utils::Item, stat};
use ahash::AHashSet;
use rayon::prelude::*;
use statrs::distribution::{DiscreteCDF, Hypergeometric};
use std::sync::{Arc, Mutex};

#[derive(Clone)]
pub struct ORAConfig {
Expand Down
2 changes: 1 addition & 1 deletion webgestalt_lib/tests/gsea_tests.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use pretty_assertions::{assert_eq, assert_ne};
use pretty_assertions::assert_eq;
use statrs::assert_almost_eq;
use webgestalt_lib;

Expand Down
2 changes: 1 addition & 1 deletion webgestalt_lib/tests/ora_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ fn ora() {
"data/genelist.txt".to_owned(),
"data/reference.txt".to_owned(),
);
let gmtcount = gmt.len();
let gmtcount: usize = gmt.len();
let x: Vec<webgestalt_lib::methods::ora::ORAResult> =
webgestalt_lib::methods::ora::get_ora(&gene_list, &reference, gmt, ORAConfig::default());
let res = x.iter().find(|x| x.set == "GO:2000147").unwrap();
Expand Down