Skip to content

Commit ad0682d

Browse files
committed
Add fisherCategoricalVariable() function
1 parent b6781dd commit ad0682d

9 files changed

+40
-90
lines changed

NAMESPACE

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# Generated by roxygen2: do not edit by hand
22

33
S3method(is,DrugAUCQuantile)
4-
S3method(is,DrugAUCQuantileNoReplicate)
54
export(fisherCategoricalVariable)
65
export(getClassOneDrug)
76
export(plotDrugAUCDensityCurve)

R/AllGenerics.R

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -16,23 +16,3 @@
1616
is.DrugAUCQuantile <- function(x, ...) {
1717
inherits(x, "DrugAUCQuantile")
1818
}
19-
20-
21-
#' @title Is an object of class \code{DrugAUCQuantileNoReplicate}
22-
#'
23-
#' @description Functions to test inheritance relationships between an
24-
#' object and class \code{DrugAUCQuantileNoReplicate}.
25-
#'
26-
#' @method is DrugAUCQuantileNoReplicate
27-
#'
28-
#' @param x an object.
29-
#'
30-
#' @param \ldots further arguments passed to or from other methods.
31-
#'
32-
#' @return a \code{logical}.
33-
#'
34-
#' @importFrom methods is
35-
#' @export
36-
is.DrugAUCQuantileNoReplicate <- function(x, ...) {
37-
inherits(x, "DrugAUCQuantileNoReplicate")
38-
}

