@@ -174,144 +174,6 @@ selectNoReplicateOrganoids <- function(drugScreening, patientInfo) {
174
174
}
175
175
176
176
177
- # ' @title Select the organoids with sensitive and resistant behavior for a
178
- # ' specific drug screening
179
- # '
180
- # ' @description The function selects the organoids within the low and upper
181
- # ' quantile, as specified by user, for a specific drug screening. When more
182
- # ' than one organoid is present for a patient, only one is retained for the
183
- # ' analysis. The selection is done randomly. To obtain reproducible results,
184
- # ' the seed should be set before running this function.
185
- # '
186
- # ' @param drugScreening a \code{data.frame} that contains the drug screening
187
- # ' results. The mandatory columns: 'organoid_id',
188
- # ' 'timestamp', 'study', 'screen_type', 'dosage_type',
189
- # ' 'drug_a', 'drug_b', 'drug_c', 'drug_background' and 'relative_auc'.
190
- # '
191
- # ' @param drugName a single \code{character} string representing the name of
192
- # ' the drug selected for the analyses. The drug must be present in the drug
193
- # ' screening dataset. The drug name can be found in the 'drug_a' column of the
194
- # ' drug screening dataset.
195
- # '
196
- # ' @param study a single \code{character} string representing the name of
197
- # ' the study selected for the analyses. The study must be present in the drug
198
- # ' screening dataset. The study can be found in the 'study' column of the
199
- # ' drug screening dataset.
200
- # '
201
- # ' @param screenType a \code{vector} of \code{character} string representing
202
- # ' the type of
203
- # ' screening selected for the analyses. The type must be present in the drug
204
- # ' screening dataset. The screen type can be found in the 'screen_type'
205
- # ' column of the drug screening dataset.
206
- # '
207
- # ' @param patientInfo a \code{data.frame} containing the meta-data information
208
- # ' related to the organoids. The mandatory columns are: 'organoid_id'
209
- # ' and 'patient_id'.
210
- # '
211
- # ' @param doseType a single \code{character} string representing the type of
212
- # ' dosage selected for the analyses. The type must be present in the drug
213
- # ' screening dataset.
214
- # '
215
- # ' @param quantile a single positive \code{numeric} between 0 and 0.5
216
- # ' indicating the quantile used to select the organoids. Default: \code{1/3}.
217
- # '
218
- # ' @return an object of class "\code{DrugAUCQuantile}" which contains the
219
- # ' sensitive and resistant organoids for a specific drug. This object is a
220
- # ' \code{list} with the following 3 components:
221
- # ' \itemize{
222
- # ' \item{quantile}{the \code{upper} and \code{lower} quantiles for the
223
- # ' specified drug.}
224
- # ' \item{dataset}{a \code{data.frame} containing the data used to
225
- # ' calculate the quantiles. }
226
- # ' \item{extreme}{a \code{data.frame} containing the sensitive and
227
- # ' resistant organoids according to the specified quantiles.
228
- # ' The \code{data.frame} also contains the relative AUC. }
229
- # ' }
230
- # '
231
- # ' @examples
232
- # '
233
- # ' ## Load drug screen dataset for 1 drug
234
- # ' data(drugScreening)
235
- # '
236
- # ' ## Load patient information dataset for 1 drug
237
- # ' data(patientInfo)
238
- # '
239
- # ' ## Calculate the extreme organoids for the methotrexate drug screening
240
- # ' ## using a quantile of 1/3
241
- # ' results <- getClassNoReplicateOneDrug(drugScreening=drugScreening,
242
- # ' drugName="Methotrexate", study="MEGA-TEST", screenType="TEST-01",
243
- # ' patientInfo=patientInfo, doseType="Averaged", quantile=1/3)
244
- # '
245
- # ' ## The classification of the organoids is in the 'extreme' entry
246
- # ' results$extreme
247
- # '
248
- # ' @author Astrid Deschênes, Pascal Belleau
249
- # ' @importFrom S4Vectors isSingleNumber
250
- # ' @encoding UTF-8
251
- # ' @export
252
- getClassNoReplicateOneDrug <- function (drugScreening , drugName , study ,
253
- screenType , patientInfo , doseType = " Averaged" , quantile = 1 / 3 ) {
254
-
255
- # # Validate input types
256
- validateSelectOrgWithoutReplicateForOneDrug(drugScreening = drugScreening ,
257
- drugName = drugName , study = study , screenType = screenType ,
258
- patientInfo = patientInfo , doseType = doseType , quantile = quantile )
259
-
260
- # # The drug must be present in the drug dataset
261
- if (! (tolower(drugName ) %in% tolower(unique(drugScreening $ drug_a )))) {
262
- stop(" The drug \' " , drugName , " \' is not present in the drug " ,
263
- " screening dataset." )
264
- }
265
-
266
- # # The study must be present in the drug dataset
267
- if (! (tolower(study ) %in% tolower(unique(drugScreening $ study )))) {
268
- stop(" The study \' " , study , " \' is not present in the drug " ,
269
- " screening dataset." )
270
- }
271
-
272
- # # The study must be present in the drug dataset
273
- if (! any(tolower(screenType ) %in%
274
- tolower(unique(drugScreening $ screen_type )))) {
275
- stop(" The screen type \' " , screenType , " \' is not present in the " ,
276
- " drug screening dataset." )
277
- }
278
-
279
- # # The doseType must be present in the drug dataset
280
- if (! (tolower(doseType ) %in%
281
- tolower(unique(drugScreening $ dosage_type )))) {
282
- stop(" The dosage type \' " , doseType , " \' is not present in the " ,
283
- " drug screening dataset." )
284
- }
285
-
286
- selectedDrugData <- filterDrugScreenOneDrug(drugData = drugScreening ,
287
- drugName = drugName , study = study , screenType = screenType ,
288
- doseType = doseType )
289
-
290
- # # All organoids should have an associated patient information
291
- if (! all(unique(selectedDrugData $ organoid_id ) %in%
292
- patientInfo $ organoid_id )) {
293
- stop(" Not all organoids have an associated patient information." )
294
- }
295
-
296
- merged_data <- merge(selectedDrugData , patientInfo , by = " organoid_id" ,
297
- all = FALSE )
298
-
299
- shuffled_data <- merged_data [sample(1 : nrow(merged_data ),
300
- replace = FALSE ), ]
301
-
302
- noReplicate <- shuffled_data [! duplicated(shuffled_data $ patient_id ), ]
303
-
304
- results <- findQuantileOneDrug(cleanDrugData = noReplicate , quantile = quantile )
305
-
306
- results [[" datasetWithReplicates" ]] <- shuffled_data
307
-
308
- # Return a list marked as an DrugAUCQuantileNoReplicate class
309
- class(results ) <- " DrugAUCQuantileNoReplicate"
310
-
311
- return (results )
312
- }
313
-
314
-
315
177
# ' @title Create a density plot using the relative AUC and the sensitivity
316
178
# ' classes (SENSITIVE, AVERAGE, RESISTANT) of the organoids for a specific
317
179
# ' drug.
0 commit comments