Skip to content

Commit 53ba0e0

Browse files
committed
Adding plotDrugAUCViolinPlot() function; adding drugScreening dataset; update output of selectOrgForOneDrug() function
1 parent ba17f2a commit 53ba0e0

14 files changed

+411
-41
lines changed

DESCRIPTION

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ Depends: R (>= 4.0),
2222
stats,
2323
utils
2424
Imports: S4Vectors,
25+
ggplot2,
2526
methods
2627
Suggests: testthat,
2728
knitr,

NAMESPACE

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

33
S3method(is,DrugAUCQuantile)
4-
export(plotDrugAUCDistribution)
4+
export(plotDrugAUCDensityCurve)
5+
export(plotDrugAUCViolinPlot)
56
export(selectOrgForOneDrug)
67
importFrom(S4Vectors,isSingleNumber)
8+
importFrom(ggplot2,.data)
9+
importFrom(ggplot2,aes)
10+
importFrom(ggplot2,element_text)
11+
importFrom(ggplot2,geom_hline)
12+
importFrom(ggplot2,geom_point)
13+
importFrom(ggplot2,geom_violin)
14+
importFrom(ggplot2,ggplot)
15+
importFrom(ggplot2,position_jitter)
16+
importFrom(ggplot2,scale_colour_manual)
17+
importFrom(ggplot2,theme)
18+
importFrom(ggplot2,theme_minimal)
19+
importFrom(ggplot2,xlab)
20+
importFrom(ggplot2,ylab)
21+
importFrom(ggplot2,ylim)
722
importFrom(methods,is)
823
importFrom(stats,quantile)

R/OrganoidsToolBox.R

Lines changed: 99 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,10 @@ NULL
2525

2626

