Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[GDR-2530] Switch to get_supported_experiments #152

Merged
merged 9 commits into from
Jun 5, 2024
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ Type: Package
Package: gDRcore
Title: Processing functions and interface to process and analyze drug
dose-response data
Version: 1.3.1
Date: 2024-05-27
Version: 1.3.2
Date: 2024-06-04
Authors@R: c(
person("Bartosz", "Czech", , "[email protected]", role = "aut",
comment = c(ORCID = "0000-0002-9908-3007")),
Expand Down
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## gDRcore 1.3.2 - 2024-06-04
* switch to `get_supported_experiments`

## gDRcore 1.3.1 - 2024-05-27
* synchronize Bioconductor and GitHub versioning

Expand Down
4 changes: 2 additions & 2 deletions R/convert_se_to_raw_data.R
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ convert_mae_to_raw_data <- function(mae) {

# Remove duplicates shared between assays to keep only original single-agent
common_records <- Reduce(intersect, lapply(data, "[[", "record_id"))
sa_name <- gDRutils::get_experiment_groups("single-agent")[["single-agent"]]
combo_name <- gDRutils::get_experiment_groups("combination")
sa_name <- gDRutils::get_supported_experiments("sa")
combo_name <- gDRutils::get_supported_experiments("combo")
# check if data contains combination data and shared single-agent records are unique (true for internal data)
if (length(names(data)) > 1 && max(table(unique(data[[combo_name]])[record_id %in% common_records]$record_id)) == 1) {
data[[sa_name]] <- data[[sa_name]][!record_id %in% common_records]
Expand Down
10 changes: 5 additions & 5 deletions R/data_type.R
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ identify_data_type <- function(df,
df[, record_id := .I]
df[, type := NA_character_]

sa_name <- gDRutils::get_experiment_groups("single-agent")[["single-agent"]]
sa_name <- gDRutils::get_supported_experiments("sa")

controls <- rowSums(df[, conc_ids, with = FALSE] == 0) == length(conc_ids)
single_agent <- rowSums(df[, conc_ids, with = FALSE] != 0) == 1
Expand All @@ -86,8 +86,8 @@ identify_data_type <- function(df,
conc_ratio <- conc_ratio[!names(conc_ratio) %in% c("Inf", "-Inf")]

type <- ifelse(length(conc_ratio) <= codilution_conc,
gDRutils::get_experiment_groups("single-agent")[["co-dilution"]],
gDRutils::get_experiment_groups("combination"))
gDRutils::get_supported_experiments("cd"),
gDRutils::get_supported_experiments("combo"))
df$type[missing_type_rows] <- type
}
df
Expand Down Expand Up @@ -167,7 +167,7 @@ split_raw_data <- function(df,
simplify = FALSE)
)

sa_name <- gDRutils::get_experiment_groups("single-agent")[["single-agent"]]
sa_name <- gDRutils::get_supported_experiments("sa")

drug_ids <- drug_ids[which(drug_ids %in% names(df))]
codrug_ids <- drug_ids[grep("[0-9]", names(drug_ids))]
Expand Down Expand Up @@ -205,7 +205,7 @@ split_raw_data <- function(df,
df_merged <- rbind(
df_list[[x]],
cotrt_matching[control, on = intersect(names(cotrt_matching), names(control))])
if (x == gDRutils::get_experiment_groups("combination")) {
if (x == gDRutils::get_supported_experiments("combo")) {
matrix_data <- rbind(df_merged, df_list[[sa_name]])
for (j in conc_idx)
data.table::set(matrix_data, which(is.na(matrix_data[[j]])), j, 0)
Expand Down
2 changes: 1 addition & 1 deletion R/fit_SE.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ fit_SE <- function(se,
# Assertions:
checkmate::assert_class(se, "SummarizedExperiment")
checkmate::assert_string(data_type)
checkmate::assert_choice(data_type, gDRutils::get_experiment_groups("single-agent"))
checkmate::assert_choice(data_type, choices = gDRutils::get_experiment_groups("single-agent"))
checkmate::assert_character(nested_identifiers, null.ok = TRUE)
checkmate::assert_string(averaged_assay)
checkmate::assert_string(metrics_assay)
Expand Down
4 changes: 2 additions & 2 deletions R/fit_SE.combinations.R
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
#' @examples
#' fmae_cms <- gDRutils::get_synthetic_data("finalMAE_combo_matrix_small")
#'
#' se1 <- fmae_cms[[gDRutils::get_experiment_groups("combination")]]
#' se1 <- fmae_cms[[gDRutils::get_supported_experiments("combo")]]
#' SummarizedExperiment::assays(se1) <-
#' SummarizedExperiment::assays(se1)["Averaged"]
#' fit_SE.combinations(se1[1, 1])
Expand All @@ -33,7 +33,7 @@
#' @export
#'
fit_SE.combinations <- function(se,
data_type = gDRutils::get_experiment_groups("combination"),
data_type = gDRutils::get_supported_experiments("combo"),
series_identifiers = NULL,
normalization_types = c("GR", "RV"),
averaged_assay = "Averaged",
Expand Down
5 changes: 2 additions & 3 deletions R/runDrugResponseProcessingPipeline.R
Original file line number Diff line number Diff line change
Expand Up @@ -234,8 +234,7 @@ runDrugResponseProcessingPipeline <- function(x,
checkmate::assert_choice(start_from, get_pipeline_steps())
checkmate::assert_character(selected_experiments, null.ok = TRUE)
checkmate::assert_subset(selected_experiments,
names(gDRutils::get_experiment_groups()),
)
gDRutils::get_supported_experiments())
j-smola marked this conversation as resolved.
Show resolved Hide resolved

if (!is.null(selected_experiments) && !partial_run) {
stop("Selected experiments are only supported with partial_run enabled")
Expand Down Expand Up @@ -347,7 +346,7 @@ runDrugResponseProcessingPipeline <- function(x,
)

# 4th step - Fit SE
if (data_type == gDRutils::get_experiment_groups("combination")) {
if (data_type == gDRutils::get_supported_experiments("combo")) {
step_args <- list(
se = se$result,
data_type = data_type,
Expand Down
40 changes: 17 additions & 23 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ data_model.data.table <- function(x) {
%in% gDRutils::get_env_identifiers("untreated_tag"))) {
"single-agent"
} else {
"combination"
"combination"
}
} else if (.get_default_single_agent_nested_identifiers() %in% colnames(x)) {
"single-agent"
Expand All @@ -208,17 +208,6 @@ data_model.data.table <- function(x) {
}
}


#' @keywords utils
get_data_type_to_data_model_mapping <- function() {
c(
`single-agent` = "single-agent",
"co-dilution" = "single-agent",
"combination" = "combination"
)
}


#' Detect model of data from experiment name
#'
#' @param x character with experiment name
Expand All @@ -228,22 +217,27 @@ get_data_type_to_data_model_mapping <- function() {
#' @keywords utils
#' @export
data_model.character <- function(x) {
# TODO: switch to gDRutils::get_experiment_groups()
# once we clean-up single-agent/combination assignemnts
exp_v <- get_data_type_to_data_model_mapping()

checkmate::assert_subset(x, names(exp_v))

exp_v[[x]]
checkmate::assert_subset(x, gDRutils::get_supported_experiments())
j-smola marked this conversation as resolved.
Show resolved Hide resolved

exp_v <- gDRutils::get_experiment_groups()
names(exp_v[grep(x, exp_v)])
}


#' Validate availability of data models
#'
#' @param d_types character vector with experiment names in \code{MultiAssayExperiment} object
#' @param s_d_models character vector with names of supported experiment
#'
#' @keywords internal
validate_data_models_availability <- function(d_types, s_d_models) {
checkmate::assert_character(d_types)
checkmate::assert_character(s_d_models, null.ok = TRUE)

dm_v <- get_data_type_to_data_model_mapping()
dm_v <- gDRutils::get_experiment_groups()

req_d_models <-
unique(as.character(dm_v[names(dm_v) %in% d_types]))
unique(names(dm_v)[vapply(d_types, function(i) grep(i, dm_v), integer(1))])
j-smola marked this conversation as resolved.
Show resolved Hide resolved
f_models <- req_d_models[!req_d_models %in% s_d_models]
if (length(f_models)) {
msg1 <-
Expand All @@ -258,7 +252,7 @@ validate_data_models_availability <- function(d_types, s_d_models) {

#' Get default nested identifiers
#'
#' @param x data.table with raw data or SummarizedExperiment object
#' @param x data.table with raw data or \code{SummarizedExperiment} object
#' with gDR assays
#' @param data_model single-agent vs combination
#'
Expand Down
4 changes: 2 additions & 2 deletions man/fit_SE.combinations.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/get_default_nested_identifiers.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions man/validate_data_models_availability.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions tests/testthat/test-data_type.R
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ test_that("identify_data_type and split_raw_data works as expected", {

df_list <- split_raw_data(df)
expect_true(inherits(df_list, "list"))
expect_true(all(names(df_list) %in% c(gDRutils::get_experiment_groups("combination"),
gDRutils::get_experiment_groups("single-agent")[["single-agent"]])))
expect_true(all(names(df_list) %in% c(gDRutils::get_supported_experiments("combo"),
gDRutils::get_supported_experiments("sa"))))


df2 <- data.table::data.table(Gnumber = c(rep("DrugA", 9), "DrugB"),
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-fit_SE.R
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ test_that("fit_SE.combinations works as expected", {

# combo data
fmae_cms <- gDRutils::get_synthetic_data("finalMAE_combo_matrix_small")
se1 <- fmae_cms[[gDRutils::get_experiment_groups("combination")]]
se1 <- fmae_cms[[gDRutils::get_supported_experiments("combo")]]
SummarizedExperiment::assays(se1) <- SummarizedExperiment::assays(se1)["Averaged"]

new_se1 <- purrr::quietly(fit_SE.combinations)(se1[1, 1])
Expand Down
Loading