Closed frnkhuang closed 5 months ago
Hi there - thanks for your comment! I can look into this. Are you encountering this problem with the tutorial or with your own data? Would you also be able to provide the AUCell package version that you have?
Andy
Could you try updating your AUCell package? In the newest versions, splitByBlocks is automatically set to TRUE if AUCell detects a dgCMatrix as input.
If this does not work, here is some custom code you can try to substitute for the function from the package:
score_Genesets_AUCell <- function (scrna, genesets, nbatches = 10, ncores = 1, output = c("metadata", "assay", "dataframe"), assay_name = "AUCell"){
AUCell_scores <- AUCell_batch_custom(Seurat::GetAssayData(scrna, assay = "RNA", slot = "counts"), genesets = genesets,
num_batches = nbatches, num_cores = ncores)
colnames(AUCell_scores) <- paste0(colnames(AUCell_scores), "_AUC")
if (output == "metadata") {
scrna <- Seurat::AddMetaData(scrna, as.data.frame(AUCell_scores))
out <- scrna
}
else if (output == "assay") {
scrna[[assay_name]] <- Seurat::CreateAssayObject(t(AUCell_scores))
out <- scrna
}
else if (output == "dataframe") {
AUCell_scores <- as.data.frame(AUCell_scores)
out <- AUCell_scores
}
else {
stop("output parameter \"{output}\" is not a valid option. Please specify output as either \"metadata\", \"assay\", or \"dataframe\".")
}
return(out)
}
AUCell_batch <- function (inp_data, genesets, num_batches = 10, num_cores = 1){
num_cells <- ncol(inp_data)
batch_size <- ceiling(num_cells/num_batches)
score_mat <- c()
print("Running AUCell scoring")
for (i in 1:num_batches) {
print(paste("batch", i))
ind1 <- (i - 1) * batch_size + 1
ind2 <- i * batch_size
if (ind2 > num_cells) {
ind2 <- num_cells
}
if (Sys.info()[["sysname"]] == "Windows") {
num_cores = 1
}
gene_rankings <- AUCell::AUCell_buildRankings(inp_data[,ind1:ind2], plotStats = FALSE, nCores = num_cores, splitByBlocks=TRUE)
score_mat_i <- AUCell::AUCell_calcAUC(geneSets = genesets, rankings = gene_rankings, nCores = num_cores)
score_mat_i <- t(SummarizedExperiment::assay(score_mat_i, "AUC"))
score_mat <- rbind(score_mat, score_mat_i)
gc(full = TRUE, verbose = TRUE)
}
print("Finished Scoring")
return(score_mat)
}
Thanks for the quick reply. Updating the AUCell package from 1.18.1 to 1.25.2 solved the issue.
Perfect! have a great weekend!
Hi Andy,
Thanks for developing this package! I am trying to score genesets as described in the leukemia projections tutorial:
query <- score_Genesets_AUCell(query, genesets = AMLgenesets, nbatches = 1, ncores = 10, output = 'metadata')
gives me the following error:
[1] "Running AUCell scoring" [1] "batch 1" Error in .AUCell_buildRankings(exprMat = exprMat, featureType = featureType, : To use a dgCMatrix as input set 'splitByBlocks=TRUE'.
Using sparse matrices requires splitByBlocks=TRUE but I can not specify this within the score_Genesets_AUCell function. Any idea how I could fix this? Thanks a lot in advance!