This vignette covers advanced usage scenarios for SpaTalk, including:
You can use your own curated LR pairs instead of the built-in CellTalkDB:
# Custom LR pairs must have these columns:
# - ligand: ligand gene symbol
# - receptor: receptor gene symbol
# - species: "Human" or "Mouse"
custom_lrpairs <- data.frame(
ligand = c("CXCL12", "CCL2", "VEGFA"),
receptor = c("CXCR4", "CCR2", "KDR"),
species = "Human"
)
# Use in find_lr_path
obj <- find_lr_path(obj, lrpairs = custom_lrpairs, pathways = pathways)# Custom pathways must have:
# - src: source gene
# - dest: destination gene (downstream)
# - type: interaction type (optional)
custom_pathways <- data.frame(
src = c("CXCR4", "CXCR4", "STAT3"),
dest = c("STAT3", "AKT1", "MYC"),
type = c("activation", "activation", "transcription")
)
obj <- find_lr_path(obj, lrpairs = lrpairs, pathways = custom_pathways)SpaTalk supports multiple deconvolution backends:
SpaTalk leverages doParallel for multi-core
computation:
For large datasets, consider:
# Process cell types in batches
celltypes <- unique(obj@meta$rawmeta$celltype)
batch_size <- 5
for(i in seq(1, length(celltypes), batch_size)) {
batch <- celltypes[i:min(i + batch_size - 1, length(celltypes))]
for(ct_sender in batch) {
for(ct_receiver in batch) {
obj <- dec_cci(obj, ct_sender, ct_receiver)
}
}
gc() # Force garbage collection
}# Load Visium data (via Seurat)
library(Seurat)
visium <- Load10X_Spatial("/path/to/visium/")
# Extract data for SpaTalk
st_data <- GetAssayData(visium, slot = "counts")
st_meta <- data.frame(
spot = colnames(visium),
x = visium@images$slice1@coordinates$col,
y = visium@images$slice1@coordinates$row
)
# Create SpaTalk object (spot-based)
obj <- createSpaTalk(
st_data = st_data,
st_meta = st_meta,
species = "Human",
if_st_is_sc = FALSE,
spot_max_cell = 10 # Expected cells per spot
)Issue: “Gene not found in ST data”
# Check gene overlap
st_genes <- rownames(obj@data$rawdata)
lr_genes <- unique(c(lrpairs$ligand, lrpairs$receptor))
overlap <- intersect(st_genes, lr_genes)
cat("Overlapping genes:", length(overlap), "\n")Issue: Memory errors with large datasets
# Reduce data size
obj <- createSpaTalk(
st_data = st_data[, sample(ncol(st_data), 5000)], # Subsample spots
...
)Issue: No significant LR pairs found
spot_max_cell based on platformsessionInfo()
#> R version 4.6.1 (2026-06-24)
#> Platform: x86_64-pc-linux-gnu
#> Running under: Ubuntu 26.04 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.32.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=en_US.UTF-8
#> [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] stats graphics grDevices utils datasets methods base
#>
#> other attached packages:
#> [1] rmarkdown_2.31
#>
#> loaded via a namespace (and not attached):
#> [1] digest_0.6.39 R6_2.6.1 fastmap_1.2.0 xfun_0.59
#> [5] maketools_1.3.2 cachem_1.1.0 knitr_1.51 htmltools_0.5.9
#> [9] buildtools_1.0.0 lifecycle_1.0.5 cli_3.6.6 sass_0.4.10
#> [13] jquerylib_0.1.4 compiler_4.6.1 sys_3.4.3 tools_4.6.1
#> [17] evaluate_1.0.5 bslib_0.11.0 yaml_2.3.12 otel_0.2.0
#> [21] jsonlite_2.0.0 rlang_1.2.0