Skip to content

Commit be826af

Browse files
committed
add fdr calculation to multilist gsea
1 parent c0b36e8 commit be826af

File tree

1 file changed

+21
-19
lines changed

1 file changed

+21
-19
lines changed

webgestalt_lib/src/methods/multilist.rs

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,17 @@ pub enum NormalizationMethod {
6060
///
6161
/// - `jobs` - A [`Vec<GSEAJob>`] containing all of the separates 'jobs' or analysis to combine
6262
/// - `method` - A [`MultiOmicsMethod`] enum detailing the analysis method to combine the runs together (meta-analysis, mean median ration, or max median ratio).
63+
/// - `fdr_method` - [`AdjustmentMethod`] of what FDR method to use to adjust p-values
6364
///
6465
/// # Returns
6566
///
6667
/// Returns a [`Vec<Vec<FullGSEAResult>>`] containing the results of each analysis. If the method was not meta-analysis, then the outer vector will only have one element.
6768
/// If the method was meta-analysis, then the first element will be the results of the meta-analysis, and the rest of the elements will be the results of each analysis run individually.
68-
pub fn multilist_gsea(jobs: Vec<GSEAJob>, method: MultiListMethod) -> Vec<Vec<GSEAResult>> {
69+
pub fn multilist_gsea(
70+
jobs: Vec<GSEAJob>,
71+
method: MultiListMethod,
72+
fdr_method: AdjustmentMethod,
73+
) -> Vec<Vec<GSEAResult>> {
6974
if let MultiListMethod::Meta(meta_method) = method {
7075
let mut phash: AHashMap<String, Vec<f64>> = AHashMap::default();
7176
let mut results: Vec<Vec<GSEAResult>> = Vec::new();
@@ -78,35 +83,32 @@ pub fn multilist_gsea(jobs: Vec<GSEAJob>, method: MultiListMethod) -> Vec<Vec<GS
7883
results.push(res);
7984
}
8085
let mut final_result: Vec<GSEAResult> = Vec::new();
86+
let mut meta_p = Vec::new();
8187
match meta_method {
8288
MetaAnalysisMethod::Stouffer => {
8389
let normal = Normal::new(0.0, 1.0).unwrap();
8490
for set in phash.keys() {
85-
final_result.push(GSEAResult {
86-
set: set.clone(),
87-
p: stouffer_with_normal(&phash[set], &normal),
88-
fdr: 0.0,
89-
nes: 0.0,
90-
es: 0.0,
91-
running_sum: Vec::new(),
92-
leading_edge: 0,
93-
});
91+
meta_p.push(stouffer_with_normal(&phash[set], &normal))
9492
}
9593
}
9694
MetaAnalysisMethod::Fisher => {
9795
for set in phash.keys() {
98-
final_result.push(GSEAResult {
99-
set: set.clone(),
100-
p: fisher(&phash[set]),
101-
fdr: 0.0,
102-
nes: 0.0,
103-
es: 0.0,
104-
running_sum: Vec::new(),
105-
leading_edge: 0,
106-
});
96+
meta_p.push(fisher(&phash[set]));
10797
}
10898
}
10999
}
100+
let meta_fdr = adjust(&meta_p, fdr_method);
101+
for (i, set) in phash.keys().enumerate() {
102+
final_result.push(GSEAResult {
103+
set: set.clone(),
104+
p: meta_p[i],
105+
fdr: meta_fdr[i],
106+
nes: 0.0,
107+
es: 0.0,
108+
running_sum: Vec::new(),
109+
leading_edge: 0,
110+
})
111+
}
110112
results.insert(0, final_result);
111113
results
112114
} else {

0 commit comments

Comments
 (0)