Contents

1 Overview

The {sparrow} package was built to facilitate the use of gene sets in the analysis of high throughput genomics data (primarily RNA-seq). It does so by providing these top-line functionalities:

The initial GSEA methods that sparrow wrapped were the ones provided by limma and edgeR. As such, many analyses using sparrow expect you to re-use the same data objects used for differential expression analysis, namely:

Other methods only require the user to provide a ranked vector of statistics that represent some differential expression statistic per gene, and the GSEA is performed by analyzing the ranks of genes within this vector.

The user can invoke one seas() call that can orchestrate multiple analyses of any type.

Currently supported gene set enrichment methods include:

##            method test_type package
## 1          camera preranked   limma
## 2        cameraPR preranked   limma
## 3           fgsea preranked   fgsea
## 4             ora       ora     ora
## 5             fry preranked   limma
## 6           roast preranked   limma
## 7           romer preranked   limma
## 8           goseq       ora   goseq
## 9     geneSetTest preranked   limma
## 10          logFC preranked   limma
## 11 svdGeneSetTest      meta sparrow

When using these methods in analyses that lead to publication, please cite the original papers that developed these methods and cite sparrow when its functionality assisted in your interpretation and analysis.

The sparrow package provides a small example expression dataset extracted from the TCGA BRCA dataset, which is available via the exampleExpressionSet function. In this vignette we will explore differential expression and gene set enrichment analysis by examining differences between basal and her2 PAM50 subtypes.

2 Standard Workflow

Let’s begin by setting up our work environment for exploratory analysis using the sparrow package.

Internally, sparrow leverages the data.table package for fast indexing and manipulation over data.frames. All functions that return data.frame looking objects back have converted it from an data.table prior to return. All such functions take an as.dt argument, which is set to FALSE by default that controls this behavior. If you want {sparrow} to return a data.table back to you from some function, try adding an as.dt = TRUE argument to the end of the function call.

2.1 Data Setup

sparrow is most straightforward to use when our data objects and analysis are performed with either the edgeR or voom/limma pipelines and when we use standard gene identifiers (like esnemble) as rownames() to these objects.

The exampleExpressionSet function gives us just such an object. We call it below in a manner that gives us an object that allows us to explore expression differences between different subtypes of breast cancer.

Below you’ll find the $targets data.frame of the voomed EList

##                                Patient_ID Cancer_Status PAM50subtype
## TCGA-A2-A0CM-01A-31R-A034-07 TCGA-A2-A0CM         tumor        Basal
## TCGA-BH-A0RX-01A-21R-A084-07 TCGA-BH-A0RX         tumor        Basal
## TCGA-BH-A18Q-01A-12R-A12D-07 TCGA-BH-A18Q         tumor        Basal
## TCGA-B6-A0RU-01A-11R-A084-07 TCGA-B6-A0RU         tumor        Basal
## TCGA-BH-A18P-01A-11R-A12D-07 TCGA-BH-A18P         tumor         Her2
## TCGA-C8-A275-01A-21R-A16F-07 TCGA-C8-A275         tumor         Her2
## TCGA-C8-A12Z-01A-11R-A115-07 TCGA-C8-A12Z         tumor         Her2
## TCGA-A2-A0T1-01A-21R-A084-07 TCGA-A2-A0T1         tumor         Her2
## TCGA-AC-A3OD-01A-11R-A21T-07 TCGA-AC-A3OD         tumor         LumA
## TCGA-AN-A0XS-01A-22R-A109-07 TCGA-AN-A0XS         tumor         LumA
## TCGA-A2-A0EM-01A-11R-A034-07 TCGA-A2-A0EM         tumor         LumA
## TCGA-AR-A24O-01A-11R-A169-07 TCGA-AR-A24O         tumor         LumA
## TCGA-D8-A4Z1-01A-21R-A266-07 TCGA-D8-A4Z1         tumor         LumA

Note that there are many tutorials online that outline how to generate expression matrices for use with differential expression and analysis, such as the one that is returned from the exampleExpressionSet function. Summarizing assay data into such a format is out of scope for this vignette, but you can reference the airway vignette for full details (among others).

2.2 Data Analysis

We will identify the genes and genesets that are differentially expressed between the basal and her2 subtypes. The vm object has already been voomd using this design:

