Closed mariafiruleva closed 4 years ago
Source of my problem is a correct_counts
function. If length of genes_bin
vector inside for-loop equals to one (which means that genes_bin
is the last gene in genes
vector), all vectors inside for-loop are unnamed and y.res
matrix has no rownames too. I'm not sure whether my actions are correct or not, but if I change the correct_counts
function like this, I have no problems with SCTransform
output.
correct_counts <- function(x, umi, cell_attr = x$cell_attr, show_progress = TRUE) {
regressor_data_orig <- model.matrix(as.formula(gsub('^y', '', x$model_str)), cell_attr)
# when correcting, set all latent variables to median values
cell_attr[, x$arguments$latent_var] <- apply(cell_attr[, x$arguments$latent_var, drop=FALSE], 2, function(x) rep(median(x), length(x)))
regressor_data <- model.matrix(as.formula(gsub('^y', '', x$model_str)), cell_attr)
genes <- rownames(umi)[rownames(umi) %in% rownames(x$model_pars_fit)]
bin_size <- x$arguments$bin_size
bin_ind <- ceiling(x = 1:length(x = genes) / bin_size)
max_bin <- max(bin_ind)
if (show_progress) {
message('Computing corrected UMI count matrix')
pb <- txtProgressBar(min = 0, max = max_bin, style = 3)
}
#corrected_data <- matrix(NA_real_, length(genes), nrow(regressor_data), dimnames = list(genes, rownames(regressor_data)))
corrected_data <- list()
for (i in 1:max_bin) {
genes_bin <- genes[bin_ind == i]
coefs <- x$model_pars_fit[genes_bin, -1]
theta <- x$model_pars_fit[genes_bin, 1]
# get pearson residuals
mu <- exp(tcrossprod(coefs, regressor_data_orig))
variance <- mu + mu^2 / theta
y <- as.matrix(umi[genes_bin, , drop=FALSE])
pearson_residual <- (y - mu) / sqrt(variance)
# generate output
mu <- exp(tcrossprod(coefs, regressor_data))
variance <- mu + mu^2 / theta
y.res <- mu + pearson_residual * sqrt(variance)
y.res <- round(y.res, 0)
y.res[y.res < 0] <- 0
if (length(theta) == 1) {
rownames(y.res) <- genes_bin
}
corrected_data[[length(corrected_data) + 1]] <- as(y.res, Class = 'dgCMatrix')
if (show_progress) {
setTxtProgressBar(pb, i)
}
}
if (show_progress) {
close(pb)
}
corrected_data <- do.call(what = rbind, args = corrected_data)
return(corrected_data)
}
I'm looking forward to your reply.
Best whishes, Maria
Hi Maria, Thank you for pointing out that bug. Should be fixed with commit 70be235 in develop.
Hi @ChristophH @satijalab
Could you help me to solve this problem, please?
I've checked the source of error, and I see that one gene within _vst.out$umicorrected object inside SCTransform function has an empty name. However, before SCTransform running all feature names are correct.
RData can be downloaded in PanglaoDB.
Code:
As a result, I receive the error:
SessionInfo:
Best wishes, Maria