From 3eef54ce89d3e390bc85bcf9af197f79634ccb0b Mon Sep 17 00:00:00 2001 From: Caitlin Winkler Date: Wed, 31 Jan 2024 09:38:27 -0700 Subject: [PATCH] Color palette fix, additional tests --- R/experiments_data.R | 4 ++-- tests/testthat/setup.R | 3 +++ tests/testthat/test-experiments_data.R | 6 ++++++ 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/R/experiments_data.R b/R/experiments_data.R index 1e1560c..2ca6874 100644 --- a/R/experiments_data.R +++ b/R/experiments_data.R @@ -384,8 +384,8 @@ add_cluster_annotations <- function(seurat_obj, cluster_obj, silent = FALSE){ } annotation_set <- data.frame( factor(cluster_number), - factor(cluster_display_name), - factor(cluster_color) + cluster_display_name, + cluster_color ) colnames(annotation_set) <- c(target_res, clean_display_name, "cluster_color") annotation_map <- annotation_set[c(target_res, clean_display_name)] diff --git a/tests/testthat/setup.R b/tests/testthat/setup.R index bf96003..b280fbe 100644 --- a/tests/testthat/setup.R +++ b/tests/testthat/setup.R @@ -42,3 +42,6 @@ CUSTOM_ANNOTATION_SETS <- c("cell_types", "default_clusters_res_0_4", "default_clusters_res_0_6", "default_clusters_res_1_0") +NUM_COLOR_PALETTES <- 5 +CLUSTER_COLOR_CHECK_1 <- "#e056fd" +CLUSTER_COLOR_CHECK_2 <- "#6366f1" diff --git a/tests/testthat/test-experiments_data.R b/tests/testthat/test-experiments_data.R index 69a9a97..dabf99d 100644 --- a/tests/testthat/test-experiments_data.R +++ b/tests/testthat/test-experiments_data.R @@ -152,12 +152,18 @@ test_that("pluto_read_seurat_object final works", { expected_cells <- NUM_EXPT_CELLS_FINAL_SCRNASEQ expected_cols <- NUM_EXPT_COLS_FINAL_SCRNASEQ_WA expected_annotation_sets <- CUSTOM_ANNOTATION_SETS + expected_palettes <- NUM_COLOR_PALETTES + expected_color_1 <- CLUSTER_COLOR_CHECK_1 + expected_color_2 <- CLUSTER_COLOR_CHECK_2 so <- pluto_read_seurat_object(experiment_id = TESTTHAT_EXPT_ID_SCRNASEQ, seurat_type = "final", silent = FALSE) expect_equal(nrow(so$obj@meta.data), expected_cells) expect_equal(ncol(so$obj@meta.data), expected_cols) expect_in(expected_annotation_sets, colnames(so$obj@meta.data)) + expect_equal(length(so$colors), expected_palettes) + expect_equal(so$colors$cell_types[[4]], expected_color_1) + expect_equal(so$colors$default_clusters_res_0_4[[1]], expected_color_2) }) test_that("pluto_download_seurat_object downloads raw RDS", {