An R package for estimating spatially varying cell-cell interaction networks in tissue imaging data. Each cell type's expression is regressed on every other cell type via a Hilbert Space Gaussian Process (HSGP) basis expansion with Matern smoothness, combined with a group horseshoe prior across neighbors for edge sparsity and a global half-Cauchy shrinkage parameter.
The original script could not run as committed. While restructuring it into
a package, four issues were fixed (all documented inline in the source and
in ?gp_group_horseshoe_sampler / ?build_hsgp_basis / ?matern32_kernel):
matern_spectral_density()andmatern32_kernel()were called but never defined anywhere in the repository. Standard, well-established closed forms are now supplied inR/kernels.R(the HSGP spectral density of Riutort-Mayol et al. 2020, and the standard Matern-3/2 kernel).build_hsgp_basis()referenced an undefinedlam_ywhen combining per-axis basis eigenvalues; fixed by reusinglam_x(the 1D eigenvalue formula depends only on mode index and domain width, not the coordinate axis).gp_group_horseshoe_sampler()sampledMASS::mvrnorm(10, ...)instead ofMASS::mvrnorm(1, ...)for thethetaupdate, producing a vector 10x too long.- The
tau_squpdate referenced an undefinedglobal_norm; now accumulated per the full-conditional derivation already documented in the source comments.
If you had different implementations of any of these in mind, they are
isolated to R/kernels.R (items 1) and R/hsgp-basis.R / R/sampler.R
(items 2-4) and can be swapped out independently.
# install.packages("remotes")
remotes::install_github("sagnikbhadury/GP-GHS")plot_all_edges() and plot_adj_heatmap() additionally require the
tidyr and reshape2 packages respectively; ggplot2 is used by all
plotting functions when available, with a base R fallback for
plot_edge_map().
library(GPGHS)
result <- gp_group_horseshoe_graph(
Y = expression_matrix, # spots/cells x cell types, normalized
coords = coords, # n x 2 spatial coordinates
m = 5, nu = 1.5,
nmc = 3000, burn = 1000, thin = 5,
symmetry = "AND"
)
print(result$adj)
plot_adj_heatmap(result)
plot_edge_map(result, "CT1", "CT3")See ?gp_group_horseshoe_graph for full documentation.