##                              Basal Her2 LumA
## TCGA-A2-A0CM-01A-31R-A034-07     1    0    0
## TCGA-BH-A0RX-01A-21R-A084-07     1    0    0
## TCGA-BH-A18Q-01A-12R-A12D-07     1    0    0
## TCGA-B6-A0RU-01A-11R-A084-07     1    0    0
## TCGA-BH-A18P-01A-11R-A12D-07     0    1    0
## TCGA-C8-A275-01A-21R-A16F-07     0    1    0
## TCGA-C8-A12Z-01A-11R-A115-07     0    1    0
## TCGA-A2-A0T1-01A-21R-A084-07     0    1    0
## TCGA-AC-A3OD-01A-11R-A21T-07     0    0    1
## TCGA-AN-A0XS-01A-22R-A109-07     0    0    1
## TCGA-A2-A0EM-01A-11R-A034-07     0    0    1
## TCGA-AR-A24O-01A-11R-A169-07     0    0    1
## TCGA-D8-A4Z1-01A-21R-A266-07     0    0    1
## attr(,"assign")
## [1] 1 1 1
## attr(,"contrasts")
## attr(,"contrasts")$PAM50subtype
## [1] "contr.treatment"

We can test for differences between basla and her2 subtypes using the following contrast:

##        Contrasts
## Levels  BvH
##   Basal   1
##   Her2   -1
##   LumA    0

2.2.1 Differential Gene Expression

In this section, we first show you the straightforward analysis you would do if you were only testing for differential gene expression.

With the data we have at hand, you would simply do the following:

2.2.2 Gene Set Enrichment Analysis

Given that we now have all of the pieces of data required for a differential expression analysis, performing GSEA is trivial using the seas wrapper function. We simply need to now define (1) the battery of gene sets we want to test against, and (2) the GSEA methods we want to explore.

2.2.3 Gene Sets to Test

The sparrow package provides a GeneSetDb class to store collections of gene sets. The GeneSetDb object is used heavily for the internal functionality of {sparrow}, however you can provide sparrow with collections of gene sets using other containers from the bioconductor universe, like a BiocSet::BiocSet or a GSEABase::GeneSetCollection. This package provides convenience methods to convert between these different types of gene set containers. Please refer to The GeneSetDb Class section for more details.

The {sparrow} package also provides convenience methods to retrieve gene set collections from different sourckes, like MSigDB, PANTHER, KEGG, etc. These methods are named using the following pattern: get<CollectionName>Collection() to return a BiocSet with the gene sets from the collection, or get<CollectionName>GeneSetDb() to get a GeneSetDb of the same.

We’ll use the getMSigGeneSetDb convenience function provided by the sparrow package to load the hallmark ("h") and c2 (curated) ("c2") gene set collections from MSigDB.

To retrieve a BiocSet of these same collections, you could do:

You can view a table of the gene sets defined inside a GeneSetDb (gdb)object via its geneSets(gdb) accessor:

##   collection                             name active  N
## 1         C2         ABBUD_LIF_SIGNALING_1_DN  FALSE 28
## 2         C2         ABBUD_LIF_SIGNALING_1_UP  FALSE 43
## 3         C2         ABBUD_LIF_SIGNALING_2_DN  FALSE  7
## 4         C2         ABBUD_LIF_SIGNALING_2_UP  FALSE 13
## 5         C2       ABDELMOHSEN_ELAVL4_TARGETS  FALSE 16
## 6         C2 ABDULRAHMAN_KIDNEY_CANCER_VHL_DN  FALSE 13

2.3 Running sparrow

Performing multiple gene set enrichment analyses over your contrast of interest simply requires you to provide a GeneSetDb (or BiocSet) object along with your data and an enumeration of the methods you want to use in your analysis.

The call to seas() will perform these analyses and return a SparrowResult object which you can then use for downstream analysis.

We will unpack the details of the seas() call shortly …

2.4 Implicit Differential Expression

First, let’s note that in addition to running a plethora of GSEA’s over our data we’ve also run a standard differential expression analysis. If you’ve passed a matrix, ExpressionSet or EList into seas(), a limma-based lmFit %>% (eBayes|treat) %>% (topTable|topTreat) pipeline was run. If a DGEList was passed, then seas utilizes the edgeR-based glmQLFit %>% (glmQLFTest | glmTreat) %>% topTags pipeline.

The result of the internally run differential expression analysis is accessible via a call to logFC function on the SparrowResult object:

##         symbol entrez_id       logFC           t      pval      padj
## 1         A1BG         1  0.67012895  1.07951394 0.2982819 0.6858344
## 2          ADA       100  0.53844094  0.92401125 0.3708544 0.7415607
## 3         CDH2      1000 -0.08180996 -0.09901074 0.9225083 0.9795974
## 4         AKT3     10000  0.58338138  1.29502525 0.2158892 0.6125318
## 5 LOC100009676 100009676 -0.09581391 -0.26985709 0.7911366 0.9398579
## 6         MED6     10001  0.04505155  0.15082239 0.8822288 0.9701384

We can confirm that the statistics generated internally in seas() mimic our explicit analysis above by verifying that the t-statistics generated by both approaches are identical.

## [1] TRUE

The internally performed differential expression analysis within the seas() call can be customized almost as extensively as an explicitly performed analysis that you would run using limma or edgeR by sending more parameters through seas()’s ... argument.

See the Custom Differential Expression section further in the vignette as well as the help available in ?calculateIndividualLogFC (which is called inside the seas() function) for more information.

2.5 Explicit GSEA

We also have the results of all the GSEA analyses that we specified to our seas call via the methods parameter.

## SparrowResult (max FDR by collection set to 0.20%)
## --------------------------------------------------- 
##    collection   method geneset_count sig_count sig_up sig_down
## 1          C2   camera          6150       349    206      143
## 2           H   camera            50         6      5        1
## 3          C2      fry          6150        95     33       62
## 4           H      fry            50         0      0        0
## 5          C2      ora          6150        96     33       63
## 6           H      ora            50         3      1        2
## 7          C2 ora.down          6150        73      6       67
## 8           H ora.down            50         2      0        2
## 9          C2   ora.up          6150        24     21        3
## 10          H   ora.up            50         0      0        0

The table above enumerates the different GSEA methods run over each geneset collection in the rows. The columns enumerate the number of genesets that the collection has in total (geneset_count), and how many were found significant at a given FDR, which is set to 20% by default. The show command for the SparrowResult object simply calls the tabulateResults() function, which you can call directly with the value of max.p that you might find more appropriate.

2.6 Exploring Results

GSEA results can be examined interactively via the command line, or via a shiny application. You can use the resultNames function to find out what GSEA methods were run, and therefore available to you, within the the SparrowResult object:

## [1] "camera"   "fry"      "ora"      "ora.down" "ora.up"

Note that when running an “over representation analysis” "ora" (or "goseq"), it will be run three different ways. The tests will be run first by testing all differentially expressed genes that meet a given set of min logFC and max FDR thresholds, then separately for only genes that go up in your contrast, and a third time for only the genes that go down.

The individual gene set statistics generated by each method are available via the result function (or several can be returned with results):

You can identify genesets with the strongest enrichment by filtering and sorting against the appropriate columns. We can, for instance, identify which hallmark gene sets show the strongest enrichment as follows:

##                                 name   n mean.logFC         padj
## 1            HALLMARK_MYC_TARGETS_V2  58  0.4461105 0.0002612790
## 2 HALLMARK_INTERFERON_ALPHA_RESPONSE  96  0.3916716 0.0874709010
## 3               HALLMARK_E2F_TARGETS 200  0.3465703 0.0001892151
## 4            HALLMARK_MYC_TARGETS_V1 200  0.2092836 0.0234431144

You can also list the members of a geneset and their individual differential expression statistics for the contrast under test using the geneSet function.

##   symbol entrez_id      logFC       pval      padj
## 1  HDAC5     10014  0.8984691 0.02253974 0.2522754
## 2 CSNK1E      1454 -0.1793725 0.52104817 0.8317753
## 3 CTNNB1      1499  0.2577554 0.54741640 0.8467181
## 4   JAG1       182  0.7293432 0.02496690 0.2625306
## 5   DVL2      1856  0.4921509 0.24186744 0.6362028
## 6   DKK1     22943  0.6567652 0.66735589 0.8982828

The results provided in the table generated from a call to geneSet are independant of GSEA method. The statistics appended to the gene set members are simply the ones generated from a differential expression analysis.

2.7 Plotting

{sparrow} provides a number of interactive plotting facilities to explore the enrichment of a single geneset under the given contrast. In the boxplots and density plots shown below, the log fold changes (logFCs) (or t-statistics) for all genes under the contrast are visualized in the “background” set, and these same values are shown for the desired geneset under the “geneset” group.