R/drugScreening.R

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -184,8 +184,7 @@ selectNoReplicateOrganoids <- function(drugScreening, patientInfo) {
184184
#' returns a "\code{ggplot}" object. The density plot can be split by
185185
#' sensitivity classes.
186186
#'
187-
#' @param drugQuantile an object of class "\code{DrugAUCQuantile}" or
188-
#' "\code{DrugAUCQuantileNoReplicate}" which
187+
#' @param drugQuantile an object of class "\code{DrugAUCQuantile}" which
189188
#' contains the sensitive and resistant information for organoids associated
190189
#' to a specific drug screening.
191190
#'
@@ -220,10 +219,9 @@ selectNoReplicateOrganoids <- function(drugScreening, patientInfo) {
220219
plotDrugAUCDensityCurve <- function(drugQuantile, byGroup=FALSE) {
221220

222221
## Validate that the drugQuantile parameter is a DrugAUCQuantile object
223-
if (!(is.DrugAUCQuantile(drugQuantile) ||
224-
is.DrugAUCQuantileNoReplicate(drugQuantile))) {
225-
stop("The \'drugQuantile\' parameter must be a DrugAUCQuantile or ",
226-
"DrugAUCQuantileNoReplicate object.")
222+
if (!(is.DrugAUCQuantile(drugQuantile))) {
223+
stop("The \'drugQuantile\' parameter must be a DrugAUCQuantile ",
224+
"object.")
227225
}
228226

229227
## Validate that the byGroup is logical
@@ -333,10 +331,9 @@ plotDrugAUCDensityCurve <- function(drugQuantile, byGroup=FALSE) {
333331
plotDrugAUCViolinPlot <- function(drugQuantile, min=0, max=100, trim=FALSE) {
334332

335333
## Validate that the drugQuantile parameter is a DrugAUCQuantile object
336-
if (!(is.DrugAUCQuantile(drugQuantile) ||
337-
is.DrugAUCQuantileNoReplicate(drugQuantile))) {
338-
stop("The \'drugQuantile\' parameter must be a DrugAUCQuantile or ",
339-
"DrugAUCQuantileNoReplicate object.")
334+
if (!(is.DrugAUCQuantile(drugQuantile))) {
335+
stop("The \'drugQuantile\' parameter must be a DrugAUCQuantile",
336+
" object.")
340337
}
341338

342339
## Validate that the min is a single numeric

R/enrichment.R

Lines changed: 9 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,8 @@
77
#' @param drugQuantile an object of class "\code{DrugAUCQuantile}" which
88
#' contains the sensitive and resistant organoids for a specific drug.
99
#'
10-
#' @param patientInfo a \code{data.frame} containing the meta-data information
11-
#' related to the organoids. The mandatory columns are: 'organoid_id'
12-
#' and 'patient_id'.
13-
#'
1410
#' @param category a single \code{character} string representing the column
15-
#' from the 'patientInfo' dataset that should be used as the
11+
#' from the "\code{DrugAUCQuantile}" extreme dataset that should be used as the
1612
#' categorical variable.
1713
#'
1814
#' @return a \code{list} containing 2 components:
@@ -32,45 +28,37 @@
3228
#' drugName="Methotrexate", study="MEGA-TEST", screenType="TEST-01",
3329
#' doseType="Averaged", quantile=1/3)
3430
#'
35-
#' ## The classification of the organoids is in the 'extreme' entry
31+
#' ## TODO
3632
#' results$extreme
3733
#'
3834
#' @author Astrid Deschênes, Pascal Belleau
3935
#' @importFrom stats fisher.test
4036
#' @encoding UTF-8
4137
#' @export
42-
fisherCategoricalVariable <- function(drugQuantile, patientInfo, category) {
38+
fisherCategoricalVariable <- function(drugQuantile, category) {
4339

4440
## Validate that the drugQuantile parameter is a DrugAUCQuantile object
45-
if (!(is.DrugAUCQuantile(drugQuantile) ||
46-
is.DrugAUCQuantileNoReplicate(drugQuantile))) {
41+
if (!(is.DrugAUCQuantile(drugQuantile))) {
4742
stop("The \'drugQuantile\' parameter must be a DrugAUCQuantile ",
4843
"object.")
4944
}
5045

51-
if (!is.data.frame(patientInfo)) {
52-
stop("The \'patientInfo\' parameter must be a data.frame.")
53-
}
54-
5546
if (!is.character(category)) {
5647
stop("The \'category\' parameter must be a character string.")
5748
}
5849

5950
## The drug must be present in the drug dataset
60-
if (!(category %in% colnames(patientInfo))) {
51+
if (!(category %in% colnames(drugQuantile$extreme))) {
6152
stop("The category \'", category, "\' must be one of the columns in ",
62-
"the \'patientInfo\' dataset.")
53+
"the \'DrugAUCQuantile\' dataset.")
6354
}
6455

6556
results <- drugQuantile$extreme
6657

67-
resultsD <- merge(results, patientInfo[, c("organoid_id", category)],
68-
by="organoid_id", all.x = TRUE)
69-
70-
sensitive <- resultsD[resultsD$group == "SENSITIVE",]
71-
resistant <- resultsD[resultsD$group == "RESISTANT",]
58+
sensitive <- results[results$group == "SENSITIVE",]
59+
resistant <- results[results$group == "RESISTANT",]
7260

73-
categoryAll <- unique(resultsD[[category]])
61+
categoryAll <- unique(results[[category]])
7462

7563
all <- list()
7664
for (i in categoryAll) {

man/fisherCategoricalVariable.Rd

Lines changed: 3 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/is.DrugAUCQuantileNoReplicate.Rd

Lines changed: 0 additions & 20 deletions
This file was deleted.

man/plotDrugAUCDensityCurve.Rd

Lines changed: 1 addition & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/testthat/test-drugScreening.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ context("plotDrugAUCViolinPlot() results")
291291
test_that("plotDrugAUCViolinPlot() must return error when drugQuantile is character string", {
292292

293293
error_message <- paste0("The \'drugQuantile\' parameter must ",
294-
"be a DrugAUCQuantile or DrugAUCQuantileNoReplicate object.")
294+
"be a DrugAUCQuantile object.")
295295

296296
expect_error(plotDrugAUCViolinPlot(drugQuantile="test", min=0, max=100,
297297
trim=FALSE), error_message, fixed=TRUE)
@@ -353,7 +353,7 @@ context("plotDrugAUCViolinPlot() results")
353353
test_that("plotDrugAUCDensityCurve() must return error when drugQuantile is character string", {
354354

355355
error_message <- paste0("The \'drugQuantile\' parameter must be a ",
356-
"DrugAUCQuantile or DrugAUCQuantileNoReplicate object.")
356+
"DrugAUCQuantile object.")
357357

358358
expect_error(plotDrugAUCDensityCurve(drugQuantile="33", byGroup=FALSE),
359359
error_message, fixed=TRUE)

tests/testthat/test-enrichment.R

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,25 @@ context("fisherCategoricalVariable() results")
1313

1414
test_that("fisherCategoricalVariable() must return error when drugQuantile is numeric", {
1515

16-
patientData <- data.frame(organoid_id=c("hT1001", "hT1082", "hT1919",
17-
"hT3312", "hT1051", "hT2211", "hT2212", "hT2213", "hT2251"),
18-
patient_id=c("1", "2", "3", "2", "3", "4", "4", "6", "7"),
19-
stringsAsFactors=FALSE)
20-
2116
error_message <- paste0("The \'drugQuantile\' parameter must be a ",
2217
"DrugAUCQuantile object.")
2318

24-
expect_error(fisherCategoricalVariable(drugQuantile=33,
25-
patientInfo=patientData, category="test"), error_message, fixed=TRUE)
19+
expect_error(fisherCategoricalVariable(drugQuantile=33, category="test"),
20+
error_message, fixed=TRUE)
21+
})
22+
23+
24+
test_that("fisherCategoricalVariable() must return error when category is numeric", {
25+
26+
drug <- readRDS(test_path("fixtures", "OneDrugDemoFile02.RDS"))
27+
28+
results <- getClassOneDrug(drugScreening=drug, drugName="Methotrexate",
29+
study="MEGA-TEST", screenType="TEST-01", doseType="Averaged",
30+
quantile=0.2)
31+
32+
error_message <- paste0("The \'category\' parameter must be a character",
33+
" string.")
34+
35+
expect_error(fisherCategoricalVariable(drugQuantile=results,
36+
category=22), error_message, fixed=TRUE)
2637
})

0 commit comments

Comments
 (0)