Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: gDRtestData
Title: gDRtestData - R data package with testing dose response data
Version: 1.11.1
Version: 1.11.2
Date: 2026-04-29
Description: R package with internal dose-response test data. Package provides functions to generate
input testing data that can be used as the input for gDR pipeline. It also contains qs2 files
Expand Down Expand Up @@ -41,5 +41,5 @@ VignetteBuilder: knitr
License: Artistic-2.0
Encoding: UTF-8
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.3.1
RoxygenNote: 7.3.3
Config/testthat/edition: 3
15 changes: 9 additions & 6 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## gDRtestData 1.11.2 - 2026-05-18
* apply updated gDRstyle rules

## gDRtestData 1.11.1 - 2026-04-29
* synchronize Bioconductor and GitHub versioning

Expand Down Expand Up @@ -76,10 +79,10 @@
* update testdata

## gDRtestData 0.99.19 - 2023-06-23
* BiocStyle added to dependency
* add BiocStyle to dependency

## gDRtestData 0.99.18 - 2023-06-22
* replaced rds files with qs
* replace rds files with qs

## gDRtestData 0.99.17 - 2023-06-15
* switch from merge to [[
Expand All @@ -90,7 +93,7 @@
## gDRtestData 0.99.15 - 2023-05-24
* format the vignette with BiocStyle

## gDRtestData 0.99.14 - 22023-05-15
## gDRtestData 0.99.14 - 2023-05-15
* fix related with data.table

## gDRtestData 0.99.13 - 2023-05-15
Expand All @@ -100,10 +103,10 @@
* update testdata as per new data model

## gDRtestData 0.99.11 - 2023-04-25
* changed data.frame to data.table
* change data.frame to data.table

## gDRtestData 0.99.10 - 2023-04-24
* removing redundant files
* remove redundant files

## gDRtestData 0.99.9 - 2023-04-20
* fix warning in Bioc check
Expand Down Expand Up @@ -135,4 +138,4 @@
## gDRtestData 0.99.0 - 2023-03-31
* preparing package for Bioc submission
* fix examples


50 changes: 25 additions & 25 deletions R/generate_data.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,17 @@
#'
#'
#' @examples
#'
#'
#' cell_lines <- create_synthetic_cell_lines()
#' add_data_replicates(cell_lines)
#'
#'
#' @return data.table with replicates
#' @keywords generate_data
#' @export
#'
add_data_replicates <- function(df_layout) {
df_layout_duplicates <- Reduce(rbind, list(df_layout)[rep(1, times = 3)])
barcode <- do.call(c, lapply(paste0("plate_", seq_len(3)), function(x) rep(x, nrow(df_layout))))
barcode <- do.call(c, lapply(paste0("plate_", seq_len(3)), function(x) rep(x, NROW(df_layout))))
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The generation of the barcode vector can be simplified and made more efficient by using the each argument of the rep function. This avoids the overhead of lapply and do.call(c, ...) while producing the same result.

  barcode <- rep(paste0("plate_", seq_len(3)), each = NROW(df_layout))

cbind(Barcode = barcode, df_layout_duplicates)
}

Expand All @@ -30,10 +30,10 @@ add_data_replicates <- function(df_layout) {
#' @keywords generate_data
#'
#' @examples
#'
#'
#' cell_lines <- create_synthetic_cell_lines()
#' add_concentration(cell_lines)
#'
#'
#' @return data.table with concentrations
#' @export
#'
Expand All @@ -55,41 +55,41 @@ add_concentration <- function(df_layout, concentrations = 10 ^ (seq(-3, 1, 0.5))
#'
#'
#' @examples
#'
#'
#' cell_lines <- create_synthetic_cell_lines()
#' drugs <- create_synthetic_drugs()
#' df_layout <- prepareData(cell_lines[seq_len(2), ], drugs[seq_len(4), ])
#' generate_response_data(df_layout)
#'
#'
#'
#' @return data.table with response data
#' @export
#'
generate_response_data <- function(df_layout, noise_level = 0.1) {

drugs <- create_synthetic_drugs()
cell_lines <- create_synthetic_cell_lines()
hill_coef <- generate_hill_coef(drugs, cell_lines)
ec50 <- generate_ec50(drugs, cell_lines)
e_inf <- generate_e_inf(drugs, cell_lines)

df_layout$ReadoutValue <- round(100 * pmax(
getReadoutCoef(df_layout, e_inf, ec50, hill_coef) +
(noise_level * stats::runif(nrow(df_layout)) - (noise_level / 2)), # add some noise
0.01 * stats::runif(nrow(df_layout)) + 0.005), # avoid hard 0 values
(noise_level * stats::runif(NROW(df_layout)) - (noise_level / 2)), # add some noise
0.01 * stats::runif(NROW(df_layout)) + 0.005), # avoid hard 0 values
1)
df_layout$BackgroundValue <- 0
df_layout$Duration <- 72
df_layout <- introduceVehicle(df_layout)

if ("Gnumber_2" %in% colnames(df_layout)) { # combo data
df_layout <- introduceGNum(df_layout, e_inf, ec50, hill_coef, "_2")
}

if ("Gnumber_3" %in% colnames(df_layout)) { # combo data
df_layout <- introduceGNum(df_layout, e_inf, ec50, hill_coef, "_3")
}

df_layout
}

Expand All @@ -98,32 +98,32 @@ getReadoutCoef <- function(df, e_inf, ec50, hill_coef, suffix = "") {
apply(df, 1, function(x) {
clid <- x["clid"]
gnum <- x[paste0("Gnumber", suffix)]

e_inf_val <- e_inf[gnum, clid]
ec50_val <- ec50[gnum, clid]
hill_val <- hill_coef[gnum, clid]
concentration <- as.numeric(x["Concentration"])
e_inf_val + (1 - e_inf_val) * (ec50_val ^ hill_val / (concentration ^ hill_val + ec50_val ^ hill_val))

e_inf_val + (1 - e_inf_val) * (ec50_val ^ hill_val / (concentration ^ hill_val + ec50_val ^ hill_val))
})
}

#' @keywords internal
introduceVehicle <- function(df, suffix = "") {
zeroIdx <- df[[paste0("Concentration", suffix)]] == 0

df[zeroIdx, paste0("Gnumber", suffix)] <- "vehicle"
df[zeroIdx, paste0("DrugName", suffix)] <- "vehicle"
df[zeroIdx, paste0("drug_moa", suffix)] <- "vehicle"

df
}

#' @keywords internal
introduceGNum <- function(df, e_inf, ec50, hill_coef, suffix) {
df$ReadoutValue <- df$ReadoutValue * getReadoutCoef(df, e_inf, ec50, hill_coef, suffix)
df <- introduceVehicle(df, suffix)

df
}

Expand All @@ -134,7 +134,7 @@ introduceGNum <- function(df, e_inf, ec50, hill_coef, suffix) {
#' @keywords generate_data
#'
#' @examples
#'
#'
#' cell_lines <- create_synthetic_cell_lines()
#' drugs <- create_synthetic_drugs()
#' df_merged <- prepareData(cell_lines[seq_len(2), ], drugs[seq_len(4), ])
Expand All @@ -152,14 +152,14 @@ add_day0_data <- function(df_merged, noise_level = 0.05) {
TRUE
}
df_Day0 <- unique(df_merged[df_merged$Concentration == 0 & cond, ])

df_Day0$ReadoutValue <- df_Day0$ReadoutValue / 2 ^ (df_Day0$Duration / df_Day0$ReferenceDivisionTime)
coef <- (1 - noise_level / 2 + noise_level * stats::runif(nrow(df_Day0)))
coef <- (1 - noise_level / 2 + noise_level * stats::runif(NROW(df_Day0)))
df_Day0$ReadoutValue <- round(df_Day0$ReadoutValue * coef, 1)

df_Day0$Duration <- 0
df_Day0$Barcode <- "plate_0"

df_merged <- rbind(df_merged, df_Day0)
df_merged
}
14 changes: 6 additions & 8 deletions R/get_test_datasets.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#' get_test_dataset_paths
#'
#'
#' Returns named vector of absolute paths to test datasets.
#'
#' @param datasets_dir path to directory with datasets (default \code{NULL}).
Expand All @@ -9,13 +9,13 @@
#' @keywords generate_test_data
#'
#' @return named vector of absolute paths
#'
#'
#' @examples
#'
#'
#' get_test_dataset_paths()
#' path <- system.file("testdata", package = "gDRtestData", mustWork = TRUE)
#' get_test_dataset_paths(path)
#'
#'
#' @export
#'
#' @author Kamil Foltyński \email{kamil.foltynski@@contractors.roche.com}
Expand All @@ -30,12 +30,10 @@ get_test_dataset_paths <-
}
checkmate::assert_string(datasets_dir, min.chars = 1)
checkmate::assert_directory_exists(datasets_dir)

checkmate::assert_string(pattern, min.chars = 1)

epaths <- list.files(datasets_dir, pattern = paste0(pattern, ".*\\.qs2$"), full.names = TRUE)
enames <- gsub(pattern, "", gsub("\\.qs2$", "", basename(epaths)))
structure(epaths, names = enames)
}


Loading
Loading