From 567db9cc162fa6710d36a717abc005cfb9a00630 Mon Sep 17 00:00:00 2001 From: David Young Date: Thu, 9 Jun 2022 15:02:43 +0800 Subject: [PATCH 1/2] Fix proportion estimation for NA values Skip NA common genes from the bulk sample by recording indices where NA common genes are found and removing the corresponding column names from the output. --- R/Deconvolution.R | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/R/Deconvolution.R b/R/Deconvolution.R index b86d59d..ec9770c 100644 --- a/R/Deconvolution.R +++ b/R/Deconvolution.R @@ -597,12 +597,19 @@ SCDC_prop <- function (bulk.eset, sc.eset, ct.varname, sample, ct.sub, iter.max prop.est.mvw <- NULL yhat <- NULL yhatgene.temp <- rownames(basis.mvw) + to.remove <- list() for (i in 1:N.bulk) { basis.mvw.temp <- basis.mvw xbulk.temp <- xbulk[, i]*100 sigma.temp <- sigma + com.genes <- sum(xbulk[, i] != 0) message(paste(colnames(xbulk)[i], "has common genes", - sum(xbulk[, i] != 0), "...")) + com.genes, "...")) + if (is.na(com.genes)) { + # store indices of NA vals to remove later + to.remove <- append(to.remove, -i) + next + } lm <- nnls::nnls(A = basis.mvw.temp, b = xbulk.temp) delta <- lm$residuals wt.gene <- 1/(nu + delta^2 + colSums((lm$x * ALS.S)^2 * @@ -640,9 +647,13 @@ SCDC_prop <- function (bulk.eset, sc.eset, ct.varname, sample, ct.sub, iter.max ]) } colnames(prop.est.mvw) <- colnames(basis.mvw) - rownames(prop.est.mvw) <- colnames(xbulk) - colnames(yhat) <- colnames(xbulk) + # remove column names for NA vals + to.remove <- unlist(to.remove) + xbulk.cols <- colnames(xbulk)[to.remove] + rownames(prop.est.mvw) <- xbulk.cols + colnames(yhat) <- xbulk.cols yobs <- exprs(bulk.eset) + yobs <- yobs[, to.remove] yeval <- SCDC_yeval(y = yobs, yest = yhat, yest.names = c("SCDC")) peval <- NULL if (!is.null(truep)) { From 4793fc9ffba44e318dfb79ff6979a019b90b7cd6 Mon Sep 17 00:00:00 2001 From: David Young Date: Thu, 14 Jul 2022 13:34:38 +0800 Subject: [PATCH 2/2] Fix attempting to remove NAs when none are present Only remove indices if they exist, which avoids attempting to index by NULL and removing all `yobs` values. --- R/Deconvolution.R | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/R/Deconvolution.R b/R/Deconvolution.R index ec9770c..dbf4e96 100644 --- a/R/Deconvolution.R +++ b/R/Deconvolution.R @@ -647,13 +647,17 @@ SCDC_prop <- function (bulk.eset, sc.eset, ct.varname, sample, ct.sub, iter.max ]) } colnames(prop.est.mvw) <- colnames(basis.mvw) + # remove column names for NA vals + xbulk.cols <- colnames(xbulk) + yobs <- exprs(bulk.eset) to.remove <- unlist(to.remove) - xbulk.cols <- colnames(xbulk)[to.remove] + if (!is.null(to.remove)) { + xbulk.cols <- xbulk.cols[to.remove] + yobs <- yobs[, to.remove] + } rownames(prop.est.mvw) <- xbulk.cols colnames(yhat) <- xbulk.cols - yobs <- exprs(bulk.eset) - yobs <- yobs[, to.remove] yeval <- SCDC_yeval(y = yobs, yest = yhat, yest.names = c("SCDC")) peval <- NULL if (!is.null(truep)) {