stuart-lab / signac

R toolkit for the analysis of single-cell chromatin data
https://stuartlab.org/signac/
Other
328 stars 88 forks source link

RunTFIDF: Error in vapply(X = keyed.objects, FUN = function(x) #872

Closed Telogen closed 2 years ago

Telogen commented 2 years ago

Hi,

When I do RunTFIDF()

pbmc.ATAC <- RunTFIDF(pbmc.ATAC)

I receive this:

Performing TF-IDF normalization Error in vapply(X = keyed.objects, FUN = function(x) { : values must be length 1, but FUN(X[[1]]) result is length 0 In addition: Warning message: In RunTFIDF.default(object = GetAssayData(object = object, slot = "counts"), : Some features contain 0 total counts

Thanks a lot for your help!

timoast commented 2 years ago

Can you show the output of sessionInfo()?

Telogen commented 2 years ago

sure.

sessionInfo() R version 4.1.0 (2021-05-18) Platform: x86_64-conda-linux-gnu (64-bit) Running under: CentOS Linux 7 (Core)

Matrix products: default BLAS/LAPACK: /local/txm/anaconda3/envs/R4.1/lib/libopenblasp-r0.3.17.so

locale: [1] LC_CTYPE=zh_CN.UTF-8 LC_NUMERIC=C [3] LC_TIME=zh_CN.UTF-8 LC_COLLATE=zh_CN.UTF-8 [5] LC_MONETARY=zh_CN.UTF-8 LC_MESSAGES=zh_CN.UTF-8 [7] LC_PAPER=zh_CN.UTF-8 LC_NAME=C [9] LC_ADDRESS=C LC_TELEPHONE=C [11] LC_MEASUREMENT=zh_CN.UTF-8 LC_IDENTIFICATION=C

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

other attached packages: [1] EnsDb.Mmusculus.v79_2.99.0 ensembldb_2.18.2 [3] AnnotationFilter_1.18.0 GenomicFeatures_1.46.1 [5] AnnotationDbi_1.56.2 Biobase_2.54.0 [7] GenomicRanges_1.46.0 GenomeInfoDb_1.30.0 [9] IRanges_2.28.0 S4Vectors_0.32.2 [11] BiocGenerics_0.40.0 ggplot2_3.3.5 [13] SeuratObject_4.0.3 Seurat_4.0.5 [15] Signac_1.4.0 devtools_2.4.2 [17] usethis_2.1.3

loaded via a namespace (and not attached): [1] utf8_1.2.2 reticulate_1.22 [3] tidyselect_1.1.1 RSQLite_2.2.8 [5] htmlwidgets_1.5.4 grid_4.1.0 [7] docopt_0.7.1 BiocParallel_1.28.0 [9] Rtsne_0.15 munsell_0.5.0 [11] codetools_0.2-18 ica_1.0-2 [13] future_1.23.0 miniUI_0.1.1.1 [15] withr_2.4.2 colorspace_2.0-2 [17] filelock_1.0.2 ROCR_1.0-11 [19] tensor_1.5 listenv_0.8.0 [21] MatrixGenerics_1.6.0 slam_0.1-49 [23] GenomeInfoDbData_1.2.7 polyclip_1.10-0 [25] bit64_4.0.5 farver_2.1.0 [27] rprojroot_2.0.2 parallelly_1.28.1 [29] vctrs_0.3.8 generics_0.1.1 [31] BiocFileCache_2.2.0 lsa_0.73.2 [33] ggseqlogo_0.1 R6_2.5.1 [35] DelayedArray_0.20.0 bitops_1.0-7 [37] spatstat.utils_2.2-0 cachem_1.0.6 [39] assertthat_0.2.1 promises_1.2.0.1 [41] BiocIO_1.4.0 scales_1.1.1 [43] gtable_0.3.0 globals_0.14.0 [45] processx_3.5.2 goftest_1.2-3 [47] rlang_0.4.12 RcppRoll_0.3.0 [49] splines_4.1.0 rtracklayer_1.54.0 [51] lazyeval_0.2.2 spatstat.geom_2.3-0 [53] yaml_2.2.1 BiocManager_1.30.16 [55] reshape2_1.4.4 abind_1.4-5 [57] httpuv_1.6.3 tools_4.1.0 [59] ellipsis_0.3.2 spatstat.core_2.3-1 [61] RColorBrewer_1.1-2 sessioninfo_1.2.1 [63] ggridges_0.5.3 Rcpp_1.0.7 [65] plyr_1.8.6 progress_1.2.2 [73] deldir_1.0-6 pbapply_1.5-0 [75] cowplot_1.1.1 zoo_1.8-9 [77] SummarizedExperiment_1.24.0 ggrepel_0.9.1 [79] cluster_2.1.2 fs_1.5.0 [81] magrittr_2.0.1 data.table_1.14.2 [83] scattermore_0.7 lmtest_0.9-39 [85] RANN_2.6.1 SnowballC_0.7.0 [87] ProtGenerics_1.26.0 fitdistrplus_1.1-6 [89] matrixStats_0.61.0 pkgload_1.2.3 [91] hms_1.1.1 patchwork_1.1.1 [93] mime_0.12 xtable_1.8-4 [95] XML_3.99-0.8 sparsesvd_0.2 [97] gridExtra_2.3 testthat_3.1.0 [99] compiler_4.1.0 biomaRt_2.50.0 [101] tibble_3.1.6 KernSmooth_2.23-20 [103] crayon_1.4.2 htmltools_0.5.2 [105] mgcv_1.8-38 later_1.3.0 [107] tidyr_1.1.4 DBI_1.1.1 [109] tweenr_1.0.2 dbplyr_2.1.1 [111] MASS_7.3-54 rappdirs_0.3.3 [113] Matrix_1.3-4 cli_3.1.0 [115] parallel_4.1.0 igraph_1.2.8 [117] pkgconfig_2.0.3 GenomicAlignments_1.30.0 [119] plotly_4.10.0 spatstat.sparse_2.0-0 [121] xml2_1.3.2 XVector_0.34.0 [123] stringr_1.4.0 callr_3.7.0 [125] digest_0.6.28 sctransform_0.3.2 [127] RcppAnnoy_0.0.19 spatstat.data_2.1-0 [129] Biostrings_2.62.0 leiden_0.3.9 [131] fastmatch_1.1-3 uwot_0.1.10 [133] restfulr_0.0.13 curl_4.3.2 [135] shiny_1.7.1 Rsamtools_2.10.0 [137] rjson_0.2.20 lifecycle_1.0.1 [139] nlme_3.1-153 jsonlite_1.7.2 [141] desc_1.4.0 viridisLite_0.4.0 [143] fansi_0.5.0 pillar_1.6.4 [145] lattice_0.20-45 KEGGREST_1.34.0 [147] fastmap_1.1.0 httr_1.4.2 [149] pkgbuild_1.2.0 survival_3.2-13 [151] glue_1.5.0 remotes_2.4.1 [153] qlcMatrix_0.9.7 png_0.1-7 [155] bit_4.0.4 ggforce_0.3.3 [157] stringi_1.7.5 blob_1.2.2 [159] memoise_2.0.0 dplyr_1.0.7 [161] irlba_2.3.3 future.apply_1.8.1

timoast commented 2 years ago

This could be an issue related to SeuratObject v4.0.3, can you try installing the previous SeuratObject version (4.0.2) and see if you still have this issue:

remotes::install_version(package = 'SeuratObject', version = package_version('4.0.2'))

Make sure to restart R after installing the SeuratObject package

Telogen commented 2 years ago

That pretty cool bro. Thanks a lot for your help!

FloWuenne commented 2 years ago

@timoast Thank you for pointing out this error here!

I am writing Galaxy wrappers for Signac at the moment and I ran into exactly this error when trying to add Annotations to a seurat object in Signac.

Error in vapply(X = keyed.objects, FUN = function(x) { : 
  values must be length 1,
 but FUN(X[[1]]) result is length 0
Calls: Annotation<- ... Annotation<-.Seurat -> [[<- -> [[<- -> Key -> Key.Seurat -> vapply
Execution halted

The problem I had, is that the dependency for SeuratObject in the conda package for Signac seems to be 4.0.3, while my local R installation had 4.0.2 installed. Since Galaxy uses conda for building environments, SeuratObject 4.0.3 was installed in my Galaxy environment the background, creating this issue.

I would suggest changing the conda dependency of Signac to SeuratObject 4.0.2 as long as this issue remains?!

timoast commented 2 years ago

Hi @FloWuenne

I don't actually maintain the r-signac conda build, but it looks like the version dependency is correctly set as SeuratObject >=4.0.0 (https://github.com/bioconda/bioconda-recipes/blob/master/recipes/r-signac/meta.yaml#L36). My guess is that it simply builds using the latest release that meets the dependency requirements, which is 4.0.3.

R doesn't allow setting version dependencies lower than a certain version, only above, so it's not possible to set the dependency in Signac to SeuratObject<4.0.3 in the R package. I believe you could pin the conda package to 4.0.2, but there should be a patch release of SeuratObject coming very soon that will resolve this so I'm not sure it's worth it.

As a workaround you can create a conda environment with SeuratObject 4.0.2 and Signac by specifying the versions like this:

conda create -n testenv -c bioconda r-seuratobject==4.0.2 r-signac
FloWuenne commented 2 years ago

Thanks for the quick reply @timoast!

I did in fact fix this it by specifying the exact version number of SeuratObject in the requirements of the Galaxy tool. It just took my a really long time to find what the problem was ^^.

If this error will be fixed with a new release of SeuratObject you are right and it might not actually be worth doing anything on your end. I just wanted anybody using the conda package to be aware that this error might occur :).

timoast commented 2 years ago

Yeah it's a good point and currently anyone using the latest SeuratObject release is going to run into this error. I pinned this issue to try to make the solution easier to find but I'm sure it's still costing people time. Hoping we can get the SeuratObject release out soon

timoast commented 2 years ago

SeuratObject 4.0.4 is now out on CRAN and should solve these issues

drewmard commented 2 years ago

Hi, I am running into similar issues, even after updating to SeuratObject 4.0.4. Any help would be appreciated! Please see some example outputs below:

> packageVersion("Seurat")
[1] '4.0.5'
> packageVersion("Signac")
[1] '1.4.0'
> packageVersion("SeuratObject")                           
[1] '4.0.4'
> dfseurat[[i]]
An object of class Seurat 
155523 features across 4215 samples within 1 assay 
Active assay: ATAC (155523 features, 0 variable features)
> FindTopFeatures(dfseurat[[i]][["ATAC"]], min.cutoff = 10)
ChromatinAssay data with 155523 features for 4215 cells
Variable features: 67495 
Genome: 
Annotation present: TRUE 
Motifs present: FALSE 
Fragment files: 1 
>   dfseurat[[i]][["ATAC"]] <- FindTopFeatures(dfseurat[[i]][["ATAC"]], min.cutoff = 10)
Error in vapply(X = keyed.objects, FUN = function(x) { : 
  values must be length 1,
 but FUN(X[[1]]) result is length 0
> FindTopFeatures(dfseurat[[i]], min.cutoff = 10,assay="ATAC")
Error in vapply(X = keyed.objects, FUN = function(x) { : 
  values must be length 1,
 but FUN(X[[1]]) result is length 0
>   dfseurat[[i]] <- FindTopFeatures(dfseurat[[i]], min.cutoff = 10,assay="ATAC")
Error in vapply(X = keyed.objects, FUN = function(x) { : 
  values must be length 1,
 but FUN(X[[1]]) result is length 0

Same errors occur for the RunTFIDF function. Thank you in advance! -Andrew

genecell commented 2 years ago

SeuratObject 4.0.4 is now out on CRAN and should solve these issues

Great! I have just tested SeuratObject 4.0.4 and it solved the above issues.

timoast commented 2 years ago

@drewmard you might need to re-construct the Seurat object using SeuratObject 4.0.4

drewmard commented 2 years ago

@timo

@drewmard you might need to re-construct the Seurat object using SeuratObject 4.0.4

Yep, running from the top and re-constructing using 4.0.4 did the trick. thank you!

ProphetDarkland commented 2 years ago

Hi, I've also encountered this issue, I have upgraded SeuratObject to 4.0.4, and restart R to rerun the pipeline. But the issue still exists. I would be really appreciated if you can help me solve this.

The error is as follows:

> library(SeuratData)
> library(Seurat)
> library(Signac)
> library(EnsDb.Hsapiens.v86)
> library(ggplot2)
> library(cowplot)
> pbmc.rna <- LoadData("pbmcMultiome", "pbmc.rna")
There were 36 warnings (use warnings() to see them)
> pbmc.atac <- LoadData("pbmcMultiome", "pbmc.atac")
There were 36 warnings (use warnings() to see them)
> pbmc.rna <- subset(pbmc.rna, seurat_annotations != "filtered")
> pbmc.atac <- subset(pbmc.atac, seurat_annotations != "filtered")
Error in vapply(X = keyed.objects, FUN = function(x) { :
  values must be length 1,
 but FUN(X[[1]]) result is length 0

And the sessionInfo:

> sessionInfo()
R version 4.1.0 (2021-05-18)
Platform: x86_64-conda-linux-gnu (64-bit)
Running under: Red Hat Enterprise Linux Server 7.6 (Maipo)

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

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

other attached packages:
[1] pbmcMultiome.SeuratData_0.1.2 Signac_1.4.0
[3] SeuratObject_4.0.4            Seurat_4.0.5
[5] SeuratData_0.2.1

loaded via a namespace (and not attached):
  [1] fastmatch_1.1-3        plyr_1.8.6             igraph_1.2.8
  [4] lazyeval_0.2.2         splines_4.1.0          BiocParallel_1.26.2
  [7] listenv_0.8.0          scattermore_0.7        SnowballC_0.7.0
 [10] usethis_2.1.3          GenomeInfoDb_1.28.4    ggplot2_3.3.5
 [13] digest_0.6.28          htmltools_0.5.2        fansi_0.5.0
 [16] magrittr_2.0.1         memoise_2.0.0          tensor_1.5
 [19] cluster_2.1.2          ROCR_1.0-11            remotes_2.4.1
 [22] globals_0.14.0         Biostrings_2.60.2      matrixStats_0.61.0
 [25] docopt_0.7.1           spatstat.sparse_2.0-0  prettyunits_1.1.1
 [28] colorspace_2.0-2       rappdirs_0.3.3         ggrepel_0.9.1
 [31] dplyr_1.0.7            callr_3.7.0            sparsesvd_0.2
 [34] crayon_1.4.2           RCurl_1.98-1.5         jsonlite_1.7.2
 [37] spatstat.data_2.1-0    survival_3.2-13        zoo_1.8-9
 [40] glue_1.5.1             polyclip_1.10-0        gtable_0.3.0
 [43] zlibbioc_1.38.0        XVector_0.32.0         leiden_0.3.9
 [46] pkgbuild_1.2.0         future.apply_1.8.1     BiocGenerics_0.38.0
 [49] abind_1.4-5            scales_1.1.1           DBI_1.1.1
 [52] miniUI_0.1.1.1         Rcpp_1.0.7             viridisLite_0.4.0
 [55] xtable_1.8-4           reticulate_1.22        spatstat.core_2.3-1
 [58] stats4_4.1.0           htmlwidgets_1.5.4      httr_1.4.2
 [61] RColorBrewer_1.1-2     ellipsis_0.3.2         ica_1.0-2
 [64] pkgconfig_2.0.3        farver_2.1.0           ggseqlogo_0.1
 [67] uwot_0.1.10            deldir_1.0-6           utf8_1.2.2
 [70] tidyselect_1.1.1       rlang_0.4.12           reshape2_1.4.4
 [73] later_1.3.0            munsell_0.5.0          tools_4.1.0
 [76] cachem_1.0.6           cli_3.1.0              generics_0.1.1
 [79] devtools_2.4.2         ggridges_0.5.3         stringr_1.4.0
 [82] fastmap_1.1.0          goftest_1.2-3          processx_3.5.2
 [85] fs_1.5.0               fitdistrplus_1.1-6     purrr_0.3.4
 [88] RANN_2.6.1             pbapply_1.5-0          future_1.23.0
 [91] nlme_3.1-153           mime_0.12              slam_0.1-49
 [94] RcppRoll_0.3.0         compiler_4.1.0         curl_4.3.2
 [97] plotly_4.10.0          png_0.1-7              testthat_3.1.0
[100] spatstat.utils_2.2-0   tibble_3.1.6           tweenr_1.0.2
[103] stringi_1.7.5          ps_1.6.0               desc_1.4.0
[106] lattice_0.20-45        Matrix_1.3-4           vctrs_0.3.8
[109] pillar_1.6.4           lifecycle_1.0.1        spatstat.geom_2.3-0
[112] lmtest_0.9-39          RcppAnnoy_0.0.19       data.table_1.14.2
[115] cowplot_1.1.1          bitops_1.0-7           irlba_2.3.3
[118] httpuv_1.6.3           patchwork_1.1.1        GenomicRanges_1.44.0
[121] R6_2.5.1               promises_1.2.0.1       KernSmooth_2.23-20
[124] gridExtra_2.3          lsa_0.73.2             IRanges_2.26.0
[127] parallelly_1.28.1      sessioninfo_1.2.1      codetools_0.2-18
[130] pkgload_1.2.3          MASS_7.3-54            assertthat_0.2.1
[133] rprojroot_2.0.2        withr_2.4.2            qlcMatrix_0.9.7
[136] sctransform_0.3.2      Rsamtools_2.8.0        S4Vectors_0.30.2
[139] GenomeInfoDbData_1.2.6 mgcv_1.8-38            parallel_4.1.0
[142] grid_4.1.0             rpart_4.1-15           tidyr_1.1.4
[145] Rtsne_0.15             pbdZMQ_0.3-6           ggforce_0.3.3
[148] shiny_1.7.1
timoast commented 2 years ago

The pbmcMultiome data package in SeuratData needs to be updated using SeuratObject 4.0.4 (@mojaveazure)

As a workaround, you can set the key for the ATAC assay and it should solve this issue: pbmc.atac@assays$ATAC@key <- "atac_"

ProphetDarkland commented 2 years ago

Thanks very much! It solved my issues!