ludvigla / semla

Other
47 stars 6 forks source link

Error in MapLabels.Seurat() #20

Open vgilbart opened 7 months ago

vgilbart commented 7 months ago

Hello,

Following the doc in the Disconnect regions part, I tried to run, with the same data:

MapLabels(se, column_name = "9_split", override_plot_dims = TRUE, 
          image_use = "raw", drop_na = TRUE, pt_size = 2) +
  plot_layout(guides = "collect") &
  theme(legend.position = "right") &
  guides(fill = guide_legend(override.aes = list(size = 3), ncol = 2))

and got the following error:

Error in `bind_cols()` at ludvigla-semla-e3dae98/R/visualization_spatial.R:873:3:
! Can't recycle `..1` (size 3813) to match `..2` (size 176).
Run `rlang::last_trace()` to see where the error occurred.
Warning message:
Removing 3637 cells missing data for vars requested 

The same problem occurs with MapFeatures().

To create my renv, I first used renv::restore() with the lock.file provided in this repo, then renv::install("ludvigla/semla") which also asked to update some packages (including Seurat, which might be the reason for this error, but I didn't check further).

sessionInfo() ```r > sessionInfo() R version 4.3.2 (2023-10-31) Platform: aarch64-apple-darwin20 (64-bit) Running under: macOS Ventura 13.6.1 Matrix products: default BLAS: /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib LAPACK: /Library/Frameworks/R.framework/Versions/4.3-arm64/Resources/lib/libRlapack.dylib; LAPACK version 3.11.0 locale: [1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8 time zone: Europe/Paris tzcode source: internal attached base packages: [1] stats graphics grDevices datasets utils methods base other attached packages: [1] hdf5r_1.3.8 semla_1.1.6 ggplot2_3.4.4 dplyr_1.1.4 [5] tibble_3.2.1 rhdf5_2.42.1 patchwork_1.1.3 Seurat_5.0.1 [9] SeuratObject_5.0.1 sp_2.0-0 loaded via a namespace (and not attached): [1] RColorBrewer_1.1-3 jsonlite_1.8.8 magrittr_2.0.3 [4] spatstat.utils_3.0-3 magick_2.8.1 farver_2.1.1 [7] vctrs_0.6.5 ROCR_1.0-11 spatstat.explore_3.2-1 [10] htmltools_0.5.7 forcats_1.0.0 Rhdf5lib_1.20.0 [13] sctransform_0.4.1 parallelly_1.36.0 KernSmooth_2.23-22 [16] htmlwidgets_1.6.4 ica_1.0-3 plyr_1.8.8 [19] plotly_4.10.2 zoo_1.8-12 igraph_1.5.1 [22] mime_0.12 lifecycle_1.0.3 pkgconfig_2.0.3 [25] Matrix_1.6-3 R6_2.5.1 fastmap_1.1.1 [28] fitdistrplus_1.1-11 future_1.33.0 shiny_1.8.0 [31] digest_0.6.33 colorspace_2.1-0 tensor_1.5 [34] RSpectra_0.16-1 irlba_2.3.5.1 progressr_0.14.0 [37] fansi_1.0.4 spatstat.sparse_3.0-2 httr_1.4.7 [40] polyclip_1.10-4 abind_1.4-5 compiler_4.3.2 [43] bit64_4.0.5 withr_2.5.0 fastDummies_1.7.3 [46] MASS_7.3-60 tools_4.3.2 lmtest_0.9-40 [49] httpuv_1.6.11 future.apply_1.11.0 goftest_1.2-3 [52] glue_1.6.2 dbscan_1.1-12 nlme_3.1-163 [55] rhdf5filters_1.10.1 promises_1.2.1 grid_4.3.2 [58] Rtsne_0.16 cluster_2.1.4 reshape2_1.4.4 [61] generics_0.1.3 gtable_0.3.4 spatstat.data_3.0-1 [64] tidyr_1.3.0 data.table_1.14.8 utf8_1.2.3 [67] spatstat.geom_3.2-4 RcppAnnoy_0.0.21 ggrepel_0.9.3 [70] RANN_2.6.1 pillar_1.9.0 stringr_1.5.0 [73] spam_2.10-0 RcppHNSW_0.5.0 later_1.3.1 [76] splines_4.3.2 lattice_0.21-9 renv_1.0.3 [79] survival_3.5-7 bit_4.0.5 deldir_1.0-9 [82] tidyselect_1.2.0 miniUI_0.1.1.1 pbapply_1.7-2 [85] gridExtra_2.3 scattermore_1.2 matrixStats_1.0.0 [88] stringi_1.7.12 lazyeval_0.2.2 yaml_2.3.7 [91] codetools_0.2-19 BiocManager_1.30.22 cli_3.6.1 [94] uwot_0.1.16 xtable_1.8-4 reticulate_1.31 [97] munsell_0.5.0 Rcpp_1.0.11 globals_0.16.2 [100] spatstat.random_3.1-5 zeallot_0.1.0 png_0.1-8 [103] parallel_4.3.2 ellipsis_0.3.2 dotCall64_1.1-1 [106] listenv_0.9.0 viridisLite_0.4.2 scales_1.3.0 [109] ggridges_0.5.4 leiden_0.4.3 purrr_1.0.2 [112] rlang_1.1.2 cowplot_1.1.1 shinyjs_2.1.0 ```

I solved it with the minor changes in this commit from my forked semla. This might be a change needed in the future!

lfranzen commented 7 months ago

Hi @vgilbart, thank you for highlighting this issue! We'll look into it as soon as possible, and glad that you managed to find a solution to it that works for you in the meanwhile.

I see that you're using Seurat v5 and we haven't had time yet to test the semla compatibility with v5, which we need to tend to and will hopefully solve some of these kinds of issues.

I'll let you know once we've updated semla, and apologies in advance for the delay!

Cheers, Lovisa

lfranzen commented 5 months ago

Hello again @vgilbart, just want to let you know that we've just pushed an update to semla that contains your fix to this issue – thank you again for noticing! The issue did seem to come from v5 of SeuratObject.

We still haven't released a new version of semla so the update is just in the dev version, but we're working on a new release in which we check compatibility with Seurat v5.

AcetylCoALab commented 1 month ago

I still encounter this problem in the current version, but there is no error when running the sample data. How can I solve this problem? I am using seurat V4. Plot multiple features

MapMultipleFeatures(se_brain_spatial, ncol =5,label_by = 'sample',

  • image_use = "raw",

  • pt_size = 1, max_cutoff = 0.99,
  • override_plot_dims = TRUE,
  • colors = c("#4DBBD5FF","#E64B35FF","#00A087FF","#3C5488FF", "#F39B7FFF","#8491B4FF",
  • "#91D1C2FF","#DC0000FF","#7E6148FF","#BC3C29FF"),
  • features = selected_celltypes[1:9]) +
  • plot_layout(guides = "collect") Error in bind_cols(): ! Can't recycle ..1 (size 18407) to match ..2 (size 18406). Run rlang::last_trace() to see where the error occurred. Warning message: Removing 1 cells missing data for vars requested
AcetylCoALab commented 1 month ago

我发现在数据中存在NA值,因此我对NA进行了填补。之后能够正常运行了。但是作者能否进一步更新,这样可以更加方便的使用。table(is.na(se_brain_spatial@assays[["celltypeprops"]]@data@x))

FALSE TRUE 145778 10

se_brain_spatial@assays[["celltypeprops"]]@data@x[is.na(se_brain_spatial@assays[["celltypeprops"]]@data@x)] <- mean(se_brain_spatial@assays[["celltypeprops"]]@data@x, na.rm = TRUE)