require(Yano)
require(SeuratData)
#InstallData("stxBrain")
<- LoadData("stxBrain", type = "anterior1")
brain <- SCTransform(brain, assay = "Spatial", verbose = FALSE)
brain <- RunPCA(brain, assay = "SCT", verbose = FALSE)
brain <- FindNeighbors(brain, reduction = "pca", dims = 1:30)
brain <- FindClusters(brain, verbose = FALSE)
brain <- RunUMAP(brain, reduction = "pca", dims = 1:30)
brain
SpatialPlot(brain)
Select cells from reduction maps and spatial locations
This vignette demonstrates how to use Yano buildin functions to interactively select or pick cells/spots from a plot using your mouse and keyboard. While tools like CellxGene are widely used for this purpose, to the best of our knowledge, an efficient solution for performing this task within the R environment is still lacking. Here, we introduce a lightweight, fast and native implementation of a cell selector to address this gap.
Prepare the data.
We use demo data from SeuratData for simplity.
Select spots from spatial plot
.1 <- SpatialSelector(brain) sel
Press ESC
on your keyboard to exist the selection!
Now the selected cells will be exported to sel.1
. If you want return a object, try to set return.object=TRUE
in the function.
Select cells from dimension reduction plot
We can also select cells from dimension reduction plot.
DimPlot(brain)
.1 <- DimSelector(brain) sel
Press ESC
on your keyboard to exist the selection!
Select cells based on a feature expression
FeaturePlot(brain, features = c('Ttr'), order=TRUE)
Warning: The `slot` argument of `FetchData()` is deprecated as of SeuratObject 5.0.0.
ℹ Please use the `layer` argument instead.
ℹ The deprecated feature was likely used in the Seurat package.
Please report the issue at <https://github.com/satijalab/seurat/issues>.
FeatureSelector(brain, feature = c('Ttr'), order=TRUE)
Please note in FeatureSelector()
only one feature is support at each selection. Therefore, I designed the parameter feature
instead of orignal features
here.
Select cells from Image-based spatial data
Here we will use 10x Genomics Xenium data, generated from Seurat’s tutorial.
<- readRDS("xenium.rds")
xenium.obj ImageDimPlot(xenium.obj, border.color = "white", border.size = 0.1, cols = "polychrome")
Warning: No FOV associated with assay 'SCT', using global default FOV
ImageDimSelector(xenium.obj, border.color = "white", border.size = 0.1)
Generate 2D concave hull of selected region
In spatial transcriptomics, it is sometimes necessary to manually define capsule or membrane regions, as these areas are often thin, mixed with neighboring cells, and difficult to identify accurately. Manually specifying these regions can be beneficial for downstream analyses, where precise spatial organization of cells is critical for understanding tissue architecture and functional gradients.
<- SpatialConcaveHull(brain) sel
Questions?
If you have any questions regarding this vignette, the usage of Yano or suggestions, please feel free to report them through the discussion forum.
sessionInfo()
R version 4.5.0 (2025-04-11)
Platform: aarch64-apple-darwin24.4.0
Running under: macOS Sequoia 15.5
Matrix products: default
BLAS: /opt/homebrew/Cellar/openblas/0.3.29/lib/libopenblasp-r0.3.29.dylib
LAPACK: /opt/homebrew/Cellar/r/4.5.0/lib/R/lib/libRlapack.dylib; LAPACK version 3.12.1
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: Asia/Shanghai
tzcode source: internal
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] future_1.49.0 stxBrain.SeuratData_0.1.2
[3] SeuratData_0.2.2.9002 dplyr_1.1.4
[5] Seurat_5.3.0 SeuratObject_5.1.0
[7] sp_2.2-0 ggplot2_3.5.2
[9] Yano_1.2
loaded via a namespace (and not attached):
[1] deldir_2.0-4 pbapply_1.7-2 gridExtra_2.3
[4] rlang_1.1.6 magrittr_2.0.3 RcppAnnoy_0.0.22
[7] spatstat.geom_3.3-6 matrixStats_1.5.0 ggridges_0.5.6
[10] compiler_4.5.0 png_0.1-8 vctrs_0.6.5
[13] reshape2_1.4.4 stringr_1.5.1 crayon_1.5.3
[16] pkgconfig_2.0.3 fastmap_1.2.0 labeling_0.4.3
[19] promises_1.3.2 rmarkdown_2.29 purrr_1.0.4
[22] xfun_0.52 jsonlite_2.0.0 goftest_1.2-3
[25] later_1.4.2 spatstat.utils_3.1-4 irlba_2.3.5.1
[28] parallel_4.5.0 cluster_2.1.8.1 R6_2.6.1
[31] ica_1.0-3 stringi_1.8.7 RColorBrewer_1.1-3
[34] spatstat.data_3.1-6 reticulate_1.42.0 spatstat.univar_3.1-3
[37] parallelly_1.44.0 lmtest_0.9-40 scattermore_1.2
[40] Rcpp_1.0.14 knitr_1.50 tensor_1.5
[43] future.apply_1.11.3 zoo_1.8-14 R.utils_2.13.0
[46] sctransform_0.4.2 httpuv_1.6.16 Matrix_1.7-3
[49] splines_4.5.0 igraph_2.1.4 tidyselect_1.2.1
[52] viridis_0.6.5 abind_1.4-8 yaml_2.3.10
[55] spatstat.random_3.3-3 codetools_0.2-20 miniUI_0.1.2
[58] spatstat.explore_3.4-2 listenv_0.9.1 lattice_0.22-6
[61] tibble_3.2.1 plyr_1.8.9 withr_3.0.2
[64] shiny_1.10.0 ROCR_1.0-11 evaluate_1.0.3
[67] Rtsne_0.17 fastDummies_1.7.5 survival_3.8-3
[70] polyclip_1.10-7 fitdistrplus_1.2-2 pillar_1.10.2
[73] KernSmooth_2.23-26 plotly_4.10.4 generics_0.1.4
[76] RcppHNSW_0.6.0 scales_1.4.0 gtools_3.9.5
[79] globals_0.18.0 xtable_1.8-4 glue_1.8.0
[82] lazyeval_0.2.2 tools_4.5.0 data.table_1.17.2
[85] RSpectra_0.16-2 RANN_2.6.2 dotCall64_1.2
[88] cowplot_1.1.3 grid_4.5.0 tidyr_1.3.1
[91] nlme_3.1-168 patchwork_1.3.0 cli_3.6.5
[94] rappdirs_0.3.3 spatstat.sparse_3.1-0 spam_2.11-1
[97] viridisLite_0.4.2 uwot_0.2.3 gtable_0.3.6
[100] R.methodsS3_1.8.2 digest_0.6.37 progressr_0.15.1
[103] ggrepel_0.9.6 htmlwidgets_1.6.4 farver_2.1.2
[106] htmltools_0.5.8.1 R.oo_1.27.1 lifecycle_1.0.4
[109] httr_1.4.7 mime_0.13 MASS_7.3-65