2727
#' Simple demo drug screening for one drug (Methotrexate). The results have
28-
#' been generated for demonstration purpose.
28+
#' been generated for demonstration purpose. There is only one study in the
29+
#' dataset. There is also only one type of screening in the dataset. Some
30+
#' entries have a value for a second drug. There is not entry for a third
31+
#' drug. There is no background drug.
2932
#'
3033
#' @name simpleDrugScreening
3134
#'
@@ -112,3 +115,98 @@ NULL
112115
#'
113116
#'
114117
NULL
118+
119+
120+
121+
122+
#' Simple demo drug screening for one drug (Methotrexate). The results have
123+
#' been generated for demonstration purpose. There is two studies present in
124+
#' the dataset. There is also only two types of screening in the dataset. Some
125+
#' entries have a value for a second drug. There is not entry for a third
126+
#' drug. There is no background drug. At last, there is two types of dosage.
127+
#'
128+
#' @name drugScreening
129+
#'
130+
#' @docType data
131+
#'
132+
#' @aliases drugScreening
133+
#'
134+
#' @format a \code{data.frame} with the following columns:
135+
#' \itemize{
136+
#' \item \code{organoid_id} { a \code{character} string representing the
137+
#' organoid identifier. }
138+
#' \item \code{plate} { a \code{character} string representing the plate
139+
#' identifier. }
140+
#' \item \code{passage_number} { a \code{character} string representing the
141+
#' passage number of the organoid. }
142+
#' \item \code{timestamp} { a \code{character} string representing the date
143+
#' when the screening was done. }
144+
#' \item \code{study} { a \code{character} string representing the study. }
145+
#' \item \code{screen_type} { a \code{character} string representing the
146+
#' screen type. }
147+
#' \item \code{z_prime} { a \code{numeric} representing the assay quality. }
148+
#' \item \code{drug_a} { a \code{character} string representing the name of
149+
#' the first drug used for the drug screen. There is at least one drug used
150+
#' in a drug screening.}
151+
#' \item \code{drug_b} { a \code{character} string representing the name of
152+
#' the second drug used for the drug screen. When no second drug has been
153+
#' used, the value is \code{'N/A'}. }
154+
#' \item \code{drug_c} { a \code{character} string representing the name of
155+
#' the third drug used for the drug screen. When no third drug has been
156+
#' used, the value is \code{'N/A'}. }
157+
#' \item \code{drug_background} { a \code{character} string representing the
158+
#' name of
159+
#' the drug used as background for the drug screen. When no drug has been used
160+
#' as background, the value is \code{'N/A'}. }
161+
#' \item \code{dosage_type} { a \code{character} string representing the type
162+
#' of dosage. }
163+
#' \item \code{dosage_concentration_a} { a \code{numeric}
164+
#' representing the dosage of
165+
#' the first drug used for the drug screen. This column should always have a
166+
#' value as there is at least one drug used in a drug screening.}
167+
#' \item \code{dosage_concentration_b} { a \code{numeric}
168+
#' representing the dosage of the second drug used for the drug screen.
169+
#' When no second drug has been used, the value is \code{0}.}
170+
#' \item \code{dosage_concentration_c} { a \code{numeric}
171+
#' representing the dosage of the third drug used for the drug screen.
172+
#' When no third drug has been used, the value is \code{0}. }
173+
#' \item \code{dosage_concentration_background} { a \code{numeric}
174+
#' representing the dosage of the background drug used for the drug screen.
175+
#' When no background drug has been used, the value is \code{0}. }
176+
#' \item \code{percent_viability} { a \code{numeric}
177+
#' representing the percentage of viability of the organoids under the
178+
#' specific screening conditions. }
179+
#' \item \code{relative_auc} { a \code{numeric}
180+
#' representing the relative AUC (area under the curve) for the specified
181+
#' organoids under specific conditions. The AUC is calculated using the
182+
#' percentage of viability under different drug concentrations. So, the same
183+
#' relative AUC is repeated on multiple lines.}
184+
#' }
185+
#'
186+
#' @seealso
187+
#' \itemize{
188+
#' \item \code{\link{selectOrgForOneDrug}} { for selecting the organoids
189+
#' with sensitive and resistant behavior for a
190+
#' specific drug screening.}
191+
#' }
192+
#'
193+
#' @usage data(drugScreening)
194+
#'
195+
#' @keywords datasets
196+
#'
197+
#' @examples
198+
#'
199+
#' ## Load drug screen dataset for 1 drug
200+
#' data(drugScreening)
201+
#'
202+
#' ## Calculate the extreme organoids for the methotrexate drug screening
203+
#' ## using a quantile of 1/3
204+
#' results <- selectOrgForOneDrug(drugScreening=drugScreening,
205+
#' drugName="Methotrexate", study="MEGA-TEST", screenType="TEST-01",
206+
#' doseType="Averaged", quantile=1/4)
207+
#'
208+
#' ## The information of the extreme organoids is found it the 'extreme' entry
209+
#' results$extreme
210+
#'
211+
#'
212+
NULL

