Starting from Version 1.2.0,
escheR
package supports additional two data structures as
input, including SpatialExperiment
and data.frame
from base
R. In addition,
escheR
supports in-situ visualization of image-based
spatially resolved data, which will be the focus of future
development.
SingleCellExperiment
SpatialExperiment
inherits
SingleCellExperiment
Following the same syntax, one can also visualize dimensionality
reduced embeddings of a SpatialExperiment
object by
providing the argument dimred
with a non-null value. Hence,
the first 2 columns of the corresponding reducedDim(spe)
assay will be used as the x-y coordinate of the plot, replacing
spatialCoords(spe)
.
library(escheR)
library(STexampleData)
library(scater)
library(scran)
spe <- Visium_humanDLPFC() |>
logNormCounts()
spe <- spe[, spe$in_tissue == 1]
spe <- spe[, !is.na(spe$ground_truth)]
top.gene <- getTopHVGs(spe, n=500)
set.seed(100) # See below.
spe <- runPCA(spe, subset_row = top.gene)
make_escheR(
spe,
dimred = "PCA"
) |>
add_fill(var = "ground_truth") +
theme_minimal()
spe$counts_MOBP <- counts(spe)[which(rowData(spe)$gene_name=="MOBP"),]
spe$ground_truth <- factor(spe$ground_truth)
# Point Binning version
make_escheR(
spe,
dimred = "PCA"
) |>
add_ground_bin(
var = "ground_truth"
) |>
add_fill_bin(
var = "counts_MOBP"
) +
# Customize aesthetics
scale_fill_gradient(low = "white", high = "black", name = "MOBP Count")+
scale_color_discrete(name = "Spatial Domains") +
theme_minimal()
Note 1: The strategy of binning to avoid overplotting is previously proposed in
schex
. While we provide an implementation inescheR
, we would caution our users that the binning strategy could lead to intermixing of cluster memberships. In our implementation, the majority membership of the data points belonging to a bin is selected as the label of the bin. Users should use the binning strategy under their own discretion, and interpret the visualization carefully.
Note 2:
add_fill_bin()
shoudl be applied afteradd_ground_bin()
for the better visualization outcome.
SpatialExperiment
ObjectTo demonstrate the principle that escheR
can be used to
visualize image-based spatially-resolved data pending optimization, we
include two image-based spatially resolved transcriptomics data
generated via seqFish platform and Slide-seq V2 platform respectively.
The two datasets have been previously curated in the STexampleData
package
library(STexampleData)
library(escheR)
spe_seqFISH <- seqFISH_mouseEmbryo()
make_escheR(spe_seqFISH) |>
add_fill(var = "embryo")
NOTE: trimming down the
colData(spe)
before piping into make-escheR could reduce the computation time to make the plots, specifically whencolData(spe)
contains extremely large number of irrelavent features/columns.
We aim to provide accessibility to all users regardless of their
programming background and preferred single-cell analysis pipelines.
Nevertheless , with limited resource, our sustaining efforts will
prioritize towards the maintenance of the established functionality and
the optimization for image-based spatially resolved data. We regret we
are not be able to provide seamless interface to other R pipelines such
as Seurat
and Giotto
in foreseeable
future.
Instead, we provide a generic function that works with a
data.frame
object as input. For example, relevant features
in Suerat
can be easily exported as a
data.frame
object manually or via
tidyseurat
[https://github.com/stemangiola/tidyseurat]. The exported
data frame can be pipe into escheR
.
library(escheR)
library(Seurat)
pbmc_small <- SeuratObject::pbmc_small
pbmc_2pc <- pbmc_small@reductions$pca@cell.embeddings[,1:2]
pbmc_meta <- pbmc_small@meta.data
#> Call generic function for make_escheR.data.frame
make_escheR(
object = pbmc_meta,
.x = pbmc_2pc[,1],
.y = pbmc_2pc[,2]) |>
add_fill(var = "groups")
utils::sessionInfo()
#> R version 4.4.2 (2024-10-31)
#> Platform: x86_64-pc-linux-gnu
#> Running under: Ubuntu 24.04.1 LTS
#>
#> Matrix products: default
#> BLAS: /usr/lib/x86_64-linux-gnu/openblas-pthread/libblas.so.3
#> LAPACK: /usr/lib/x86_64-linux-gnu/openblas-pthread/libopenblasp-r0.3.26.so; LAPACK version 3.12.0
#>
#> locale:
#> [1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C
#> [3] LC_TIME=en_US.UTF-8 LC_COLLATE=C
#> [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
#>
#> time zone: Etc/UTC
#> tzcode source: system (glibc)
#>
#> attached base packages:
#> [1] stats4 stats graphics grDevices utils datasets methods
#> [8] base
#>
#> other attached packages:
#> [1] BumpyMatrix_1.15.0 scran_1.35.0
#> [3] scater_1.35.0 scuttle_1.17.0
#> [5] rmarkdown_2.29 ggpubr_0.6.0
#> [7] STexampleData_1.14.0 SpatialExperiment_1.17.0
#> [9] SingleCellExperiment_1.29.1 SummarizedExperiment_1.37.0
#> [11] Biobase_2.67.0 GenomicRanges_1.59.0
#> [13] GenomeInfoDb_1.43.1 IRanges_2.41.1
#> [15] S4Vectors_0.45.2 MatrixGenerics_1.19.0
#> [17] matrixStats_1.4.1 ExperimentHub_2.15.0
#> [19] AnnotationHub_3.15.0 BiocFileCache_2.15.0
#> [21] dbplyr_2.5.0 BiocGenerics_0.53.3
#> [23] generics_0.1.3 escheR_1.7.0
#> [25] ggplot2_3.5.1 BiocStyle_2.35.0
#>
#> loaded via a namespace (and not attached):
#> [1] RColorBrewer_1.1-3 sys_3.4.3 jsonlite_1.8.9
#> [4] magrittr_2.0.3 ggbeeswarm_0.7.2 magick_2.8.5
#> [7] farver_2.1.2 zlibbioc_1.52.0 vctrs_0.6.5
#> [10] memoise_2.0.1 rstatix_0.7.2 htmltools_0.5.8.1
#> [13] S4Arrays_1.7.1 curl_6.0.1 BiocNeighbors_2.1.0
#> [16] broom_1.0.7 SparseArray_1.7.2 Formula_1.2-5
#> [19] sass_0.4.9 bslib_0.8.0 cachem_1.1.0
#> [22] buildtools_1.0.0 igraph_2.1.1 mime_0.12
#> [25] lifecycle_1.0.4 pkgconfig_2.0.3 rsvd_1.0.5
#> [28] Matrix_1.7-1 R6_2.5.1 fastmap_1.2.0
#> [31] GenomeInfoDbData_1.2.13 digest_0.6.37 colorspace_2.1-1
#> [34] AnnotationDbi_1.69.0 dqrng_0.4.1 irlba_2.3.5.1
#> [37] RSQLite_2.3.8 beachmat_2.23.1 filelock_1.0.3
#> [40] labeling_0.4.3 fansi_1.0.6 httr_1.4.7
#> [43] abind_1.4-8 compiler_4.4.2 bit64_4.5.2
#> [46] withr_3.0.2 backports_1.5.0 BiocParallel_1.41.0
#> [49] carData_3.0-5 viridis_0.6.5 DBI_1.2.3
#> [52] hexbin_1.28.5 ggsignif_0.6.4 rappdirs_0.3.3
#> [55] DelayedArray_0.33.2 rjson_0.2.23 bluster_1.17.0
#> [58] tools_4.4.2 vipor_0.4.7 beeswarm_0.4.0
#> [61] glue_1.8.0 grid_4.4.2 cluster_2.1.6
#> [64] gtable_0.3.6 tidyr_1.3.1 metapod_1.15.0
#> [67] BiocSingular_1.23.0 ScaledMatrix_1.15.0 car_3.1-3
#> [70] utf8_1.2.4 XVector_0.47.0 ggrepel_0.9.6
#> [73] BiocVersion_3.21.1 pillar_1.9.0 limma_3.63.2
#> [76] dplyr_1.1.4 lattice_0.22-6 bit_4.5.0
#> [79] tidyselect_1.2.1 locfit_1.5-9.10 maketools_1.3.1
#> [82] Biostrings_2.75.1 knitr_1.49 gridExtra_2.3
#> [85] edgeR_4.5.0 xfun_0.49 statmod_1.5.0
#> [88] UCSC.utils_1.3.0 yaml_2.3.10 evaluate_1.0.1
#> [91] codetools_0.2-20 tibble_3.2.1 BiocManager_1.30.25
#> [94] cli_3.6.3 munsell_0.5.1 jquerylib_0.1.4
#> [97] Rcpp_1.0.13-1 png_0.1-8 parallel_4.4.2
#> [100] blob_1.2.4 viridisLite_0.4.2 scales_1.3.0
#> [103] purrr_1.0.2 crayon_1.5.3 rlang_1.1.4
#> [106] cowplot_1.1.3 KEGGREST_1.47.0