Open holiday01 opened 5 days ago
I suspect the input data is not the right format. Can you show the output when you type in "pbmc" before calculating the percent.mt step? Also please run rlang::last_trace() as the error message suggest. Lastly, you may wish to submit the full code that you are using, preferably reproducible by others easily.
I suspect the input data is not the right format. Can you show the output when you type in "pbmc" before calculating the percent.mt step? Also please run rlang::last_trace() as the error message suggest. Lastly, you may wish to submit the full code that you are using, preferably reproducible by others easily.
The data was download from https://cf.10xgenomics.com/samples/cell/pbmc3k/pbmc3k_filtered_gene_bc_matrices.tar.gz
setwd("/my_part/scrna/example/filtered_gene_bc_matrices/")
library(dplyr)
library(Seurat)
library(patchwork)
# Load the PBMC dataset
pbmc.data <- Read10X(data.dir = "./hg19/")
# Initialize the Seurat object with the raw (non-normalized data).
pbmc <- CreateSeuratObject(counts = pbmc.data, project = "pbmc3k", min.cells = 3, min.features = 200)
pbmc
# The [[ operator can add columns to object metadata. This is a great place to stash QC stats
pbmc[["percent.mt"]] <- PercentageFeatureSet(pbmc, pattern = "^MT-")
And the rlang::last_trace() of 'pbmc[["percent.mt"]] <- PercentageFeatureSet(pbmc, pattern = "^MT-")'
Here is an inelegant way to narrow down the problem. You can set the input parameters for PercentageFeatureSet function:
object <- pbmc
pattern <- "^MT-"
features <- NULL
col.name <- NULL
assay <- NULL
And step through these codes (extracted from PercentageFeatureSet) line-by-line to see where the problem might be.
assay <- assay %||% DefaultAssay(object = object)
if (!is.null(x = features) && !is.null(x = pattern)) {
warn(message = "Both pattern and features provided. Pattern is being ignored.")
}
percent.featureset <- list()
layers <- Layers(object = object, search = "counts")
for (i in seq_along(along.with = layers)) {
layer <- layers[i]
features.layer <- features %||% grep(pattern = pattern,
x = rownames(x = object[[assay]][layer]), value = TRUE)
layer.data <- LayerData(object = object, assay = assay,
layer = layer)
layer.sums <- colSums(x = layer.data[features.layer,
, drop = FALSE])
layer.perc <- layer.sums/object[[]][colnames(layer.data),
paste0("nCount_", assay)] * 100
percent.featureset[[i]] <- layer.perc
}
percent.featureset <- unlist(percent.featureset)
if (!is.null(x = col.name)) {
object <- AddMetaData(object = object, metadata = percent.featureset,
col.name = col.name)
return(object)
}
Works fine for me. When I googled your error, I found similar issues: #8307 and here.
I cannot see clear solutions but this post said they updated several packages for Seurat/Signac related issues.
My Seurat, SeuratObject and dplyr versions match yours.
It's not clear from the ref to know what package version should be installed. Actually, I had updated all the packages.
Here is an inelegant way to narrow down the problem. You can set the input parameters for PercentageFeatureSet function:
object <- pbmc pattern <- "^MT-" features <- NULL col.name <- NULL assay <- NULL
And step through these codes (extracted from PercentageFeatureSet) line-by-line to see where the problem might be.
assay <- assay %||% DefaultAssay(object = object) if (!is.null(x = features) && !is.null(x = pattern)) { warn(message = "Both pattern and features provided. Pattern is being ignored.") } percent.featureset <- list() layers <- Layers(object = object, search = "counts") for (i in seq_along(along.with = layers)) { layer <- layers[i] features.layer <- features %||% grep(pattern = pattern, x = rownames(x = object[[assay]][layer]), value = TRUE) layer.data <- LayerData(object = object, assay = assay, layer = layer) layer.sums <- colSums(x = layer.data[features.layer, , drop = FALSE]) layer.perc <- layer.sums/object[[]][colnames(layer.data), paste0("nCount_", assay)] * 100 percent.featureset[[i]] <- layer.perc } percent.featureset <- unlist(percent.featureset) if (!is.null(x = col.name)) { object <- AddMetaData(object = object, metadata = percent.featureset, col.name = col.name) return(object) }
When the ran
for (i in seq_along(along.with = layers)) {
layer <- layers[i]
features.layer <- features %||% grep(pattern = pattern,
x = rownames(x = object[[assay]][layer]), value = TRUE)
layer.data <- LayerData(object = object, assay = assay,
layer = layer)
layer.sums <- colSums(x = layer.data[features.layer,
, drop = FALSE])
layer.perc <- layer.sums/object[[]][colnames(layer.data),
paste0("nCount_", assay)] * 100
percent.featureset[[i]] <- layer.perc
}
The error appeared. I found the error that was from
features.layer <- features %||% grep(pattern = pattern,
x = rownames(x = object[[assay]][layer]), value = TRUE)
Recently, after installing the seurat package on two new computers, I re-executed the Seurat - Guided Clustering Tutorial (https://satijalab.org/seurat/articles/pbmc3k_tutorial) using the same data and parameters. The results are different from those in the tutorial, such as the following
pbmc[["percent.mt"]] <- PercentageFeatureSet(pbmc, pattern = "^MT-") not "counts". ℹ Did you mean "CLINT1"? Run
rlang::last_trace()
to see where the error occurred.