The logFC (or t-statistics) of the genes in the gene set are plotted as points, which allow you to hover to identify the identity of the genes that land in the regions of the distributions you care about.

Including interactive plots increases the size of the vignette’s by a lot and will be rejected by the bioconductor build servers, so all plots included in this vignette are static snapshots of the javascript enabled plots you would normally get from iplot().

Boxplot

boxplot of geneset log2FC’s

boxplot of geneset log2FC’s

Density

density plot of geneset log2FC’s

density plot of geneset log2FC’s

GSEA plot

gsea plot of geneset log2FC’s

gsea plot of geneset log2FC’s

2.7.1 Interactive Exploration

A sister {sparrow.shiny} package is available that can be used to interactively explore SparrowResult objects to help you try to make sense of the enrichment hits you get (or not!). The application can be invoked as follows:

Screen shot of interactive sparrow exploration

Screen shot of interactive sparrow exploration

Please refer to the "sparrow-shiny" vignette in the {sparrow.shiny} package for documentation on the application’s use.

The {sparrow.shiny} package is currently only available to install from GitHub, but will be available through Bioconductor soon.

3 Singe Sample Gene Set Scoring

It can be both convenient and effective to transform a gene-by-sample expression matrix to a geneset-by-sample expression matrix. By doing so, so we can quickly identify biological processes that are up/down regulated (loosely speaking) in each sample.

We can generate single sample gene set scores using the gene sets defined in a GeneSetDb using the scoreSingleSamples function. This function takes a GeneSetDb, an expression container, and a methods argument, which is analagous to the methods argument in the seas() call: it defines all of the scoring methos the user wants to apply to each sample.

Let’s pick a few gene sets to score our samples with for this exercise. We’ll take the significant hallmark gene sets, or any other significant gene set that has a large (on average) log fold change between conditions.

Refer to the Subsetting a GeneSetDb section to learn how to subset a GeneSetDb object to create a derivative object with fewer gene sets.

Recall that the GSEA analysis we performed was perfomed between the Basal and Her2 subtypes, so we will use an expression matrix that only has the samples from those two groups.

3.1 Generating Single Sample Gene Set Scores

Once we have a GeneSetDb object that contains all of the gene sets we wish to use to create single sample gene set scores, we can use the scoreSingleSamples function to produce these scores using a variety of algorithmes, which the user species using the methods parameter.

The scoreSingleSamples function will return a long data.frame with length(methods) * ncol(exprs) rows. Each row represents the score for the given sample using the specified method. You can subset against the method column to extract all of the single sample scores for a given method.

## [1] "Calculating ranks..."
## [1] "Calculating absolute values from ranks..."
## [1] "Normalizing..."

We can see how the scores from different methods compare to each other:

It is, perhaps, interesting to compare how the ewm method scores change when we choose not to “uncenter” and “unscale” them:

Further exposition on the “ewm” (eigenWeightedMean) scoring method can be found in the ?eigenWeightedMean function.

3.2 Visualizing Single Sample Gene Set Scores

The “long” data.frame nature of the results produced by scoreSingleSamples makes it convenient to use with graphing libraries like ggplot2 so that we can create arbitrary visualizations. Creating boxplots for gene sets per subtype is an easy way to explore these results.

Let’s annotate each row in scores.all with the subtype annotation and observe how these methods score each sample for a few gene sets.

4 Gene Set Based Heatmap with mgheatmap

We often want to create expression based heatmaps that highlight the behavior of gene sets across our samples. The mgheatmap function uses the ComplexHeatmap package to create two different types of heatmaps:

  1. Gene based heatmaps, that split the genes (rows) based on their genesets
  2. Single sample gene set based heatmaps, optionally split by gene set collection.

The mgheatmap function has a set of arguments that customize how the heatmap is to be created (gene level vs. gene set level, whether to split it, etcv) and will also use the ... argument to pass any parameters down to the inner ComplexHeatmap::Heatmap function call and customize its behavior. The mgheatmap function returns a ComplexHeatmap,Heatmap object for plotting or combining with other ComplexHeatmap heatmaps or annotations in order to create arbitrarily complex/informative heatmap figures.

4.1 Gene level based heatmap (from genesets)

