Skip to content

Commit 1bb5dd3

Browse files
committed
alter plotting behaviour
1 parent 9fa2e37 commit 1bb5dd3

File tree

2 files changed

+64
-22
lines changed

2 files changed

+64
-22
lines changed

vignettes/img/iSEEhex_binned.png

145 KB
Loading

vignettes/workshop_isee_extension.Rmd

Lines changed: 64 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ vignette: >
88
%\VignetteEncoding{UTF-8}
99
---
1010

11-
1211
```{r, include = FALSE}
1312
## Track time spent on making the vignette
1413
startTime <- Sys.time()
@@ -50,8 +49,7 @@ Relevant background reading:
5049
[materials](https://isee.github.io/iSEEWorkshop2019/),
5150
[slides](https://isee.github.io/iSEEWorkshop2019Slides/)
5251
* Rue-Albrecht K, Marini F, Soneson C and Lun ATL.
53-
iSEE: Interactive SummarizedExperiment Explorer
54-
[version 1; peer review: 3 approved]. F1000Research 2018, 7:741
52+
iSEE: Interactive SummarizedExperiment Explorer [version 1; peer review: 3 approved]. F1000Research 2018, 7:741
5553
(https://doi.org/10.12688/f1000research.14966.1)
5654
* Vignette: [SummarizedExperiment for Coordinating Experimental Assays, Samples, and Regions of Interest](https://bioconductor.org/packages/release/bioc/vignettes/SummarizedExperiment/inst/doc/SummarizedExperiment.html#anatomy-of-a-summarizedexperiment)
5755

@@ -331,8 +329,8 @@ For instance, the same initial state illustrated above can be achieved using the
331329

332330
```{r}
333331
initial <- list(
334-
ReducedDimensionPlot(),
335-
FeatureAssayPlot()
332+
ReducedDimensionPlot(),
333+
FeatureAssayPlot()
336334
)
337335
```
338336

@@ -479,9 +477,9 @@ Due to the use of `uniquifyFeatureNames()` above, the function must first map to
479477

480478
```{r}
481479
map_GO <- function(pathway_id, se) {
482-
pathway_ensembl <- mapIds(org.Hs.eg.db, pathway_id, "ENSEMBL", keytype = "GOALL", multiVals = "CharacterList")[[pathway_id]]
483-
pathway_rownames <- rownames(se)[rowData(se)[["gene_id"]] %in% pathway_ensembl]
484-
pathway_rownames
480+
pathway_ensembl <- mapIds(org.Hs.eg.db, pathway_id, "ENSEMBL", keytype = "GOALL", multiVals = "CharacterList")[[pathway_id]]
481+
pathway_rownames <- rownames(se)[rowData(se)[["gene_id"]] %in% pathway_ensembl]
482+
pathway_rownames
485483
}
486484
airway <- registerAppOptions(airway, Pathways.map.functions = list(GO = map_GO))
487485
```
@@ -541,7 +539,14 @@ In this demo, let us create a new class called `ReducedDimensionHexPlot`, that i
541539

542540
The objective is to produce a panel that displays the same information as the original `ReducedDimensionPlot()` panel, but summarising data points into hexagonal bins.
543541

544-
For this, the new class needs an additional slot to store the number of hexagonal bins to create (i.e., a resolution for the plot).
542+
One major motivation for this functionality is that arbitrarily large data sets comprising many data points may be summarised into a modest number of hexagonal bins, providing a boost in speed when rendering the plot.
543+
544+
However, this is not without caveats:
545+
546+
* Summarising can take many forms (e.g., counting, averaging).
547+
* The ideal number of bins may be different for different data sets.
548+
549+
To proceed, the new class needs at least one additional slot to store the number of hexagonal bins to create (i.e., a resolution for the plot).
545550

546551
```{r}
547552
setClass("ReducedDimensionHexPlot", contains="ReducedDimensionPlot", slots=c(BinResolution = "numeric"))
@@ -554,11 +559,11 @@ We set the default resolution to 100 hexagonal bins along each axis.
554559

