1 Scenario

In this vignette, we demonstrate how one may use the package GO.db to dynamically display additional information about selected pathways in the interactive user interface.

2 Demonstration

2.1 Example data

First, we generate pathway analysis results for simulated data using fgsea.

In particular, we use the package org.Hs.eg.db to fetch real gene sets. To reduce memory footprint, we retain only the gene sets associated with 15 to 500 genes.

Then, we simulate a score for each of the gene present in any of those remaining gene sets. In practice, that score could be the log2 fold-change of the gene in a differential expression analysis (among other possibilities).

Finally, we perform an FGSEA on the simulated data.

library("org.Hs.eg.db")
library("fgsea")

# Example data ----

## Pathways
pathways <- select(org.Hs.eg.db, keys(org.Hs.eg.db, "SYMBOL"), c("GOALL"), keytype = "SYMBOL")
pathways <- subset(pathways, ONTOLOGYALL == "BP")
pathways <- unique(pathways[, c("SYMBOL", "GOALL")])
pathways <- split(pathways$SYMBOL, pathways$GOALL)
len_pathways <- lengths(pathways)
pathways <- pathways[len_pathways > 15 & len_pathways < 500]

## Features
set.seed(1)
# simulate a score for all genes found across all pathways
feature_stats <- rnorm(length(unique(unlist(pathways))))
names(feature_stats) <- unique(unlist(pathways))
# arbitrarily select a pathway to simulate enrichment
pathway_id <- "GO:0046324"
pathway_genes <- pathways[[pathway_id]]
# increase score of genes in the selected pathway to simulate enrichment
feature_stats[pathway_genes] <- feature_stats[pathway_genes] + 1

# fgsea ----

set.seed(42)
fgseaRes <- fgsea(pathways = pathways, 
                  stats    = feature_stats,
                  minSize  = 15,
                  maxSize  = 500)
head(fgseaRes[order(pval), ])
#>       pathway         pval         padj   log2err        ES      NES size
#> 1: GO:0046324 4.629962e-09 2.272849e-05 0.7614608 0.6091185 2.514113   60
#> 2: GO:0046323 7.223065e-08 1.772901e-04 0.7049757 0.5333744 2.317403   77
#> 3: GO:0010827 9.846789e-07 1.611263e-03 0.6435518 0.4963806 2.161258   78
#> 4: GO:0046326 7.244809e-06 8.891192e-03 0.6105269 0.5941057 2.196318   37
#> 5: GO:0010828 3.659219e-05 3.592621e-02 0.5573322 0.5549609 2.126911   44
#> 6: GO:0046325 1.164013e-04 9.523566e-02 0.5384341 0.6975496 2.065874   16
#>                                  leadingEdge
#> 1: IRS2,MIR107,GPC3,MAPK14,RPS6KB1,SIRT6,...
#> 2: IRS2,MIR107,GPC3,MAPK14,RPS6KB1,SIRT6,...
#> 3: IRS2,MIR107,GPC3,MAPK14,RPS6KB1,SIRT6,...
#> 4:     IRS2,GPC3,MAPK14,OPN3,ARPP19,OCLN,...
#> 5:     IRS2,GPC3,MAPK14,OPN3,ARPP19,OCLN,...
#> 6:    MIR107,SIRT6,ENPP1,OSTN,PID1,APPL2,...

Then, we embed the fgsea results in a SummarizedExperiment object.

In this case, we create an empty ?SummarizedExperiment-class object, without any simulated count data nor metadata, as we will not be using any of those data in this example.

We then embed the pathway analysis results in the newly created ?SummarizedExperiment-class object.

But first, we reorder the results by increasing p-value. Although not essential, this implicitly defines the default ordering of the table in the live app.

library("SummarizedExperiment")
library("iSEEpathways")
se <- SummarizedExperiment()
fgseaRes <- fgseaRes[order(pval), ]
se <- embedPathwaysResults(fgseaRes, se, name = "fgsea", class = "fgsea", pathwayType = "GO")

2.2 Pathway information

In this example, we configure the app option PathwaysTable.select.details to define a function that, given the identifier of the GO term currently selected in a panel, displays information about that GO term.

Although not essential, this is a user-friendly and immediate way to ‘translate’ machine-friendly database identifiers into human-friendly descriptions.

library("iSEE")
library("GO.db")
library("shiny")
go_details <- function(x) {
    info <- select(GO.db, x, c("TERM", "ONTOLOGY", "DEFINITION"), "GOID")
    html <- list(p(strong(info$GOID), ":", info$TERM, paste0("(", info$ONTOLOGY, ")")))
    if (!is.na(info$DEFINITION)) {
        html <- append(html, list(p(info$DEFINITION)))
    }
    tagList(html)
}
se <- registerAppOptions(se, PathwaysTable.select.details = go_details)

2.3 Live app

Finally, we configure the app initial state and launch the live app.

app <- iSEE(se, initial = list(
  PathwaysTable(ResultName="fgsea", Selected = "GO:0046324", PanelWidth = 12L)
))

if (interactive()) {
  shiny::runApp(app)
}