You can plot a heatmap of the genes from a predefined set of gene sets by providing the gene sets you want to visualize in a GeneSetDb object.

We’ll create a new GeneSetDb object using the first two gene sets in gdb.sub and draw a heatmap of their expression.

4.2 Gene set-based heatmap

You can often get a higher information:ink ratio by plotting heatmaps based on single sample gene set scores as opposed to the genes that make up a geneset.

Let’s see what the simple 2-geneset version of the heatmap above looks like:

Plotted in this way, we can now show the activity of a greater number of genesets

5 The GeneSetDb Class

The GeneSetDb class was developed to address the internal needs of the sparrow package for fast look up, subsetting, cross reference, etc. of a collection of gene sets. At the time (~2015), it was developed because the classes used for this purpose in the bioconductor ecosystem (a GSEABase::GeneSetCollection, or a simple list of gene vectors) didn’t cut the mustard.

More recently, bioc-core has developed a new class called a BiocSet that is feature-rich and shares significant overlap with the features in the sparrow::GeneSetDb class. Although we can’t quite replace the internals of {sparrow} to use the BiocSet just yet, users are encouraged to provide collections of gene sets in the form of a BiocSet everywhere {sparrow} functions require gene set collections, like seas() and scoreSingleSamples(). You can also convert a sparrow::GeneSetDb() to a BiocSet via a simple call: as(gdb, "BiocSet").

The remainder of this section provides a quick overview of the GeneSetDb class.

The GeneSetDb object uses the data.table package internally for fast lookup. Internally the collection of gene set information is minimally stored as a three-column data.table in “long form”, which has the following columns:

More columns can be added to the internal data.table (a “symbol” column, for instance), but those are the only three you need.

To see what we are talking about, exactly, you can call the as.data.frame function on a GeneSetDb object:

##     collection                     name feature_id   symbol
## 1           C2 ABBUD_LIF_SIGNALING_1_DN  100133941     CD24
## 2           C2 ABBUD_LIF_SIGNALING_1_DN      10753    CAPN9
## 3           C2 ABBUD_LIF_SIGNALING_1_DN     146556 C16orf89
## 4           C2 ABBUD_LIF_SIGNALING_1_DN       1644      DDC
## 5           C2 ABBUD_LIF_SIGNALING_1_DN       1943    EFNA2
## 201         C2    ABE_VEGFA_TARGETS_2HR       3949     LDLR
## 202         C2    ABE_VEGFA_TARGETS_2HR       4171     MCM2
## 203         C2    ABE_VEGFA_TARGETS_2HR       5055 SERPINB2
## 204         C2    ABE_VEGFA_TARGETS_2HR       5133    PDCD1
## 205         C2    ABE_VEGFA_TARGETS_2HR       5493      PPL

The (collection,name) tuple is the primary key of a gene set. The feature_id column stores gene identifiers. For the time being, it will be most natural for these IDs to simply be ensembl gene identifiers (or entrez ids) as many of the annotation databases use these identifiers, as well. In reality, you will want the values in the feature_id columns to match with the feature id’s you have in your data container (ie. the rownames() of a SummarizedExperiment, for instance).

5.1 Building a GeneSetDb

The sparrow package provides convenience functions to fetch genesets from many sources and convert them into a GeneSetDb object. The two most useful sources may be:

  • MSigDB via getMSigGeneSetDb(...). Although the core sparrow package provides the getter function for these genesets, the main data retrieval functionality is provided through the msigdbr package.
  • PANTHER (pathways and GOSLIM) via getPantherGeneSetDb()
  • KEGG via getKeggGeneSetDb(...)

We also provide similarly named methos to retrieve these gene set collections as a BiocSet, just substitute "Collection" for "GeneSetDb", ie. getMsigCollection(...), getPantherCollection(...), and getKeggCollection(...).

You can create a custom GeneSetDb via the GeneSetDb() constructor, which accepts the following types of inputs.

  1. A BiocSet
  2. A GeneSetCollection
  3. A data.frame of geneset membership. This requires collection, name, and feature_id columns. Reference the output of as.data.frame(gdb) shown above.
  4. A named list of gene identifier vectors that represent genesets for a single collection
  5. A named list of (2)-like lists. The top level names are the names of the different collections, and each sublist represents the genesets in that collection.

