Browse code

- Made precision pathway evaluation functions generics.

Dario Strbenac authored on 20/02/2023 06:25:02
Showing 3 changed files

... ...
@@ -1,6 +1,9 @@
1 1
 # Generated by roxygen2: do not edit by hand
2 2
 
3
+S3method(bubblePlot,PrecisionPathways)
4
+S3method(flowchart,PrecisionPathways)
3 5
 S3method(predict,trainedByClassifyR)
6
+S3method(strataPlot,PrecisionPathways)
4 7
 S3method(summary,PrecisionPathways)
5 8
 S3method(train,DataFrame)
6 9
 S3method(train,MultiAssayExperiment)
... ...
@@ -19,7 +22,6 @@ export(TransformParams)
19 22
 export(actualOutcome)
20 23
 export(allFeatureNames)
21 24
 export(available)
22
-export(bubblePlot.PrecisionPathways)
23 25
 export(calcCVperformance)
24 26
 export(calcCostsAndPerformance)
25 27
 export(calcExternalPerformance)
... ...
@@ -32,7 +34,6 @@ export(distribution)
32 34
 export(edgesToHubNetworks)
33 35
 export(featureSetSummary)
34 36
 export(finalModel)
35
-export(flowchart.PrecisionPathways)
36 37
 export(interactorDifferences)
37 38
 export(models)
38 39
 export(performance)
... ...
@@ -46,7 +47,6 @@ export(runTests)
46 47
 export(sampleNames)
47 48
 export(samplesMetricMap)
48 49
 export(selectionPlot)
49
-export(strataPlot.PrecisionPathways)
50 50
 export(totalPredictions)
51 51
 export(tunedParameters)
52 52
 exportClasses(ClassifyResult)
