From fa2442b67dc3327ee75ea01932ed764b64cb1ee6 Mon Sep 17 00:00:00 2001 From: Marco Stock Date: Sat, 19 Aug 2023 21:36:12 +0200 Subject: [PATCH 1/2] Correct weighting in enrich score of target Currently the formula will calculate a weight of zero for the last window of the target (and also slightly too low for the upper half of the target. The error is small for a large number of target windows, but increases with a smaller number of target windows. --- R/EnrichedHeatmap.R | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/R/EnrichedHeatmap.R b/R/EnrichedHeatmap.R index 3729be1..b9ca008 100755 --- a/R/EnrichedHeatmap.R +++ b/R/EnrichedHeatmap.R @@ -52,16 +52,16 @@ enriched_score = function(mat) { if(length(n1) && length(n2)) { sum(x1 * x1_index/n1) + - sum(x2 * abs(n2/2 - abs(x2_index - n2/2))) + + sum(x2 * abs((n2+1)/2 - abs(x2_index - (n2+1)/2))) + sum(x3 * rev(x3_index)/n3) } else if(!length(n1) && length(n2)) { - sum(x2 * abs(n2/2 - abs(x2_index - n2/2))) + + sum(x2 * abs((n2+1)/2 - abs(x2_index - (n2+1)/2))) + sum(x3 * rev(x3_index)/n3) } else if(length(n1) && !length(n2)) { sum(x1 * x1_index/n1) + - sum(x2 * abs(n2/2 - abs(x2_index - n2/2))) + sum(x2 * abs((n2+1)/2 - abs(x2_index - (n2+1)/2))) } else { - sum(x2 * abs(n2/2 - abs(x2_index - n2/2))) + sum(x2 * abs((n2+1)/2 - abs(x2_index - (n2+1)/2))) } } From d398b6ab0ea5bce821df73ce60a1af52b6e501b7 Mon Sep 17 00:00:00 2001 From: Marco Stock Date: Sat, 19 Aug 2023 21:56:02 +0200 Subject: [PATCH 2/2] Correct calculation of enrich score In the current version, the if-statements don't seem to fit for me. First, I think instead of checking the target section n2, it looks like n3 should be checked when I look at what is calculated in each case. Second, checking the length of n, which is calculated above as the length of x doesn't make sense since this will always give an integer > 0 and therefore will always be true. In fact, since x1, x2 and x3 are set to an empty matrix anyway in the normalizeToMatrix function you can also instead of correcting the points above just always calculate the whole formula and if up/downstream or target vector is empty it will be zero in the sum and thus not change the result. --- R/EnrichedHeatmap.R | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) diff --git a/R/EnrichedHeatmap.R b/R/EnrichedHeatmap.R index b9ca008..f63a40a 100755 --- a/R/EnrichedHeatmap.R +++ b/R/EnrichedHeatmap.R @@ -50,19 +50,11 @@ enriched_score = function(mat) { x3 = x3[l3] x3_index = x3_index[l3] - if(length(n1) && length(n2)) { - sum(x1 * x1_index/n1) + - sum(x2 * abs((n2+1)/2 - abs(x2_index - (n2+1)/2))) + + enrich = sum(x1 * x1_index/n1) + + sum(x2 * abs((n2+1)/2 - abs(x2_index - (n2+1)/2))) + sum(x3 * rev(x3_index)/n3) - } else if(!length(n1) && length(n2)) { - sum(x2 * abs((n2+1)/2 - abs(x2_index - (n2+1)/2))) + - sum(x3 * rev(x3_index)/n3) - } else if(length(n1) && !length(n2)) { - sum(x1 * x1_index/n1) + - sum(x2 * abs((n2+1)/2 - abs(x2_index - (n2+1)/2))) - } else { - sum(x2 * abs((n2+1)/2 - abs(x2_index - (n2+1)/2))) - } + + return(enrich) } upstream_index = attr(mat, "upstream_index") @@ -77,9 +69,8 @@ enriched_score = function(mat) { calc_score(x1, x2, x3) }) return(score) -} - + # == title # Constructor Method for the Enriched Heatmap #