555560
```{r}
556561
setMethod("initialize", "ReducedDimensionHexPlot", function(.Object, ...) {
557-
args <- list(...)
558-
559-
args <- .emptyDefault(args, "BinResolution", 100)
560-
561-
do.call(callNextMethod, c(list(.Object), args))
562+
args <- list(...)
563+
564+
args <- .emptyDefault(args, "BinResolution", 20)
565+
566+
do.call(callNextMethod, c(list(.Object), args))
562567
})
563568
```
564569

@@ -572,7 +577,7 @@ This is standard practice in `r BiocStyle::Biocpkg("iSEE")`, where the arguments
572577

573578
```{r}
574579
ReducedDimensionHexPlot <- function(...) {
575-
new("ReducedDimensionHexPlot", ...)
580+
new("ReducedDimensionHexPlot", ...)
576581
}
577582
```
578583

@@ -591,7 +596,7 @@ iSEE(sce, initial = list(
591596

592597
How can we even tell which is which?!
593598

594-
### Overwriting S4 methods
599+
### Changing the public panel name
595600

596601
The generic `.fullName()` declares the label shown in the interface, at the top of each panel.
597602

@@ -614,6 +619,8 @@ iSEE(sce, initial = list(
614619

615620
<br/>
616621

622+
### Changing the background panel colour
623+
617624
Similarly, the generic `.panelColor()` declares the background colour of the panel header (as well as the colour of brushes for compatible panels).
618625

619626
Let us create a method for the new class, that gives it a different colour.
@@ -635,6 +642,8 @@ iSEE(sce, initial = list(
635642

636643
<br/>
637644

645+
### Altering the user interface
646+
638647
At this point, there is still no component in the user interface to control the resolution value store in the new slot.
639648

640649
A number of S4 methods control the interface elements displayed in the variousgroups of parameters located under each panel.
@@ -646,12 +655,12 @@ Thus, the generic `.defineVisualSizeInterface()` is the natural choice to use fo
646655

647656
```{r}
648657
setMethod(".defineVisualSizeInterface", "ReducedDimensionHexPlot", function(x) {
649-
plot_name <- .getEncodedName(x)
650-
651-
tagList(
652-
.numericInput.iSEE(x, "BinResolution", label="Bin resolution:",
653-
min=1, value=x[["BinResolution"]], step = 1)
654-
)
658+
plot_name <- .getEncodedName(x)
659+
660+
tagList(
661+
.numericInput.iSEE(x, "BinResolution", label="Bin resolution:",
662+
min=1, value=x[["BinResolution"]], step = 1)
663+
)
655664
})
656665
```
657666

@@ -666,6 +675,39 @@ iSEE(sce, initial = list(
666675

667676
<br/>
668677

678+
### Altering the panel output
679+
680+
Time for the most exciting and challenging task: making the panel produce a different type of plot!
681+
682+
To this end, the generic `.generateDotPlot()` is key.
683+
Given a panel state, axis labels, and an environment that contains the `SummarizedExperiment()` object and possibly other relevant values such as incoming selections,
684+
685+
```{r}
686+
setMethod(".generateDotPlot", "ReducedDimensionHexPlot", function(x, labels, envir) {
687+
plot_cmds <- list()
688+
plot_cmds[["ggplot"]] <- "ggplot() +"
689+
color_lab <- "Count"
690+
new_aes <- .buildAes()
691+
plot_cmds[["hex"]] <- sprintf(
692+
"ggplot2::geom_hex(%s, bins = %i, plot.data) +",
693+
new_aes,
694+
as.integer(x[["BinResolution"]])
695+
)
696+
plot_cmds[["theme_base"]] <- "theme_bw()"
697+
698+
list(plot=.textEval(plot_cmds, envir), commands=plot_cmds)
699+
})
700+
```
701+
702+
```{r, message=FALSE, warning=FALSE, eval=FALSE}
703+
iSEE(sce, initial = list(
704+
ReducedDimensionHexPlot(PanelWidth = 6L, VisualBoxOpen = TRUE, VisualChoices = "Size"),
705+
ReducedDimensionPlot(PanelWidth = 6L, VisualBoxOpen = TRUE, VisualChoices = "Size")
706+
))
707+
```
708+
709+
![Screenshot of iSEE app including a parent ReducedDimensionPlot and a ReducedDimensionHexPlot extension after replacing the internal plotting code in the child panel.](img/iSEEhex_binned.png)
710+
669711
## Session info
670712

671713
```{r}

0 commit comments

Comments
 (0)