From 63bbc9bc3684e20d59c80edacb9a928c259ce2e1 Mon Sep 17 00:00:00 2001 From: Constantin Zackl Date: Mon, 15 Sep 2025 11:51:53 +0200 Subject: [PATCH 1/3] added new parameter to comparison function --- R/visualization.R | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/R/visualization.R b/R/visualization.R index 70f92f7a..a008e524 100644 --- a/R/visualization.R +++ b/R/visualization.R @@ -399,6 +399,7 @@ plot_most_abundant <- function(spe, method = NULL, cell_type = NULL, remove = NU #' @param spe deconvolution result in Form of a SpatialExperiment #' @param cell_type_1 celltype to plot #' @param cell_type_2 celltype to plot +#' @param comparison_type method to calculate comparison, logfc (default) or zscore #' @param palette colorspace palette (sequential) #' @param transform_scale data transform_scaleation to use, "log" #' @param reverse_palette reverse color palette @@ -429,6 +430,7 @@ plot_most_abundant <- function(spe, method = NULL, cell_type = NULL, remove = NU #' #' @export plot_comparison <- function(spe, cell_type_1 = NULL, cell_type_2 = NULL, + comparison_type = c("logfc", "zscore"), palette = "Blue-Red", transform_scale = NULL, sample_id = "sample01", image_id = "lowres", reverse_palette = FALSE, background = NULL, zoom = TRUE, @@ -439,23 +441,25 @@ plot_comparison <- function(spe, cell_type_1 = NULL, cell_type_2 = NULL, legend_size = 20, palette_type = "diverging", density = TRUE, save = FALSE, path = NULL, png_width = 1500, png_height = 750, show_legend = TRUE, ...) { - spe <- filter_sample_id(spe, sample_id) - df <- as.data.frame(cbind(SpatialExperiment::spatialCoords(spe), colData(spe))) + comparison_type <- match.arg(comparison_type) - # comparison <-df[, cell_type_1] - df[, cell_type_2] - # - # cmean <- mean(comparison) - # csd <- sd(comparison) - # - # zcomparison <- (comparison-cmean)/csd - # comparison <- zcomparison + spe <- filter_sample_id(spe, sample_id) + df <- as.data.frame(cbind(SpatialExperiment::spatialCoords(spe), colData(spe))) - comparison <- (df[, cell_type_1] + 1) / (df[, cell_type_2] + 1) - # comparison <- comparison - 1 - comparison <- log(comparison) - comparison[is.infinite(comparison)] <- NA # ? + if (comparison_type == "logfc") { + # log fold change + comparison <- (df[, cell_type_1] + 1) / (df[, cell_type_2] + 1) + comparison <- log(comparison) + comparison[is.infinite(comparison)] <- NA + } else if (comparison_type == "zscore") { + # z-score of difference + comparison <- df[, cell_type_1] - df[, cell_type_2] + cmean <- mean(comparison, na.rm = TRUE) + csd <- sd(comparison, na.rm = TRUE) + comparison <- (comparison - cmean) / csd + } df <- cbind(df, comparison = comparison) From 8ad2e3661af506cf9fb8b884cdab58b07cc264c9 Mon Sep 17 00:00:00 2001 From: Constantin Zackl Date: Mon, 15 Sep 2025 12:09:10 +0200 Subject: [PATCH 2/3] documented --- DESCRIPTION | 2 +- man/plot_comparison.Rd | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index 14b6c708..60fc94c7 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -8,7 +8,7 @@ Description: Collection of 31 deconvolution tools for spatial transcriptomics da License: GPL-3 + file LICENSE Encoding: UTF-8 Roxygen: list(markdown = TRUE) -RoxygenNote: 7.3.2 +RoxygenNote: 7.3.3 VignetteBuilder: knitr LazyData: FALSE Depends: diff --git a/man/plot_comparison.Rd b/man/plot_comparison.Rd index 9ae848c4..f2f047d1 100644 --- a/man/plot_comparison.Rd +++ b/man/plot_comparison.Rd @@ -8,6 +8,7 @@ plot_comparison( spe, cell_type_1 = NULL, cell_type_2 = NULL, + comparison_type = c("logfc", "zscore"), palette = "Blue-Red", transform_scale = NULL, sample_id = "sample01", @@ -42,6 +43,8 @@ plot_comparison( \item{cell_type_2}{celltype to plot} +\item{comparison_type}{method to calculate comparison, logfc (default) or zscore} + \item{palette}{colorspace palette (sequential)} \item{transform_scale}{data transform_scaleation to use, "log"} From 1d84c6a1e74dda2c28e0df5dcb8c225c6e41c4de Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 15 Sep 2025 10:36:38 +0000 Subject: [PATCH 3/3] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- R/visualization.R | 1 - 1 file changed, 1 deletion(-) diff --git a/R/visualization.R b/R/visualization.R index a008e524..dc8893fb 100644 --- a/R/visualization.R +++ b/R/visualization.R @@ -441,7 +441,6 @@ plot_comparison <- function(spe, cell_type_1 = NULL, cell_type_2 = NULL, legend_size = 20, palette_type = "diverging", density = TRUE, save = FALSE, path = NULL, png_width = 1500, png_height = 750, show_legend = TRUE, ...) { - comparison_type <- match.arg(comparison_type) spe <- filter_sample_id(spe, sample_id)