diff --git a/webgestalt_lib/src/methods/multiomics.rs b/webgestalt_lib/src/methods/multiomics.rs index 284b907..533628e 100644 --- a/webgestalt_lib/src/methods/multiomics.rs +++ b/webgestalt_lib/src/methods/multiomics.rs @@ -243,8 +243,8 @@ fn normalize(list: &mut Vec, method: NormalizationMethod) -> Vec list.clone(), NormalizationMethod::MedianRank => { list.sort_by(|a, b| { - b.rank - .partial_cmp(&a.rank) + a.rank + .partial_cmp(&b.rank) .expect("Invalid float comparison during normalization") }); let median = list.len() as f64 / 2.0; @@ -265,11 +265,12 @@ fn normalize(list: &mut Vec, method: NormalizationMethod) -> Vec = Vec::new(); for item in list.iter() { final_list.push(RankListItem { analyte: item.analyte.clone(), - rank: (item.rank - min) / median + min / median, + rank: (item.rank - min) / median + shift, }); } final_list @@ -281,12 +282,14 @@ fn normalize(list: &mut Vec, method: NormalizationMethod) -> Vec() / (list.len() as f64) - min; + let mean: f64 = list.iter().map(|x| x.rank - min).sum::() / (list.len() as f64) + - min / (list.len() as f64); + let shift = min / mean; let mut final_list: Vec = Vec::new(); for item in list.iter() { final_list.push(RankListItem { analyte: item.analyte.clone(), - rank: (item.rank - min) / mean + min / mean, + rank: (item.rank - min) / mean + shift, }); } final_list