From 8b2288127ae014c11b46b610737bfc5087ee9093 Mon Sep 17 00:00:00 2001 From: Mukerrem Tufekcioglu <94932092+MTufekcioglu@users.noreply.github.com> Date: Thu, 19 Feb 2026 16:42:15 -0500 Subject: [PATCH 1/2] Fix swapped medv error messages in run.CSIDE.single Minor fix. medv error message, and vice versa. --- R/CSIDE.R | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/R/CSIDE.R b/R/CSIDE.R index a2e61c6..471ece3 100644 --- a/R/CSIDE.R +++ b/R/CSIDE.R @@ -44,15 +44,15 @@ run.CSIDE.single <- function(myRCTD, explanatory.variable, cell_types = NULL, c region_thresh <- cell_type_threshold / 2 r1 <- barcodes[X2[,2] < medv] if(length(r1) < region_thresh) - stop(paste0('run.CSIDE.single: number of pixels with explanatory.variable at least medv = ',medv, + stop(paste0('run.CSIDE.single: number of pixels with explanatory.variable below medv = ',medv, " is less than (one half of cell_type_threshold) = ", region_thresh, - ". Please make sure that explanatory.variable attains a large value sufficiently often.")) + ". Please make sure that explanatory.variable attains a small value sufficiently often.")) cell_type_filter <- aggregate_cell_types(myRCTD, r1, doublet_mode = doublet_mode) >= region_thresh r2 <- barcodes[X2[,2] > medv] if(length(r2) < region_thresh) - stop(paste0('run.CSIDE.single: number of pixels with explanatory.variable below medv = ',medv, + stop(paste0('run.CSIDE.single: number of pixels with explanatory.variable above medv = ',medv, " is less than (one half of cell_type_threshold) = ", region_thresh, - ". Please make sure that explanatory.variable attains a small value sufficiently often.")) + ". Please make sure that explanatory.variable attains a large value sufficiently often.")) cell_type_filter <- cell_type_filter & (aggregate_cell_types(myRCTD, r2, doublet_mode = doublet_mode) >= region_thresh) message(paste0('run.CSIDE.single: filtered out cell types: ', list(which(!cell_type_filter)), ' due to not having sufficiently many pixels with explanatory.value on either side of medv = ',medv, From dffa427a6a2ac74bc393ae2ffda16966da38c60e Mon Sep 17 00:00:00 2001 From: Mukerrem Tufekcioglu <94932092+MTufekcioglu@users.noreply.github.com> Date: Thu, 26 Feb 2026 08:34:52 -0500 Subject: [PATCH 2/2] exvar.point.density barcode subset bug fix Bug: exvar.point.density takes in a list of barcodes (pixels) of the spatialRNA object to be used when constructing the explanatory variable, but overwrites this list and and uses all barcodes (pixels) to construct explanatory variable. --- R/CSIDE_utils.R | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/R/CSIDE_utils.R b/R/CSIDE_utils.R index 4b2ed10..e354400 100644 --- a/R/CSIDE_utils.R +++ b/R/CSIDE_utils.R @@ -426,15 +426,15 @@ exvar.celltocell.interactions <- function(myRCTD, barcodes, cell_type, radius = #' @export exvar.point.density <- function(myRCTD, barcodes, points, radius = 50) { puck <- myRCTD@spatialRNA - explanatory.variable = c(rep(0,length(barcodes))) - names(explanatory.variable) = barcodes + target_coords <- puck@coords[barcodes, , drop = FALSE] # fields::rdist treats rows as coordinates and computes all distances between placing them in a distance matrix. - dist_matrix = fields::rdist(as.matrix(puck@coords), as.matrix(points)) - rownames(dist_matrix) = rownames(puck@coords) + dist_matrix <- fields::rdist(as.matrix(target_coords), as.matrix(points)) + rownames(dist_matrix) <- barcodes # Precompute the exponent component of the proximity score for all pairs of cells - exponent_mat = exp(-dist_matrix/radius) + exponent_mat <- exp(-dist_matrix/radius) explanatory.variable <- rowSums(exponent_mat) - explanatory.variable = normalize_ev(explanatory.variable) + explanatory.variable <- normalize_ev(explanatory.variable) + return(explanatory.variable) } # Normalize explanatory.variable so the values span from 0 to 1.