... ...
@@ -308,6 +308,10 @@ summary.PrecisionPathways <- function(object, weights = c(accuracy = 0.5, cost =
308 308
   summaryTable
309 309
 }
310 310
 
311
+bubblePlot <- function (precisionPathways, ...) {
312
+   UseMethod("bubblePlot", precisionPathways)
313
+ }
314
+
311 315
 #' @param precisionPathways A pathway of class \code{PrecisionPathways}.
312 316
 #' @param pathwayColours A named vector of colours with names being the names of pathways. If none is specified,
313 317
 #' a default colour scheme will automatically be chosen.
... ...
@@ -319,10 +323,14 @@ bubblePlot.PrecisionPathways <- function(precisionPathways, pathwayColours = NUL
319 323
   if(is.null(pathwayColours)) pathwayColours <- scales::hue_pal()(length(precisionPathways[["pathways"]]))
320 324
   performance <- precisionPathways[["performance"]]
321 325
   performance <- cbind(Sequence = rownames(performance), performance)
322
-  ggplot2::ggplot(performance, aes(x = accuracy, y = cost, colour = Sequence)) + geom_point() +
323
-    ggplot2::scale_color_manual(values = pathwayColours) + labs(x = "Balanced Accuracy", y = "Total Cost")
326
+  ggplot2::ggplot(performance, aes(x = accuracy, y = cost, colour = Sequence, size = 4)) + ggplot2::geom_point() +
327
+    ggplot2::scale_color_manual(values = pathwayColours) + ggplot2::labs(x = "Balanced Accuracy", y = "Total Cost") + ggplot2::guides(size = FALSE)
324 328
 }
325 329
 
330
+flowchart <- function (precisionPathways, ...) {
331
+   UseMethod("flowchart", precisionPathways)
332
+ }
333
+
326 334
 #' @param precisionPathways A pathway of class \code{PrecisionPathways}.
327 335
 #' @param pathway A chracter vector of length 1 specifying which pathway to plot, e.g. "clinical-mRNA".
328 336
 #' @param nodeColours A named vector of colours with names being \code{"assay"}, \code{"class1"},\code{"class2"}.
... ...
@@ -394,6 +402,9 @@ flowchart.PrecisionPathways <- function(precisionPathways, pathway, nodeColours
394 402
   return(colour)
395 403
 }
396 404
 
405
+strataPlot <- function (precisionPathways, ...) {
406
+   UseMethod("strataPlot", precisionPathways)
407
+ }
397 408
 
398 409
 #' @param classColours A named vector of colours with names being \code{"class1"},\code{"class2"}, and \code{"accuracy"}.
399 410
 #' a default colour scheme will automatically be chosen.
... ...
@@ -410,30 +421,30 @@ strataPlot.PrecisionPathways <- function(precisionPathways, pathway, classColour
410 421
   samplesTiers$ID = 1:nrow(samplesTiers)
411 422
   samplesTiers$colour = ifelse(samplesTiers$trueClass == levels(samplesTiers[, "Predicted"])[1], classColours["class1"], classColours["class2"])
412 423
 
413
-  strataPlot <- ggplot(mapping = aes(x = ID, y = Tier), data = samplesTiers) +
414
-                geom_tile(aes(fill = trueClass)) +
415
-    scale_fill_manual(values = unname(classColours))  +
416
-    labs(title = paste("Pathway:", pathway), fill = "True Class", x = "", y = "") +
417
-    guides(fill = guide_legend(title.position = "top")) +
424
+  strataPlot <- ggplot2::ggplot(mapping = ggplot2::aes(x = ID, y = Tier), data = samplesTiers) +
425
+                ggplot2::geom_tile(aes(fill = trueClass)) +
426
+    ggplot2::scale_fill_manual(values = unname(classColours))  +
427
+    ggplot2::labs(title = paste("Pathway:", pathway), fill = "True Class", x = "", y = "") +
428
+    ggplot2::guides(fill = guide_legend(title.position = "top")) +
418 429
     ggnewscale::new_scale_fill() +
419 430
     geom_tile(aes(fill = Accuracy)) +
420
-    scale_fill_gradient(low = "#377EB8", high = "#E41A1C") +
421
-    labs(fill = "Accuracy") +
422
-    guides(fill = guide_colorbar(title.position = "top")) +
423
-    theme(panel.background = element_blank(),
424
-          axis.text.x = element_blank(),
431
+    ggplot2::scale_fill_gradient(low = "#377EB8", high = "#E41A1C") +
432
+    ggplot2::labs(fill = "Accuracy") +
433
+    ggplot2::guides(fill = guide_colorbar(title.position = "top")) +
434
+    ggplot2::theme(panel.background = ggplot2::element_blank(),
435
+          axis.text.x = ggplot2::element_blank(),
425 436
           aspect.ratio = 1/4, 
426
-          plot.title = element_text(face = "bold", size = 20),
427
-          legend.title = element_text(face = "bold", size = 12),
428
-          legend.text = element_text(size = 10),
437
+          plot.title = ggplot2::element_text(face = "bold", size = 20),
438
+          legend.title = ggplot2::element_text(face = "bold", size = 12),
439
+          legend.text = ggplot2::element_text(size = 10),
429 440
           legend.position = "bottom",
430
-          axis.text = element_text(size = 15)) +
441
+          axis.text = ggplot2::element_text(size = 15)) +
431 442
     annotate("tile",
432 443
                x = samplesTiers$ID,
433 444
                y = length(levels(samplesTiers[, "Tier"])) + 0.8,
434 445
                height = 0.6,
435 446
                fill = samplesTiers$colour)  +
436
-    coord_cartesian(expand = FALSE) 
447
+    ggplot2::coord_cartesian(expand = FALSE) 
437 448
     
438 449
   strataPlot
439 450
 }
440 451
\ No newline at end of file
... ...
@@ -12,15 +12,15 @@ calcCostsAndPerformance(precisionPathways, costs = NULL)
12 12
 
13 13
 \method{summary}{PrecisionPathways}(object, weights = c(accuracy = 0.5, cost = 0.5))
14 14
 
15
-bubblePlot.PrecisionPathways(precisionPathways, pathwayColours = NULL)
15
+\method{bubblePlot}{PrecisionPathways}(precisionPathways, pathwayColours = NULL)
16 16
 
17
-flowchart.PrecisionPathways(
17
+\method{flowchart}{PrecisionPathways}(
18 18
   precisionPathways,
19 19
   pathway,
20 20
   nodeColours = c(assay = "#86C57C", class1 = "#ACCEE0", class2 = "#F47F72")
21 21
 )
22 22
 
23
-strataPlot.PrecisionPathways(
23
+\method{strataPlot}{PrecisionPathways}(
24 24
   precisionPathways,
25 25
   pathway,
26 26
   classColours = c(class1 = "#4DAF4A", class2 = "#984EA3")