panoramic_analyze)PANORAMIC is designed for multi-sample spatial colocalization analysis. It estimates sample-level spatial effects, then pools them with multilevel meta-analysis to test group-level differences.
Compared with single-sample analyses, PANORAMIC gives you:
beta_diff, p_diff, fdr_diff)This vignette focuses on practical usage:
panoramic_analyze()).if (!requireNamespace("BiocManager", quietly = TRUE)) {
install.packages("BiocManager")
}
BiocManager::install("panoramic")
library(panoramic)
library(SummarizedExperiment)
library(BiocParallel)
library(dplyr)
library(ggplot2)
| Step | Function | Primary output | Why it matters |
|---|---|---|---|
| 1 | panoramic_prepare() |
list of prepared SpatialExperiments with cached spatial objects |
standardizes per-sample inputs |
| 2 | panoramic_spatialstats() |
SummarizedExperiment with sample-level yi / vi |
quantifies within-sample spatial effects |
| 3 | panoramic_meta_mv() |
pooled multilevel results + differential contrasts | tests group-level biology |
| Convenience | panoramic_analyze() |
list with prep, stats, pooled, tables |
one-call reproducible pipeline |
We simulate two groups of samples with different spatial structure:
group1: mostly random cell mixinggroup2: stronger local colocalization for early cell typesset.seed(123)
toy <- panoramic_simulate_dataset(
n_group1 = 3,
n_group2 = 3,
n_cells_group1 = 200,
n_cells_group2 = 350,
group_labels = c("group1", "group2"),
scenario_group1 = "random",
scenario_group2 = "colocalized",
seed = 123
)
spe_list <- toy$spe_list
design <- toy$design
design
#> sample group
#> 1 sample_1 group1
#> 2 sample_2 group1
#> 3 sample_3 group1
#> 4 sample_4 group2
#> 5 sample_5 group2
#> 6 sample_6 group2
Quick geometric sanity check:
plot_df <- do.call(rbind, lapply(spe_list, function(spe) {
coords <- SpatialExperiment::spatialCoords(spe)
data.frame(
x = coords[, 1],
y = coords[, 2],
cell_type = SummarizedExperiment::colData(spe)$cell_type,
sample_id = SummarizedExperiment::colData(spe)$sample_id,
stringsAsFactors = FALSE
)
}))
ggplot(plot_df, aes(x = x, y = y, color = cell_type)) +
geom_point(size = 0.7, alpha = 0.7) +
facet_wrap(~ sample_id, nrow = 2) +
coord_equal() +
theme_bw() +
labs(x = "x", y = "y", color = "Cell type")
prep <- panoramic_prepare(
spe_list = spe_list,
design = design,
cell_type = "cell_type",
min_cells = 5,
window = "concave"
)
names(S4Vectors::metadata(prep[[1]])$panoramic)
#> [1] "sample_id" "group_id" "ppp" "ppp_rescaled" "marks_tab"
#> [6] "results"
Default PANORAMIC statistic is stat = "local_comp_enrichment"
(percentage-point enrichment vs local null expectation).
radii_um <- c(25)
se <- panoramic_spatialstats(
prep = prep,
radii_um = radii_um,
stat = "local_comp_enrichment",
nsim = 30,
seed = 123,
BPPARAM = BiocParallel::SerialParam()
)
dim(se)
#> [1] 9 6
head(as.data.frame(rowData(se))[, c("ct1", "ct2", "radius_um", "stat")])
#> ct1 ct2 radius_um stat
#> A|A|25 A A 25 local_comp_enrichment
#> B|A|25 B A 25 local_comp_enrichment
#> C|A|25 C A 25 local_comp_enrichment
#> A|B|25 A B 25 local_comp_enrichment
#> B|B|25 B B 25 local_comp_enrichment
#> C|B|25 C B 25 local_comp_enrichment
panoramic_meta_mv() pools sample-level effects and computes
differential contrasts between groups.
# Here patient_col and sample_col are both "sample" in toy data.
# In real data, patient_col can differ from sample_col (e.g., multiple cores per patient).
se_meta <- panoramic_meta_mv(
se,
patient_col = "sample",
group_col = "group",
sample_col = "sample",
tau_structure = "patient",
method = "REML",
group_tau2 = "separate"
)
Each row in rowData(se_meta) is one feature (ct1, ct2,
radius_um) with pooled effects and contrasts.
For differential terms:
beta_diff: stronger spatial effect in group2 vs
group1beta_diff: weaker spatial effect in group2fdr_diff: stronger evidence after multiplicity correctionres <- panoramic_extract_contrast(se_meta)
head(res[, c("ct1", "ct2", "radius_um", "beta_diff", "p_diff", "fdr_diff")])
#> ct1 ct2 radius_um beta_diff p_diff fdr_diff
#> 1 A A 25 13.557679 9.276207e-08 1.043573e-07
#> 2 B A 25 15.649632 6.122546e-38 1.836764e-37
#> 3 C A 25 9.858781 9.285220e-09 1.193814e-08
#> 4 A B 25 12.296240 1.572884e-25 3.538988e-25
#> 5 B B 25 12.052931 1.720677e-10 2.581015e-10
#> 6 C B 25 4.774375 4.457909e-05 4.457909e-05
res %>% dplyr::filter(fdr_diff < 0.05)
#> ct1 ct2 radius_um beta_diff se_diff z_diff p_diff fdr_diff
#> 1 A A 25 13.557679 2.5387199 5.340360 9.276207e-08 1.043573e-07
#> 2 B A 25 15.649632 1.2153857 12.876268 6.122546e-38 1.836764e-37
#> 3 C A 25 9.858781 1.7165725 5.743294 9.285220e-09 1.193814e-08
#> 4 A B 25 12.296240 1.1774314 10.443275 1.572884e-25 3.538988e-25
#> 5 B B 25 12.052931 1.8878713 6.384403 1.720677e-10 2.581015e-10
#> 6 C B 25 4.774375 1.1695110 4.082368 4.457909e-05 4.457909e-05
#> 7 A C 25 -10.281512 0.7757830 -13.253076 4.330794e-40 1.948857e-39
#> 8 B C 25 -12.744308 0.7577186 -16.819314 1.761880e-63 1.585692e-62
#> 9 C C 25 -8.871954 0.9331915 -9.507109 1.960345e-21 3.528622e-21
#> coloc_source coloc_target coloc_direction
#> 1 A A A -> A
#> 2 A B A -> B
#> 3 A C A -> C
#> 4 B A B -> A
#> 5 B B B -> B
#> 6 B C B -> C
#> 7 C A C -> A
#> 8 C B C -> B
#> 9 C C C -> C
panoramic_analyze)Use panoramic_analyze() when you want a single reproducible entry
point for end-to-end runs.
out <- panoramic_analyze(
spe_list = spe_list,
design = design,
cell_type = "cell_type",
radii_um = radii_um,
nsim = 20,
min_cells = 5,
window = "concave",
BPPARAM = BiocParallel::SerialParam()
)
names(out)
#> [1] "prep" "stats" "pooled" "tables"
names(out$tables)
#> [1] "spatialstats" "meta" "contrast"
plot_forest(
se_meta,
ct1 = "A",
ct2 = "B",
radius_um = 25,
group_col = "group"
)
plot_volcano(se_meta)
net <- create_spatial_network(
se_meta,
fdr_threshold = 0.2,
directed = FALSE,
leiden_resolution = 1.0
)
plot_spatial_network(
se_meta,
fdr_threshold = 0.2,
directed = FALSE,
layout = "fr",
node_size_by = "degree"
)
local_comp_enrichment unless you have a specific reason
to use L/K-function alternatives.nsim for final analyses (the vignette uses modest values
for speed).sample, group, patient) explicit and
consistent early in your workflow.