# Work with other geneset databases

#### Zuguang Gu ( z.gu@dkfz.de )

#### 2022-11-21

rGREAT has integrated Gene Ontology gene sets for all supported organisms and MSigDB gene sets for human. It is very easy to apply GREAT analysis on other geneset databases such as KEGG. THe basical use has been explained in the section “Manually set gene sets” in the vignette “Analyze with local GREAT”. In this vignette, we will just show you several examples.

## KEGG pathways

KEGG pathway database is widely used for gene set enrichment analysis. To apply GREAT anlaysis with KEGG pathways, we need to construct the corresponding gene sets.

KEGG provides its data via a REST API (https://rest.kegg.jp/). There are several commands that can be used to retrieve specific types of data. Here we use the package KEGGREST to obtain data directly from KEGG. To get a list of genes involved in pathways, we use the “link” command which is implemented in the function `keggLink()`.

    library(KEGGREST)
    pathway2gene = keggLink("pathway", "hsa")
    head(pathway2gene)

    ##       hsa:10327         hsa:124         hsa:125         hsa:126         hsa:127
    ## "path:hsa00010" "path:hsa00010" "path:hsa00010" "path:hsa00010" "path:hsa00010"
    ##         hsa:128
    ## "path:hsa00010"

The returned object `pathway2gene` is a named vector, where the names are gene Entrez IDs (with an additional `"hsa:"` prefix) and values are pathway IDs (with an additional `"path:"` prefix). You can try to execute `keggLink("hsa","pathway")` to compare the results. The named vectors are not common for downstream gene set analysis. Let’s convert it to a list of genes, also remove the prefix.

    kegg_pathways = split(gsub("hsa:", "", names(pathway2gene)),
                          gsub("path:", "", pathway2gene))

Now simply send `kegg_pathways` to `great()` to perform GREAT analysis.

    library(rGREAT)
    gr = randomRegions(genome = "hg19")
    great(gr, kegg_pathways, "hg19")

    ## 908 regions are associated to 1377 genes' extended TSSs.
    ##   TSS source: TxDb.Hsapiens.UCSC.hg19.knownGene
    ##   Genome: hg19
    ##   OrgDb: org.Hs.eg.db
    ##   Gene sets: self-provided
    ##   Background: whole genome excluding gaps
    ## Mode: Basal plus extension
    ##   Proximal: 5000 bp upstream, 1000 bp downstream,
    ##   plus Distal: up to 1000000 bp

Here we only include the KEGG pathway IDs. The full name of pathways can be obtained by the following command:

    pn = keggList("pathway/hsa")
    head(pn)

    ##                                                     path:hsa00010
    ##             "Glycolysis / Gluconeogenesis - Homo sapiens (human)"
    ##                                                     path:hsa00020
    ##                "Citrate cycle (TCA cycle) - Homo sapiens (human)"
    ##                                                     path:hsa00030
    ##                "Pentose phosphate pathway - Homo sapiens (human)"
    ##                                                     path:hsa00040
    ## "Pentose and glucuronate interconversions - Homo sapiens (human)"
    ##                                                     path:hsa00051
    ##          "Fructose and mannose metabolism - Homo sapiens (human)"
    ##                                                     path:hsa00052
    ##                     "Galactose metabolism - Homo sapiens (human)"

Please go the the documentation of KEGGREST or the main website of KEGG API (https://rest.kegg.jp/) to find out commands for retrieving various datasets there.

Please note, KEGG pathways are only free for academic users, https://www.pathway.jp/en/licensing.html.

## Reactome pathways

Reactome is another popular pathway database for gene set enrichment analysis. In Bioconductor, there is a package reactome.db that contains genes associated to every pathway in Reactome.

To get the Reactome pathway gene sets, simply use the object `reactomePATHID2EXTID`.

    library(reactome.db)
    gs = as.list(reactomePATHID2EXTID)
    great(gr, gs, "hg19")

    ## 908 regions are associated to 1377 genes' extended TSSs.
    ##   TSS source: TxDb.Hsapiens.UCSC.hg19.knownGene
    ##   Genome: hg19
    ##   OrgDb: org.Hs.eg.db
    ##   Gene sets: self-provided
    ##   Background: whole genome excluding gaps
    ## Mode: Basal plus extension
    ##   Proximal: 5000 bp upstream, 1000 bp downstream,
    ##   plus Distal: up to 1000000 bp

The full pathway names are in the object `reactomePATHID2NAME`. You can convert the object to a normal list by `as.list(reactomePATHID2NAME)`.

## UniProt keywords gene sets

UniProt database provides a list of controlled vocabulary represented as keywords for genes or proteins (https://www.uniprot.org/keywords/). This is useful for summarizing gene functions in a compact way. The UniProtKeywords package contains gene sets associated to keywords.

UniProtKeywords support several organisms. Here we use human as an example. In the function `load_keyword_genesets()`, you need to specify the taxon ID for the organism.

    ## * checking for file 'F:\biocbuild\bbs-3.16-bioc\tmpdir\Rtmpq8aBTq\remotes289015fd3158\jokergoo-UniProtKeywords-4da0868/DESCRIPTION' ... OK
    ## * preparing 'UniProtKeywords':
    ## * checking DESCRIPTION meta-information ... OK
    ## * checking for LF line-endings in source and make files and shell scripts
    ## * checking for empty or unneeded directories
    ## * looking to see if a 'data/datalist' file should be added
    ## * building 'UniProtKeywords_0.99.4.tar.gz'
    ##

    library(UniProtKeywords)
    gs = load_keyword_genesets(9606)
    great(gr, gs, "hg19")

    ## 908 regions are associated to 1377 genes' extended TSSs.
    ##   TSS source: TxDb.Hsapiens.UCSC.hg19.knownGene
    ##   Genome: hg19
    ##   OrgDb: org.Hs.eg.db
    ##   Gene sets: self-provided
    ##   Background: whole genome excluding gaps
    ## Mode: Basal plus extension
    ##   Proximal: 5000 bp upstream, 1000 bp downstream,
    ##   plus Distal: up to 1000000 bp

## Specific gene sets in .gmt format

Please refer to the section “Manually set gene sets” in the vignette “Analyze with local GREAT”. There introduces a function `read_gmt()` which can import a `.gmt` file into a list of genes.

The tool Enrichr provides a great resource of gene sets in `.gmt` format. See https://maayanlab.cloud/Enrichr/#libraries.

## Session info

    sessionInfo()

    ## R version 4.2.2 (2022-10-31 ucrt)
    ## Platform: x86_64-w64-mingw32/x64 (64-bit)
    ## Running under: Windows Server x64 (build 20348)
    ##
    ## Matrix products: default
    ##
    ## locale:
    ## [1] LC_COLLATE=C
    ## [2] LC_CTYPE=English_United States.utf8
    ## [3] LC_MONETARY=English_United States.utf8
    ## [4] LC_NUMERIC=C
    ## [5] LC_TIME=English_United States.utf8
    ##
    ## attached base packages:
    ## [1] stats4    stats     graphics  grDevices utils     datasets  methods
    ## [8] base
    ##
    ## other attached packages:
    ##  [1] UniProtKeywords_0.99.4
    ##  [2] reactome.db_1.82.0
    ##  [3] KEGGREST_1.38.0
    ##  [4] TxDb.Hsapiens.UCSC.hg19.knownGene_3.2.2
    ##  [5] GenomicFeatures_1.50.2
    ##  [6] AnnotationDbi_1.60.0
    ##  [7] Biobase_2.58.0
    ##  [8] rGREAT_2.0.2
    ##  [9] GenomicRanges_1.50.1
    ## [10] GenomeInfoDb_1.34.3
    ## [11] IRanges_2.32.0
    ## [12] S4Vectors_0.36.0
    ## [13] BiocGenerics_0.44.0
    ## [14] knitr_1.41
    ##
    ## loaded via a namespace (and not attached):
    ##   [1] colorspace_2.0-3
    ##   [2] rjson_0.2.21
    ##   [3] ellipsis_0.3.2
    ##   [4] rprojroot_2.0.3
    ##   [5] circlize_0.4.15
    ##   [6] XVector_0.38.0
    ##   [7] GlobalOptions_0.1.2
    ##   [8] remotes_2.4.2
    ##   [9] DT_0.26
    ##  [10] bit64_4.0.5
    ##  [11] fansi_1.0.3
    ##  [12] xml2_1.3.3
    ##  [13] codetools_0.2-18
    ##  [14] doParallel_1.0.17
    ##  [15] cachem_1.0.6
    ##  [16] jsonlite_1.8.3
    ##  [17] Rsamtools_2.14.0
    ##  [18] GO.db_3.16.0
    ##  [19] dbplyr_2.2.1
    ##  [20] png_0.1-7
    ##  [21] shiny_1.7.3
    ##  [22] BiocManager_1.30.19
    ##  [23] compiler_4.2.2
    ##  [24] httr_1.4.4
    ##  [25] assertthat_0.2.1
    ##  [26] Matrix_1.5-3
    ##  [27] fastmap_1.1.0
    ##  [28] cli_3.4.1
    ##  [29] later_1.3.0
    ##  [30] htmltools_0.5.3
    ##  [31] prettyunits_1.1.1
    ##  [32] tools_4.2.2
    ##  [33] glue_1.6.2
    ##  [34] GenomeInfoDbData_1.2.9
    ##  [35] dplyr_1.0.10
    ##  [36] rappdirs_0.3.3
    ##  [37] Rcpp_1.0.9
    ##  [38] TxDb.Hsapiens.UCSC.hg38.knownGene_3.16.0
    ##  [39] jquerylib_0.1.4
    ##  [40] vctrs_0.5.1
    ##  [41] Biostrings_2.66.0
    ##  [42] rtracklayer_1.58.0
    ##  [43] iterators_1.0.14
    ##  [44] xfun_0.35
    ##  [45] stringr_1.4.1
    ##  [46] ps_1.7.2
    ##  [47] mime_0.12
    ##  [48] lifecycle_1.0.3
    ##  [49] restfulr_0.0.15
    ##  [50] XML_3.99-0.12
    ##  [51] org.Hs.eg.db_3.16.0
    ##  [52] zlibbioc_1.44.0
    ##  [53] hms_1.1.2
    ##  [54] promises_1.2.0.1
    ##  [55] MatrixGenerics_1.10.0
    ##  [56] parallel_4.2.2
    ##  [57] SummarizedExperiment_1.28.0
    ##  [58] RColorBrewer_1.1-3
    ##  [59] yaml_2.3.6
    ##  [60] curl_4.3.3
    ##  [61] memoise_2.0.1
    ##  [62] sass_0.4.3
    ##  [63] biomaRt_2.54.0
    ##  [64] stringi_1.7.8
    ##  [65] RSQLite_2.2.18
    ##  [66] highr_0.9
    ##  [67] BiocIO_1.8.0
    ##  [68] foreach_1.5.2
    ##  [69] filelock_1.0.2
    ##  [70] pkgbuild_1.3.1
    ##  [71] BiocParallel_1.32.1
    ##  [72] shape_1.4.6
    ##  [73] rlang_1.0.6
    ##  [74] pkgconfig_2.0.3
    ##  [75] matrixStats_0.63.0
    ##  [76] bitops_1.0-7
    ##  [77] evaluate_0.18
    ##  [78] lattice_0.20-45
    ##  [79] GenomicAlignments_1.34.0
    ##  [80] htmlwidgets_1.5.4
    ##  [81] bit_4.0.5
    ##  [82] tidyselect_1.2.0
    ##  [83] processx_3.8.0
    ##  [84] magrittr_2.0.3
    ##  [85] R6_2.5.1
    ##  [86] generics_0.1.3
    ##  [87] DelayedArray_0.24.0
    ##  [88] DBI_1.1.3
    ##  [89] pillar_1.8.1
    ##  [90] withr_2.5.0
    ##  [91] RCurl_1.98-1.9
    ##  [92] tibble_3.1.8
    ##  [93] crayon_1.5.2
    ##  [94] utf8_1.2.2
    ##  [95] BiocFileCache_2.6.0
    ##  [96] rmarkdown_2.18
    ##  [97] BioMartGOGeneSets_0.99.8
    ##  [98] GetoptLong_1.0.5
    ##  [99] progress_1.2.2
    ## [100] grid_4.2.2
    ## [101] blob_1.2.3
    ## [102] callr_3.7.3
    ## [103] digest_0.6.30
    ## [104] xtable_1.8-4
    ## [105] httpuv_1.6.6
    ## [106] bslib_0.4.1