Two GeneSetDb objects can be combined using the cobine() function. For now it is your responsibility to ensure that the two GeneSetDb objects are “reasonably conformable”, ie. they use the same types of gene identifiers, and are referencing the same species, etc.

See the help and examples in ?GeneSetDb for more information.

For some reason the PANTHER.db package needs to be installed in a user-writable package location for this to work properly. If you see an error that speaks to using “rsqlite to write to a readonly database”, you will have to re-install PANTHER.db in a user-writable directory using BiocManager::install("PANTHER.db")

5.2 Subsetting a GeneSetDb

The subsetting functionality for a GeneSetDb is a bit clunky. We assume you want to subset a GeneSetDb to include a subset of, well, gene sets.

One way you can do that is to provide a logical vector that is as long as there are gene sets in the GeneSetDb as an index.

For instance, if we want to include only the genesets in CP:PID, you can do that. This subcatory information is stored in the "subcategory" column from geneSets(gdb)

##   collection                           name active  N  n subcategory gs_id
## 1         C2 PID_A6B1_A6B4_INTEGRIN_PATHWAY  FALSE 46 NA      CP:PID  M239
## 2         C2            PID_AJDISS_2PATHWAY  FALSE 48 NA      CP:PID  M142
## 3         C2               PID_ALK1_PATHWAY  FALSE 26 NA      CP:PID  M185
## 4         C2               PID_ALK2_PATHWAY  FALSE 11 NA      CP:PID  M203
## 5         C2    PID_ALPHA_SYNUCLEIN_PATHWAY  FALSE 32 NA      CP:PID  M275
## 6         C2   PID_AMB2_NEUTROPHILS_PATHWAY  FALSE 41 NA      CP:PID  M159

You can also subset a GeneSetDb to only include gene sets that contain certain features:

## [1] 6230
## [1] 120

5.3 Active vs Inactive Gene Sets

A GeneSetDb is used to hold “the universe” of genes that belong to different gene sets across different collections. Depending on the assay performed to measure these genes, the set of genes you observe in your study will likely be a subset of the genes in the GeneSetDb. As such, prior to using a GeneSetDb for GSEA, it must be “conformed” to a target object that will be used for the input to the GESA (either a matrix of expression, or a pre ranked vector of statistics). This step will index into the target expression object and identify which rows of the object correspond to which genes in the GeneSetDb.

“Conformation” happens automatically within the seas() call, but we call it explicitly below to outline its functionality. The command below conforms the GeneSetDb to our target “voomed” EList, and deactivates gene sets (i.e. removes them from downstream GSEA) that have less than 10 or more than 100 genes that were found in vm:

##   collection                             name active  N  n subcategory gs_id
## 1         C2         ABBUD_LIF_SIGNALING_1_DN   TRUE 28 25         CGP M1423
## 2         C2         ABBUD_LIF_SIGNALING_1_UP   TRUE 43 37         CGP M1458
## 3         C2         ABBUD_LIF_SIGNALING_2_DN  FALSE  7  5         CGP M1481
## 4         C2         ABBUD_LIF_SIGNALING_2_UP   TRUE 13 12         CGP M1439
## 5         C2       ABDELMOHSEN_ELAVL4_TARGETS   TRUE 16 15         CGP M2509
## 6         C2 ABDULRAHMAN_KIDNEY_CANCER_VHL_DN   TRUE 13 12         CGP M2096

We can see that, only 23 of the 26 genes in the (C2,ABBUD_LIF_SIGNALING_1_DN) were found in the rows of vm, and the (C2,ABBUD_LIF_SIGNALING_2_DN) was “deactivated.” Deactivated (active == FALSE) gene sets will be ignored during downstream analyses. This gene set was deactivated because it only has five “conformed” genes, but the minimum geneset size we wanted to consider (min.gs.size) was set to ten in our call to conform.

5.4 Accessing members of a gene set

The geneSet and featureIds functions allow the user to identify the genes found in a gene set. Both of these functions take an active.only argument, which is TRUE by default. This specifies that only the genes that have been successfully conformed to a gene set should be the ones that are returned.

For instance, we can identify which genes belong to the (C2,ABBUD_LIF_SIGNALING_1_DN), and which three were not found in vm like so:

## [1] "1644" "1943" "3170"

or we can use the geneSet function to return a data.frame of these results:

