Skip to content

Commit

Permalink
Merge pull request #190 from bigomics/fix-ruv
Browse files Browse the repository at this point in the history
fix RUV error on Lxgn data
  • Loading branch information
zitoa authored Nov 25, 2024
2 parents 6d5a5cf + 45ab504 commit bae7b46
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions R/pgx-correct.R
Original file line number Diff line number Diff line change
Expand Up @@ -1962,7 +1962,9 @@ svaCorrect <- function(X, y) {
# pp <- paste0(model.par, collapse = "+")
# lm.expr <- paste0("lm(t(X) ~ ", pp, ", data=pheno)")
X.r <- t(stats::resid(lm(t(X) ~ y)))
n.sv <- isva::EstDimRMT(X.r, FALSE)$dim + 1
##n.sv <- isva::EstDimRMT(X.r, FALSE)$dim + 1
n.sv <- isva::EstDimRMT(X.r, FALSE)$dim
n.sv
## top 1000 genes only (faster)
X1 <- Matrix::head(X[order(-matrixStats::rowSds(X, na.rm = TRUE)), ], 1000)
## add a little bit of noise to avoid singular error
Expand Down Expand Up @@ -2071,10 +2073,11 @@ ruvCorrect <- function(X, y, k = NULL, type = c("III", "g"), controls = 0.10) {
if (any(is.na(X))) {
stop("[ruvCorrect] cannot handle missing values in X.")
}

sdx <- matrixStats::rowSds(X,na.rm=TRUE)

## F-test using limma just variables
if (!is.null(y) && length(controls) == 1 && is.numeric(controls[1])) {
ii <- which(!duplicated(rownames(X)))
ii <- which(!duplicated(rownames(X)) & sdx > 0)
jj <- which(!is.na(y))
F <- gx.limmaF(X[ii, jj], y[jj], lfc = 0, fdr = 1, method = 1, sort.by = "none", compute.means = FALSE, verbose = 0)
nc <- pmax(nrow(X) * as.numeric(controls), 1)
Expand Down

0 comments on commit bae7b46

Please sign in to comment.