# 1 GSEA algorithm

A common approach in analyzing gene expression profiles was identifying differential expressed genes that are deemed interesting. The enrichment analysis we demonstrated in Disease enrichment analysis vignette were based on these differential expressed genes. This approach will find genes where the difference is large, but it will not detect a situation where the difference is small, but evidenced in coordinated way in a set of related genes. Gene Set Enrichment Analysis (GSEA)1 directly addresses this limitation. All genes can be used in GSEA; GSEA aggregates the per gene statistics across genes within a gene set, therefore making it possible to detect situations where all genes in a predefined set change in a small but coordinated way. Since it is likely that many relevant phenotypic differences are manifested by small but consistent changes in a set of genes.

Genes are ranked based on their phenotypes. Given a priori defined set of gens S (e.g., genes shareing the same DO category), the goal of GSEA is to determine whether the members of S are randomly distributed throughout the ranked gene list (L) or primarily found at the top or bottom.

There are three key elements of the GSEA method:

• Calculation of an Enrichment Score.
• The enrichment score (ES) represent the degree to which a set S is over-represented at the top or bottom of the ranked list L. The score is calculated by walking down the list L, increasing a running-sum statistic when we encounter a gene in S and decreasing when it is not. The magnitude of the increment depends on the gene statistics (e.g., correlation of the gene with phenotype). The ES is the maximum deviation from zero encountered in the random walk; it corresponds to a weighted Kolmogorov-Smirnov-like statistic1.
• Esimation of Significance Level of ES.
• The p-value of the ES is calculated using permutation test. Specifically, we permute the gene labels of the gene list L and recompute the ES of the gene set for the permutated data, which generate a null distribution for the ES. The p-value of the observed ES is then calculated relative to this null distribution.
• Adjustment for Multiple Hypothesis Testing.
• When the entire gene sets were evaluated, DOSE adjust the estimated significance level to account for multiple hypothesis testing and also q-values were calculated for FDR control.

We implemented GSEA algorithm proposed by Subramanian1. Alexey Sergushichev implemented an algorithm for fast GSEA analysis in the fgsea2 package.

In DOSE3, user can use GSEA algorithm implemented in DOSE or fgsea by specifying the parameter by="DOSE" or by="fgsea". By default, DOSE use fgsea since it is much more fast.

## 1.1 Leading edge analysis and core enriched genes

Leading edge analysis reports Tags to indicate the percentage of genes contributing to the enrichment score, List to indicate where in the list the enrichment score is attained and Signal for enrichment signal strength.

It would also be very interesting to get the core enriched genes that contribute to the enrichment.

DOSE supports leading edge analysis and report core enriched genes in GSEA analysis.

## 1.2gseDO fuction

In the following example, in order to speedup the compilation of this document, only gene sets with size above 120 were tested and only 100 permutations were performed.

library(DOSE)
data(geneList)
y <- gseDO(geneList,
nPerm         = 100,
minGSSize     = 120,
pvalueCutoff  = 0.2,
verbose       = FALSE)
head(y, 3)
##                  ID            Description setSize enrichmentScore
## DOID:1492 DOID:1492 eye and adnexa disease     459      -0.3105160
## DOID:5614 DOID:5614            eye disease     450      -0.3125247
## DOID:374   DOID:374      nutrition disease     313      -0.3421127
##                 NES     pvalue   p.adjust    qvalues rank
## DOID:1492 -1.399095 0.01204819 0.08718993 0.04325883 1793
## DOID:5614 -1.412086 0.01234568 0.08718993 0.04325883 1768
## DOID:374  -1.512394 0.01298701 0.08718993 0.04325883 1464
## DOID:1492 tags=22%, list=14%, signal=19%
## DOID:5614 tags=22%, list=14%, signal=19%
## DOID:374  tags=22%, list=12%, signal=20%
##                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      core_enrichment
## DOID:1492 3371/3082/5914/2878/4153/3791/23247/1543/80184/6750/1958/2098/7450/596/9187/2034/482/948/1490/1280/3931/5737/4314/4881/2261/3426/187/629/6403/7042/6785/7507/2934/5176/4060/1277/7078/5950/2057/727/10516/4311/2247/1295/358/10203/2192/582/10218/57125/3485/585/1675/6310/2202/4313/2944/4254/3075/1501/2099/3480/4653/1195/6387/3305/1471/857/4016/1909/4053/6678/1296/7033/4915/55812/1191/5654/10631/2152/2697/7043/2952/6935/2200/3572/7177/7031/3479/2006/10451/9370/771/3117/125/652/4693/5346/1524
## DOID:5614           3082/5914/2878/4153/3791/23247/1543/80184/6750/1958/2098/7450/596/9187/2034/482/948/1490/1280/3931/5737/4314/4881/2261/3426/187/629/6403/7042/6785/7507/2934/5176/4060/1277/7078/5950/2057/727/10516/4311/2247/1295/358/10203/2192/582/10218/57125/3485/585/1675/6310/2202/4313/2944/4254/3075/1501/2099/3480/4653/6387/3305/1471/857/4016/1909/4053/6678/1296/7033/4915/55812/1191/5654/10631/2152/2697/7043/2952/6935/2200/3572/7177/7031/3479/2006/10451/9370/771/3117/125/652/4693/5346/1524
## DOID:374                                                                                                                                                                 2169/1490/7840/4887/4314/595/4018/6403/590/3087/866/66036/5919/5176/3953/164656/5950/2638/2166/5243/5468/5108/10560/4023/3485/7350/3952/1149/585/1513/3489/79068/4671/477/4313/3625/9369/6720/7494/2099/3480/3991/23446/6678/4915/5167/8228/165/2152/185/367/4982/3667/4128/9607/3572/150/563/1489/3479/9370/9122/5105/2167/5346/79689/5241

