Here, we demonstrate BANKSY domain segmentation on a STARmap PLUS dataset of the mouse brain from Shi et al. (2022).
library(Banksy)
library(data.table)
library(SummarizedExperiment)
library(SpatialExperiment)
library(scater)
library(cowplot)
library(ggplot2)Data from the study is available from the Single
Cell Portal. We analyze data from well11. The data
comprise 1,022 genes profiled at subcellular resolution in 43,341
cells.
#' Change paths accordingly
gcm_path <- "../data/well11processed_expression_pd.csv.gz"
mdata_path <- "../data/well11_spatial.csv.gz"
#' Gene cell matrix
gcm <- fread(gcm_path)
genes <- gcm$GENE
gcm <- as.matrix(gcm[, -1])
rownames(gcm) <- genes
#' Spatial coordinates and metadata
mdata <- fread(mdata_path, skip = 1)
headers <- names(fread(mdata_path, nrows = 0))
colnames(mdata) <- headers
#' Orient spatial coordinates
xx <- mdata$X
yy <- mdata$Y
mdata$X <- max(yy) - yy
mdata$Y <- max(xx) - xx
mdata <- data.frame(mdata)
rownames(mdata) <- colnames(gcm)
locs <- as.matrix(mdata[, c("X", "Y", "Z")])
#' Create SpatialExperiment
se <- SpatialExperiment(
assay = list(processedExp = gcm),
spatialCoords = locs,
colData = mdata
)Run BANKSY in domain segmentation mode with lambda=0.8.
This places larger weights on the mean neighborhood expression in
constructing the BANKSY matrix.
Note that the parameter values for domain segmentation for datasets generated using the older Visium v1 / v2 55um technologies are
lambda = 0.2andk_geom = 18. See the note in the tutorial on the main page for more details.
lambda <- 0.8
k_geom <- 30
npcs <- 50
set.seed(1000)
se <- Banksy::runBanksyPCA(se, lambda = lambda, npcs = npcs, k_geom = k_geom)
set.seed(1000)
se <- Banksy::clusterBanksy(se, lambda = lambda, npcs = npcs, resolution = 0.6)Cluster labels are stored in the colData slot:
head(colData(se))
#> DataFrame with 6 rows and 4 columns
#> X Y clust_M0_lam0.8_k50_res0.6 sample_id
#> <numeric> <numeric> <factor> <character>
#> 1 24225.5 23984.2 9 sample01
#> 2 24849.2 22679.1 9 sample01
#> 3 24488.3 22970.3 9 sample01
#> 4 24371.4 23727.5 9 sample01
#> 5 24362.2 23300.6 9 sample01
#> 6 24644.5 23112.8 9 sample01Visualize clustering results:
cnames <- colnames(colData(se))
cnames <- cnames[grep("^clust", cnames)]
plotColData(se, x = "X", y = "Y", point_size = 0.01, colour_by = cnames[1]) +
scale_color_manual(values = pals::glasbey()) +
coord_equal() +
theme(legend.position = "none")options(width = 120)
sessioninfo::session_info()
#> ─ Session info ───────────────────────────────────────────────────────────────────────────────────────────────────────
#> setting value
#> version R version 4.6.1 (2026-06-24)
#> os Ubuntu 26.04.1 LTS
#> system x86_64, linux-gnu
#> ui X11
#> language (EN)
#> collate en_US.UTF-8
#> ctype en_US.UTF-8
#> tz Etc/UTC
#> date 2026-09-30
#> pandoc 3.8.3 @ /usr/local/bin/ (via rmarkdown)
#> quarto 1.9.37 @ /usr/local/bin/quarto
#>
#> ─ Packages ───────────────────────────────────────────────────────────────────────────────────────────────────────────
#> package * version date (UTC) lib source
#> abind 1.4-8 2024-09-12 [2] RSPM (R 4.6.0)
#> AnnotationDbi 1.75.2 2026-08-27 [2] https://bioc.r-universe.dev (R 4.6.1)
#> AnnotationHub * 4.3.2 2026-06-30 [2] https://bioc.r-universe.dev (R 4.6.1)
#> aricode 1.1.0 2026-05-13 [2] RSPM (R 4.6.0)
#> attempt 0.3.1 2020-05-03 [2] RSPM (R 4.6.0)
#> Banksy * 1.9.4 2026-09-29 [1] https://bioc.r-universe.dev (R 4.6.1)
#> beachmat 2.29.3 2026-09-23 [2] https://bioc.r-universe.dev (R 4.6.1)
#> beeswarm 0.4.0 2021-06-01 [2] RSPM (R 4.6.0)
#> benchmarkme 1.0.8 2022-06-12 [2] RSPM (R 4.6.0)
#> benchmarkmeData 2.0.0 2026-01-19 [2] RSPM (R 4.6.0)
#> Biobase * 2.73.2 2026-07-28 [2] https://bioc.r-universe.dev (R 4.6.1)
#> BiocBaseUtils 1.15.1 2026-05-08 [2] https://bioc.r-universe.dev (R 4.6.1)
#> BiocFileCache * 3.3.0 2026-04-28 [2] https://bioc.r-universe.dev (R 4.6.1)
#> BiocGenerics * 0.59.12 2026-08-10 [2] https://bioc.r-universe.dev (R 4.6.1)
#> BiocIO 1.23.3 2026-04-28 [2] https://bioc.r-universe.dev (R 4.6.1)
#> BiocManager 1.30.27 2025-11-14 [2] RSPM (R 4.6.0)
#> BiocNeighbors 2.7.3 2026-08-21 [2] https://bioc.r-universe.dev (R 4.6.1)
#> BiocParallel 1.47.0 2026-04-28 [2] https://bioc.r-universe.dev (R 4.6.1)
#> BiocSingular 1.29.1 2026-08-27 [2] https://bioc.r-universe.dev (R 4.6.1)
#> BiocStyle * 2.41.0 2026-04-28 [2] https://bioc.r-universe.dev (R 4.6.1)
#> BiocVersion 3.24.0 2026-04-28 [2] https://bioc.r-universe.dev (R 4.6.1)
#> Biostrings 2.81.9 2026-09-05 [2] https://bioc.r-universe.dev (R 4.6.1)
#> bit 4.6.0 2025-03-06 [2] RSPM (R 4.6.0)
#> bit64 4.8.6 2026-09-01 [2] RSPM (R 4.6.0)
#> bitops 1.1-0 2026-07-30 [2] RSPM (R 4.6.0)
#> blob 1.3.0 2026-01-14 [2] RSPM (R 4.6.0)
#> bluster 1.23.1 2026-08-25 [2] https://bioc.r-universe.dev (R 4.6.1)
#> bslib 0.12.0 2026-08-04 [2] RSPM (R 4.6.0)
#> buildtools 1.0.0 2026-09-15 [3] local (/pkg)
#> cachem 1.1.0 2024-05-16 [2] RSPM (R 4.6.0)
#> cigarillo 1.3.1 2026-09-02 [2] https://bioc.r-universe.dev (R 4.6.1)
#> circlize 0.4.18 2026-04-04 [2] RSPM (R 4.6.0)
#> cli 3.6.6 2026-04-09 [2] RSPM (R 4.6.0)
#> clue 0.3-68 2026-03-26 [2] RSPM (R 4.6.0)
#> cluster 2.1.8.3 2026-07-30 [2] RSPM (R 4.6.0)
#> codetools 0.2-20 2024-03-31 [2] RSPM (R 4.6.0)
#> colorspace 2.1-3 2026-07-12 [2] RSPM (R 4.6.0)
#> ComplexHeatmap 2.29.0 2026-04-28 [2] https://bioc.r-universe.dev (R 4.6.1)
#> config 0.3.2 2023-08-30 [2] RSPM (R 4.6.0)
#> cowplot * 1.2.0 2025-07-07 [2] RSPM (R 4.6.0)
#> crayon 1.5.3 2024-06-20 [2] RSPM (R 4.6.0)
#> curl 8.0.0 2026-08-25 [2] RSPM (R 4.6.0)
#> data.table * 1.18.6.1 2026-08-24 [2] RSPM (R 4.6.0)
#> DBI 1.3.0 2026-02-25 [2] RSPM (R 4.6.0)
#> dbplyr * 2.6.0 2026-06-17 [2] RSPM (R 4.6.0)
#> dbscan 1.2.6 2026-08-25 [2] RSPM (R 4.6.0)
#> DelayedArray 0.39.7 2026-09-23 [2] https://bioc.r-universe.dev (R 4.6.1)
#> deldir 2.0-4 2024-02-28 [2] RSPM (R 4.6.0)
#> dichromat 2.0-1 2026-07-22 [2] RSPM (R 4.6.0)
#> digest 0.6.39 2025-11-19 [2] RSPM (R 4.6.0)
#> doParallel 1.0.17 2022-02-07 [2] RSPM (R 4.6.0)
#> dotCall64 1.2 2024-10-04 [2] RSPM (R 4.6.0)
#> dplyr 1.2.1 2026-04-03 [2] RSPM (R 4.6.0)
#> dqrng 0.4.1 2024-05-28 [2] RSPM (R 4.6.0)
#> DT 0.34.0 2025-09-02 [2] RSPM (R 4.6.0)
#> edgeR 4.99.6 2026-09-12 [2] https://bioc.r-universe.dev (R 4.6.1)
#> evaluate 1.0.5 2025-08-27 [2] RSPM (R 4.6.0)
#> ExperimentHub * 3.3.2 2026-08-12 [2] https://bioc.r-universe.dev (R 4.6.1)
#> farver 2.1.2 2024-05-13 [2] RSPM (R 4.6.0)
#> fastDummies 1.7.6 2026-04-22 [2] RSPM (R 4.6.0)
#> fastmap 1.2.0 2024-05-15 [2] RSPM (R 4.6.0)
#> filelock 1.0.3 2023-12-11 [2] RSPM (R 4.6.0)
#> fitdistrplus 1.2-6 2026-01-24 [2] RSPM (R 4.6.0)
#> foreach 1.5.2 2022-02-02 [2] RSPM (R 4.6.0)
#> future 1.76.0 2026-09-24 [2] RSPM (R 4.6.0)
#> future.apply 1.20.2 2026-02-20 [2] RSPM (R 4.6.0)
#> generics * 0.1.4 2025-05-09 [2] RSPM (R 4.6.0)
#> GenomicAlignments 1.49.2 2026-09-16 [2] https://bioc.r-universe.dev (R 4.6.1)
#> GenomicRanges * 1.65.4 2026-09-02 [2] https://bioc.r-universe.dev (R 4.6.1)
#> GetoptLong 1.1.1 2026-04-08 [2] RSPM (R 4.6.0)
#> ggbeeswarm 0.7.3 2025-11-29 [2] RSPM (R 4.6.0)
#> ggplot2 * 4.0.3 2026-04-22 [2] RSPM (R 4.6.0)
#> ggrepel 0.9.8 2026-03-17 [2] RSPM (R 4.6.0)
#> ggridges 0.5.7 2025-08-27 [2] RSPM (R 4.6.0)
#> GlobalOptions 0.1.4 2026-04-08 [2] RSPM (R 4.6.0)
#> globals 0.19.1 2026-03-13 [2] RSPM (R 4.6.0)
#> glue 1.8.1 2026-04-17 [2] RSPM (R 4.6.0)
#> goftest 1.2-3 2021-10-07 [2] RSPM (R 4.6.0)
#> golem 1.0.1 2026-07-07 [2] RSPM (R 4.6.0)
#> gridExtra 2.3.1 2026-06-25 [2] RSPM (R 4.6.0)
#> gtable 0.3.6 2024-10-25 [2] RSPM (R 4.6.0)
#> harmony * 2.0.5 2026-06-12 [2] RSPM (R 4.6.0)
#> htmltools 0.5.9 2025-12-04 [2] RSPM (R 4.6.0)
#> htmlwidgets 1.6.4 2023-12-06 [2] RSPM (R 4.6.0)
#> httpuv 1.6.17 2026-03-18 [2] RSPM (R 4.6.0)
#> httr 1.4.9 2026-09-01 [2] RSPM (R 4.6.0)
#> httr2 1.3.0 2026-07-13 [2] RSPM (R 4.6.0)
#> ica 1.0-3 2022-07-08 [2] RSPM (R 4.6.0)
#> igraph 2.3.3 2026-06-26 [2] RSPM (R 4.6.0)
#> IRanges * 2.47.5 2026-08-27 [2] https://bioc.r-universe.dev (R 4.6.1)
#> irlba 2.3.7 2026-01-30 [2] RSPM (R 4.6.0)
#> iterators 1.0.14 2022-02-05 [2] RSPM (R 4.6.0)
#> jquerylib 0.1.4 2021-04-26 [2] RSPM (R 4.6.0)
#> jsonlite 2.0.0 2025-03-27 [2] RSPM (R 4.6.0)
#> KEGGREST 1.53.6 2026-07-22 [2] https://bioc.r-universe.dev (R 4.6.1)
#> KernSmooth 2.23-27 2026-08-12 [2] RSPM (R 4.6.0)
#> knitr 1.52 2026-09-06 [2] RSPM (R 4.6.0)
#> labeling 0.4.3 2023-08-29 [2] RSPM (R 4.6.0)
#> later 1.4.8 2026-03-05 [2] RSPM (R 4.6.0)
#> lattice 0.23-1 2026-08-12 [2] RSPM (R 4.6.0)
#> leidenAlg 1.1.8 2026-05-31 [2] RSPM (R 4.6.0)
#> lifecycle 1.0.5 2026-01-08 [2] RSPM (R 4.6.0)
#> limma 3.99.0 2026-08-30 [2] https://bioc.r-universe.dev (R 4.6.1)
#> listenv 1.0.0 2026-06-22 [2] RSPM (R 4.6.0)
#> lmtest 0.9-40 2022-03-21 [2] RSPM (R 4.6.0)
#> locfit 1.5-9.12 2025-03-05 [2] RSPM (R 4.6.0)
#> magick 2.9.1 2026-02-28 [2] RSPM (R 4.6.0)
#> magrittr 2.0.5 2026-04-04 [2] RSPM (R 4.6.0)
#> maketools 1.3.2 2025-01-25 [3] RSPM (R 4.6.0)
#> mapproj 1.2.12 2025-05-19 [2] RSPM (R 4.6.0)
#> maps 3.4.3 2025-05-26 [2] RSPM (R 4.6.0)
#> MASS 7.3-66 2026-07-15 [2] RSPM (R 4.6.0)
#> Matrix 1.7-6 2026-07-25 [2] RSPM (R 4.6.0)
#> MatrixGenerics * 1.25.0 2026-04-28 [2] https://bioc.r-universe.dev (R 4.6.1)
#> matrixStats * 1.5.0 2025-01-07 [2] RSPM (R 4.6.0)
#> mclust 6.1.3 2026-07-05 [2] RSPM (R 4.6.0)
#> memoise 2.0.1 2021-11-26 [2] RSPM (R 4.6.0)
#> metapod 1.21.0 2026-04-28 [2] https://bioc.r-universe.dev (R 4.6.1)
#> mime 0.13 2025-03-17 [2] RSPM (R 4.6.0)
#> miniUI 0.1.2 2025-04-17 [2] RSPM (R 4.6.0)
#> nlme 3.1-171 2026-09-01 [2] RSPM (R 4.6.0)
#> otel 0.2.0 2025-08-29 [2] RSPM (R 4.6.0)
#> paletteer 1.7.0 2026-01-08 [2] RSPM (R 4.6.0)
#> pals 1.10 2025-03-07 [2] RSPM (R 4.6.0)
#> parallelly 1.48.0 2026-06-29 [2] RSPM (R 4.6.0)
#> patchwork 1.3.2 2025-08-25 [2] RSPM (R 4.6.0)
#> pbapply 1.7-5 2026-09-01 [2] RSPM (R 4.6.0)
#> pillar 1.11.1 2025-09-17 [2] RSPM (R 4.6.0)
#> pkgconfig 2.0.3 2019-09-22 [2] RSPM (R 4.6.0)
#> plotly 4.12.1 2026-07-22 [2] RSPM (R 4.6.0)
#> plyr 1.8.9 2023-10-02 [2] RSPM (R 4.6.0)
#> png 0.1-9 2026-03-15 [2] RSPM (R 4.6.0)
#> polyclip 1.10-7 2024-07-23 [2] RSPM (R 4.6.0)
#> progressr 1.0.0 2026-07-04 [2] RSPM (R 4.6.0)
#> promises 1.5.0 2025-11-01 [2] RSPM (R 4.6.0)
#> purrr 1.2.2 2026-04-10 [2] RSPM (R 4.6.0)
#> R6 2.6.1 2025-02-15 [2] RSPM (R 4.6.0)
#> RANN 2.6.3 2026-08-24 [2] RSPM (R 4.6.0)
#> rappdirs 0.3.4 2026-01-17 [2] RSPM (R 4.6.0)
#> RColorBrewer 1.1-3 2022-04-03 [2] RSPM (R 4.6.0)
#> Rcpp * 1.1.2 2026-07-05 [2] RSPM (R 4.6.0)
#> RcppAnnoy 0.0.23 2026-01-12 [2] RSPM (R 4.6.0)
#> RcppHNSW 0.7.0 2026-05-26 [2] RSPM (R 4.6.0)
#> RcppHungarian 0.3 2023-09-05 [2] RSPM (R 4.6.0)
#> RCurl 1.98-1.20 2026-08-21 [2] RSPM (R 4.6.0)
#> rematch2 2.1.2 2020-05-01 [2] RSPM (R 4.6.0)
#> reshape2 1.4.5 2025-11-12 [2] RSPM (R 4.6.0)
#> restfulr 0.0.17 2026-06-11 [2] RSPM (R 4.6.0)
#> reticulate 1.47.0 2026-09-03 [2] RSPM (R 4.6.0)
#> RhpcBLASctl 0.23-42 2023-02-11 [2] RSPM (R 4.6.0)
#> rjson 0.2.23 2024-09-16 [2] RSPM (R 4.6.0)
#> rlang 1.3.0 2026-07-05 [2] RSPM (R 4.6.0)
#> rmarkdown 2.32 2026-09-01 [2] RSPM (R 4.6.0)
#> ROCR 1.0-12 2026-01-23 [2] RSPM (R 4.6.0)
#> Rsamtools 2.29.0 2026-04-28 [2] https://bioc.r-universe.dev (R 4.6.1)
#> RSpectra 0.16-2 2024-07-18 [2] RSPM (R 4.6.0)
#> RSQLite 3.53.3 2026-06-30 [2] RSPM (R 4.6.0)
#> rsvd 1.0.5 2021-04-16 [2] RSPM (R 4.6.0)
#> rtracklayer 1.73.0 2026-06-11 [2] https://bioc.r-universe.dev (R 4.6.1)
#> Rtsne 0.17 2023-12-07 [2] RSPM (R 4.6.0)
#> S4Arrays 1.13.1 2026-09-22 [2] https://bioc.r-universe.dev (R 4.6.1)
#> S4Vectors * 0.51.10 2026-09-15 [2] https://bioc.r-universe.dev (R 4.6.1)
#> S7 0.2.2 2026-04-22 [2] RSPM (R 4.6.0)
#> sass 0.4.10 2025-04-11 [2] RSPM (R 4.6.0)
#> ScaledMatrix 1.21.0 2026-04-28 [2] https://bioc.r-universe.dev (R 4.6.1)
#> scales 1.4.0 2025-04-24 [2] RSPM (R 4.6.0)
#> scater * 1.41.2 2026-06-30 [2] https://bioc.r-universe.dev (R 4.6.1)
#> scattermore 1.2 2023-06-12 [2] RSPM (R 4.6.0)
#> sccore 1.0.7 2026-04-06 [2] RSPM (R 4.6.0)
#> scran * 1.41.1 2026-05-20 [2] https://bioc.r-universe.dev (R 4.6.1)
#> sctransform 0.4.3 2026-01-10 [2] RSPM (R 4.6.0)
#> scuttle * 1.23.2 2026-08-27 [2] https://bioc.r-universe.dev (R 4.6.1)
#> Seqinfo * 1.3.2 2026-08-26 [2] https://bioc.r-universe.dev (R 4.6.1)
#> sessioninfo 1.2.4 2026-06-04 [2] RSPM (R 4.6.0)
#> Seurat * 5.5.1 2026-06-26 [2] RSPM (R 4.6.0)
#> SeuratObject * 5.4.0 2026-04-11 [2] RSPM (R 4.6.0)
#> shape 1.4.6.1 2024-02-23 [2] RSPM (R 4.6.0)
#> shiny 1.14.0 2026-06-21 [2] RSPM (R 4.6.0)
#> shinyWidgets 0.9.1 2026-03-09 [2] RSPM (R 4.6.0)
#> SingleCellExperiment * 1.35.2 2026-07-16 [2] https://bioc.r-universe.dev (R 4.6.1)
#> sp * 2.2-3 2026-07-19 [2] RSPM (R 4.6.0)
#> spam 2.11-4 2026-05-29 [2] RSPM (R 4.6.0)
#> SparseArray 1.13.3 2026-09-24 [2] https://bioc.r-universe.dev (R 4.6.1)
#> SpatialExperiment * 1.23.0 2026-04-28 [2] https://bioc.r-universe.dev (R 4.6.1)
#> spatialLIBD * 1.25.2 2026-07-28 [2] Bioconductor 3.24 (R 4.6.1)
#> spatstat.data 3.1-9 2025-10-18 [2] RSPM (R 4.6.0)
#> spatstat.explore 3.8-3 2026-09-23 [2] RSPM (R 4.6.0)
#> spatstat.geom 3.8-3 2026-09-18 [2] RSPM (R 4.6.0)
#> spatstat.random 3.5-2 2026-09-22 [2] RSPM (R 4.6.0)
#> spatstat.sparse 3.2-0 2026-05-21 [2] RSPM (R 4.6.0)
#> spatstat.univar 3.2-0 2026-05-18 [2] RSPM (R 4.6.0)
#> spatstat.utils 3.2-5 2026-09-11 [2] RSPM (R 4.6.0)
#> statmod 1.5.2 2026-05-17 [2] RSPM (R 4.6.0)
#> stringi 1.8.9 2026-08-04 [2] RSPM (R 4.6.0)
#> stringr 1.6.0 2025-11-04 [2] RSPM (R 4.6.0)
#> SummarizedExperiment * 1.43.0 2026-04-28 [2] https://bioc.r-universe.dev (R 4.6.1)
#> survival 3.8-12 2026-09-09 [2] RSPM (R 4.6.0)
#> sys 3.4.3 2024-10-04 [2] RSPM (R 4.6.0)
#> tensor 1.5.1 2025-06-17 [2] RSPM (R 4.6.0)
#> tibble 3.3.1 2026-01-11 [2] RSPM (R 4.6.0)
#> tidyr 1.3.2 2025-12-19 [2] RSPM (R 4.6.0)
#> tidyselect 1.2.1 2024-03-11 [2] RSPM (R 4.6.0)
#> uwot 0.2.5 2026-08-29 [2] RSPM (R 4.6.0)
#> vctrs 0.7.3 2026-04-11 [2] RSPM (R 4.6.0)
#> vipor 0.4.7 2023-12-18 [2] RSPM (R 4.6.0)
#> viridis 0.6.5 2024-01-29 [2] RSPM (R 4.6.0)
#> viridisLite 0.4.3 2026-02-04 [2] RSPM (R 4.6.0)
#> withr 3.0.3 2026-06-19 [2] RSPM (R 4.6.0)
#> xfun 0.61 2026-09-16 [2] RSPM (R 4.6.0)
#> XML 3.99-0.25 2026-09-27 [2] RSPM (R 4.6.0)
#> xtable 1.8-8 2026-02-22 [2] RSPM (R 4.6.0)
#> XVector 0.53.0 2026-04-28 [2] https://bioc.r-universe.dev (R 4.6.1)
#> yaml 2.3.12 2025-12-10 [2] RSPM (R 4.6.0)
#> zoo 1.9-1 2026-09-25 [2] RSPM (R 4.6.0)
#>
#> [1] /tmp/Rtmpe0t8Qn/Rinst279a59bf5c95
#> [2] /github/workspace/pkglib
#> [3] /usr/local/lib/R/site-library
#> [4] /usr/lib/R/site-library
#> [5] /usr/lib/R/library
#> * ── Packages attached to the search path.
#>
#> ──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────