Open vertesy opened 8 months ago
Actually same at NormalizeData()
> tic(); combined.obj <- NormalizeData(object = combined.obj, normalization.method = "LogNormalize", scale.factor = 10000); toc()
Normalizing layer: counts
Performing log-normalization
0% 10 20 30 40 50 60 70 80 90 100%
[----|----|----|----|----|----|----|----|----|----|
**************************************************|
Error in `fn()`:
! Cannot add new cells with [[<-
Run `rlang::last_trace()` to see where the error occurred.
---
Backtrace:
▆
1. ├─Seurat::NormalizeData(...)
2. └─Seurat:::NormalizeData.Seurat(...)
3. ├─methods (local) `[[<-`(`*tmp*`, assay, value = `<Assay5[,212490]>`)
4. └─SeuratObject (local) `[[<-`(`*tmp*`, assay, value = `<Assay5[,212490]>`)
5. ├─methods::callNextMethod(x = x, i = i, ..., value = value)
6. │ └─base::eval(call, callEnv)
7. │ └─base::eval(call, callEnv)
8. └─SeuratObject (local) .nextMethod(x = x, i = i, ..., value = value)
9. └─SeuratObject (local) fn(x = x, i = i, value = value)
Run rlang::last_trace(drop = FALSE) to see 1 hidden frame.
I am facing the exact same issue. Is this due to the new updates or something specific when subset is done?
I did not have similar problems before v5.
That's correct was not an issue before, did you address this issue with a work around? I am currently stuck in the analysis due to this issue, does not matter if I do log normalization or SCTransform.
Well, I do not subset. This however really limits me in testing parameters.
I think it is indeed related to https://github.com/satijalab/seurat/issues/7804, if you try to "split" or "JoinLayers" after "subset", either way there is going to be errors!!
combined.obj <- JoinLayers(combined.obj) combined.obj <- subset(x = combined.obj, cluster = cluster.keep) combined.obj[["RNA"]] <- split(combined.obj[["RNA"]], f = combined.obj$random)
Splitting ‘counts’, ‘data’ layers. Not splitting ‘scale.data’. If you would like to split other layers, set in layers
argument.
Error in validObject(object = object) :
invalid class “Assay5” object: Layers must be two-dimensional objects
######### combined.obj[["RNA"]] <- split(combined.obj[["RNA"]], f = combined.obj$random) combined.obj <- subset(x = combined.obj, cluster = cluster.keep) combined.obj <- JoinLayers(combined.obj)
Error in methods::slot(object = object, name = "layers")[[layer]][features, : incorrect number of dimensions
Dear All,
I'm encountering a similar issue while attempting to subset my Seurat object and subsequently splitting it. The error message I'm encountering is as follows
Splitting ‘counts’, ‘data’ layers. Not splitting ‘scale.data’. If you would like to split other layers, set in
layers
argument. Error insplit()
: ! The following layers are already split: ‘counts’, ‘data’ Please join before splitting Runrlang::last_trace()
to see where the error occurred.
When attempting to apply functions such as NormalizeData or ScaleData to the object, I consistently encounter this error, and the code never completes execution.
Normalizing layer: counts Performing log-normalization 0% 10 20 30 40 50 60 70 80 90 100% [----|----|----|----|----|----|----|----|----|----| **| Error in
fn()
: ! Cannot add new cells with [[<- Runrlang::last_trace()
to see where the error occurred.
When I print the myeloid_cells
object, I notice a reduction in the number of cells, indicating a focus on specific cell types or criteria.
An object of class Seurat 36620 features across 21912 samples within 2 assays Active assay: RNA (36601 features, 2000 variable features) 3 layers present: data, counts, scale.data 1 other assay present: HTO 4 dimensional reductions calculated: pca, umap, harmony, umap.harmony
Upon investigation of my Seurat object, I discovered that myeloid_cells@assays[["RNA"]]
contains the same number of cells as the original object, which was 45635
myeloid_cells@assays[["RNA"]]
Assay (v5) data with 36601 features for 45635 cells Top 10 variable features: IGHG1, IGHGP, GNLY, IGHG3, JCHAIN, IGKC, CXCL10, IGHA1, CXCL9, SPP1 Layers: data, counts, scale.data
Upon inspecting the layers of the RNA
assay, I observed that the data
and counts
layers contain a number of cells equal to the subsetted data. However, I noticed that the myeloid_cells@assays[["RNA"]]@cells
section in the object still retains the original number
myeloid_cells@assays[["RNA"]]@cells
A logical map for 45635 values across 10 observations
maybe this why it we get this error ? I am not sure how to resolve this.
I figured out the issue, it has to do with the some layers not getting properly removed when splitting and merging. The best way around it is to just recreate that assay in place. As below, I get rid of the data and scale.data components, then put the counts back in the same assay. Then you can normalize, scale, and findvariable features again and do any subsetting.
combined_seurat@assays$RNA@layers$data = NULL
combined_seurat@assays$RNA@layers$scale.data = NULL
counts = GetAssayData(combined_seurat, assay = "RNA", layer = "counts")
combined_seurat[["RNA"]] = CreateAssay5Object(counts = counts)
check your "RNA" assay and make sure the number of cells in it match the number in your metadata
I encountered the same issue. Agree with @moutazhelal and @stupidstupidstupidstupid . I think it is because $RNA@cells
is not subsetted properly and contains the original cell number, which is inconsistent with @meta.data
. Manually subsetting $RNA@cells
and overwriting the subsetted seurat object solves the issue for me.
cells.Data <- subset(Original_Object@assays$RNA@cells@.Data, subset = Original_Object@meta.data == [However you subsetted the data])
Subsetted_Object@assays$RNA@cells@.Data <- cells.Data
This solution also fixes issue #8198 which I also encountered. Apparently subsetted objects can not be split, joined or processed unless $RNA@cells
matches with @meta.data
.
I get the same error, strangely, not when running NormalizeData or ScaleData, only with SCTransform. In my case, it is not that I have more cells in one layer than in the metadata, but I have extra "genes" from antibody capture. Or at least that is what I suppose the problem is.
pat2 <- Load10X_Spatial(data.dir=pat2dir, slice = "pat2")
pat2 <- SCTransform(pat2, assay = "Spatial", verbose = FALSE)
Error in
[[<-
: ! Cannot add new cells with [[<-
Session
R version 4.4.1 (2024-06-14 ucrt)
Platform: x86_64-w64-mingw32/x64
Running under: Windows 10 x64 (build 19045)
Matrix products: default
locale:
[1] LC_COLLATE=English_United States.utf8 LC_CTYPE=English_United States.utf8
[3] LC_MONETARY=English_United States.utf8 LC_NUMERIC=C
[5] LC_TIME=English_United States.utf8
time zone: Europe/Zurich
tzcode source: internal
attached base packages:
[1] grid parallel stats4 stats graphics grDevices utils datasets
[9] methods base
other attached packages:
[1] infercnv_1.20.0
[2] CellChat_2.1.2
[3] igraph_2.0.3
[4] dsb_1.0.4
[5] spacexr_2.2.1
[6] qs_0.26.3
[7] tibble_3.2.1
[8] ggrepel_0.9.5
[9] fgsea_1.30.0
[10] msigdbr_7.5.1
[11] plotly_4.10.4
[12] cowplot_1.1.3
[13] patchwork_1.2.0
[14] Seurat_5.1.0
[15] SeuratObject_5.0.2
[16] sp_2.1-4
[17] ggbiplot_0.6.2
[18] FlowSorted.BloodExtended.EPIC_1.1.2
[19] FlowSorted.Blood.EPIC_2.8.0
[20] methylGSA_1.22.0
[21] dplyr_1.1.4
[22] Rtsne_0.17
[23] data.table_1.16.0
[24] tidyr_1.3.1
[25] scales_1.3.0
[26] ggplot2_3.5.1
[27] irlba_2.3.5.1
[28] Matrix_1.7-0
[29] umap_0.2.10.0
[30] IlluminaHumanMethylationEPICv2anno.20a1.hg38_1.0.0
[31] IlluminaHumanMethylationEPICv2manifest_1.0.0
[32] sesame_1.22.1
[33] sesameData_1.22.0
[34] mCSEA_1.24.0
[35] Homo.sapiens_1.3.1
[36] TxDb.Hsapiens.UCSC.hg19.knownGene_3.2.2
[37] org.Hs.eg.db_3.19.1
[38] GO.db_3.19.1
[39] OrganismDbi_1.46.0
[40] GenomicFeatures_1.56.0
[41] AnnotationDbi_1.66.0
[42] mCSEAdata_1.24.0
[43] stringr_1.5.1
[44] DMRcatedata_2.22.0
[45] ExperimentHub_2.12.0
[46] AnnotationHub_3.12.0
[47] BiocFileCache_2.12.0
[48] dbplyr_2.5.0
[49] DMRcate_3.0.2
[50] Gviz_1.48.0
[51] missMethyl_1.38.0
[52] IlluminaHumanMethylationEPICanno.ilm10b4.hg19_0.6.0
[53] RColorBrewer_1.1-3
[54] minfiData_0.50.0
[55] IlluminaHumanMethylation450kanno.ilmn12.hg19_0.6.1
[56] IlluminaHumanMethylation450kmanifest_0.4.0
[57] minfi_1.50.0
[58] bumphunter_1.46.0
[59] locfit_1.5-9.9
[60] iterators_1.0.14
[61] foreach_1.5.2
[62] Biostrings_2.72.1
[63] XVector_0.44.0
[64] SummarizedExperiment_1.34.0
[65] Biobase_2.64.0
[66] MatrixGenerics_1.16.0
[67] matrixStats_1.4.0
[68] GenomicRanges_1.56.1
[69] GenomeInfoDb_1.40.1
[70] IRanges_2.38.0
[71] S4Vectors_0.42.0
[72] BiocGenerics_0.50.0
[73] limma_3.60.3
[74] knitr_1.48
[75] readr_2.1.5
loaded via a namespace (and not attached):
[1] graph_1.82.0 ica_1.0-3
[3] Formula_1.2-5 zlibbioc_1.50.0
[5] doParallel_1.0.17 tidyselect_1.2.1
[7] bit_4.0.5 clue_0.3-65
[9] lattice_0.22-6 rjson_0.2.21
[11] nor1mix_1.3-3 blob_1.2.4
[13] rngtools_1.5.2 S4Arrays_1.4.1
[15] base64_2.0.1 dichromat_2.0-0.1
[17] scrime_1.3.5 png_0.1-8
[19] registry_0.5-1 cli_3.6.3
[21] ggplotify_0.1.2 ProtGenerics_1.36.0
[23] askpass_1.2.0 goftest_1.2-3
[25] multtest_2.60.0 openssl_2.2.1
[27] BiocIO_1.14.0 glmGamPoi_1.16.0
[29] purrr_1.0.2 ggnetwork_0.5.13
[31] BiocNeighbors_1.22.0 uwot_0.2.2
[33] shadowtext_0.1.3 curl_5.2.2
[35] mime_0.12 evaluate_0.24.0
[37] tidytree_0.4.6 coin_1.4-3
[39] leiden_0.4.3.1 ComplexHeatmap_2.20.0
[41] stringi_1.8.4 rjags_4-15
[43] backports_1.5.0 parallelDist_0.2.6
[45] XML_3.99-0.16.1 httpuv_1.6.15
[47] magrittr_2.0.3 clusterProfiler_4.12.0
[49] rappdirs_0.3.3 splines_4.4.1
[51] mclust_6.1.1 RApiSerialize_0.1.3
[53] jpeg_0.1-10 doRNG_1.8.6
[55] wheatmap_0.2.0 ggraph_2.2.1
[57] sctransform_0.4.1 bsseq_1.40.0
[59] DBI_1.2.3 HDF5Array_1.32.0
[61] jquerylib_0.1.4 genefilter_1.86.0
[63] reactome.db_1.88.0 withr_3.0.1
[65] systemfonts_1.1.0 enrichplot_1.24.0
[67] lmtest_0.9-40 RBGL_1.80.0
[69] tidygraph_1.3.1 formatR_1.14
[71] rtracklayer_1.64.0 BiocManager_1.30.25
[73] htmlwidgets_1.6.4 fs_1.6.4
[75] SingleCellExperiment_1.26.0 biomaRt_2.60.0
[77] statnet.common_4.9.0 SparseArray_1.4.8
[79] cellranger_1.1.0 annotate_1.82.0
[81] reticulate_1.39.0 VariantAnnotation_1.50.0
[83] zoo_1.8-12 network_1.18.2
[85] UCSC.utils_1.0.0 beanplot_1.3.1
[87] fansi_1.0.6 caTools_1.18.3
[89] ggtree_3.12.0 rhdf5_2.48.0
[91] R.oo_1.26.0 RSpectra_0.16-2
[93] fastDummies_1.7.4 gridGraphics_0.5-1
[95] phyclust_0.1-34 lazyeval_0.2.2
[97] yaml_2.3.10 survival_3.7-0
[99] scattermore_1.2 BiocVersion_3.19.1
[101] crayon_1.5.3 RcppAnnoy_0.0.22
[103] progressr_0.14.0 tweenr_2.0.3
[105] later_1.3.2 GlobalOptions_0.1.2
[107] ggridges_0.5.6 codetools_0.2-20
[109] base64enc_0.1-3 KEGGREST_1.44.0
[111] shape_1.4.6.1 Rsamtools_2.20.0
[113] filelock_1.0.3 foreign_0.8-86
[115] pkgconfig_2.0.3 ggpubr_0.6.0
[117] xml2_1.3.6 spatstat.univar_3.0-1
[119] GenomicAlignments_1.40.0 aplot_0.2.3
[121] gridBase_0.4-7 spatstat.sparse_3.1-0
[123] BSgenome_1.72.0 ape_5.8
[125] viridisLite_0.4.2 biovizBase_1.52.0
[127] xtable_1.8-4 interp_1.1-6
[129] fastcluster_1.2.6 car_3.1-2
[131] plyr_1.8.9 httr_1.4.7
[133] tools_4.4.1 globals_0.16.3
[135] broom_1.0.6 htmlTable_2.4.2
[137] checkmate_2.3.1 nlme_3.1-165
[139] hdf5r_1.3.10 lambda.r_1.2.4
[141] futile.logger_1.4.3 HDO.db_0.99.1
[143] digest_0.6.37 permute_0.9-7
[145] farver_2.1.2 tzdb_0.4.0
[147] AnnotationFilter_1.28.0 reshape2_1.4.4
[149] yulab.utils_0.1.4 viridis_0.6.5
[151] rpart_4.1.23 glue_1.7.0
[153] cachem_1.1.0 polyclip_1.10-7
[155] Hmisc_5.1-3 generics_0.1.3
[157] ggalluvial_0.12.5 mvtnorm_1.2-5
[159] parallelly_1.38.0 txdbmaker_1.0.0
[161] pkgload_1.3.4 statmod_1.5.0
[163] RcppHNSW_0.6.0 carData_3.0-5
[165] GEOquery_2.72.0 pbapply_1.7-2
[167] httr2_1.0.1 spam_2.10-0
[169] gson_0.1.0 utf8_1.2.4
[171] siggenes_1.78.0 graphlayouts_1.1.1
[173] gtools_3.9.5 readxl_1.4.3
[175] preprocessCore_1.66.0 ggsignif_0.6.4
[177] gridExtra_2.3 shiny_1.9.1
[179] GenomeInfoDbData_1.2.12 R.utils_2.12.3
[181] rhdf5filters_1.16.0 RCurl_1.98-1.14
[183] memoise_2.0.1 rmarkdown_2.28
[185] RobustRankAggreg_1.2.1 R.methodsS3_1.8.2
[187] svglite_2.1.3 future_1.34.0
[189] reshape_0.8.9 RANN_2.6.2
[191] illuminaio_0.46.0 stringfish_0.16.0
[193] spatstat.data_3.1-2 rstudioapi_0.16.0
[195] cluster_2.1.6 spatstat.utils_3.1-0
[197] hms_1.1.3 fitdistrplus_1.2-1
[199] munsell_0.5.1 colorspace_2.1-1
[201] FNN_1.1.4 rlang_1.1.4
[203] quadprog_1.5-8 DelayedMatrixStats_1.26.0
[205] sparseMatrixStats_1.16.0 dotCall64_1.1-1
[207] circlize_0.4.16 ggforce_0.4.2
[209] xfun_0.47 TH.data_1.1-2
[211] coda_0.19-4.1 sna_2.7-2
[213] modeltools_0.2-23 abind_1.4-5
[215] GOSemSim_2.30.0 libcoin_1.0-10
[217] treeio_1.28.0 Rhdf5lib_1.26.0
[219] futile.options_1.0.1 bitops_1.0-8
[221] promises_1.3.0 scatterpie_0.2.3
[223] RSQLite_2.3.7 qvalue_2.36.0
[225] sandwich_3.1-0 DelayedArray_0.30.1
[227] compiler_4.4.1 prettyunits_1.2.0
[229] listenv_0.9.1 Rcpp_1.0.13
[231] edgeR_4.2.0 tensor_1.5
[233] MASS_7.3-61 progress_1.2.3
[235] BiocParallel_1.38.0 babelgene_22.9
[237] spatstat.random_3.3-1 R6_2.5.1
[239] multcomp_1.4-25 rstatix_0.7.2
[241] fastmap_1.2.0 fastmatch_1.1-4
[243] ensembldb_2.28.0 ROCR_1.0-11
[245] nnet_7.3-19 gtable_0.3.5
[247] KernSmooth_2.23-24 latticeExtra_0.6-30
[249] miniUI_0.1.1.1 deldir_2.0-4
[251] htmltools_0.5.8.1 RcppParallel_5.1.7
[253] bit64_4.0.5 spatstat.explore_3.3-2
[255] lifecycle_1.0.4 restfulr_0.0.15
[257] sass_0.4.9 vctrs_0.6.5
[259] spatstat.geom_3.3-2 DOSE_3.30.1
[261] NMF_0.27 ggfun_0.1.5
[263] future.apply_1.11.2 bslib_0.8.0
[265] pillar_1.9.0 gplots_3.1.3.1
[267] argparse_2.2.3 jsonlite_1.8.8
[269] GetoptLong_1.0.5
I got an Error on ScaleData on a subset object "Cannot add new cells" .
Code
May be related to #7804
Error
Session