Contents

1 Introduction

This vignette is meant as an extension of what already exists in the GOstatsHyperG vignette. It is intended to explain how a user can run hypergeometric testing on GO terms or KEGG terms when the organism in question is not supported by an annotation package. The 1st thing for a user to determine then is whether or not their organism is supported by an organism package through AnnotationForge. In order to do that, they need only to call the available.dbschemas() method from AnnotationForge.

library("AnnotationForge")
available.dbschemas()
##  [1] "ARABIDOPSISCHIP_DB" "BOVINECHIP_DB"      "BOVINE_DB"         
##  [4] "CANINECHIP_DB"      "CANINE_DB"          "CHICKENCHIP_DB"    
##  [7] "CHICKEN_DB"         "ECOLICHIP_DB"       "ECOLI_DB"          
## [10] "FLYCHIP_DB"         "FLY_DB"             "GO_DB"             
## [13] "HUMANCHIP_DB"       "HUMANCROSSCHIP_DB"  "HUMAN_DB"          
## [16] "INPARANOIDDROME_DB" "INPARANOIDHOMSA_DB" "INPARANOIDMUSMU_DB"
## [19] "INPARANOIDRATNO_DB" "INPARANOIDSACCE_DB" "KEGG_DB"           
## [22] "MALARIA_DB"         "MOUSECHIP_DB"       "MOUSE_DB"          
## [25] "PFAM_DB"            "PIGCHIP_DB"         "PIG_DB"            
## [28] "RATCHIP_DB"         "RAT_DB"             "WORMCHIP_DB"       
## [31] "WORM_DB"            "YEASTCHIP_DB"       "YEAST_DB"          
## [34] "ZEBRAFISHCHIP_DB"   "ZEBRAFISH_DB"

If the organism that you are using is listed here, then your organism is supported. If not, then you will need to find a source or GO (org KEGG) to gene mappings. One source for GO to gene mappings is the blast2GO project. But you might also find such mappings at Ensembl or NCBI. If your organism is not a typical model organism, then the GO terms you will find are probably going to be predictions based on sequence similarity measures instead of direct measurements. This is something that you might want to bear in mind when you draw conclusions later.

In preparation for our subsequent demonstrations, lets get some data to work with by borrowing from an organism package. We will assume that you will use something like read.table to load your own annotation packages into a data.frame object. The starting object needs to be a data.frame with the GO Id’s in the 1st col, the evidence codes in the 2nd column and the gene Id’s in the 3rd.

library("org.Hs.eg.db")
frame = toTable(org.Hs.egGO)
goframeData = data.frame(frame$go_id, frame$Evidence, frame$gene_id)
head(goframeData)
##   frame.go_id frame.Evidence frame.gene_id
## 1  GO:0008150             ND             1
## 2  GO:0001553            IEA             2
## 3  GO:0001869            IDA             2
## 4  GO:0002438            IEA             2
## 5  GO:0006953            IEA             2
## 6  GO:0007584            IEA             2

1.1 Preparing GO to gene mappings

When using GO mappings, it is important to consider the data structure of the GO ontologies. The terms are organized into a directed acyclic graph. The structure of the graph creates implications about the mappings of less specific terms to genes that are mapped to more specific terms. The Category and GOstats packages normally deal with this kind of complexity by using a special GO2All mapping in the annotation packages. You won’t have one of those, so instead you will have to make one. AnnotationDbi provides some simple tools to represent your GO term to gene mappings so that this process will be easy. First you need to put your data into a GOFrame object. Then the simple act of casting this object to a GOAllFrame object will tap into the GO.db package and populate this object with the implicated GO2All mappings for you.

goFrame=GOFrame(goframeData,organism="Homo sapiens")
goAllFrame=GOAllFrame(goFrame)

In an effort to standardize the way that we pass this kind of custom information around, we have chosen to support geneSetCollection objects from GSEABase package. You can generate one of these objects in the following way:

library("GSEABase")
gsc <- GeneSetCollection(goAllFrame, setType = GOCollection())

1.2 Setting up the parameter object

Now we can make a parameter object for GOstats by using a special constructor function. For the sake of demonstration, I will just use all the EGs as the universe and grab some arbitrarily to be the geneIds tested. For your case, you need to make sure that the gene IDs you use are unique and that they are the same type for both the universe, the geneIds and the IDs that are part of your geneSetCollection.

library("GOstats")
universe = Lkeys(org.Hs.egGO)
genes = universe[1:500]
params <- GSEAGOHyperGParams(name="My Custom GSEA based annot Params", 
                             geneSetCollection=gsc, 
                             geneIds = genes, 
                             universeGeneIds = universe, 
                             ontology = "MF", 
                             pvalueCutoff = 0.05, 
                             conditional = FALSE, 
                             testDirection = "over")

And finally we can call hyperGTest in the same way we always have before.

Over <- hyperGTest(params)
head(summary(Over))
##       GOMFID       Pvalue OddsRatio    ExpCount Count Size
## 1 GO:0042626 1.004713e-31  25.59234   2.1799308    34   96
## 2 GO:0019829 2.432159e-29  45.81218   1.1807958    26   52
## 3 GO:0003824 2.933131e-26   2.87794 126.7538927   230 5582
## 4 GO:0036094 1.610365e-23   3.14233  57.9044118   137 2550
## 5 GO:0015399 3.996585e-23  12.15951   3.7240484    34  164
## 6 GO:0140358 7.983034e-22 102.22914   0.5222751    16   23
##                                                                  Term
## 1                   ATPase-coupled transmembrane transporter activity
## 2 ATPase-coupled monoatomic cation transmembrane transporter activity
## 3                                                  catalytic activity
## 4                                              small molecule binding
## 5                   primary active transmembrane transporter activity
## 6                           P-type transmembrane transporter activity

