Skip to content

Commit

Permalink
refactor: update as per review
Browse files Browse the repository at this point in the history
  • Loading branch information
bczech committed Aug 22, 2024
1 parent 1ef7ff2 commit 3a67c32
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 9 deletions.
8 changes: 5 additions & 3 deletions R/data_type.R
Original file line number Diff line number Diff line change
Expand Up @@ -408,12 +408,14 @@ process_perturbations <- function(dt,

drug_order <- gsub(".*_(\\d+)$|.*", "\\1", drug_col)
drug_cols <-
get_relevant_ids(paste0(
unique(c(
get_relevant_ids(paste0(
c("drug", "drug_name", "drug_moa", "concentration"), drug_order),
dt)
dt),
drug_col, conc_col))

# Remove the current drug and concentration columns
dt[, (drug_cols, drug_col, conc_col) := NULL]
dt[, (drug_cols) := NULL]
}
}
}
Expand Down
34 changes: 28 additions & 6 deletions tests/testthat/test-data_type.R
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,14 @@ test_that("collapse drugs works as expected", {

test_that("process_perturbations works as expected", {
dt <- data.table::data.table(
drug1 = c("vehicle", "drugA", "drugA"),
conc1 = c(0, 10, 0),
drug2 = c("vehicle", "drugB", "drugB"),
conc2 = c(0, 20, 0)
DrugName = c("vehicle", "drugA", "drugA"),
Concentration = c(0, 10, 0),
DrugName_2 = c("vehicle", "drugB", "drugB"),
Concentration_2 = c(0, 20, 0)
)

drugs_cotrt_ids <- c("drug1", "drug2")
conc_cotrt_ids <- c("conc1", "conc2")
drugs_cotrt_ids <- c("DrugName", "DrugName_2")
conc_cotrt_ids <- c("Concentration", "Concentration_2")

result <- process_perturbations(dt, drugs_cotrt_ids, conc_cotrt_ids)

Expand Down Expand Up @@ -134,5 +134,27 @@ test_that("process_perturbations works as expected", {
drugC = c(0, 30, 0)
)
expect_equal(result, expected)


dt4 <- data.table::data.table(
Gnumber = c("vehicle", "drugA", "drugB"),
Concentration = c(0, 10, 2),
Gnumber_2 = c("vehicle", "drugB", "drugB"),
Concentration_2 = c(0, 20, 0),
drug_moa_2 = c("vehicle", "moa_A", "moa_A"),
DrugName_2 = c("vehicle", "drugB", "drugB")
)

drugs_cotrt_ids <- "Gnumber_2"
conc_cotrt_ids <- "Concentration_2"

result <- process_perturbations(dt4, drugs_cotrt_ids, conc_cotrt_ids)

expected <- data.table::data.table(
Gnumber = c("vehicle", "drugA", "drugB"),
Concentration = c(0, 10, 2),
drugB = c(0, 20, 0)
)
expect_equal(result, expected)
})

0 comments on commit 3a67c32

Please sign in to comment.