Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The "mapping" parameter cannot be used correctly when using sc_dim() #16

Closed
WhyLIM opened this issue Dec 4, 2023 · 5 comments
Closed

Comments

@WhyLIM
Copy link

WhyLIM commented Dec 4, 2023

My code:

> sc_dim(sce.all.int, reduction = "tsne", mapping = aes(colour = RNA_snn_res.0.8))
Error:
! Problem while computing aesthetics.Error occurred in the 1st layer.
Caused by error:
! object 'RNA_snn_res.0.8' not found
Run `rlang::last_trace()` to see where the error occurred.
> rlang::last_trace()
<error/rlang_error>
Error:
! Problem while computing aesthetics.Error occurred in the 1st layer.
Caused by error:
! object 'RNA_snn_res.0.8' not found
---
Backtrace:1. ├─base (local) `<fn>`(x)
  2. └─ggplot2:::print.ggplot(x)
  3.   ├─ggplot2::ggplot_build(x)
  4.   └─ggplot2:::ggplot_build.ggplot(x)
  5.     └─ggplot2:::by_layer(...)
  6.       ├─rlang::try_fetch(...)
  7.       │ ├─base::tryCatch(...)
  8.       │ │ └─base (local) tryCatchList(expr, classes, parentenv, handlers)
  9.       │ │   └─base (local) tryCatchOne(expr, names, parentenv, handlers[[1L]])
 10.       │ │     └─base (local) doTryCatch(return(expr), name, parentenv, handler)
 11.       │ └─base::withCallingHandlers(...)
 12.       └─ggplot2 (local) f(l = layers[[i]], d = data[[i]])
 13.         └─l$compute_aesthetics(d, plot)
 14.           └─ggplot2 (local) compute_aesthetics(..., self = self)
 15.             └─ggplot2:::scales_add_defaults(...)
 16.               └─base::lapply(aesthetics[new_aesthetics], eval_tidy, data = data)
 17.                 └─rlang (local) FUN(X[[i]], ...)
Run rlang::last_trace(drop = FALSE) to see 5 hidden frames.
> rlang::last_trace(drop = FALSE)
<error/rlang_error>
Error:
! Problem while computing aesthetics.Error occurred in the 1st layer.
Caused by error:
! object 'RNA_snn_res.0.8' not found
---
Backtrace:1. ├─base (local) `<fn>`(x)
  2. ├─ggplot2:::print.ggplot(x)
  3. │ ├─ggplot2::ggplot_build(x)
  4. │ └─ggplot2:::ggplot_build.ggplot(x)
  5. │   └─ggplot2:::by_layer(...)
  6. │     ├─rlang::try_fetch(...)
  7. │     │ ├─base::tryCatch(...)
  8. │     │ │ └─base (local) tryCatchList(expr, classes, parentenv, handlers)
  9. │     │ │   └─base (local) tryCatchOne(expr, names, parentenv, handlers[[1L]])
 10. │     │ │     └─base (local) doTryCatch(return(expr), name, parentenv, handler)
 11. │     │ └─base::withCallingHandlers(...)
 12. │     └─ggplot2 (local) f(l = layers[[i]], d = data[[i]])
 13. │       └─l$compute_aesthetics(d, plot)
 14. │         └─ggplot2 (local) compute_aesthetics(..., self = self)
 15. │           └─ggplot2:::scales_add_defaults(...)
 16. │             └─base::lapply(aesthetics[new_aesthetics], eval_tidy, data = data)
 17. │               └─rlang (local) FUN(X[[i]], ...)
 18. └─base::.handleSimpleError(...)
 19.   └─rlang (local) h(simpleError(msg, call))
 20.     └─handlers[[1L]](cnd)
 21.       └─cli::cli_abort(...)
 22.         └─rlang::abort(...)

It seems that the specified column could not be found in the seurat object.

> colnames(sce.all.int@meta.data)
 [1] "orig.ident"       "nCount_RNA"       "nFeature_RNA"     "percent_mito"     "percent_ribo"     "percent_hb"       "RNA_snn_res.0.01"
 [8] "seurat_clusters"  "RNA_snn_res.0.05" "RNA_snn_res.0.1"  "RNA_snn_res.0.2"  "RNA_snn_res.0.3"  "RNA_snn_res.0.5"  "RNA_snn_res.0.8" 
[15] "RNA_snn_res.1" 

sessionInfo:

> sessionInfo()
R version 4.3.1 (2023-06-16)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 22.04.3 LTS

Matrix products: default
BLAS:   /usr/lib/x86_64-linux-gnu/blas/libblas.so.3.10.0 
LAPACK: /usr/lib/x86_64-linux-gnu/lapack/liblapack.so.3.10.0

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

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

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

other attached packages:
 [1] ggsc_1.0.2         patchwork_1.1.3    cowplot_1.1.1      clustree_0.5.1     ggraph_2.1.0       future_1.33.0      lubridate_1.9.3   
 [8] forcats_1.0.0      stringr_1.5.1      dplyr_1.1.4        purrr_1.0.2        readr_2.1.4        tidyr_1.3.0        tibble_3.2.1      
[15] tidyverse_2.0.0    ggsci_3.0.0        harmony_1.1.0      Rcpp_1.0.11        COSG_0.9.0         R.utils_2.12.3     R.oo_1.25.0       
[22] R.methodsS3_1.8.2  data.table_1.14.8  ggplot2_3.4.4      SeuratObject_4.1.3 Seurat_4.3.0       Matrix_1.6-1.1    

