Skip to content
Open
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
2 changes: 1 addition & 1 deletion 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
5 changes: 4 additions & 1 deletion 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 @@ -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)
}


64 changes: 32 additions & 32 deletions R/helper_functions.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Helper functions

#' prepareData
#'
#'
#' Create data.table with input data for testing purposes
#'
#' @param cell_lines data.table with cell line info
Expand All @@ -10,11 +10,11 @@
#' @keywords generate_test_data
#'
#' @return data.table with input data for testing
#'
#'
#' @examples
#'
#'
#' prepareData(create_synthetic_cell_lines(), create_synthetic_drugs())
#'
#'
#' @export
prepareData <- function(cell_lines, drugs, conc = 10 ^ (seq(-3, 1, 0.5))) {
df_layout <- data.table::as.data.table(merge.data.frame(cell_lines, drugs, by = NULL))
Expand All @@ -23,29 +23,29 @@ prepareData <- function(cell_lines, drugs, conc = 10 ^ (seq(-3, 1, 0.5))) {
}

#' prepareMergedData
#'
#' Create data.table with input data containing noise for testing purposes
#'
#' Create data.table with input data containing noise for testing purposes
#'
#' @param cell_lines data.table with cell line info
#' @param drugs data.table with drug info
#' @param noise number indicating level of noise
#' @keywords generate_test_data
#'
#' @return data.table with input data for testing
#'
#'
#' @examples
#'
#'
#' prepareMergedData(create_synthetic_cell_lines(), create_synthetic_drugs())
#'
#'
#' @export
prepareMergedData <- function(cell_lines, drugs, noise = 0.1) {
df <- prepareData(cell_lines, drugs)
generate_response_data(df, noise)
}

#' prepareComboMergedData
#'
#' Create data.table with input combination data containing noise for testing purposes
#'
#' Create data.table with input combination data containing noise for testing purposes
#'
#' @param cell_lines data.table with cell line info
#' @param drugs data.table with drug info
Expand All @@ -58,68 +58,68 @@ prepareMergedData <- function(cell_lines, drugs, noise = 0.1) {
#' @keywords generate_test_data
#'
#' @return data.table with input data for testing
#'
#'
#' @examples
#'
#'
#' prepareComboMergedData(create_synthetic_cell_lines(), create_synthetic_drugs())
#'
#'
#' @export
prepareComboMergedData <- function(cell_lines,
drugs,
prepareComboMergedData <- function(cell_lines,
drugs,
drugsIdx1 = 2:4,
drugsIdx2 = c(26, 26, 26),
concentration = c(0, .2, 1),
noise = 0.1,
drugsIdx2 = c(26, 26, 26),
concentration = c(0, .2, 1),
noise = 0.1,
modifyDf2 = FALSE) {
df_layout <- prepareData(cell_lines, drugs[drugsIdx1, ])

df_2 <- cbind(drugs[drugsIdx2, ], Concentration = concentration)
colnames(df_2) <- paste0(colnames(df_2), "_2")

df_layout_2 <- data.table::as.data.table(merge.data.frame(df_layout, df_2, by = NULL))
if (modifyDf2) {
df_layout_2 <- df_layout_2[!(df_layout_2$Concentration == 0 & df_layout_2$Concentration_2 > 0), ]
}

generate_response_data(df_layout_2, noise)
}

#' prepareCodilutionData
#'
#' Create data.table with input co-dilution data containing noise for testing purposes
#'
#' Create data.table with input co-dilution data containing noise for testing purposes
#'
#' @param cell_lines data.table with cell line info
#' @param drugs data.table with drug info
#' @param drugsIdx2 numeric vector of ids for secondary drug (in `drugs` data.table)
#' @param conc vector of doses
#' @param noise number indicating level of noise
#' @keywords generate_test_data
#'
#'
#' @return data.table with input data for testing
#'
#'
#' @examples
#'
#'
#' prepareCodilutionData(create_synthetic_cell_lines()[seq_len(2), ],
#' create_synthetic_drugs()[seq_len(4), ])
#'
#'
#' @export
prepareCodilutionData <- function(cell_lines,
drugs,
drugsIdx2 = 1,
conc = 10 ^ (seq(-3, 1, 0.5)),
noise = 0.1) {

df_layout <- prepareData(cell_lines = cell_lines, drugs = drugs, conc = conc)

df_2 <- cbind(drugs[drugsIdx2, , drop = FALSE],
df_layout[, "Concentration", drop = FALSE])
colnames(df_2) <- paste0(colnames(df_2), "_2")

df_layout_2 <- cbind(df_layout, df_2)
df_layout_2 <- df_layout_2[df_layout_2$DrugName != df_layout_2$DrugName_2, ]
rows <- which(df_layout_2$Concentration_2 > 0)
cols <- c("Concentration", "Concentration_2")
df_layout_2[rows, (cols) := lapply(.SD, function(x) x / 2), .SDcols = cols]

generate_response_data(df_layout_2, noise)
}
6 changes: 3 additions & 3 deletions R/package.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#' @examples
#' path <- system.file("annotation_data", "cell_lines.csv", package = "gDRtestData")
#' data.table::fread(file = path)
#'
#'
#' @return data.table
NULL

Expand All @@ -15,9 +15,9 @@ NULL
#' @name drugs
#' @docType data
#' @keywords data internal
#' @examples
#' @examples
#' path <- system.file("annotation_data", "drugs.csv", package = "gDRtestData")
#' data.table::fread(file = path)
#'
#'
#' @return data.table
NULL
Loading
Loading