1.3 Preparing KEGG to gene mappings

This is much the same as what you did with the GO mappings except for two important simplifications. First of all you will no longer need to track evidence codes, so the object you start with only needs to hold KEGG Ids and gene IDs. Seconly, since KEGG is not a directed graph, there is no need for a KEGG to All mapping. Once again I will borrow some data to use as an example. Notice that we have to put the KEGG Ids in the left hand column of our initial two column data.frame.

frame = toTable(org.Hs.egPATH)
keggframeData = data.frame(frame$path_id, frame$gene_id)
head(keggframeData)
##   frame.path_id frame.gene_id
## 1         04610             2
## 2         00232             9
## 3         00983             9
## 4         01100             9
## 5         00232            10
## 6         00983            10
keggFrame=KEGGFrame(keggframeData,organism="Homo sapiens")

The rest of the process should be very similar.

gsc <- GeneSetCollection(keggFrame, setType = KEGGCollection())
universe = Lkeys(org.Hs.egGO)
genes = universe[1:500]
kparams <- GSEAKEGGHyperGParams(name="My Custom GSEA based annot Params", 
                               geneSetCollection=gsc, 
                               geneIds = genes, 
                               universeGeneIds = universe,  
                               pvalueCutoff = 0.05, 
                               testDirection = "over")
kOver <- hyperGTest(params)
head(summary(kOver))
##       GOMFID       Pvalue OddsRatio    ExpCount Count Size
## 1 GO:0042626 1.004713e-31  25.59234   2.1799308    34   96
## 2 GO:0019829 2.432159e-29  45.81218   1.1807958    26   52
## 3 GO:0003824 2.933131e-26   2.87794 126.7538927   230 5582
## 4 GO:0036094 1.610365e-23   3.14233  57.9044118   137 2550
## 5 GO:0015399 3.996585e-23  12.15951   3.7240484    34  164
## 6 GO:0140358 7.983034e-22 102.22914   0.5222751    16   23
##                                                                  Term
## 1                   ATPase-coupled transmembrane transporter activity
## 2 ATPase-coupled monoatomic cation transmembrane transporter activity
## 3                                                  catalytic activity
## 4                                              small molecule binding
## 5                   primary active transmembrane transporter activity
## 6                           P-type transmembrane transporter activity
sessionInfo()
## R version 4.3.1 (2023-06-16)
## Platform: x86_64-pc-linux-gnu (64-bit)
## Running under: Ubuntu 22.04.3 LTS
## 
## Matrix products: default
## BLAS:   /home/biocbuild/bbs-3.18-bioc/R/lib/libRblas.so 
## LAPACK: /usr/lib/x86_64-linux-gnu/lapack/liblapack.so.3.10.0
## 
## 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       
## 
## time zone: America/New_York
## tzcode source: system (glibc)
## 
## attached base packages:
## [1] stats4    stats     graphics  grDevices utils     datasets  methods  
## [8] base     
## 
## other attached packages:
##  [1] GOstats_2.68.0         Category_2.68.0        Matrix_1.6-1.1        
##  [4] GO.db_3.18.0           GSEABase_1.64.0        graph_1.80.0          
##  [7] annotate_1.80.0        XML_3.99-0.14          org.Hs.eg.db_3.18.0   
## [10] AnnotationForge_1.44.0 AnnotationDbi_1.64.0   IRanges_2.36.0        
## [13] S4Vectors_0.40.0       Biobase_2.62.0         BiocGenerics_0.48.0   
## [16] BiocStyle_2.30.0      
## 
## loaded via a namespace (and not attached):
##  [1] sass_0.4.7              bitops_1.0-7            RSQLite_2.3.1          
##  [4] lattice_0.22-5          digest_0.6.33           evaluate_0.22          
##  [7] grid_4.3.1              genefilter_1.84.0       bookdown_0.36          
## [10] fastmap_1.1.1           blob_1.2.4              jsonlite_1.8.7         
## [13] GenomeInfoDb_1.38.0     DBI_1.1.3               survival_3.5-7         
## [16] BiocManager_1.30.22     httr_1.4.7              Rgraphviz_2.46.0       
## [19] Biostrings_2.70.0       jquerylib_0.1.4         cli_3.6.1              
## [22] rlang_1.1.1             crayon_1.5.2            XVector_0.42.0         
## [25] splines_4.3.1           bit64_4.0.5             cachem_1.0.8           
## [28] yaml_2.3.7              tools_4.3.1             memoise_2.0.1          
## [31] GenomeInfoDbData_1.2.11 curl_5.1.0              vctrs_0.6.4            
## [34] R6_2.5.1                png_0.1-8               matrixStats_1.0.0      
## [37] zlibbioc_1.48.0         KEGGREST_1.42.0         RBGL_1.78.0            
## [40] bit_4.0.5               pkgconfig_2.0.3         bslib_0.5.1            
## [43] xfun_0.40               MatrixGenerics_1.14.0   knitr_1.44             
## [46] xtable_1.8-4            htmltools_0.5.6.1       rmarkdown_2.25         
## [49] compiler_4.3.1          RCurl_1.98-1.12