From 11324c92d257aac613ee06ace0b470418a206549 Mon Sep 17 00:00:00 2001 From: Constantin Zackl Date: Mon, 11 Mar 2024 18:03:15 +0100 Subject: [PATCH 1/2] updated scaling --- R/scale_cell_counts.R | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/R/scale_cell_counts.R b/R/scale_cell_counts.R index 4d4e5743..048f55b6 100644 --- a/R/scale_cell_counts.R +++ b/R/scale_cell_counts.R @@ -26,12 +26,14 @@ scale_cell_counts <- function(spe, value, cell_counts, resName = NULL) { resName <- paste0(value, "_absolute") } - if (any(is.na(match(rownames(colData(spe)), names(cell_densities))))) { - stop("Not all rownames in colData have a matching entry in cell_densities.") + if (cell_counts %in% colnames(colData(spe))){ + cell_densities = colData(spe)[, cell_counts] + } else { + stop("Cell count data not available in the object") } # Calculate absolute cell densities - absoluteValues <- colData(spe)[, value] * cell_densities[rownames(colData(spe))] + absoluteValues <- colData(spe)[, value] * cell_densities # Add the absolute cell densities as a new column colData(spe)[[resName]] <- absoluteValues From 9259e20d114119a43f77226ea9b6fc0e214c31c4 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 12 Mar 2024 13:23:09 +0000 Subject: [PATCH 2/2] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- R/scale_cell_counts.R | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/R/scale_cell_counts.R b/R/scale_cell_counts.R index 048f55b6..d1bac1d2 100644 --- a/R/scale_cell_counts.R +++ b/R/scale_cell_counts.R @@ -26,8 +26,8 @@ scale_cell_counts <- function(spe, value, cell_counts, resName = NULL) { resName <- paste0(value, "_absolute") } - if (cell_counts %in% colnames(colData(spe))){ - cell_densities = colData(spe)[, cell_counts] + if (cell_counts %in% colnames(colData(spe))) { + cell_densities <- colData(spe)[, cell_counts] } else { stop("Cell count data not available in the object") }