satijalab / seurat

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

Error ScaleData or NormalizeData on a subset object "Cannot add new cells" #8407

Open vertesy opened 8 months ago

vertesy commented 8 months ago

I got an Error on ScaleData on a subset object "Cannot add new cells" .

Code

combined.obj <- subset(x = combined.obj, cells = cellIDs.keep)
combined.obj <- FindVariableFeatures(combined.obj, assay = "RNA", verbose = T)
combined.obj <- ScaleData(combined.obj, assay = "RNA", verbose = T)

May be related to #7804

Error

Finding variable features for layer counts
Calculating gene variances
0%   10   20   30   40   50   60   70   80   90   100%
[----|----|----|----|----|----|----|----|----|----|
**************************************************|
Calculating feature variances of standardized and clipped values
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.
Warning messages:
1: Removing 191241 cells missing data for vars requested 
2: Removing 191241 cells missing data for vars requested 
3: Removing 191241 cells missing data for vars requested 
4: Removing 191241 cells missing data for vars requested 
Connected to your session in progress, last started 2024-Feb-02 08:05:14 UTC (50 minutes ago)
> rlang::last_trace()
<error/rlang_error>
Error in `fn()`:
! Cannot add new cells with [[<-
---
Backtrace:
    ▆
 1. ├─Seurat::FindVariableFeatures(combined.obj, assay = "RNA", verbose = T)
 2. └─Seurat:::FindVariableFeatures.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.

Session

> session_info()
─ Session info ──────────────────────────────────────────────────────────
 setting  value
 version  R version 4.3.0 (2023-04-21)
 os       CentOS Linux 7 (Core)
 system   x86_64, linux-gnu
 ui       RStudio
 language (EN)
 collate  en_US.UTF-8
 ctype    en_US.UTF-8
 tz       Europe/Vienna
 date     2024-02-02
 rstudio  2023.09.1+494.pro2 Desert Sunflower (server)
 pandoc   3.1.1 @ /software/system/rstudio/rstudio-server-2023.09.1/bin/quarto/bin/tools/ (via rmarkdown)

─ Packages ──────────────────────────────────────────────────────────────
 !  package              * version   date (UTC) lib source
    abind                  1.4-5     2016-07-21 [1] CRAN (R 4.3.0)
    assertive            * 0.3-6     2020-08-01 [4] CRAN (R 4.3.0)
    assertive.base         0.0-9     2021-02-08 [4] CRAN (R 4.3.0)
    assertive.code         0.0-4     2023-05-30 [2] CRAN (R 4.3.0)
    assertive.data         0.0-3     2018-11-21 [4] CRAN (R 4.3.0)
    assertive.data.uk      0.0-2     2018-10-21 [4] CRAN (R 4.3.0)
    assertive.data.us      0.0-2     2018-10-21 [4] CRAN (R 4.3.0)
    assertive.datetimes    0.0-3     2020-07-30 [4] CRAN (R 4.3.0)
    assertive.files        0.0-2     2016-05-10 [4] CRAN (R 4.3.0)
    assertive.matrices     0.0-2     2018-11-20 [4] CRAN (R 4.3.0)
    assertive.models       0.0-2     2018-10-21 [4] CRAN (R 4.3.0)
    assertive.numbers      0.0-2     2016-05-09 [4] CRAN (R 4.3.0)
    assertive.properties   0.0-5     2022-04-21 [4] CRAN (R 4.3.0)
    assertive.reflection   0.0-5     2020-07-31 [4] CRAN (R 4.3.0)
    assertive.sets         0.0-3     2016-12-30 [4] CRAN (R 4.3.0)
    assertive.strings      0.0-3     2016-05-10 [4] CRAN (R 4.3.0)
    assertive.types        0.0-3     2016-12-30 [4] CRAN (R 4.3.0)
    assertthat             0.2.1     2019-03-21 [4] CRAN (R 4.3.0)
    backports              1.4.1     2021-12-13 [1] CRAN (R 4.3.0)
    BiocGenerics           0.46.0    2023-04-25 [1] Bioconductor
    Biostrings             2.68.1    2023-05-16 [1] Bioconductor
    bit                    4.0.5     2022-11-15 [1] CRAN (R 4.3.0)
    bit64                  4.0.5     2020-08-30 [1] CRAN (R 4.3.0)
    bitops                 1.0-7     2021-04-24 [1] CRAN (R 4.3.0)
    brio                   1.1.4     2023-12-10 [1] CRAN (R 4.3.0)
    broom                  1.0.5     2023-06-09 [1] CRAN (R 4.3.0)
    cachem                 1.0.8     2023-05-01 [1] CRAN (R 4.3.0)
    car                    3.1-2     2023-03-30 [1] CRAN (R 4.3.0)
    carData                3.0-5     2022-01-06 [1] CRAN (R 4.3.0)
    caTools                1.18.2    2021-03-28 [1] CRAN (R 4.3.0)
    cellranger             1.1.0     2016-07-27 [1] CRAN (R 4.3.0)
    checkmate            * 2.3.0     2023-10-25 [1] CRAN (R 4.3.0)
    cli                    3.6.2     2023-12-11 [1] CRAN (R 4.3.0)
    clipr                  0.8.0     2022-02-22 [1] CRAN (R 4.3.0)
    cluster                2.1.4     2022-08-22 [4] CRAN (R 4.3.0)
    codetools              0.2-19    2023-02-01 [1] CRAN (R 4.3.0)
    colorout             * 1.2-2     2023-09-18 [1] Github (jalvesaq/colorout@79931fd)
    colorRamps             2.3.1     2022-05-02 [1] CRAN (R 4.3.0)
    colorspace             2.1-0     2023-01-23 [1] CRAN (R 4.3.0)
    covr                   3.6.2     2023-03-25 [2] CRAN (R 4.3.0)
    cowplot              * 1.1.2     2023-12-15 [1] CRAN (R 4.3.0)
    crayon                 1.5.2     2022-09-29 [1] CRAN (R 4.3.0)
    data.table             1.14.8    2023-02-17 [1] CRAN (R 4.3.0)
    deldir                 1.0-9     2023-05-17 [1] CRAN (R 4.3.0)
    desc                   1.4.3     2023-12-10 [1] CRAN (R 4.3.0)
    devtools               2.4.5     2022-10-11 [1] CRAN (R 4.3.0)
    digest                 0.6.33    2023-07-07 [1] CRAN (R 4.3.0)
    doMC                 * 1.3.8     2022-02-05 [4] CRAN (R 4.3.0)
    dotCall64              1.1-0     2023-10-17 [1] CRAN (R 4.3.0)
    dplyr                * 1.1.4     2023-11-17 [1] CRAN (R 4.3.0)
    DT                     0.29      2023-08-29 [2] CRAN (R 4.3.0)
    ellipsis               0.3.2     2021-04-29 [1] CRAN (R 4.3.0)
    EnhancedVolcano        1.18.0    2023-04-25 [1] Bioconductor
    evaluate               0.23      2023-11-01 [1] CRAN (R 4.3.0)
    fansi                  1.0.6     2023-12-08 [1] CRAN (R 4.3.0)
    farver                 2.1.1     2022-07-06 [1] CRAN (R 4.3.0)
    fastDummies            1.7.3     2023-07-06 [1] CRAN (R 4.3.0)
    fastmap                1.1.1     2023-02-24 [1] CRAN (R 4.3.0)
    fitdistrplus           1.1-11    2023-04-25 [1] CRAN (R 4.3.0)
    forcats              * 1.0.0     2023-01-29 [1] CRAN (R 4.3.0)
    foreach              * 1.5.2     2022-02-02 [4] CRAN (R 4.3.0)
    formatR                1.14      2023-01-17 [1] CRAN (R 4.3.0)
    fs                     1.6.3     2023-07-20 [1] CRAN (R 4.3.0)
    futile.logger          1.4.3     2016-07-10 [1] CRAN (R 4.3.0)
    futile.options         1.0.1     2018-04-20 [1] CRAN (R 4.3.0)
    future               * 1.33.1    2023-12-22 [1] CRAN (R 4.3.0)
    future.apply           1.11.0    2023-05-21 [1] CRAN (R 4.3.0)
    gargle                 1.5.2     2023-07-20 [1] CRAN (R 4.3.0)
    generics               0.1.3     2022-07-05 [1] CRAN (R 4.3.0)
    GenomeInfoDb           1.36.4    2023-10-02 [1] Bioconductor
    GenomeInfoDbData       1.2.10    2023-11-22 [1] Bioconductor
    ggcorrplot             0.1.4.1   2023-09-05 [1] CRAN (R 4.3.0)
    ggExtra                0.10.1    2023-08-21 [2] CRAN (R 4.3.0)
    ggplot2              * 3.4.4     2023-10-12 [1] CRAN (R 4.3.0)
    ggpubr               * 0.6.0     2023-02-10 [1] CRAN (R 4.3.0)
    ggrepel                0.9.4     2023-10-13 [1] CRAN (R 4.3.0)
    ggridges               0.5.4     2022-09-26 [1] CRAN (R 4.3.0)
    ggsignif               0.6.4     2022-10-13 [1] CRAN (R 4.3.0)
    ggVennDiagram          1.2.3     2023-08-14 [1] CRAN (R 4.3.0)
    globals                0.16.2    2022-11-21 [1] CRAN (R 4.3.0)
    glue                   1.6.2     2022-02-24 [1] CRAN (R 4.3.0)
    goftest                1.2-3     2021-10-07 [1] CRAN (R 4.3.0)
    googledrive            2.1.1     2023-06-11 [1] CRAN (R 4.3.0)
    googlesheets4          1.1.1     2023-06-11 [1] CRAN (R 4.3.0)
    gplots                 3.1.3     2022-04-25 [1] CRAN (R 4.3.0)
    gridExtra              2.3       2017-09-09 [1] CRAN (R 4.3.0)
    gtable                 0.3.4     2023-08-21 [1] CRAN (R 4.3.0)
    gtools                 3.9.5     2023-11-20 [1] CRAN (R 4.3.0)
    HGNChelper             0.8.1     2019-10-24 [1] CRAN (R 4.3.0)
    hms                    1.1.3     2023-03-21 [1] CRAN (R 4.3.0)
    htmltools              0.5.7     2023-11-03 [1] CRAN (R 4.3.0)
    htmlwidgets            1.6.3     2023-11-22 [1] CRAN (R 4.3.0)
    httpuv                 1.6.12    2023-10-23 [1] CRAN (R 4.3.0)
    httr                   1.4.7     2023-08-15 [1] CRAN (R 4.3.0)
    ica                    1.0-3     2022-07-08 [1] CRAN (R 4.3.0)
    igraph                 1.5.1     2023-08-10 [1] CRAN (R 4.3.0)
    IRanges                2.34.1    2023-06-22 [1] Bioconductor
    irlba                  2.3.5.1   2022-10-03 [1] CRAN (R 4.3.0)
    iterators            * 1.0.14    2022-02-05 [4] CRAN (R 4.3.0)
    job                    0.3.0     2021-06-04 [1] CRAN (R 4.3.0)
    jsonlite               1.8.8     2023-12-04 [1] CRAN (R 4.3.0)
    KernSmooth             2.23-22   2023-07-10 [2] CRAN (R 4.3.0)
    knitr                  1.45      2023-10-30 [1] CRAN (R 4.3.0)
    labeling               0.4.3     2023-08-29 [1] CRAN (R 4.3.0)
    lambda.r               1.2.4     2019-09-18 [1] CRAN (R 4.3.0)
    later                  1.3.1     2023-05-02 [1] CRAN (R 4.3.0)
    lattice                0.21-8    2023-04-05 [2] CRAN (R 4.3.0)
    lazyeval               0.2.2     2019-03-15 [1] CRAN (R 4.3.0)
    leiden                 0.4.3.1   2023-11-17 [1] CRAN (R 4.3.0)
    lifecycle              1.0.4     2023-11-07 [1] CRAN (R 4.3.0)
    listenv                0.9.0     2022-12-16 [1] CRAN (R 4.3.0)
    lmtest                 0.9-40    2022-03-21 [1] CRAN (R 4.3.0)
    lubridate            * 1.9.3     2023-09-27 [1] CRAN (R 4.3.0)
    magrittr             * 2.0.3     2022-03-30 [1] CRAN (R 4.3.0)
    MASS                   7.3-60    2023-05-04 [2] CRAN (R 4.3.0)
    Matrix                 1.6-3     2023-11-14 [1] CRAN (R 4.3.0)
    MatrixGenerics         1.12.3    2023-07-30 [1] Bioconductor
    matrixStats            1.2.0     2023-12-11 [1] CRAN (R 4.3.0)
    memoise                2.0.1     2021-11-26 [1] CRAN (R 4.3.0)
    mime                   0.12      2021-09-28 [1] CRAN (R 4.3.0)
    miniUI                 0.1.1.1   2018-05-18 [1] CRAN (R 4.3.0)
    munsell                0.5.0     2018-06-12 [1] CRAN (R 4.3.0)
    NCmisc                 1.2.0     2022-10-17 [4] CRAN (R 4.3.0)
    nlme                   3.1-163   2023-08-09 [2] CRAN (R 4.3.0)
    openxlsx               4.2.5.2   2023-02-06 [1] CRAN (R 4.3.0)
    parallelly             1.36.0    2023-05-26 [1] CRAN (R 4.3.0)
    patchwork              1.1.3     2023-08-14 [1] CRAN (R 4.3.0)
    pbapply                1.7-2     2023-06-27 [1] CRAN (R 4.3.0)
    pheatmap               1.0.12    2019-01-04 [1] CRAN (R 4.3.0)
    pillar                 1.9.0     2023-03-22 [1] CRAN (R 4.3.0)
    pkgbuild               1.4.3     2023-12-10 [1] CRAN (R 4.3.0)
    pkgconfig              2.0.3     2019-09-22 [1] CRAN (R 4.3.0)
    pkgload                1.3.3     2023-09-22 [1] CRAN (R 4.3.0)
    pkgnet                 0.4.2     2021-12-23 [1] CRAN (R 4.3.0)
    plotly                 4.10.3    2023-10-21 [1] CRAN (R 4.3.0)
    plyr                   1.8.9     2023-10-02 [1] CRAN (R 4.3.0)
    png                    0.1-8     2022-11-29 [1] CRAN (R 4.3.0)
    polyclip               1.10-6    2023-09-27 [1] CRAN (R 4.3.0)
    pracma                 2.4.4     2023-11-10 [1] CRAN (R 4.3.0)
    prettycode             1.1.0     2019-12-16 [1] CRAN (R 4.3.0)
    princurve              2.1.6     2021-01-18 [1] CRAN (R 4.3.0)
    profvis                0.3.8     2023-05-02 [1] CRAN (R 4.3.0)
    progressr              0.14.0    2023-08-10 [1] CRAN (R 4.3.0)
    promises               1.2.1     2023-08-10 [1] CRAN (R 4.3.0)
    purrr                * 1.0.2     2023-08-10 [1] CRAN (R 4.3.0)
    qs                     0.25.5    2023-02-22 [1] CRAN (R 4.3.0)
    R.methodsS3            1.8.2     2022-06-13 [1] CRAN (R 4.3.0)
    R.oo                   1.25.0    2022-06-12 [1] CRAN (R 4.3.0)
    R.utils                2.12.3    2023-11-18 [1] CRAN (R 4.3.0)
    R6                     2.5.1     2021-08-19 [1] CRAN (R 4.3.0)
    ragg                   1.2.6     2023-10-10 [1] CRAN (R 4.3.0)
    RANN                   2.6.1     2019-01-08 [1] CRAN (R 4.3.0)
    RApiSerialize          0.1.2     2022-08-25 [1] CRAN (R 4.3.0)
    RColorBrewer           1.1-3     2022-04-03 [1] CRAN (R 4.3.0)
    Rcpp                   1.0.11    2023-07-06 [1] CRAN (R 4.3.0)
    RcppAnnoy              0.0.21    2023-07-02 [1] CRAN (R 4.3.0)
    RcppHNSW               0.5.0     2023-09-19 [1] CRAN (R 4.3.0)
    RcppParallel           5.1.7     2023-02-27 [4] CRAN (R 4.3.0)
    RCurl                  1.98-1.13 2023-11-02 [1] CRAN (R 4.3.0)
    readr                * 2.1.4     2023-02-10 [1] CRAN (R 4.3.0)
    remotes                2.4.2.1   2023-07-18 [1] CRAN (R 4.3.0)
    renv                   1.0.2     2023-08-15 [2] CRAN (R 4.3.0)
    reshape2               1.4.4     2020-04-09 [1] CRAN (R 4.3.0)
    reticulate             1.32.0    2023-09-11 [1] CRAN (R 4.3.0)
    rex                    1.2.1     2021-11-26 [4] CRAN (R 4.3.0)
    rlang                  1.1.2     2023-11-04 [1] CRAN (R 4.3.0)
    rmarkdown              2.25      2023-09-18 [1] CRAN (R 4.3.0)
    ROCR                   1.0-11    2020-05-02 [1] CRAN (R 4.3.0)
    rprojroot              2.0.4     2023-11-05 [1] CRAN (R 4.3.0)
    RSpectra               0.16-1    2022-04-24 [1] CRAN (R 4.3.0)
    rstatix                0.7.2     2023-02-01 [1] CRAN (R 4.3.0)
    rstudioapi             0.15.0    2023-07-07 [1] CRAN (R 4.3.0)
    Rtsne                  0.16      2022-04-17 [1] CRAN (R 4.3.0)
    RVenn                  1.1.0     2019-07-18 [1] CRAN (R 4.3.0)
    S4Vectors              0.38.2    2023-09-22 [1] Bioconductor
    scales                 1.3.0     2023-11-28 [1] CRAN (R 4.3.0)
    scattermore            1.2       2023-06-12 [1] CRAN (R 4.3.0)
    sctransform            0.4.1     2023-10-19 [1] CRAN (R 4.3.0)
    sessioninfo            1.2.2     2021-12-06 [1] CRAN (R 4.3.0)
    Seurat               * 5.0.1     2023-11-17 [1] CRAN (R 4.3.0)
    SeuratObject         * 5.0.1     2023-11-17 [1] CRAN (R 4.3.0)
    shiny                  1.8.0     2023-11-17 [1] CRAN (R 4.3.0)
    sm                     2.2-5.7.1 2022-07-04 [1] CRAN (R 4.3.0)
    SoupX                  1.6.2     2022-11-01 [1] CRAN (R 4.3.0)
    sp                   * 2.1-1     2023-10-16 [1] CRAN (R 4.3.0)
    spam                   2.10-0    2023-10-23 [1] CRAN (R 4.3.0)
    sparseMatrixStats      1.12.2    2023-07-02 [1] Bioconductor
    spatstat.data          3.0-3     2023-10-24 [1] CRAN (R 4.3.0)
    spatstat.explore       3.2-3     2023-09-07 [1] CRAN (R 4.3.0)
    spatstat.geom          3.2-7     2023-10-20 [1] CRAN (R 4.3.0)
    spatstat.random        3.1-6     2023-09-09 [1] CRAN (R 4.3.0)
    spatstat.sparse        3.0-3     2023-10-24 [1] CRAN (R 4.3.0)
    spatstat.utils         3.0-4     2023-10-24 [1] CRAN (R 4.3.0)
    stringdist             0.9.10    2022-11-07 [4] CRAN (R 4.3.0)
    stringfish             0.15.8    2023-05-30 [1] CRAN (R 4.3.0)
    stringi                1.8.3     2023-12-11 [1] CRAN (R 4.3.0)
    stringr              * 1.5.1     2023-11-14 [1] CRAN (R 4.3.0)
    survival               3.5-7     2023-08-14 [2] CRAN (R 4.3.0)
    systemfonts            1.0.5     2023-10-09 [1] CRAN (R 4.3.0)
    tensor                 1.5       2012-05-05 [1] CRAN (R 4.3.0)
    testthat             * 3.2.1     2023-12-02 [1] CRAN (R 4.3.0)
    textshaping            0.3.7     2023-10-09 [1] CRAN (R 4.3.0)
    tibble               * 3.2.1     2023-03-20 [1] CRAN (R 4.3.0)
    tictoc               * 1.2       2023-04-23 [1] CRAN (R 4.3.0)
    tidyr                * 1.3.0     2023-01-24 [1] CRAN (R 4.3.0)
    tidyselect             1.2.0     2022-10-10 [1] CRAN (R 4.3.0)
    tidyverse            * 2.0.0     2023-02-22 [1] CRAN (R 4.3.0)
    timechange             0.2.0     2023-01-11 [1] CRAN (R 4.3.0)
    tzdb                   0.4.0     2023-05-12 [1] CRAN (R 4.3.0)
    urlchecker             1.0.1     2021-11-30 [1] CRAN (R 4.3.0)
    usethis                2.2.2     2023-07-06 [1] CRAN (R 4.3.0)
    utf8                   1.2.4     2023-10-22 [1] CRAN (R 4.3.0)
    uwot                   0.1.16    2023-06-29 [1] CRAN (R 4.3.0)
    vctrs                  0.6.5     2023-12-01 [1] CRAN (R 4.3.0)
    VennDiagram            1.7.3     2022-04-12 [1] CRAN (R 4.3.0)
    vioplot                0.4.0     2022-12-09 [1] CRAN (R 4.3.0)
    viridisLite            0.4.2     2023-05-02 [1] CRAN (R 4.3.0)
    visNetwork             2.1.2     2022-09-29 [4] CRAN (R 4.3.0)
    vroom                  1.6.4     2023-10-02 [1] CRAN (R 4.3.0)
    withr                  2.5.2     2023-10-30 [1] CRAN (R 4.3.0)
    xfun                   0.41      2023-11-01 [1] CRAN (R 4.3.0)
    xtable                 1.8-4     2019-04-21 [1] CRAN (R 4.3.0)
    XVector                0.40.0    2023-04-25 [1] Bioconductor
    zip                    2.3.0     2023-04-17 [1] CRAN (R 4.3.0)
    zlibbioc               1.46.0    2023-04-25 [1] Bioconductor
    zoo                    1.8-12    2023-04-13 [1] CRAN (R 4.3.0)

 [2] /software/f2022/software/r-bundle-bioconductor/3.17-foss-2022b-r-4.3.0
 [3] /software/f2022/software/arrow-r/12.0.0-foss-2022b-r-4.3.0
 [4] /software/f2022/software/r/4.3.0-foss-2022b/lib64/R/library

 V ── Loaded and on-disk version mismatch.
 P ── Loaded and on-disk path mismatch.
vertesy commented 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.
shivUSF commented 8 months ago

I am facing the exact same issue. Is this due to the new updates or something specific when subset is done?

vertesy commented 8 months ago

I did not have similar problems before v5.

shivUSF commented 8 months ago

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.

vertesy commented 8 months ago

Well, I do not subset. This however really limits me in testing parameters.

behrangsh commented 8 months ago

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

moutazhelal commented 6 months ago

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 in split(): ! The following layers are already split: ‘counts’, ‘data’ Please join before splitting Run rlang::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 [[<- Run rlang::last_trace() to see where the error occurred.

When I print the myeloid_cellsobject, 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 RNAassay, I observed that the dataand countslayers 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.

jonhsussman commented 6 months ago

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)
stupidstupidstupidstupid commented 6 months ago

check your "RNA" assay and make sure the number of cells in it match the number in your metadata

Xianyugeh commented 6 months ago

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.

zsolt-balazs commented 1 month ago

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