##    collection                     name active  N  n feature_id symbol
## 4          C2 ABBUD_LIF_SIGNALING_1_DN   TRUE 28 25       1644    DDC
## 5          C2 ABBUD_LIF_SIGNALING_1_DN   TRUE 28 25       1943  EFNA2
## 12         C2 ABBUD_LIF_SIGNALING_1_DN   TRUE 28 25       3170  FOXA2

5.5 Mapping of gene set featureIds to target expression containers

It may be that the IDs used in a gene set collection are different from the ones used as the rownames of your expression container. For instance, the IDs used for a given gene set collection in the GeneSetDb might be Ensembl gene identifiers, but the rownames of the expression object might be Entrez ID. This is where the mapping parameter becomes useful.

The GeneSetDb class has a concept of an internal featureIdMap to accommodate these scenarios, which would allow for a non-destructive mapping of the original IDs to a new “ID space” (entrez to ensembl, for instance).

This functionality is not ready for this release, but it’s just a note to keep the user aware of some future development of the package. For the time being, the user is required to manually map the feautreIds in their expression matrix to be concordant with the ones found in the GeneSetDb.

In the meantime, a renameRows convenience function is provided here to easily rename the rows of our expression container to different values. For instance, to rename this is how you might rename the rows of your assay container to use symbols:

##      [,1]        [,2]          
## [1,] "1"         "A1BG"        
## [2,] "100"       "ADA"         
## [3,] "1000"      "CDH2"        
## [4,] "10000"     "AKT3"        
## [5,] "100009676" "LOC100009676"
## [6,] "10001"     "MED6"

We grabbed the symbol column from vm$genes and “smartly” renamed the rows of vm with the values there. Refer to the ?renameRows man page for more details. This, of course, still requires you to manually fetch and map identifiers, but still …

6 Customizing Analyses

The internal differential expression analysis as well the gene set enrichment analyses can be customized by passing parameters through the ... in the seas() function.

6.1 Custom Differential Expression

The internal differential expression pipeline, exported via the calculateIndividualLogFC function allows the end user to configure an “arbitrarily complex” differential expression analysis using either edgeR’s quasilikelihood framework (if the input is a DGEList) or a direct limma analysis (with a pre-voomed EList, expression matrix, or whatever).

User’s should refer to the ?calculateIndividualLogFC help page to see which parameters are exposed for a differential expression analysis and configure them accordingly. When calling seas() use these same parameters in the call and they will be provided to calculateIndividualLogFC.

For instance, if you wanted to use limma’s “treat” functionality to specify a minimal log fold change threshold for statistical significance, you would do so as follows:

Using the internal treat functionality would really only affect enrichment tests that first threshold the genes in your experiment as “significant” or not, like goseq and not tests like camera.

6.2 Custom GSEA

The GSEA methods that are wrapped by seas() all take the same parameters that are defined by their implementation. Simply pass these parameters down via the ... in the seas() call.

For instance, you can read ?camera to find that the camera method accepts an inter.gene.cor parameter, and ?roast will tell you that you can specify the number of rotations used via the nrot parameter.

7 Reproducibility

Session Information

