satijalab / seurat

R toolkit for single cell genomics
http://www.satijalab.org/seurat
Other
2.27k stars 910 forks source link

Unable to reproduce tutorial - Seurat - Guided Clustering Tutorial #9399

Open holiday01 opened 5 days ago

holiday01 commented 5 days ago

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.

> sessionInfo()
R version 4.4.1 (2024-06-14)
Platform: x86_64-pc-linux-gnu
Running under: Ubuntu 22.04.4 LTS

Matrix products: default
BLAS:   /usr/lib/x86_64-linux-gnu/openblas-pthread/libblas.so.3 
LAPACK: /usr/lib/x86_64-linux-gnu/openblas-pthread/libopenblasp-r0.3.20.so;  LAPACK version 3.10.0

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C               LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8     LC_MONETARY=en_US.UTF-8   
 [6] LC_MESSAGES=en_US.UTF-8    LC_PAPER=en_US.UTF-8       LC_NAME=C                  LC_ADDRESS=C               LC_TELEPHONE=C            
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       

time zone: Asia/Taipei
tzcode source: system (glibc)

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] patchwork_1.3.0    Seurat_5.1.0       SeuratObject_5.0.2 sp_2.1-4           dplyr_1.1.4       

loaded via a namespace (and not attached):
  [1] deldir_2.0-4           pbapply_1.7-2          gridExtra_2.3          rlang_1.1.4            magrittr_2.0.3         RcppAnnoy_0.0.22      
  [7] matrixStats_1.4.1      ggridges_0.5.6         compiler_4.4.1         spatstat.geom_3.3-3    png_0.1-8              vctrs_0.6.5           
 [13] reshape2_1.4.4         stringr_1.5.1          pkgconfig_2.0.3        fastmap_1.2.0          utf8_1.2.4             promises_1.3.0        
 [19] purrr_1.0.2            jsonlite_1.8.9         goftest_1.2-3          later_1.3.2            spatstat.utils_3.1-0   irlba_2.3.5.1         
 [25] parallel_4.4.1         cluster_2.1.6          R6_2.5.1               ica_1.0-3              stringi_1.8.4          RColorBrewer_1.1-3    
 [31] spatstat.data_3.1-2    reticulate_1.39.0      parallelly_1.38.0      spatstat.univar_3.0-1  lmtest_0.9-40          scattermore_1.2       
 [37] Rcpp_1.0.13            tensor_1.5             future.apply_1.11.2    zoo_1.8-12             sctransform_0.4.1      httpuv_1.6.15         
 [43] Matrix_1.6-5           splines_4.4.1          igraph_2.0.3           tidyselect_1.2.1       abind_1.4-8            spatstat.random_3.3-2 
 [49] codetools_0.2-19       miniUI_0.1.1.1         spatstat.explore_3.3-2 listenv_0.9.1          lattice_0.22-5         tibble_3.2.1          
 [55] plyr_1.8.9             shiny_1.9.1            ROCR_1.0-11            Rtsne_0.17             fastDummies_1.7.4      future_1.34.0         
 [61] survival_3.7-0         polyclip_1.10-7        fitdistrplus_1.2-1     pillar_1.9.0           KernSmooth_2.23-24     plotly_4.10.4         
 [67] generics_0.1.3         RcppHNSW_0.6.0         ggplot2_3.5.1          munsell_0.5.1          scales_1.3.0           globals_0.16.3        
 [73] xtable_1.8-4           glue_1.8.0             lazyeval_0.2.2         tools_4.4.1            data.table_1.16.0      RSpectra_0.16-2       
 [79] RANN_2.6.2             leiden_0.4.3.1         dotCall64_1.2          cowplot_1.1.3          grid_4.4.1             tidyr_1.3.1           
 [85] colorspace_2.1-1       nlme_3.1-165           cli_3.6.3              spatstat.sparse_3.1-0  spam_2.11-0            fansi_1.0.6           
 [91] viridisLite_0.4.2      uwot_0.2.2             gtable_0.3.5           digest_0.6.37          progressr_0.14.0       ggrepel_0.9.6         
 [97] htmlwidgets_1.6.4      farver_2.1.2           htmltools_0.5.8.1      lifecycle_1.0.4        httr_1.4.7             mime_0.12             
[103] MASS_7.3-61  
adairama commented 4 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.

holiday01 commented 4 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.

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-")

image

And the rlang::last_trace() of 'pbmc[["percent.mt"]] <- PercentageFeatureSet(pbmc, pattern = "^MT-")'

image

adairama commented 4 days ago

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.

adairama commented 4 days ago

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)
}
holiday01 commented 3 days ago

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.

holiday01 commented 3 days ago

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)