18  Frequently asked questions

18.1 How to prepare your own geneList

GSEA analysis requires a ranked gene list, which contains three features:

  • numeric vector: fold change or other type of numerical variable
  • named vector: every number has a name, the corresponding gene ID
  • sorted vector: number should be sorted in decreasing order

If you import your data from a csv file, the file should contains two columns, one for gene ID (no duplicated ID allowed) and another one for fold change. You can prepare your own geneList via the following command:

d = read.csv(your_csv_file)
## assume 1st column is ID
## 2nd column is FC

## feature 1: numeric vector
geneList = d[,2]

## feature 2: named vector
names(geneList) = as.character(d[,1])

## feature 3: decreasing order
geneList = sort(geneList, decreasing = TRUE)

18.2 No gene can be mapped

18.3 Showing specific pathways

By default, all the visualization methods provided by enrichplot display most significant pathways. If users are interested to show some specific pathways (e.g. excluding some unimportant pathways among the top categories), users can pass a vector of selected pathways to the showCategory parameter in dotplot(), barplot(), treeplot(), cnetplot() and emapplot() etc.

See Figure 18.1 for a side-by-side comparison of default top categories versus user-selected pathways.

library(clusterProfiler)
library(enrichplot)
data(geneList, package='DOSE')
de <- names(geneList)[abs(geneList)>1]

x <- enrichKEGG(de)

## show top 10 most significant pathways and want to exclude the second one
## dotplot(x, showCategory = x$Description[1:10][-2])

set.seed(2020-10-27)
selected_pathways <- sample(x$Description, 5)
selected_pathways
[1] "Protein digestion and absorption"                             
[2] "Viral protein interaction with cytokine and cytokine receptor"
[3] "Cytokine-cytokine receptor interaction"                       
[4] "DNA replication"                                              
[5] "Cytoskeleton in muscle cells"                                 
p1 <- dotplot(x, showCategory = 10, font.size=14)
p2 <- dotplot(x, showCategory = selected_pathways, font.size=14)


aplot::plot_list(p1, p2, tag_levels = "A")
Figure 18.1: Showing specific pathways. Top ten most significant pathways (A), selected ten pathways (B).

Note: Another solution is using the filter verb to extract a subset of the result as described in Chapter 16.

18.4 How to extract genes of a specific term/pathway

id <- x$ID[1:3]
id
[1] "hsa04110" "hsa04061" "hsa04974"
x[[id[1]]]
 [1] "10403" "9319"  "4175"  "1869"  "699"   "5347"  "81620" "983"   "23594"
[10] "891"   "6502"  "9133"  "5111"  "9134"  "898"   "994"   "8318"  "4085" 
[19] "4174"  "26271" "4171"  "993"   "990"   "1029"  "7272"  "9700"  "4173" 
[28] "701"   "4609"  "7043"  "991"   "890"   "1111"  "9232"  "4998"  "9212" 
[37] "10926"
geneInCategory(x)[id]
$hsa04110
 [1] "10403" "9319"  "4175"  "1869"  "699"   "5347"  "81620" "983"   "23594"
[10] "891"   "6502"  "9133"  "5111"  "9134"  "898"   "994"   "8318"  "4085" 
[19] "4174"  "26271" "4171"  "993"   "990"   "1029"  "7272"  "9700"  "4173" 
[28] "701"   "4609"  "7043"  "991"   "890"   "1111"  "9232"  "4998"  "9212" 
[37] "10926"

$hsa04061
 [1] "3561"  "6373"  "6347"  "57007" "6362"  "6364"  "1236"  "6387"  "3576" 
[10] "3572"  "1230"  "1524"  "6355"  "4283"  "11009" "6352"  "10563" "1237" 
[19] "9547"  "3627"  "2921"  "6351"  "3559"  "53832"

$hsa04974
 [1] "1290"  "1300"  "7373"  "1359"  "1307"  "1287"  "50509" "5645"  "1292" 
[10] "1296"  "23428" "59272" "2006"  "1294"  "477"   "1289"  "1281"  "6505" 
[19] "1299"  "1360"  "1308" 

18.5 Wrap long axis labels

Most of the functions in enrichplot can automatically split long labels across multiple lines. Users can passed a line width to the label_format parameter (default is 30). It also supports user defined function to format label strings.

See Figure 18.2 for examples of wrapping long axis labels using numeric width and a custom labeller.

library(ReactomePA)
y <- enrichPathway(de)

p1 <- dotplot(y, label_format = 20) 
p2 <- dotplot(y, label_format = function(x) stringr::str_wrap(x, width=20))
cowplot::plot_grid(p1, p2, ncol=2, labels=c("A", "B")) 
Figure 18.2: Wrap long axis labels. Passing a numeric value to specify string width (A), a user specifiable labeller function (B).

The label_format option works with barplot(), dotplot(), heatplot(), treeplot and ridgeplot().

18.6 Why many genes are not annotated in KEGG?

Users often find that a significant portion of their gene list is dropped in the KEGG enrichment analysis. For example, a user reported that only 281 genes were retained from a list of over 700 genes.

This is not a software issue but rather a reflection of the database coverage. KEGG pathways mainly focus on metabolic and signaling pathways, and many genes are not annotated in any KEGG pathway.

We can verify the annotation coverage using bitr_kegg():

# gene is a vector of gene IDs (e.g., Entrez IDs)
kk <- bitr_kegg(geneID = gene, fromType='ncbi-geneid', toType='Path', organism='hsa')

The warning message will indicate the percentage of genes that failed to map.

To manually verify a specific gene, you can visit the KEGG website using a URL constructed with the organism code and gene ID, for example: http://www.genome.jp/dbget-bin/www_bget?hsa:100506775. If the gene page does not list any pathway, it means the gene has no KEGG pathway annotation.