## R version 4.2.1 (2022-06-23)
## Platform: x86_64-pc-linux-gnu (64-bit)
## Running under: Ubuntu 20.04.5 LTS
## 
## Matrix products: default
## BLAS:   /home/biocbuild/bbs-3.16-bioc/R/lib/libRblas.so
## LAPACK: /home/biocbuild/bbs-3.16-bioc/R/lib/libRlapack.so
## 
## locale:
##  [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C              
##  [3] LC_TIME=en_GB              LC_COLLATE=C              
##  [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8   
##  [7] LC_PAPER=en_US.UTF-8       LC_NAME=C                 
##  [9] LC_ADDRESS=C               LC_TELEPHONE=C            
## [11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       
## 
## attached base packages:
## [1] grid      stats     graphics  grDevices utils     datasets  methods  
## [8] base     
## 
## other attached packages:
##  [1] data.table_1.14.4     edgeR_3.40.0          limma_3.54.0         
##  [4] circlize_0.4.15       ComplexHeatmap_2.14.0 ggplot2_3.3.6        
##  [7] dplyr_1.0.10          magrittr_2.0.3        sparrow_1.4.0        
## [10] BiocStyle_2.26.0     
## 
## loaded via a namespace (and not attached):
##   [1] colorspace_2.0-3            rjson_0.2.21               
##   [3] XVector_0.38.0              GenomicRanges_1.50.0       
##   [5] GlobalOptions_0.1.2         clue_0.3-62                
##   [7] farver_2.1.1                bit64_4.0.5                
##   [9] AnnotationDbi_1.60.0        fansi_1.0.3                
##  [11] codetools_0.2-18            sparseMatrixStats_1.10.0   
##  [13] doParallel_1.0.17           cachem_1.0.6               
##  [15] knitr_1.40                  jsonlite_1.8.3             
##  [17] Cairo_1.6-0                 annotate_1.76.0            
##  [19] cluster_2.1.4               png_0.1-7                  
##  [21] graph_1.76.0                HDF5Array_1.26.0           
##  [23] BiocManager_1.30.19         msigdbr_7.5.1              
##  [25] compiler_4.2.1              httr_1.4.4                 
##  [27] backports_1.4.1             assertthat_0.2.1           
##  [29] Matrix_1.5-1                fastmap_1.1.0              
##  [31] ontologyIndex_2.10          lazyeval_0.2.2             
##  [33] cli_3.4.1                   BiocSingular_1.14.0        
##  [35] htmltools_0.5.3             tools_4.2.1                
##  [37] rsvd_1.0.5                  gtable_0.3.1               
##  [39] glue_1.6.2                  GenomeInfoDbData_1.2.9     
##  [41] Rcpp_1.0.9                  Biobase_2.58.0             
##  [43] jquerylib_0.1.4             rhdf5filters_1.10.0        
##  [45] vctrs_0.5.0                 Biostrings_2.66.0          
##  [47] babelgene_22.9              iterators_1.0.14           
##  [49] DelayedMatrixStats_1.20.0   xfun_0.34                  
##  [51] stringr_1.4.1               beachmat_2.14.0            
##  [53] lifecycle_1.0.3             irlba_2.3.5.1              
##  [55] statmod_1.4.37              XML_3.99-0.12              
##  [57] zlibbioc_1.44.0             scales_1.2.1               
##  [59] MatrixGenerics_1.10.0       parallel_4.2.1             
##  [61] SummarizedExperiment_1.28.0 rhdf5_2.42.0               
##  [63] RColorBrewer_1.1-3          SingleCellExperiment_1.20.0
##  [65] yaml_2.3.6                  memoise_2.0.1              
##  [67] gridExtra_2.3               sass_0.4.2                 
##  [69] stringi_1.7.8               RSQLite_2.2.18             
##  [71] GSVA_1.46.0                 highr_0.9                  
##  [73] S4Vectors_0.36.0            BiocIO_1.8.0               
##  [75] ScaledMatrix_1.6.0          foreach_1.5.2              
##  [77] checkmate_2.1.0             BiocGenerics_0.44.0        
##  [79] BiocParallel_1.32.0         shape_1.4.6                
##  [81] GenomeInfoDb_1.34.0         rlang_1.0.6                
##  [83] pkgconfig_2.0.3             matrixStats_0.62.0         
##  [85] bitops_1.0-7                evaluate_0.17              
##  [87] lattice_0.20-45             Rhdf5lib_1.20.0            
##  [89] purrr_0.3.5                 labeling_0.4.2             
##  [91] htmlwidgets_1.5.4           bit_4.0.4                  
##  [93] tidyselect_1.2.0            GSEABase_1.60.0            
##  [95] plyr_1.8.7                  bookdown_0.29              
##  [97] R6_2.5.1                    magick_2.7.3               
##  [99] IRanges_2.32.0              generics_0.1.3             
## [101] DelayedArray_0.24.0         DBI_1.1.3                  
## [103] pillar_1.8.1                withr_2.5.0                
## [105] KEGGREST_1.38.0             RCurl_1.98-1.9             
## [107] tibble_3.1.8                crayon_1.5.2               
## [109] BiocSet_1.12.0              utf8_1.2.2                 
## [111] plotly_4.10.0               rmarkdown_2.17             
## [113] viridis_0.6.2               GetoptLong_1.0.5           
## [115] locfit_1.5-9.6              blob_1.2.3                 
## [117] digest_0.6.30               xtable_1.8-4               
## [119] tidyr_1.2.1                 stats4_4.2.1               
## [121] munsell_0.5.0               viridisLite_0.4.1          
## [123] BiasedUrn_2.0.8             bslib_0.4.0