Skip to content

Commit

Permalink
start third part
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinrue committed Jul 29, 2024
1 parent 2b43c11 commit d29335c
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions vignettes/workshop_isee_extension.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,52 @@ This bottleneck can be circumnavigated by storing pathways as a regular `list()`

## Writing iSEE extensions

### Overview

In the next 10 minutes, we will:

* Extend an existing panel class into a new panel class
* Derive a new panel class from an existing panel

### Philosophy

`r BiocStyle::Biocpkg("iSEE")` panels are implemented as S4 classes that store the state of each panel in designated slots, and most of the functionality is implemented as S4 methods that describe various behavioural aspects of each panel class.

As a result, new classes can be created simply by inheritance from existing classes, overwriting methods to produce a different behaviour.

### Deriving an S4 class

In this demo, let us create a new class called `ReducedDimensionHexPlot`, that inherits from the existing class `ReducedDimensionPlot()` (implemented in the `r BiocStyle::Biocpkg("iSEE")` package).

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

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).

```{r}
setClass("ReducedDimensionHexPlot", contains="ReducedDimensionPlot", slots=c(BinResolution = "numeric"))
```

### Creating a constructor function

It is best practice to give users a function to create objects a particular class.
Traditionally, the function is named identically to the class.

In this example, the function passes all its arguments to the `new()` function.
This is standard practice in `r BiocStyle::Biocpkg("iSEE")`, where the arguments for constructor functions are typically the values of the various slots that describe the initial state of the panel.

```{r}
ReducedDimensionHexPlot <- function(...) {
new("ReducedDimensionHexPlot", ...)
}
```

At this point, we can already demonstrate that we have a functional new panel class... that is a carbon copy of the parent class it inherits from!

```{r}
iSEE(sce, initial = list(
ReducedDimensionHexPlot(),
ReducedDimensionPlot()
))
```

How can we even tell which is which?!

0 comments on commit d29335c

Please sign in to comment.