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.2 (2026-10-29)
#> 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-11-25
#> 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.77.0 2026-11-23 [2] https://bioc.r-universe.dev (R 4.6.2)
#> AnnotationHub * 4.4.0 2026-11-23 [2] Bioconductor 3.24 (R 4.6.2)
#> 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.10.0 2026-11-23 [1] Bioconductor 3.24 (R 4.6.2)
#> beachmat 2.30.0 2026-11-23 [2] Bioconductor 3.24 (R 4.6.2)
#> 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.74.0 2026-11-23 [2] Bioconductor 3.24 (R 4.6.2)
#> BiocBaseUtils 1.17.0 2026-11-23 [2] https://bioc.r-universe.dev (R 4.6.2)
#> BiocFileCache * 3.4.0 2026-11-23 [2] Bioconductor 3.24 (R 4.6.2)
#> BiocGenerics * 0.60.0 2026-11-24 [2] Bioconductor 3.24 (R 4.6.2)
#> BiocIO 1.25.0 2026-11-23 [2] https://bioc.r-universe.dev (R 4.6.2)
#> BiocManager 1.30.27 2025-11-14 [2] RSPM (R 4.6.0)
#> BiocNeighbors 2.9.0 2026-11-23 [2] https://bioc.r-universe.dev (R 4.6.2)
#> BiocParallel 1.48.0 2026-11-23 [2] Bioconductor 3.24 (R 4.6.2)
#> BiocSingular 1.31.0 2026-11-23 [2] https://bioc.r-universe.dev (R 4.6.2)
#> BiocStyle * 2.42.0 2026-11-23 [2] Bioconductor 3.24 (R 4.6.2)
#> BiocVersion 3.25.0 2026-11-23 [2] https://bioc.r-universe.dev (R 4.6.2)
#> Biostrings 2.82.0 2026-11-24 [2] Bioconductor 3.24 (R 4.6.2)
#> 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.24.0 2026-11-23 [2] Bioconductor 3.24 (R 4.6.2)
#> bslib 0.12.0 2026-08-04 [2] RSPM (R 4.6.0)
#> buildtools 1.0.0 2026-11-24 [3] local (/pkg)
#> cachem 1.1.0 2024-05-16 [2] RSPM (R 4.6.0)
#> cigarillo 1.5.0 2026-11-23 [2] https://bioc.r-universe.dev (R 4.6.2)
#> 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-4 2026-10-08 [2] RSPM (R 4.6.0)
#> ComplexHeatmap 2.30.0 2026-11-23 [2] Bioconductor 3.24 (R 4.6.2)
#> 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.2.0 2026-11-23 [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.3.0 2026-11-17 [2] RSPM (R 4.6.0)
#> DelayedArray 0.40.0 2026-11-24 [2] Bioconductor 3.24 (R 4.6.2)
#> 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 5.0.0 2026-11-23 [2] Bioconductor 3.24 (R 4.6.2)
#> evaluate 1.0.5 2025-08-27 [2] RSPM (R 4.6.0)
#> ExperimentHub * 3.4.0 2026-11-23 [2] Bioconductor 3.24 (R 4.6.2)
#> 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)
#> foreach 1.5.2 2022-02-02 [2] RSPM (R 4.6.0)
#> future 1.82.0 2026-11-02 [2] RSPM (R 4.6.0)
#> future.apply 1.21.0 2026-10-16 [2] RSPM (R 4.6.0)
#> generics * 0.1.4 2025-05-09 [2] RSPM (R 4.6.0)
#> GenomicAlignments 1.51.0 2026-11-23 [2] https://bioc.r-universe.dev (R 4.6.2)
#> GenomicRanges * 1.67.0 2026-11-23 [2] https://bioc.r-universe.dev (R 4.6.2)
#> 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.4 2026-11-14 [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.20.0 2026-10-11 [2] RSPM (R 4.6.0)
#> glue 1.8.1 2026-04-17 [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.4 2026-09-30 [2] RSPM (R 4.6.0)
#> IRanges * 2.48.0 2026-11-24 [2] Bioconductor 3.24 (R 4.6.2)
#> irlba 2.4.1 2026-10-05 [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.54.0 2026-11-23 [2] Bioconductor 3.24 (R 4.6.2)
#> 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 4.0.0 2026-11-23 [2] Bioconductor 3.24 (R 4.6.2)
#> listenv 1.1.0 2026-10-04 [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.4 2026-10-23 [2] RSPM (R 4.6.0)
#> markdown 2.1 2026-10-27 [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.27.0 2026-11-23 [2] https://bioc.r-universe.dev (R 4.6.2)
#> matrixStats * 1.5.0 2025-01-07 [2] RSPM (R 4.6.0)
#> mclust 6.1.4 2026-11-18 [2] RSPM (R 4.6.0)
#> memoise 2.0.1 2021-11-26 [2] RSPM (R 4.6.0)
#> metapod 1.22.0 2026-11-23 [2] Bioconductor 3.24 (R 4.6.2)
#> mime 0.13 2025-03-17 [2] RSPM (R 4.6.0)
#> otel 0.3.0 2026-11-07 [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.50.0 2026-10-31 [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)
#> pls 2.9-0 2026-02-21 [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)
#> progressr 1.1.0 2026-10-18 [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)
#> 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)
#> Rsamtools 2.31.0 2026-11-23 [2] https://bioc.r-universe.dev (R 4.6.2)
#> 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 2.0.0 2026-11-02 [2] RSPM (R 4.6.0)
#> rtracklayer 1.75.0 2026-11-23 [2] https://bioc.r-universe.dev (R 4.6.2)
#> Rtsne 0.17 2023-12-07 [2] RSPM (R 4.6.0)
#> S4Arrays 1.15.0 2026-11-24 [2] https://bioc.r-universe.dev (R 4.6.2)
#> S4Vectors * 0.53.0 2026-11-24 [2] https://bioc.r-universe.dev (R 4.6.2)
#> S7 1.0.0 2026-11-19 [2] RSPM (R 4.6.0)
#> sass 0.5.0 2026-11-20 [2] RSPM (R 4.6.0)
#> ScaledMatrix 1.22.0 2026-11-23 [2] Bioconductor 3.24 (R 4.6.2)
#> scales 1.4.0 2025-04-24 [2] RSPM (R 4.6.0)
#> scater * 1.42.0 2026-11-23 [2] Bioconductor 3.24 (R 4.6.2)
#> 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.42.0 2026-11-23 [2] Bioconductor 3.24 (R 4.6.2)
#> scrapper 1.8.0 2026-11-23 [2] Bioconductor 3.24 (R 4.6.2)
#> sctransform 0.4.3 2026-01-10 [2] RSPM (R 4.6.0)
#> scuttle * 1.24.0 2026-11-23 [2] Bioconductor 3.24 (R 4.6.2)
#> Seqinfo * 1.5.0 2026-11-24 [2] https://bioc.r-universe.dev (R 4.6.2)
#> sessioninfo 1.2.4 2026-06-04 [2] RSPM (R 4.6.0)
#> Seurat * 6.0.0 2026-11-07 [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.15.0 2026-11-20 [2] RSPM (R 4.6.0)
#> shinyWidgets 0.9.1 2026-03-09 [2] RSPM (R 4.6.0)
#> SingleCellExperiment * 1.36.0 2026-11-23 [2] Bioconductor 3.24 (R 4.6.2)
#> sp * 2.2-4 2026-10-11 [2] RSPM (R 4.6.0)
#> spam 2.11-4 2026-05-29 [2] RSPM (R 4.6.0)
#> SparseArray 1.15.0 2026-11-24 [2] https://bioc.r-universe.dev (R 4.6.2)
#> SpatialExperiment * 1.25.0 2026-11-23 [2] https://bioc.r-universe.dev (R 4.6.2)
#> spatialLIBD * 1.25.5 2026-11-11 [2] https://bioc.r-universe.dev (R 4.6.2)
#> 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.45.0 2026-11-24 [2] https://bioc.r-universe.dev (R 4.6.2)
#> sys 3.4.3 2024-10-04 [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.62 2026-10-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.54.0 2026-11-23 [2] Bioconductor 3.24 (R 4.6.2)
#> yaml 2.3.12 2025-12-10 [2] RSPM (R 4.6.0)
#>
#> [1] /tmp/RtmpSfhKOb/Rinst246a5d887429
#> [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.
#>
#> ──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────