From 1bd8483501cababca1bf07e1fc1d4cd4302e6e2f Mon Sep 17 00:00:00 2001 From: nilseling Date: Tue, 12 Dec 2023 16:44:28 +0100 Subject: [PATCH] Initialize objects with colnames and add check to binAcrossPixels --- NEWS | 2 ++ R/binAcrossPixels.R | 8 ++++++-- R/read_cpout.R | 3 +++ R/read_steinbock.R | 3 +++ 4 files changed, 14 insertions(+), 2 deletions(-) diff --git a/NEWS b/NEWS index 8dfc183..3a36587 100644 --- a/NEWS +++ b/NEWS @@ -216,4 +216,6 @@ Changes in version 1.7.8 (2023-10-19) Changes in version 1.9.1 (2023-11-20) + Switched from aes_ to .data ++ Initialise SPE and SCE objects with colnames ++ Additional test within binAcrossPixels diff --git a/R/binAcrossPixels.R b/R/binAcrossPixels.R index 722f278..5e3eb3a 100644 --- a/R/binAcrossPixels.R +++ b/R/binAcrossPixels.R @@ -54,8 +54,12 @@ binAcrossPixels <- function(object, stop("'statistic' must be 'sum', 'mean' or 'median'.") } - cur_split <- split(object[[spot_id]], f = object[[spot_id]]) - cur_split <- lapply(cur_split, function(x){ceiling(seq_along(x)/bin_size)}) + cur_split_tmp <- split(object[[spot_id]], f = object[[spot_id]]) + cur_split <- lapply(cur_split_tmp, function(x){ceiling(seq_along(x)/bin_size)}) + + if (!isTRUE(all.equal(unlist(cur_split_tmp), object[[spot_id]]))) { + stop("Spot IDs of pixels within 'object' are not ordered alphabetically.") + } cur_df <- DataFrame(spot_id = object[[spot_id]], bin = unlist(cur_split)) diff --git a/R/read_cpout.R b/R/read_cpout.R index 373530f..87c0118 100644 --- a/R/read_cpout.R +++ b/R/read_cpout.R @@ -171,5 +171,8 @@ read_cpout <- function(path, object <- .add_panel(object, path, panel_file, extract_metal_from) + # Add colnames + colnames(object) <- paste0(object$sample_id, "_", object$ObjectNumber) + return(object) } diff --git a/R/read_steinbock.R b/R/read_steinbock.R index 178e153..42337ad 100644 --- a/R/read_steinbock.R +++ b/R/read_steinbock.R @@ -161,5 +161,8 @@ read_steinbock <- function(path, # Add panel data object <- .add_panel(object, path, panel_file, extract_names_from) + # Add colnames + colnames(object) <- paste0(object$sample_id, "_", object$ObjectNumber) + return(object) }