SpNeigh: spatial neighborhood and differential expression analysis for high-resolution spatial transcriptomics.
28 blocks of code here have a permanent identifier (oscr:b:…), listed with the matches below: citable for good, with a page of its own. Select a match and press Cite to copy it. What a block identifier is.
The 40 matches · 13 of them tie a paragraph to a whole file without given lines: weak matches, whose lines are not tinted
- [1] § Materials and methods › Data preparation for SpNeigh ↔ inst/script/generate_vignette_data.R, the whole file · a weak match · score 0.93 · FindClusters, FindNeighbors, RunPCA, ScaleData, RunUMAP, NormalizeData · block
oscr:b:H8JFWF0M78PVT-O· Report a mismatch - [2] § Materials and methods › Data preparation for SpNeigh ↔ source_code/00_Prepare.Rmd, lines 161 to 195 · score 0.88 · FindClusters, FindNeighbors, RunPCA, ScaleData, RunUMAP, NormalizeData · block
oscr:b:TJJNQPT21DV6M-Q· Report a mismatch - [3] § Materials and methods › SpNeigh framework for spatial neighborhood modeling › Gradient-based spatial differential expression ↔ R/RunDE.R, lines 268 to 328 · score 0.88 · QR decomposition, augmented matrix, positively correlated, spline basis, design matrix, orthonormalize · block
oscr:b:YE6JZ35MB5AK7-4· Report a mismatch - [4] § Materials and methods › SpNeigh framework for spatial neighborhood modeling › Gradient-based spatial differential expression ↔ R/RunDE.R, lines 268 to 328 · score 0.88 · QR decomposition, augmented matrix, positively correlated, spline basis, design matrix, orthonormalize · block
oscr:b:QAS8V2B2HFAJT-K· Report a mismatch - [5] § Materials and methods › Analysis of human healthy liver MERFISH dataset using SpNeigh ↔ R/RunDE.R, lines 147 to 265 · score 0.88 · natural splines, computeBoundaryWeights, models gene expression, smooth function, runSpatialDE, getBoundary · block
oscr:b:ZSQ9J1RXP7G4B-0· Report a mismatch - [6] § Materials and methods › Analysis of human healthy liver MERFISH dataset using SpNeigh ↔ R/RunDE.R, lines 147 to 265 · score 0.88 · natural splines, ComputeBoundaryWeights, models gene expression, smooth function, RunSpatialDE, GetBoundary · block
oscr:b:A7PWASBVT9KVG-J· Report a mismatch - [7] § Materials and methods › SpNeigh framework for spatial neighborhood modeling › Gradient-based spatial differential expression ↔ R/RunDE.R, lines 268 to 328 · score 0.82 · natural cubic spline, spline basis, design matrix, spatial distance, freedom, ns · block
oscr:b:YE6JZ35MB5AK7-4· Report a mismatch - [8] § Materials and methods › SpNeigh framework for spatial neighborhood modeling › Gradient-based spatial differential expression ↔ R/RunDE.R, lines 268 to 328 · score 0.82 · natural cubic spline, spline basis, design matrix, spatial distance, freedom, ns · block
oscr:b:QAS8V2B2HFAJT-K· Report a mismatch - [9] § Materials and methods › Analysis of mouse brain Xenium dataset using SpNeigh ↔ R/GetBoundary.R, lines 684 to 756 · score 0.81 · getOuterBoundary, buildBoundaryPoly, getRingRegion, Boundary polygons, getBoundary, ring regions · block
oscr:b:A2CMM3KPEAR7N-0· Report a mismatch - [10] § Materials and methods › Analysis of mouse brain Xenium dataset using SpNeigh ↔ R/GetBoundary.R, lines 560 to 632 · score 0.81 · GetOuterBoundary, BuildBoundaryPoly, GetRingRegion, Boundary polygons, GetBoundary, ring regions · block
oscr:b:A6TC2N3EB3HES-T· Report a mismatch - [11] § Materials and methods › Benchmarking differential expression and spatial modeling in SpNeigh ↔ R/RunDE.R, lines 1 to 143 · score 0.80 · log fold changes, min.pct, log FC, runLimmaDE, mouse brain, Seurat · block
oscr:b:JWE083J17686N-C· Report a mismatch - [12] § Materials and methods › Benchmarking differential expression and spatial modeling in SpNeigh ↔ R/RunDE.R, lines 1 to 143 · score 0.80 · log fold changes, min.pct, log FC, RunLimmaDE, mouse brain, Seurat · block
oscr:b:7SJNQ71YNF4NT-J· Report a mismatch - [13] § Materials and methods › Analysis of human breast cancer Xenium dataset using SpNeigh › Neighborhood analysis of tumor and DCIS regions ↔ R/PlotInteractionMatrix.R, the whole file · a weak match · score 0.80 · plotInteractionMatrix, computeSpatialInteractionMatrix, focal clusters, row scaled, neighboring clusters, interactions · block
oscr:b:0DVFM2BS9DJV7-2· Report a mismatch - [14] § Materials and methods › Analysis of human breast cancer Xenium dataset using SpNeigh › Neighborhood analysis of tumor and DCIS regions ↔ R/PlotInteractionMatrix.R, the whole file · a weak match · score 0.80 · PlotInteractionMatrix, ComputeSpatialInteractionMatrix, focal clusters, row scaled, neighboring clusters, interactions · block
oscr:b:JK9R3C2J53SCY-S· Report a mismatch - [15] § Materials and methods › Analysis of human breast cancer Xenium dataset using SpNeigh › Neighborhood analysis of tumor and DCIS regions ↔ source_code_to_reproduce_figures/02_vignette_HumanBreastCancerXenium.Rmd, lines 217 to 231 · score 0.76 · human breast cancer, PlotStatsPie, plot_donut, StatsCellsInside, DCIS, ring · block
oscr:b:S3MF2QK25JP4R-8· Report a mismatch - [16] § Materials and methods › SpNeigh framework for spatial neighborhood modeling › Spatial enrichment index ↔ R/ComputeSpatialEnrichmentIndex.R, lines 1 to 103 · score 0.75 · avoid division, spatial enrichment, normalized SEI, zero, unweighted, gene expression · block
oscr:b:Q3J6J9CVH90KM-W· Report a mismatch - [17] § Results › Overview of the SpNeigh framework ↔ R/ComputeSpatialInteractionMatrix.R, the whole file · a weak match · score 0.75 · neighboring cluster identities, spatial interaction matrix, focal cluster, nearest neighbors, tabulating, rings · block
oscr:b:DZGD0HTVBE1M8-S· Report a mismatch - [18] § Results › Overview of the SpNeigh framework ↔ R/ComputeSpatialInteractionMatrix.R, the whole file · a weak match · score 0.75 · neighboring cluster identities, spatial interaction matrix, focal cluster, nearest neighbors, tabulating, rings · block
oscr:b:4JSMB6WBB0EPB-8· Report a mismatch - [19] § Materials and methods › Analysis of mouse brain Visium HD dataset using SpNeigh ↔ R/GetCellsInside.R, the whole file · a weak match · score 0.74 · Cells located inside, getRingRegion, getCellsInside, getBoundary, mouse brain, spatial boundaries · block
oscr:b:TM6DN2V4GQ1KM-K· Report a mismatch - [20] § Materials and methods › Analysis of mouse brain Visium HD dataset using SpNeigh ↔ R/GetCellsInside.R, the whole file · a weak match · score 0.74 · Cells located inside, GetRingRegion, GetCellsInside, GetBoundary, mouse brain, spatial boundaries · block
oscr:b:C37CQSNT9GFX4-J· Report a mismatch - [21] § Materials and methods › SpNeigh framework for spatial neighborhood modeling › Spatial neighborhood interaction matrix ↔ R/ComputeSpatialInteractionMatrix.R, the whole file · a weak match · score 0.74 · neighborhood interaction matrix, cluster identities, cell clusters, spatial neighbors, NN, nearest · block
oscr:b:DZGD0HTVBE1M8-S· Report a mismatch - [22] § Materials and methods › SpNeigh framework for spatial neighborhood modeling › Spatial neighborhood interaction matrix ↔ R/ComputeSpatialInteractionMatrix.R, the whole file · a weak match · score 0.74 · neighborhood interaction matrix, cluster identities, cell clusters, spatial neighbors, NN, nearest · block
oscr:b:4JSMB6WBB0EPB-8· Report a mismatch - [23] § Materials and methods › Benchmarking differential expression and spatial modeling in SpNeigh ↔ source_code_to_reproduce_figures/01_vignette_MouseBrainXenium.Rmd, lines 649 to 679 · score 0.72 · mouse brain Xenium, Spearman correlation, normalized SEI, RunSpatialDE, spatial enrichment, ranked · block
oscr:b:0545NMMD2T0GA-Y· Report a mismatch - [24] § Results › Overview of the SpNeigh framework ↔ R/RunDE.R, lines 147 to 265 · score 0.72 · smooth function, runLimmaDE, runSpatialDE, Bayes, fits, linear · block
oscr:b:ZSQ9J1RXP7G4B-0· Report a mismatch - [25] § Results › Overview of the SpNeigh framework ↔ R/RunDE.R, lines 147 to 265 · score 0.72 · smooth function, RunLimmaDE, RunSpatialDE, Bayes, fits, linear · block
oscr:b:A7PWASBVT9KVG-J· Report a mismatch - [26] § Materials and methods › SpNeigh framework for spatial neighborhood modeling › Spatial boundary detection and outlier removal ↔ R/GetBoundary.R, lines 253 to 321 · score 0.70 · concave hull algorithm, spatial boundaries, DBSCAN, subregions, smoothed, filtering · block
oscr:b:F8AJJ3CPAQHQ0-Q· Report a mismatch - [27] § Materials and methods › SpNeigh framework for spatial neighborhood modeling › Spatial boundary detection and outlier removal ↔ R/GetBoundary.R, lines 133 to 201 · score 0.70 · concave hull algorithm, spatial boundaries, DBSCAN, subregions, smoothed, filtering · block
oscr:b:VXW5M8AAQGDSA-B· Report a mismatch - [28] § Materials and methods › SpNeigh framework for spatial neighborhood modeling › Spatial boundary detection and outlier removal ↔ R/GetBoundary.R, lines 1 to 73 · score 0.67 · local density, remove spatial outliers, nearest neighbor, NN, distance, boundaries · block
oscr:b:W7PK3JTAT8XMA-Q· Report a mismatch - [29] § Materials and methods › SpNeigh framework for spatial neighborhood modeling › Spatial boundary detection and outlier removal ↔ R/GetBoundary.R, lines 1 to 73 · score 0.67 · local density, remove spatial outliers, nearest neighbor, NN, distance, boundaries · block
oscr:b:M284J749A10G4-A· Report a mismatch - [30] § Materials and methods › SpNeigh framework for spatial neighborhood modeling › Spatial boundary detection and outlier removal ↔ R/GetBoundary.R, lines 1 to 73 · score 0.67 · NN distance, spatial outliers, nearest neighbor, threshold, boundary, cell · block
oscr:b:W7PK3JTAT8XMA-Q· Report a mismatch - [31] § Materials and methods › SpNeigh framework for spatial neighborhood modeling › Spatial boundary detection and outlier removal ↔ R/GetBoundary.R, lines 1 to 73 · score 0.67 · NN distance, spatial outliers, nearest neighbor, threshold, boundary, cell · block
oscr:b:M284J749A10G4-A· Report a mismatch - [32] § Results › SpNeigh reveals immune microenvironment differences between breast tumor and DCIS neighborhoods ↔ R/PlotInteractionMatrix.R, the whole file · a weak match · score 0.66 · row scaled heatmap, spatial interaction matrices, computeSpatialInteractionMatrix, proximity, populations, neighborhoods · block
oscr:b:0DVFM2BS9DJV7-2· Report a mismatch - [33] § Results › SpNeigh reveals immune microenvironment differences between breast tumor and DCIS neighborhoods ↔ R/PlotInteractionMatrix.R, the whole file · a weak match · score 0.66 · row scaled heatmap, spatial interaction matrices, ComputeSpatialInteractionMatrix, proximity, populations, neighborhoods · block
oscr:b:JK9R3C2J53SCY-S· Report a mismatch - [34] § Materials and methods › Analysis of mouse brain Xenium dataset using SpNeigh ↔ R/ComputeWeights.R, lines 101 to 225 · score 0.66 · splitBoundaryPolyByAnchor, computeBoundaryWeights, boundary polygon, segmented, edges, spatial weights · block
oscr:b:4B75VT03BJEJE-D· Report a mismatch - [35] § Materials and methods › Analysis of mouse brain Xenium dataset using SpNeigh ↔ R/ComputeWeights.R, lines 93 to 212 · score 0.66 · SplitBoundaryPolyByAnchor, ComputeBoundaryWeights, boundary polygon, segmented, edges, spatial weights · block
oscr:b:45KKKF2PNVSA1-0· Report a mismatch - [36] § Materials and methods › Analysis of human breast cancer Xenium dataset using SpNeigh › Differential expression and spatial modeling of tumor and DCIS cells ↔ R/ComputeSpatialEnrichmentIndex.R, lines 1 to 103 · score 0.66 · normalized SEI scores, computeCentroidWeights, gene expression, spatial weights, enriched, cells · block
oscr:b:Q3J6J9CVH90KM-W· Report a mismatch - [37] § Materials and methods › Analysis of human breast cancer Xenium dataset using SpNeigh › Differential expression and spatial modeling of tumor and DCIS cells ↔ R/ComputeSpatialEnrichmentIndex.R, the whole file · a weak match · score 0.66 · normalized SEI scores, ComputeCentroidWeights, gene expression, spatial weights, enriched, cells · block
oscr:b:Y0N9Q0STGP26B-Q· Report a mismatch - [38] § Results › SpNeigh reveals intermediate cell populations at brain region boundaries in mouse cortex ↔ source_code_to_reproduce_figures/01_vignette_MouseBrainXenium.Rmd, lines 347 to 365 · score 0.65 · mouse brain Xenium, Slc17a7, RunLimmaDE, cells inside, ring, gene · block
oscr:b:57WVMY7ENPGAV-S· Report a mismatch - [39] § Results › SpNeigh reveals intermediate cell populations at brain region boundaries in mouse cortex ↔ inst/script/generate_vignette_data.R, the whole file · a weak match · score 0.65 · remove low quality, quality cells, mouse brain Xenium, Genomics, tiny, Seurat · block
oscr:b:H8JFWF0M78PVT-O· Report a mismatch - [40] § Results › SpNeigh reveals gene expression changes along spatial gradients of liver zonation ↔ source_code_to_reproduce_figures/03_vignette_HumanHealthyLiverMERFISH.Rmd, lines 402 to 436 · score 0.59 · COL1A1, CYP2E1, GLS2, liver, hepatocyte, MERFISH · block
oscr:b:Y3X3PN9QBBR2F-8· Report a mismatch
Paper
Loaded from Europe PMC by your browser; OSCR does not store it: doi.org · Europe PMC
The paper is loaded when this pane is shown.
The authors' code
R · 328 lines · 11 KB · GPL-3.0 · 5 matches
- #' Differential expression analysis between two groups of cells using limma
- #'
- #' Performs differential expression analysis between two groups of cells
- #' using the `limma` linear modeling framework.
- #' Supports optional observation-level weights (e.g., spatial weights)
- #' and filters genes by minimum expression threshold across groups.
- #'
- #' @param exp_mat A normalized gene expression matrix (genes x cells),
- #' either a `matrix` or `dgCMatrix`.
- #' Typically log-normalized counts, e.g., from a Seurat object.
- #' @param cells_reference A character vector of cell IDs to use as the
- #' reference (baseline) group.
- #' @param cells_target A character vector of cell IDs to use as the
- #' target (comparison) group.
- #' @param weights Optional numeric vector of observation-level weights.
- #' Must be named with cell IDs and
- #' match the length of `cells_reference + cells_target`.
- #' @param adj_p.value Adjusted p-value threshold for reporting
- #' differentially expressed genes. Default is `0.05`.
- #' @param min.pct Minimum proportion of cells expressing the gene in
- #' either group (values between 0 and 1).
- #' Genes not meeting this threshold are excluded before testing.
- #' Default is `0`.
- #'
- #' @return A data frame with differentially expressed genes,
- #' sorted by absolute log fold change.
- #' Includes columns:
- #' \describe{
- #' \item{logFC}{Log2 fold change of expression (target vs. reference)}
- #' \item{AveExpr}{Average expression across both groups}
- #' \item{t, P.Value, adj.P.Val, B}{Statistical results from `limma`}
- #' \item{pct.reference}{Proportion of reference cells expressing the gene}
- #' \item{pct.target}{Proportion of target cells expressing the gene}
- #' \item{gene}{Gene name (rownames from `exp_mat`)}
- #' }
- #'
- #' @export
- #'
- #' @examples
- #' # Load coordinates and log-normalized expression data
- #' coords <- readRDS(system.file("extdata", "MouseBrainCoords.rds",
- #' package = "SpNeigh"
- #' ))
- #' logNorm_expr <- readRDS(system.file("extdata", "LogNormExpr.rds",
- #' package = "SpNeigh"
- #' ))
- #'
- #' # Subset cells from cluster 0 and 2
- #' cells_ref <- subset(coords, cluster == 0)$cell
- #' cells_tar <- subset(coords, cluster == 2)$cell
- #'
- #' # Run differential expression with minimum expression threshold
- #' tab <- runLimmaDE(
- #' exp_mat = logNorm_expr,
- #' cells_reference = cells_ref,
- #' cells_target = cells_tar,
- #' min.pct = 0.25
- #' )
- #'
- #' head(tab[, c("gene", "logFC", "adj.P.Val", "pct.reference", "pct.target")])
- #'
- runLimmaDE <- function(
- exp_mat = NULL,
- cells_reference = NULL,
- cells_target = NULL,
- weights = NULL,
- adj_p.value = 0.05,
- min.pct = 0) {
- # --- Input checks ---
- if (is.null(exp_mat) || !inherits(exp_mat, c("matrix", "dgCMatrix"))) {
- stop(
- "'exp_mat' must be a numeric",
- " matrix or dgCMatrix (genes x cells)."
- )
- }
- if (is.null(cells_reference) || is.null(cells_target)) {
- stop("Both 'cells_reference' and 'cells_target' must be provided.")
- }
- all_cells <- c(cells_reference, cells_target)
- if (!all(all_cells %in% colnames(exp_mat))) {
- stop("Some cell IDs not found in column names of 'exp_mat'.")
- }
- if (!is.null(weights)) {
- if (is.null(names(weights)) || length(weights) != length(all_cells)) {
- stop(
- "'weights' must be a named numeric vector",
- " with the same length as all selected cells."
- )
- }
- weights <- weights[all_cells] # ensure correct order
- }
- # --- Convert to sparse matrix if needed ---
- if (inherits(exp_mat, "matrix")) {
- exp_mat <- Matrix::Matrix(exp_mat, sparse = TRUE)
- }
- # --- Subset expression matrix ---
- expr <- exp_mat[, all_cells, drop = FALSE]
- # --- Compute percentage of expressing cells ---
- df_pct <- data.frame(
- pct.reference = Matrix::rowMeans(expr[, cells_reference] > 0),
- pct.target = Matrix::rowMeans(expr[, cells_target] > 0)
- )
- rownames(df_pct) <- rownames(expr)
- # --- Filter genes ---
- keep_genes <- rowSums(df_pct >= min.pct) >= 1
- expr <- expr[keep_genes, , drop = FALSE]
- df_pct <- df_pct[keep_genes, , drop = FALSE]
- if (nrow(expr) == 0) {
- stop("No genes passed the 'min.pct' filter.")
- }
- # --- Build design matrix ---
- group <- factor(c(
- rep(1, length(cells_reference)),
- rep(2, length(cells_target))
- ))
- design <- stats::model.matrix(~group)
- # --- Fit model using limma ---
- fit <- limma::lmFit(expr, design, weights = weights)
- fit <- limma::eBayes(fit)
- tab <- limma::topTable(fit, coef = 2, number = Inf, p.value = adj_p.value)
- if (nrow(tab) == 0) {
- warning("No genes passed the adjusted p-value threshold.")
- return(tab)
- }
- # --- Add gene-level annotations ---
- tab <- cbind(tab, df_pct[rownames(tab), ])
- tab$gene <- rownames(tab)
- tab <- tab[order(abs(tab$logFC), decreasing = TRUE), ]
- return(tab)
- }
- #' Differential expression along spatial distance gradients using splines
- #'
- #' Performs spatially-aware differential expression (DE) analysis by
- #' modeling gene expression as a smooth function of a continuous
- #' spatial covariate (e.g., distance to a boundary or centroid).
- #' Natural spline basis functions are used to capture non-linear trends
- #' in expression relative to spatial distance.
- #' This method is suitable for identifying genes whose expression varies
- #' continuously across spatial structures.
- #'
- #' @inheritParams runLimmaDE
- #' @inheritParams splineDesign
- #' @param cell_ids A character vector of cell IDs (column names of `exp_mat`)
- #' used for DE analysis.
- #' @param spatial_distance A named numeric vector containing the spatial
- #' distance (or weights) for each cell.
- #' Must be the same length as `cell_ids`.
- #' Scaled distances are recommended.
- #'
- #' @return A data frame of differentially expressed genes, including:
- #' \describe{
- #' \item{AveExpr, F, P.Value, adj.P.Val}{limma differential expression
- #' outputs}
- #' \item{Z1, Z2, Z3}{Spline coefficients (Z1 typically corresponds
- #' to linear trend)}
- #' \item{gene}{Gene name (from `exp_mat`)}
- #' \item{trend}{"Positive" or "Negative" trend based
- #' on the sign of `Z1`}
- #' }
- #' The first spline coefficient (`Z1`) captures the main expression trend
- #' along the spatial distance.
- #'
- #'
- #' @export
- #'
- #' @examples
- #' # Load example data
- #' coords <- readRDS(system.file("extdata", "MouseBrainCoords.rds",
- #' package = "SpNeigh"
- #' ))
- #' logNorm_expr <- readRDS(system.file("extdata", "LogNormExpr.rds",
- #' package = "SpNeigh"
- #' ))
- #'
- #' # Identify cluster-specific cells and compute spatial weights
- #' cells_c0 <- subset(coords, cluster == 0)$cell
- #' bon_c0 <- getBoundary(data = coords, one_cluster = 0)
- #' weights <- computeBoundaryWeights(
- #' data = coords, cell_ids = cells_c0,
- #' boundary = bon_c0
- #' )
- #'
- #' # Run spatial DE
- #' result <- runSpatialDE(
- #' exp_mat = logNorm_expr, cell_ids = cells_c0,
- #' spatial_distance = weights
- #' )
- #' head(result)
- #'
- runSpatialDE <- function(
- exp_mat = NULL,
- cell_ids = NULL,
- spatial_distance = NULL,
- adj_p.value = 0.05,
- df = 3) {
- # --- Input checks ---
- if (is.null(exp_mat) || !inherits(exp_mat, c("matrix", "dgCMatrix"))) {
- stop("'exp_mat' must be a non-null numeric matrix (genes x cells).")
- }
- if (is.null(cell_ids)) {
- stop("'cell_ids' must be provided.")
- }
- if (!all(cell_ids %in% colnames(exp_mat))) {
- stop("Some cell IDs not found in column names of 'exp_mat'.")
- }
- all_cells <- cell_ids
- if (is.null(spatial_distance) || is.null(names(spatial_distance)) ||
- length(spatial_distance) != length(all_cells)) {
- stop(
- "'spatial_distance' must be a named vector, and its",
- " length must match the number of selected cells."
- )
- }
- # --- Make spatial_distance numeric and in correct order ---
- t1 <- as.numeric(spatial_distance[all_cells])
- # --- Subset expression matrix ---
- expr <- exp_mat[, all_cells, drop = FALSE]
- # --- Create spline-based design matrix ---
- Z <- splineDesign(t1, df = df)
- design <- stats::model.matrix(~Z)
- # --- Run limma ---
- fit <- limma::lmFit(expr, design)
- fit <- limma::eBayes(fit)
- tab <- limma::topTable(fit,
- coef = 2:(df + 1), number = Inf,
- p.value = adj_p.value
- )
- if (nrow(tab) == 0) {
- warning("No genes passed the adjusted p-value threshold.")
- return(tab)
- }
- # --- Annotate results ---
- tab$gene <- rownames(tab)
- tab$trend <- ifelse(tab$Z1 > 0, "Positive", "Negative")
- return(tab)
- }
- #' Generate an orthonormal spline-based design matrix
- #'
- #' Constructs an orthonormal design matrix from a numeric covariate
- #' (e.g., spatial distance) using a natural cubic spline basis.
- #' The output matrix can be used in linear modeling to capture smooth,
- #' non-linear trends along continuous variables.
- #'
- #' The first column of the resulting matrix is aligned to show
- #' a positive correlation with the input vector and typically captures
- #' the main linear or monotonic trend.
- #'
- #' @param x A numeric vector representing a continuous covariate
- #' (e.g., distance or pseudotime).
- #' @param df Integer. Degrees of freedom for the spline basis. Default is 3.
- #'
- #' @return A numeric matrix with orthonormal columns
- #' (same number of rows as `x`). The columns represent smoothed
- #' trends extracted from the spline basis. The first column is
- #' directionally aligned with the input vector (`x`).
- #'
- #' @importFrom splines ns
- #' @importFrom stats cor
- #'
- #' @export
- #'
- #' @examples
- #' x <- seq(0, 1, length.out = 100)
- #' Z <- splineDesign(x)
- #' cor(Z[, 1], x) # Should be > 0
- #'
- #' # Use Z in modeling
- #' y <- sin(2 * pi * x) + rnorm(100, sd = 0.2)
- #' fit <- lm(y ~ Z)
- #' summary(fit)
- splineDesign <- function(x, df = 3) {
- if (!is.numeric(x)) {
- stop("'x' must be a numeric vector.")
- }
- # Generate spline basis
- X <- splines::ns(as.numeric(x), df = df)
- # Augment matrix with intercept and original variable
- A <- cbind(1, x, X)
- # Orthonormalize via QR decomposition
- QR <- qr(A)
- r <- QR$rank
- R_rank <- QR$qr[seq(from = 1, to = r), seq(from = 1, to = r)]
- Z <- t(backsolve(R_rank, t(A), transpose = TRUE))
- # Remove intercept column
- Z <- Z[, -1]
- # Ensure first component is positively correlated with input
- if (stats::cor(Z[, 1], x) < 0) {
- Z[, 1] <- -Z[, 1]
- }
- return(Z)
- }
RunDE.R at commit a4af022, under GPL-3.0 · at the source
Overview
- Centre for Biomedical Data Science, Duke-NUS Medical School, Singapore169857, Singapore
- Duke-NUS AI + Medical Sciences Initiative, Duke-NUS Medical School, Singapore169857, Singapore
- Surgery Academic-Clinical Program, Duke-NUS Medical School, Singapore169857, Singapore
- Department of Hepato-pancreato-biliary and Transplant Surgery, Singapore General Hospital and National Cancer Centre Singapore, Singapore169610, Singapore
- Pre-hospital and Emergency Research Centre, Health Services Research and Population Health, Duke-NUS Medical School, Singapore169857, Singapore
- NUS Artificial Intelligence Institute, National University of Singapore, Singapore119077, Singapore
- Department of Biostatistics and Bioinformatics, Duke University, Durham 27710, United States
Abstract
Spatial transcriptomics technologies such as Xenium, MERFISH, and Visium HD enable high-resolution profiling of gene expression while preserving tissue architecture. However, most computational methods for spatial analysis do not explicitly model local tissue context, such as boundaries, neighborhoods, or gradients. Here, we present SpNeigh (https://
Reproduced under the paper's license (CC BY), from the paper cited above.
Repositories
Its files are read in the Code ↔ Paper reader above, with 40 matches between paragraphs and lines of code.
jinming-cheng/cheng_annotation_bmc_bioinfo
e304de70f45026388d9e281cf6e5bba8e4f12b4f, 17 July 2025Availability: 1 check, the latest on 29 September 2026: the link answers
- 29 September 2026: the link answers
10 files
- source_code/
00_Prepare.Rmd , R, 203 lines, 1 match - source_code/
01_01_Flex_Sample1_Seura , R, 477 linest_analysis.Rmd - source_code/
01_02_Flex_Sample1_prepa , R, 153 linesre_data_for_infercnv.Rmd - source_code/
01_03_Flex_Sample1_run_i , R, 318 linesnfercnv.Rmd - source_code/
02_01_Prepare_reference_ , R, 103 linesfor_Azimuth_and_RCTD.Rmd - source_code/
02_02_Prepare_reference_ , R, 123 linessubsets_for_Azimuth_and_ RCTD_for_runtime_compari ng.Rmd - source_code/
02_03_Xenium_Sample1_ana , R, 1,210 lineslysis.Rmd - source_code/
02_04_Xenium_Sample1_mul , R, 594 linestiple_runs_for_runtime_c omparing.Rmd - source_code/
02_05_Xenium_Sample2_ana , R, 1,044 lineslysis.Rmd - README.md, Text, 27 lines
jinming-cheng/SpNeigh
a4af022b7ad793a29c6a968326c8fc518bf64a61, 31 August 2026Availability: 1 check, the latest on 29 September 2026: the link answers
- 29 September 2026: the link answers
36 files
- R/
ComputeSpatialEnrichment , R, 131 lines, 2 matchesIndex.R - R/
ComputeSpatialInteractio , R, 91 lines, 2 matchesnMatrix.R - R/
ComputeWeights.R , R, 225 lines, 1 match - R/
GetBoundary.R , R, 847 lines, 4 matches - R/
GetCellsInside.R , R, 67 lines, 1 match - R/
PlotBoundary.R , R, 427 lines - R/
PlotCellsInside.R , R, 95 lines - R/
PlotExpression.R , R, 359 lines - R/
PlotInteractionMatrix.R , R, 103 lines, 2 matches - R/
PlotStats.R , R, 210 lines - R/
PlotWeights.R , R, 83 lines - R/
RunDE.R , R, 328 lines, 5 matches - R/
SpNeigh-package.R , R, 7 lines - R/
StatsCellsInside.R , R, 55 lines - R/
data.R , R, 18 lines - R/
utils.R , R, 108 lines - README.Rmd, R, 58 lines
- inst/
script/ , R, 48 lines, 2 matchesgenerate_vignette_data.R - tests/
testthat.R , R, 12 lines - tests/
testthat/ , R, 115 linestest-ComputeSpatialEnric hmentIndex.R - tests/
testthat/ , R, 30 linestest-ComputeSpatialInter actionMatrix.R - tests/
testthat/ , R, 224 linestest-ComputeWeights.R - tests/
testthat/ , R, 295 linestest-GetBoundary.R - tests/
testthat/ , R, 23 linestest-GetCellsInside.R - tests/
testthat/ , R, 60 linestest-PlotBoundary.R - tests/
testthat/ , R, 25 linestest-PlotCellsInside.R - tests/
testthat/ , R, 129 linestest-PlotExpression.R - tests/
testthat/ , R, 13 linestest-PlotInteractionMatr ix.R - tests/
testthat/ , R, 30 linestest-PlotStats.R - tests/
testthat/ , R, 23 linestest-PlotWeights.R - tests/
testthat/ , R, 385 linestest-RunDE.R - tests/
testthat/ , R, 22 linestest-StatsCellsInside.R - tests/
testthat/ , R, 41 linestest-utils.R - vignettes/
SpNeigh.Rmd , R, 686 lines - LICENSE.md, License, 595 lines
- README.md, Text, 64 lines
Zenodo 17505217
Availability: 1 check, the latest on 29 September 2026: the link answers (HTTP 200)
- 29 September 2026: the link answers (HTTP 200)
34 files
- R/
ComputeSpatialEnrichment , R, 97 lines, 1 matchIndex.R - R/
ComputeSpatialInteractio , R, 88 lines, 2 matchesnMatrix.R - R/
ComputeWeights.R , R, 212 lines, 1 match - R/
GetBoundary.R , R, 723 lines, 4 matches - R/
GetCellsInside.R , R, 63 lines, 1 match - R/
PlotBoundary.R , R, 384 lines - R/
PlotCellsInside.R , R, 90 lines - R/
PlotExpression.R , R, 338 lines - R/
PlotInteractionMatrix.R , R, 99 lines, 2 matches - R/
PlotStats.R , R, 208 lines - R/
PlotWeights.R , R, 83 lines - R/
RunDE.R , R, 328 lines, 5 matches - R/
StatsCellsInside.R , R, 52 lines - R/
data.R , R, 18 lines - R/
utils.R , R, 108 lines - README.Rmd, R, 40 lines
- tests/
testthat.R , R, 12 lines - tests/
testthat/ , R, 35 linestest-ComputeSpatialEnric hmentIndex.R - tests/
testthat/ , R, 9 linestest-ComputeSpatialInter actionMatrix.R - tests/
testthat/ , R, 71 linestest-ComputeWeights.R - tests/
testthat/ , R, 112 linestest-GetBoundary.R - tests/
testthat/ , R, 21 linestest-GetCellsInside.R - tests/
testthat/ , R, 49 linestest-PlotBoundary.R - tests/
testthat/ , R, 17 linestest-PlotCellsInside.R - tests/
testthat/ , R, 117 linestest-PlotExpression.R - tests/
testthat/ , R, 11 linestest-PlotInteractionMatr ix.R - tests/
testthat/ , R, 25 linestest-PlotStats.R - tests/
testthat/ , R, 21 linestest-PlotWeights.R - tests/
testthat/ , R, 134 linestest-RunDE.R - tests/
testthat/ , R, 17 linestest-StatsCellsInside.R - tests/
testthat/ , R, 22 linestest-utils.R - vignettes/
SpNeigh.Rmd , R, 521 lines - LICENSE.md, License, 595 lines
- README.md, Text, 27 lines
jinming-cheng/Rcodes_for_figures_SpNeigh_ms
25133ffb466986cb6ec381e54d24270377eed92d, 9 May 2026Availability: 1 check, the latest on 29 September 2026: the link answers
- 29 September 2026: the link answers
4 files
- source_code_to_reproduce
_figures/ , R, 778 lines, 2 matches01_vignette_MouseBrainXe nium.Rmd - source_code_to_reproduce
_figures/ , R, 520 lines, 1 match02_vignette_HumanBreastC ancerXenium.Rmd - source_code_to_reproduce
_figures/ , R, 457 lines, 1 match03_vignette_HumanHealthy LiverMERFISH.Rmd - README.md, Text, 25 lines
Zenodo 19109340
Availability: 1 check, the latest on 29 September 2026: the link answers (HTTP 200)
- 29 September 2026: the link answers (HTTP 200)
4 files
- source_code_to_reproduce
_figures/ , R, 778 lines01_vignette_MouseBrainXe nium.Rmd - source_code_to_reproduce
_figures/ , R, 520 lines02_vignette_HumanBreastC ancerXenium.Rmd - source_code_to_reproduce
_figures/ , R, 457 lines03_vignette_HumanHealthy LiverMERFISH.Rmd - README.md, Text, 2 lines
Code availability
The SpNeigh package is available at this GitHub repository: https://
Reproduced under the paper's license (CC BY), from the paper cited above.
Tracing map
Proposed by the machine: these links were found in the paper and verified at the source, without human review. The map will receive a Zenodo DOI once one of the paper's authors has validated it with their ORCID.
What the map holds:
- 5 repositories of the authors' code, each at its verified commit, with its license and how the link was found in the paper;
- 81 scripts, each with its path and the digest of its content;
- 40 matches between paragraphs of the paper and lines of the code (method lexical-v1);
- neither the text of the paper nor the code itself.
Its JSON (tracing-map.json) is deposited on Zenodo with its DOI once the map is validated.
Data
Datasets cited
- doi:10.5061/
dryad.37pvmcvsg , at Dryad; found in the text, “Spatial transcriptomics and single-cell datasets” - geo:GSE185862, at NCBI GEO; found in the text, “Spatial transcriptomics and single-cell datasets”
Data availability
In this study, we used publicly available datasets as detailed in Methods. Mouse brain tiny Xenium dataset: https://
Reproduced under the paper's license (CC BY), from the paper cited above.
Versions
The history of this record: each version stored by the harvester or made by a correction of its authors or of the maintainers of its code, and what changed in its facts. The texts of the paper (its abstract, its availability statements) are not part of it; versions that changed only those are not listed.
Version 1, 29 September 2026: the first record
Recorded: type, language, journal, volume, issue, pages, dates, 3 authors, 11 MeSH terms, 2 funders, 33 references.
Cite
This paper
Cheng, J., Chow, P. K. H., & Liu, N. (2026). SpNeigh: spatial neighborhood and differential expression analysis for high-resolution spatial transcriptomics. NAR genomics and bioinformatics, 8(2), lqag039. https://
BibTeX
@article{cheng2026spneig
author = {Cheng, Jinming and Chow, Pierce Kah Hoe and Liu, Nan},
title = {{SpNeigh: spatial neighborhood and differential expression analysis for high-resolution spatial transcriptomics}},
journal = {NAR genomics and bioinformatics},
year = {2026},
month = apr,
volume = {8},
number = {2},
pages = {lqag039},
publisher = {Oxford University Press},
issn = {2631-9268},
doi = {10.1093/
url = {https://
pmid = {41972009},
pmcid = {PMC13069690}
}
RIS
TY - JOUR
AU - Cheng, Jinming
AU - Chow, Pierce Kah Hoe
AU - Liu, Nan
TI - SpNeigh: spatial neighborhood and differential expression analysis for high-resolution spatial transcriptomics
T2 - NAR genomics and bioinformatics
J2 - NAR Genom Bioinform
PY - 2026
DA - 2026/
VL - 8
IS - 2
SP - lqag039
SN - 2631-9268
PB - Oxford University Press
DO - 10.1093/
UR - https://
LA - en
ER -
CSL-JSON
{
"id": "10.1093/
"type": "article-journal",
"title": "SpNeigh: spatial neighborhood and differential expression analysis for high-resolution spatial transcriptomics",
"container-title": "NAR genomics and bioinformatics",
"author": [
{
"family": "Cheng",
"given": "Jinming"
},
{
"family": "Chow",
"given": "Pierce Kah Hoe"
},
{
"family": "Liu",
"given": "Nan"
}
],
"container-title-short":
"volume": "8",
"issue": "2",
"page": "lqag039",
"DOI": "10.1093/
"PMID": "41972009",
"PMCID": "PMC13069690",
"ISSN": "2631-9268",
"publisher": "Oxford University Press",
"URL": "https://
"language": "en",
"issued": {
"date-parts": [
[
2026,
4,
8
]
]
}
}
The tracing map gets a citation of its own once an author has validated it and it has a DOI.
Similar papers
The papers with a page that share the most with this one: the tools found in their code, their categories, datasets, cited references and authors, the rarest counting most.
- [1] doi:10.1038/s41592-026-03194-8 [code]
- Beyond benchmarking: an expert-guided consensus approach to spatially aware clustering.Journal: Nature methodsIn common: SingleCellExperiment, limma, Seurat, 3 other tools, methods / tools, genetics / omics, 7 references
- [2] doi:10.15252/msb.202211080 [code]
- Vesalius: high-resolution in silico anatomization of spatial transcriptomic data using image analysis.Journal: Molecular systems biologyIn common: SingleCellExperiment, edgeR, limma, 7 other tools, genetics / omics, mouse, 2 references
- [3] doi:10.1038/s41588-024-01664-3 [code]
- BANKSY unifies cell typing and tissue domain segmentation for scalable spatial omics data analysis.Journal: Nature geneticsIn common: SingleCellExperiment, limma, circlize, 5 other tools, genetics / omics, mouse, 4 references
- [4] doi:10.1016/j.isci.2026.115982 [code]
- Multi-omics profiling-derived signature links cellular ecosystem to glioblastoma prognosis.Journal: iScienceIn common: edgeR, limma, circlize, 6 other tools, genetics / omics, 2 references
- [5] doi:10.1186/s13073-026-01704-z [code]
- Gene expression profiling enables refined parcellation of cortical layers in the heterogeneous human cerebral cortex.Journal: Genome medicineIn common: SingleCellExperiment, ComplexHeatmap, Seurat, 4 other tools, genetics / omics, mouse, 4 references
- [6] doi:10.1158/0008-5472.can-24-2248 [code]
- FOXR2 Targets LHX6+/
DLX+ Neural Lineages to Drive Central Nervous System Neuroblastoma. Journal: Cancer researchIn common: SingleCellExperiment, circlize, ComplexHeatmap, 4 other tools, genetics / omics, mouse, 4 references - [7] doi:10.1093/bib/bbaf316 [code]
- TriCLFF: a multi-modal feature fusion framework using contrastive learning for spatial domain identification.Journal: Briefings in bioinformaticsIn common: SingleCellExperiment, edgeR, limma, 4 other tools, genetics / omics, mouse, 3 references
- [8] doi:10.1038/s41588-023-01435-6 [code]
- Spatiotemporal transcriptomic maps of whole mouse embryos at the onset of organogenesis.Journal: Nature geneticsIn common: SingleCellExperiment, edgeR, limma, 5 other tools, genetics / omics, mouse, 2 references
- [9] doi:10.1038/s41467-024-50904-x [code]
- Inferring histology-associated gene expression gradients in spatial transcriptomic studies.Journal: Nature communicationsIn common: SingleCellExperiment, Seurat, patchwork, 3 other tools, genetics / omics, mouse, 4 references
- [10] doi:10.1038/s42003-026-10034-0 [code]
- Region- and cell type-specific changes in gene expression in the cerebellum after classical fear conditioning.Journal: Communications biologyIn common: SingleCellExperiment, limma, circlize, 5 other tools, genetics / omics, mouse, 2 references
Contribute
The authors of this paper can claim it, correct its record and validate its tracing map, and the maintainers of its code (its owner, or a public member of its organization) correct what it says of their repository; anyone signed in can ask for its removal. Every request goes to OSCR's own machine, which answers it; your account page follows them.
Sign in with ORCID to claim this paper as one of its authors, correct its record or validate its tracing map: when the paper's metadata lists your ORCID iD, you are recognized at once. Maintainers of its code: sign in with GitHub, then claim the repository on your account page.
Claim this paper
Correct its record
Say what each link of this record is, remove the ones that are not the paper's, add the ones that are missing. The correction becomes a new version of the record, in its Versions section.
Validate its tracing map
You validate the map as this page shows it: 5 repositories of the authors' code, each at its verified commit and with its license, 81 scripts, and 40 matches between paragraphs and code (see the Code and Map sections). It then receives a DOI on Zenodo, with you (your ORCID iD) and OSCR as its creators; the code itself is not deposited.
The map's fingerprint: sha256:dc3770ca53982caf…
Add the badge to the code's README
If you are an author or a maintainer of this paper's code, you can add this badge. It says what OSCR knows of the paper (its code, its validated tracing map) and links the code to this page. Paste one of these snippets under the README's title. Keep the two marks around it, so that the badge can be replaced in place and is never added twice. OSCR changes nothing in your repository.
Markdown
<!-- oscr-badge:start -->
[](https://openscicode.org/badge/doi/10.1093/nargab/lqag039)
<!-- oscr-badge:end -->reStructuredText
.. oscr-badge:start
.. image:: https://openscicode.org/badge/doi/10.1093/nargab/lqag039.svg
:target: https://openscicode.org/badge/doi/10.1093/nargab/lqag039
:alt: OSCR
.. oscr-badge:endHTML
<!-- oscr-badge:start -->
<a href="https://openscicode.org/badge/doi/10.1093/nargab/lqag039"><img src="https://openscicode.org/badge/doi/10.1093/nargab/lqag039.svg" alt="OSCR"></a>
<!-- oscr-badge:end -->On GitHub, open the README, choose Edit (the pencil), paste the snippet under the title, then "Commit changes".
- jinming-cheng/cheng_annotation_bmc_bioinfo: README.md on GitHub
- jinming-cheng/SpNeigh: README.md on GitHub
- jinming-cheng/Rcodes_for_figures_SpNeigh_ms: README.md on GitHub
If you choose to, you can have the badge kept up to date for you, with oscr badge --write from the command line or with the GitHub Action in your repository's workflows. Every other form and option (a card, AsciiDoc, LaTeX, shields.io) is on the badge page.
Request its removal
To ask OSCR to remove this record, the copies of its authors' scripts or its tracing map, use the removal request page: signed in, you say who you are, what to remove and why, then review and confirm the request. Published rules decide every request (how).
Discussion, reproductions, activity
Discussion: code errors and mismatches between the code and the paper about this paper and its code, from readers and its authors, beside the paper and its tracing map.
Report a mismatch between the code and the paper · Report a code error (signed in)
Reproductions: reports from readers who ran the authors' code and did not get the paper's result, what they ran, with which environment, commit and data.
Report a reproduction failure (signed in)
Versions of its code: the releases of its code tied to a version of this paper (the preprint, the accepted manuscript, the version of record…), each with the tracing map versioned with it.
Activity: what happens around this paper: new versions of its record, its map's validation, discussions and reproductions. It opens with sign-in.