R/drugScreening-internal.R

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,19 @@
3434
#'
3535
#' @examples
3636
#'
37-
#' ## Path to the demo pedigree file is located in this package
38-
#' data.dir <- system.file("extdata", package="RAIDS")
37+
#' ## Load drug screen dataset for 1 drug
38+
#' data(simpleDrugScreening)
3939
#'
40-
#' ## TODO
40+
#' ## Calculate the extreme organoids for the methotrexate drug screening
41+
#' ## using a quantile of 1/4
42+
#' results <- OrganoidsToolBox:::findOneDrugQuantile(
43+
#' drugData=simpleDrugScreening,
44+
#' drugName="Methotrexate", doseType="Averaged", quantile=1/4)
45+
#'
46+
#' ## The classification of the organoids is in the 'extreme' entry
47+
#' results$extreme
4148
#'
42-
#' @author Pascal Belleau and Astrid Deschênes
49+
#' @author Pascal Belleau, Astrid Deschênes
4350
#' @importFrom stats quantile
4451
#' @encoding UTF-8
4552
#' @keywords internal
@@ -71,6 +78,7 @@ findOneDrugQuantile <- function(drugData, drugName, doseType="Averaged",
7178
results[["quantile"]] <- list()
7279

7380
## Calculate upper and lower quantile
81+
results[["quantile"]][["value"]] <- quantile
7482
results[["quantile"]][["lower"]] <-
7583
unname(quantile(orgDR.avr.u$relative_auc, quantile))
7684
results[["quantile"]][["upper"]] <-
@@ -82,15 +90,21 @@ findOneDrugQuantile <- function(drugData, drugName, doseType="Averaged",
8290
## Select sensitive organoids
8391
extreme <- orgDR.avr.u[which(orgDR.avr.u$relative_auc <=
8492
results[["quantile"]][["lower"]]),]
85-
extreme$GROUP <- rep("SENSITIVE", nrow(extreme))
93+
extreme$group <- rep("SENSITIVE", nrow(extreme))
8694

8795
## Select resistant organoids
8896
extreme2 <- orgDR.avr.u[which(orgDR.avr.u$relative_auc >=
8997
results[["quantile"]][["upper"]]),]
90-
extreme2$GROUP <- rep("RESISTANT", nrow(extreme2))
98+
extreme2$group <- rep("RESISTANT", nrow(extreme2))
99+
100+
101+
## Select resistant organoids
102+
extreme3 <- orgDR.avr.u[which(!orgDR.avr.u$organoid_id %in%
103+
c(extreme$organoid_id, extreme2$organoid_id)),]
104+
extreme3$group <- rep("AVERAGE", nrow(extreme3))
91105

92-
final <- rbind(extreme, extreme2)
93-
final <- final[, c("organoid_id", "relative_auc", "GROUP")]
106+
final <- rbind(extreme, extreme2, extreme3)
107+
final <- final[, c("organoid_id", "relative_auc", "group")]
94108
results[["extreme"]] <- final[order(final$relative_auc, decreasing=FALSE),]
95109
rownames(results[["extreme"]]) <- NULL
96110

R/drugScreening.R

Lines changed: 76 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,17 @@
4949
#' @examples
5050
#'
5151
#' ## Load drug screen dataset for 1 drug
52-
#' data(simpleDrugScreening)
52+
#' data(drugScreening)
5353
#'
5454
#' ## Calculate the extreme organoids for the methotrexate drug screening
5555
#' ## using a quantile of 1/3
56-
#' results <- selectOrgForOneDrug(drugScreening=simpleDrugScreening,
56+
#' results <- selectOrgForOneDrug(drugScreening=drugScreening,
5757
#' drugName="Methotrexate", study="MEGA-TEST", screenType="TEST-01",
5858
#' doseType="Averaged", quantile=1/3)
5959
#'
60+
#' ## The classification of the organoids is in the 'extreme' entry
61+
#' results$extreme
62+
#'
6063
#' @author Astrid Deschênes, Pascal Belleau
6164
#' @importFrom S4Vectors isSingleNumber
6265
#' @encoding UTF-8
@@ -103,8 +106,9 @@ selectOrgForOneDrug <- function(drugScreening, drugName, study,
103106
selectedDrugData <- selectedDrugData[
104107
which(tolower(selectedDrugData$screen_type) %in% tolower(screenType)), ]
105108

106-
results <- findOneDrugQuantile(drugData=selectedDrugData, drugName=drugName,
107-
doseType="Averaged", quantile=quantile)
109+
results <- findOneDrugQuantile(drugData=selectedDrugData,
110+
drugName=drugName, doseType="Averaged",
111+
quantile=quantile)
108112

109113
# Return a list marked as an DrugAUCQuantile class
110114
class(results) <- "DrugAUCQuantile"
@@ -117,7 +121,9 @@ selectOrgForOneDrug <- function(drugScreening, drugName, study,
117121
#'
118122
#' @description The function TODO
119123
#'
120-
#' @param drugQuantile TODO
124+
#' @param drugQuantile an object of class "\code{DrugAUCQuantile}" which
125+
#' contains the
126+
#' sensitive and resistant organoids for a specific drug.
121127
#'
122128
#' @return TODO
123129
#'
@@ -130,11 +136,75 @@ selectOrgForOneDrug <- function(drugScreening, drugName, study,
130136
#' @importFrom S4Vectors isSingleNumber
131137
#' @encoding UTF-8
132138
#' @export
133-
plotDrugAUCDistribution <- function(drugQuantile) {
139+
plotDrugAUCDensityCurve <- function(drugQuantile) {
140+
141+
## Validate that the drugQuantile parameter is a DrugAUCQuantile object
142+
if (!is.DrugAUCQuantile(drugQuantile)) {
143+
stop("\'drugQuantile\' must be a DrugAUCQuantile object.")
144+
}
145+
146+
}
147+
148+
149+
#' @title TODO
150+
#'
151+
#' @description The function TODO
152+
#'
153+
#' @param drugQuantile an object of class "\code{DrugAUCQuantile}" which
154+
#' contains the
155+
#' sensitive and resistant organoids for a specific drug.
156+
#'
157+
#' @param min a single \code{numeric} representing the minimum value of the
158+
#' y-axis. Default: \code{0}.
159+
#'
160+
#' @param max a single \code{numeric} representing the maximum value of the
161+
#' y-axis. Default: \code{100}.
162+
#'
163+
#' @param trim a \code{logical} indicating if the tails of the violins
164+
#' are trimmed to the range of the data. Default: \code{FALSE}.
165+
#'
166+
#' @return a \code{ggplot} object for a violin plot built with the specified
167+
#' data.
168+
#'
169+
#' @examples
170+
#'
171+
#' ## TODO
172+
#' drugName <- "Methotrexate"
173+
#'
174+
#' @author Astrid Deschênes, Pascal Belleau
175+
#' @importFrom ggplot2 ggplot geom_violin ylim ylab theme_minimal aes .data
176+
#' position_jitter geom_point xlab geom_hline scale_colour_manual theme
177+
#' element_text
178+
#' @encoding UTF-8
179+
#' @export
180+
plotDrugAUCViolinPlot <- function(drugQuantile, min=0, max=100, trim=FALSE) {
134181

135182
## Validate that the drugQuantile parameter is a DrugAUCQuantile object
136183
if (!is.DrugAUCQuantile(drugQuantile)) {
137184
stop("\'drugQuantile\' must be a DrugAUCQuantile object.")
138185
}
139186

187+
aucResults <- drugQuantile$extreme
188+
aucResults$drug <- drugQuantile$dataset$drug_a
189+
190+
colorsR <- c("RESISTANT"="red2", "AVERAGE"="darkgray",
191+
"SENSITIVE"="blue3")
192+
193+
p <- ggplot(data=aucResults, aes(x=.data$drug, y=.data$relative_auc)) +
194+
geom_violin(size=1, colour="gray", trim=trim) +
195+
geom_point(aes(colour = .data$Group), size=3,
196+
position = position_jitter(seed = 1, width = 0.15)) +
197+
scale_colour_manual(name="Group", values=colorsR) +
198+
geom_hline(yintercept=drugQuantile$quantile$lower, linetype="dashed",
199+
color = "blue3", size=0.9) +
200+
geom_hline(yintercept=drugQuantile$quantile$upper, linetype="dashed",
201+
color = "red2", size=0.9) +
202+
ylab("Relative AUC") + ylim(c(0, 100)) + xlab("") +
203+
theme_minimal() +
204+
theme(axis.title=element_text(size=13, face="bold"),
205+
axis.text.x=element_text(size=13, face="bold"),
206+
legend.text=element_text(size=12),
207+
legend.title = element_text(size=13, face="bold"))
208+
209+
return(p)
140210
}

data/drugScreening.RData

2.43 KB
Binary file not shown.

0 commit comments

Comments
 (0)