alevax / pyviper

Porting of Protein Activity and Pathway Inference to single cell and Python.
MIT License
10 stars 0 forks source link

Fix NaRneA numerical approximation of qnorm in the function #11

Closed alevax closed 1 year ago

alevax commented 1 year ago

combine_nes <- function(D.nes, U.nes, COV.nes) { NES.pos <- (D.nes + U.nes) / sqrt(2 + 2COV.nes) NES.neg <- (D.nes - U.nes) / sqrt(2 - 2COV.nes)

calculate p values

p.pos <- pnorm(NES.pos, lower.tail = FALSE, log.p = TRUE) p.neg <- pnorm(NES.neg, lower.tail = TRUE, log.p = TRUE)

combine p values

p.dif <- (p.pos < p.neg) min.p <- (p.pos p.dif + p.neg (!p.dif)) final.p <- min.p + log(2) + log1p(exp(min.p) / (-2))

calculate final nes

pos.nes <- qnorm(final.p - log(2), lower.tail = FALSE, log.p = TRUE) neg.nes <- qnorm(final.p - log(2), lower.tail = TRUE, log.p = TRUE) NES.mat <- (pos.nes p.dif + neg.nes (!p.dif))

alexanderlewis99 commented 1 year ago

Resolved by commit 00b5f4c that took log_normalize code of R's qnorm in Python written by zl3263 and rewrote it to be a fast vectorized NumPy-based version