From aeb44caa44af78a24427553b400a9f22a2882e74 Mon Sep 17 00:00:00 2001 From: Arkadiusz Gladki Date: Thu, 3 Oct 2024 08:24:29 +0200 Subject: [PATCH 1/6] bugfix: issue in average_biological_replicated (fit_type) --- R/headers_list.R | 16 ++++++++++++++-- R/utils.R | 6 +++++- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/R/headers_list.R b/R/headers_list.R index 995c035d..df09f265 100644 --- a/R/headers_list.R +++ b/R/headers_list.R @@ -191,8 +191,20 @@ "GR50", "GEC50", "IC50", - "EC50" - ) + "EC50", + "GR_xc50", + "RV_xc50", + "GR_ec50", + "RV_ec50" + ), + fit_type = c( + "fit_type", + "Fit Type", + "Fit Type RV", + "Fit Type GR", + "RV_fit_type", + "GR_fit_type" + ) ) } diff --git a/R/utils.R b/R/utils.R index 007a1cb7..83d56297 100644 --- a/R/utils.R +++ b/R/utils.R @@ -433,6 +433,8 @@ geometric_mean <- function(x, fixed = TRUE, maxlog10Concentration = 1) { #' @param fixed Flag indicating whether to add a fix for -Inf in the geometric mean. #' @param geometric_average_fields Character vector of column names in \code{dt} #' to take the geometric average of. +#' @param fit_type_average_fields Character vector of column names in \code{dt} +#' that should be treated as a column with fit type data #' @param add_sd Flag indicating whether to add standard deviation and count columns. #' #' @examples @@ -449,6 +451,7 @@ average_biological_replicates_dt <- function( prettified = FALSE, fixed = TRUE, geometric_average_fields = get_header("metric_average_fields")$geometric_mean, + fit_type_average_fields = get_header("metric_average_fields")$fit_type, add_sd = FALSE) { data <- data.table::copy(dt) @@ -465,7 +468,8 @@ average_biological_replicates_dt <- function( average_fields <- setdiff(names(Filter(is.numeric, data)), c(unlist(pidfs), var, iso_cols)) geometric_average_fields <- intersect(geometric_average_fields, names(dt)) - group_by <- setdiff(names(data), c(average_fields, var, id_cols, "fit_type", "Fit Type")) + fit_type_average_fields <- intersect(fit_type_average_fields, names(dt)) + group_by <- setdiff(names(data), c(average_fields, var, id_cols, fit_type_average_fields)) if (add_sd) { # Calculate standard deviation for both average_fields and geometric_average_fields From 92e57acf90d614c68957a20c91d46e5379e2656b Mon Sep 17 00:00:00 2001 From: Arkadiusz Gladki Date: Thu, 3 Oct 2024 08:24:49 +0200 Subject: [PATCH 2/6] chore: bump v+c --- DESCRIPTION | 4 ++-- NEWS.md | 3 +++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 90b9cf61..da2068b5 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,8 +1,8 @@ Package: gDRutils Type: Package Title: A package with helper functions for processing drug response data -Version: 1.3.13 -Date: 2024-09-16 +Version: 1.3.14 +Date: 2024-10-03 Authors@R: c(person("Bartosz", "Czech", role=c("aut"), comment = c(ORCID = "0000-0002-9908-3007")), person("Arkadiusz", "Gladki", role=c("cre", "aut"), email="gladki.arkadiusz@gmail.com", diff --git a/NEWS.md b/NEWS.md index b0cd85c0..d6c0d80e 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,6 @@ +## gDRutils 1.3.14 - 2024-10-03 +* fixed issue in average_biological_replicated (fit_type) + ## gDRutils 1.3.13 - 2024-09-16 * add functions set_unique_cl_names_dt and set_unique_drug_names_dt From d617407113137bf396caa270de1d3c6e69df7a19 Mon Sep 17 00:00:00 2001 From: Arkadiusz Gladki Date: Thu, 3 Oct 2024 08:25:00 +0200 Subject: [PATCH 3/6] doc: udpate documentation --- man/average_biological_replicates_dt.Rd | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/man/average_biological_replicates_dt.Rd b/man/average_biological_replicates_dt.Rd index 8f712fa6..ba726af1 100644 --- a/man/average_biological_replicates_dt.Rd +++ b/man/average_biological_replicates_dt.Rd @@ -10,6 +10,7 @@ average_biological_replicates_dt( prettified = FALSE, fixed = TRUE, geometric_average_fields = get_header("metric_average_fields")$geometric_mean, + fit_type_average_fields = get_header("metric_average_fields")$fit_type, add_sd = FALSE ) } @@ -25,6 +26,9 @@ average_biological_replicates_dt( \item{geometric_average_fields}{Character vector of column names in \code{dt} to take the geometric average of.} +\item{fit_type_average_fields}{Character vector of column names in \code{dt} +that should be treated as a column with fit type data} + \item{add_sd}{Flag indicating whether to add standard deviation and count columns.} } \value{ From f053c6bcb07c592848e59a619e2bef80a8cbade4 Mon Sep 17 00:00:00 2001 From: Arkadiusz Gladki Date: Thu, 3 Oct 2024 10:39:47 +0200 Subject: [PATCH 4/6] test: add unit tests to protection against regression (GDR-2591) --- R/utils.R | 7 +++++++ tests/testthat/test-utils.R | 30 ++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/R/utils.R b/R/utils.R index 83d56297..85895572 100644 --- a/R/utils.R +++ b/R/utils.R @@ -454,6 +454,13 @@ average_biological_replicates_dt <- function( fit_type_average_fields = get_header("metric_average_fields")$fit_type, add_sd = FALSE) { + checkmate::assert_data_table(dt) + checkmate::assert_string(var) + checkmate::assert_flag(prettified) + checkmate::assert_character(geometric_average_fields) + checkmate::assert_character(fit_type_average_fields) + checkmate::assert_flag(add_sd) + data <- data.table::copy(dt) if (prettified) { diff --git a/tests/testthat/test-utils.R b/tests/testthat/test-utils.R index 11f775fb..d8471632 100644 --- a/tests/testthat/test-utils.R +++ b/tests/testthat/test-utils.R @@ -223,6 +223,36 @@ test_that("average_biological_replicates_dt works as expected", { expect_equal(dim(avg_metrics_data2), c(40, 44)) expect_equal(sum(grepl("_sd", names(avg_metrics_data2))), 15) expect_true("count" %in% names(avg_metrics_data2)) + + # protection against regression + # (GDR-2591, fit_type correctly recognized in wide and long format) + sdata <- get_synthetic_data("finalMAE_small") + smetrics_data <- convert_se_assay_to_dt(sdata[[1]], "Metrics") + tdata <- smetrics_data[1:8, ] + tdata$Gnumber <- tdata$Gnumber[1] + tdata$DrugName <- tdata$DrugName[1] + tdata$source_id <- paste0("DS", rep(1:4, each = 2)) + tdata$fit_type <- letters[1:8] + + av1b <- average_biological_replicates_dt(tdata, var = "source_id") + av1f <- gDRutils::flatten( + av1, + groups = c("normalization_type", "fit_source"), + wide_cols = gDRutils::get_header("response_metrics") + ) + + av2f <- gDRutils::flatten( + tdata, + groups = c("normalization_type", "fit_source"), + wide_cols = gDRutils::get_header("response_metrics") + ) + av2b <- average_biological_replicates_dt(av2f, var = "source_id") + expect_true(all.equal(av1f, av2b)) + expect_true(nrow(av1f) == 1) + av1i <- average_biological_replicates_dt(tdata, var = "source_id", fit_type_average_fields = "bad_value") + expect_true(nrow(av1i) == 8) + + }) test_that("get_duplicated_rows works as expected", { From ac9331d720281bdbe295f7ebad67dd6bb9df1a17 Mon Sep 17 00:00:00 2001 From: Arek Gladki <41166437+gladkia@users.noreply.github.com> Date: Thu, 3 Oct 2024 12:31:04 +0200 Subject: [PATCH 5/6] Update tests/testthat/test-utils.R Co-authored-by: j-smola <31825957+j-smola@users.noreply.github.com> --- tests/testthat/test-utils.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/testthat/test-utils.R b/tests/testthat/test-utils.R index d8471632..d436b186 100644 --- a/tests/testthat/test-utils.R +++ b/tests/testthat/test-utils.R @@ -225,7 +225,7 @@ test_that("average_biological_replicates_dt works as expected", { expect_true("count" %in% names(avg_metrics_data2)) # protection against regression - # (GDR-2591, fit_type correctly recognized in wide and long format) + # fit_type correctly recognized in wide and long format sdata <- get_synthetic_data("finalMAE_small") smetrics_data <- convert_se_assay_to_dt(sdata[[1]], "Metrics") tdata <- smetrics_data[1:8, ] From 3d479c0655744e0261cfbaecdd7fdacfa45d8dfa Mon Sep 17 00:00:00 2001 From: Arek Gladki <41166437+gladkia@users.noreply.github.com> Date: Thu, 3 Oct 2024 12:31:18 +0200 Subject: [PATCH 6/6] Update tests/testthat/test-utils.R Co-authored-by: j-smola <31825957+j-smola@users.noreply.github.com> --- tests/testthat/test-utils.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/testthat/test-utils.R b/tests/testthat/test-utils.R index d436b186..143fa9f4 100644 --- a/tests/testthat/test-utils.R +++ b/tests/testthat/test-utils.R @@ -236,7 +236,7 @@ test_that("average_biological_replicates_dt works as expected", { av1b <- average_biological_replicates_dt(tdata, var = "source_id") av1f <- gDRutils::flatten( - av1, + av1b, groups = c("normalization_type", "fit_source"), wide_cols = gDRutils::get_header("response_metrics") )