## 1.3gseNCG fuction

ncg <- gseNCG(geneList,
nPerm         = 100,
minGSSize     = 120,
pvalueCutoff  = 0.2,
verbose       = FALSE)
head(ncg, 3)
##                ID Description setSize enrichmentScore       NES     pvalue
## lung         lung        lung     173      -0.3880662 -1.593892 0.01562500
## breast     breast      breast     133      -0.4869070 -1.951255 0.01587302
## lymphoma lymphoma    lymphoma     188       0.2999589  1.331374 0.02777778
## lung     0.04761905 0.02506266 2775 tags=31%, list=22%, signal=25%
## breast   0.04761905 0.02506266 2930 tags=33%, list=23%, signal=26%
## lymphoma 0.05555556 0.02923977 2087 tags=21%, list=17%, signal=18%
##                                                                                                                                                                                                         core_enrichment
## breast                                                                                   KMT2A/ERBB3/SETD2/ARID1A/GPS2/NCOR1/RB1/MAP2K4/NF1/TP53/PIK3R1/STK11/CDKN1B/PTGFR/APC/CCND1/TRAF5/MAP3K1/ESR1/TBX3/FOXA1/GATA3
## lymphoma                                        DUSP2/EZH2/PRDM1/MYC/ZWILCH/IKZF3/PLCG2/IDH2/HIST1H1C/MAGEC3/CD79B/ETV6/HIST1H1E/HIST1H1B/IRF8/CD28/SLC29A2/DUSP9/TNFAIP3/DNMT3A/SYK/TNF/BCR/HIST1H1D/DSC3/UBE2A/PABPC1

## 1.4gseDGN fuction

dgn <- gseDGN(geneList,
nPerm         = 100,
minGSSize     = 120,
pvalueCutoff  = 0.2,
verbose       = FALSE)
head(dgn, 3)
##                          ID                     Description setSize
## umls:C0011581 umls:C0011581             Depressive disorder     464
## umls:C0043094 umls:C0043094                     Weight Gain     210
## umls:C0024668 umls:C0024668 Mammary Neoplasms, Experimental     192
##               enrichmentScore       NES     pvalue  p.adjust    qvalues
## umls:C0011581      -0.2963136 -1.279482 0.01282051 0.1173709 0.07769816
## umls:C0043094      -0.3798961 -1.560773 0.01333333 0.1173709 0.07769816
## umls:C0024668      -0.3560902 -1.437279 0.01351351 0.1173709 0.07769816
## umls:C0011581 2587 tags=25%, list=21%, signal=21%
## umls:C0043094 2016 tags=25%, list=16%, signal=21%
## umls:C0024668 2060 tags=27%, list=16%, signal=23%
##                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      core_enrichment
## umls:C0024668                                                                                                                                                                                                                                                                                                                                                                                 SLC12A2/MRC2/ID3/PIK3R1/NCOA1/KDR/CDKN1B/STAT5A/TNFSF10/BCL2/S1PR1/COL18A1/G0S2/MMP3/CCND1/GATM/MGP/TSC22D1/ID1/LIN7A/ID4/GSN/RBP4/SELENOP/DUSP6/AQP1/LPL/TRPS1/DIO1/LEP/PRLR/EFEMP1/MMP2/TXNIP/PLK2/KITLG/ESR1/PTN/COL5A1/AFP/ALCAM/AGTR1/IL6ST/TFF1/IGF1/ADIPOQ/FABP4/STC2/GATA3/PGR

# 2 Visualization

## 2.1 cnetplot

cnetplot(ncg, categorySize="pvalue", foldChange=geneList)

## 2.2 enrichMap

enrichMap(y, n=20)

## 2.3 gseaplot

gseaplot(y, geneSetID = y$ID[1], title=y$Description[1])

# References

1. Subramanian, A. et al. Gene set enrichment analysis: A knowledge-based approach for interpreting genome-wide expression profiles. Proceedings of the National Academy of Sciences of the United States of America 102, 15545–15550 (2005).

2. S., A. An algorithm for fast preranked gene set enrichment analysis using cumulative statistic calculation. biorxiv doi:10.1101/060012

3. Yu, G., Wang, L.-G., Yan, G.-R. & He, Q.-Y. DOSE: An r/bioconductor package for disease ontology semantic and enrichment analysis. Bioinformatics 31, 608–609 (2015).