loaded via a namespace (and not attached):
  [1] RcppAnnoy_0.0.21            splines_4.3.1               later_1.3.1                 bitops_1.0-7               
  [5] polyclip_1.10-6             lifecycle_1.0.4             globals_0.16.2              lattice_0.22-5             
  [9] MASS_7.3-60                 magrittr_2.0.3              plotly_4.10.3               httpuv_1.6.12              
 [13] sctransform_0.4.1           spam_2.10-0                 sp_2.1-1                    spatstat.sparse_3.0-3      
 [17] reticulate_1.34.0           pbapply_1.7-2               RColorBrewer_1.1-3          abind_1.4-5                
 [21] zlibbioc_1.48.0             Rtsne_0.16                  GenomicRanges_1.54.1        BiocGenerics_0.48.1        
 [25] RCurl_1.98-1.13             yulab.utils_0.1.0           tweenr_2.0.2                GenomeInfoDbData_1.2.11    
 [29] IRanges_2.36.0              S4Vectors_0.40.2            ggrepel_0.9.4               irlba_2.3.5.1              
 [33] listenv_0.9.0               spatstat.utils_3.0-4        goftest_1.2-3               spatstat.random_3.2-1      
 [37] fitdistrplus_1.1-11         parallelly_1.36.0           leiden_0.4.3.1              codetools_0.2-19           
 [41] DelayedArray_0.28.0         ggforce_0.4.1               tidyselect_1.2.0            farver_2.1.1               
 [45] viridis_0.6.4               matrixStats_1.1.0           stats4_4.3.1                spatstat.explore_3.2-5     
 [49] jsonlite_1.8.7              ellipsis_0.3.2              tidygraph_1.2.3             progressr_0.14.0           
 [53] ggridges_0.5.4              survival_3.5-7              tools_4.3.1                 ica_1.0-3                  
 [57] glue_1.6.2                  gridExtra_2.3               SparseArray_1.2.2           MatrixGenerics_1.14.0      
 [61] GenomeInfoDb_1.38.1         withr_2.5.2                 fastmap_1.1.1               fansi_1.0.5                
 [65] digest_0.6.33               timechange_0.2.0            R6_2.5.1                    mime_0.12                  
 [69] colorspace_2.1-0            scattermore_1.2             tensor_1.5                  spatstat.data_3.0-3        
 [73] utf8_1.2.4                  generics_0.1.3              graphlayouts_1.0.2          httr_1.4.7                 
 [77] htmlwidgets_1.6.3           S4Arrays_1.2.0              uwot_0.1.16                 pkgconfig_2.0.3            
 [81] gtable_0.3.4                lmtest_0.9-40               SingleCellExperiment_1.24.0 XVector_0.42.0             
 [85] shadowtext_0.1.2            htmltools_0.5.7             dotCall64_1.1-1             scales_1.3.0               
 [89] Biobase_2.62.0              png_0.1-8                   ggfun_0.1.3                 rstudioapi_0.15.0          
 [93] tzdb_0.4.0                  reshape2_1.4.4              nlme_3.1-164                cachem_1.0.8               
 [97] zoo_1.8-12                  KernSmooth_2.23-22          parallel_4.3.1              miniUI_0.1.1.1             
[101] pillar_1.9.0                grid_4.3.1                  vctrs_0.6.4                 RANN_2.6.1                 
[105] promises_1.2.1              tidydr_0.0.5                xtable_1.8-4                cluster_2.1.6              
[109] cli_3.6.1                   compiler_4.3.1              rlang_1.1.2                 crayon_1.5.2               
[113] future.apply_1.11.0         labeling_0.4.3              fs_1.6.3                    plyr_1.8.9                 
[117] stringi_1.8.2               viridisLite_0.4.2           deldir_2.0-2                munsell_0.5.0              
[121] lazyeval_0.2.2              spatstat.geom_3.2-7         hms_1.1.3                   shiny_1.8.0                
[125] SummarizedExperiment_1.32.0 ROCR_1.0-11                 memoise_2.0.1               igraph_1.5.1               
[129] RcppParallel_5.1.7 
@lch14forever
Copy link
Contributor

lch14forever commented Dec 8, 2023

I think one work around is to reassign the identity:

Idents(sce.all.int) <- sce.all.int$RNA_snn_res.0.8
sc_dim(sce.all.int, reduction = "tsne")

@WhyLIM
Copy link
Author

WhyLIM commented Dec 11, 2023

I think one work around is to reassign the identity:

Idents(sce.all.int) <- sce.all.int$RNA_snn_res.0.8
sc_dim(sce.all.int, reduction = "tsne")

Yes, I did try this and it works. But I think this way is not very elegant, especially when I want to draw multiple groups of images at the same time (similar to what is achieved by the split.by parameter in seurat).

@xiangpin
Copy link
Member

Because we did not bind the meta.data of Seurat object, we might need to extract meta.data slot of Seurat object with [email protected], and bind them. Although this operation is risky, the Seurat might not provide any function to access the meta.data directly.

@lch14forever
Copy link
Contributor

FetchData works on variables from meta.data as well.
Currently, sc_dim does not expose the features variable in get_dim_data. Maybe one way is to add that variable to sc_dim.

@xiangpin
Copy link
Member

I know the FetchData function can extract some columns of meta.data, but we need to provide var argument (the column names of meta.data). which is inconvenient because we need to extract the specified names from mapping. I think it is better to extract all the metadata and bind them directly, just like the colData of SingleCellExperiment. I had submitted the pr#17

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants