Note: On Aug 19 2019 GREAT released version 4 which supports hg38 genome and removes some ontologies such pathways. submitGreatJob() still takes hg19 as default. hg38 can be specified by argument species = "hg38". To use the older versions such as 3.0.0, specify as submitGreatJob(..., version = "3").

GREAT (Genomic Regions Enrichment of Annotations Tool) is a popular web-based tool to associate biological functions to genomic regions. The rGREAT package makes GREAT anlaysis automatic by first constructing a HTTP POST request according to user’s input and retrieving results from GREAT web server afterwards.

Submit the job

Load the package:

library(rGREAT)

The input data is either a GRanges object or a BED-format data frame, no matter it is sorted or not. In following example, we use a GRanges object which is randomly generated.

set.seed(123)
gr = randomRegions(nr = 1000, genome = "hg19")
head(gr)
## GRanges object with 6 ranges and 0 metadata columns:
##       seqnames            ranges strand
##          <Rle>         <IRanges>  <Rle>
##   [1]     chr1   9204434-9208784      *
##   [2]     chr1   9853594-9859363      *
##   [3]     chr1 10862809-10871681      *
##   [4]     chr1 12716970-12723206      *
##   [5]     chr1 13814692-13823250      *
##   [6]     chr1 19243285-19247097      *
##   -------
##   seqinfo: 26 sequences from an unspecified genome; no seqlengths

Submit genomic regions by submitGreatJob().

The returned variable job is a GreatJob class instance which can be used to retrieve results from GREAT server and store results which are already downloaded.

job = submitGreatJob(gr)

You can get the summary of your job by directly printing job.

job
## Submit time: 2022-06-05 16:10:27 
##   Note the results may only be avaiable on GREAT server for 24 hours.
## Version: 4.0.4 
## Species: hg19 
## Inputs: 3748 regions
## Mode: Basal plus extension 
##   Proximal: 5 kb upstream, 1 kb downstream,
##   plus Distal: up to 1000 kb
## Include curated regulatory domains
## 
## Enrichment tables for following ontologies have been downloaded:
##   GO Biological Process
##   GO Cellular Component
##   GO Molecular Function

More parameters can be set for the job:

job = submitGreatJob(gr, species = "mm9") # of course, gr should be from mm9
job = submitGreatJob(gr, adv_upstream = 10, adv_downstream = 2, adv_span = 2000)
job = submitGreatJob(gr, rule = "twoClosest", adv_twoDistance = 2000)
job = submitGreatJob(gr, rule = "oneClosest", adv_oneDistance = 2000)

Also you can choose different versions of GREAT for the analysis.

job = submitGreatJob(gr, version = "3.0")
job = submitGreatJob(gr, version = "2.0")

Note: from rGREAT package 1.99.0, background by bg argument is not supported any more (currently you can still use it, but you will see a warning message), because GREAT requires a special format for gr and bg if both are set, and it uses a different method for the enrichment analysis and returns enrichment tables in a different format. But still, you can use local GREAT to integrate background regions.

Available parameters are (following content is copied from GREAT website):

  • species: “hg38”, “hg19”, “mm10”, “mm9” are supported in GREAT version 4.x.x, “hg19”, “mm10”, “mm9”, “danRer7” are supported in GREAT version 3.x.x and “hg19”, “hg18”, “mm9”, “danRer7” are supported in GREAT version 2.x.x.
  • includeCuratedRegDoms: Whether to include curated regulatory domains.
  • rule: How to associate genomic regions to genes.
    • basalPlusExt: mode ‘Basal plus extension’. Gene regulatory domain definition: Each gene is assigned a basal regulatory domain of a minimum distance upstream and downstream of the TSS (regardless of other nearby genes). The gene regulatory domain is extended in both directions to the nearest gene’s basal domain but no more than the maximum extension in one direction.
      • adv_upstream: proximal extension to upstream (unit: kb)
      • adv_downstream: proximal extension to downstream (unit: kb)
      • adv_span: maximum extension (unit: kb)
    • twoClosest: mode ‘Two nearest genes’. Gene regulatory domain definition: Each gene is assigned a regulatory domain that extends in both directions to the nearest gene’s TSS but no more than the maximum extension in one direction.
      • adv_twoDistance: maximum extension (unit: kb)
    • oneClosest: mode ‘Single nearest gene’. Gene regulatory domain definition: Each gene is assigned a regulatory domain that extends in both directions to the midpoint between the gene’s TSS and the nearest gene’s TSS but no more than the maximum extension in one direction.
      • adv_oneDistance: maximum extension (unit: kb)

GREAT uses the UCSC bed-format where genomic coordinates are 0-based. Many R packages generate genomic regions as 1-based. Thus by default, the start positions of regions are subtracted by 1. If your regions are already 0-based, you can specify gr_is_zero_based = TRUE in submitGreatJob(). Anyway in most cases, this will only slightly affect the enrichment results.

Get enrichment tables

With job, we can now retrieve results from GREAT. The first and the primary results are the tables which contain enrichment statistics for the analysis. By default it will retrieve results from three GO Ontologies. All tables contains statistics for all terms no matter they are significant or not. Users can then make filtering with self-defined cutoff.

There is a column for adjusted p-values by “BH” method. Other p-value adjustment methods can be applied by p.adjust().

The returned value of getEnrichmentTables() is a list of data frames in which each one corresponds to the table for a single ontology. The structure of data frames are same as the tables on GREAT website.

tbl = getEnrichmentTables(job)
## The default enrichment tables contain no associated genes for the input
## regions.You can set `download_by = 'tsv'` to download the complete
## table,but note only the top 500 regions can be retreived. See the
## following link:
## 
## https://great-help.atlassian.net/wiki/spaces/GREAT/pages/655401/Export#Export-GlobalExport
names(tbl)
## [1] "GO Molecular Function" "GO Biological Process" "GO Cellular Component"
tbl[[1]][1:2, ]
##           ID            name Binom_Genome_Fraction Binom_Expected
## 1 GO:0005515 protein binding             0.7515051       2816.641
## 2 GO:0005488         binding             0.8694407       3258.664
##   Binom_Observed_Region_Hits Binom_Fold_Enrichment Binom_Region_Set_Coverage
## 1                       3186              1.131135                 0.8500534
## 2                       3505              1.075594                 0.9351654
##   Binom_Raw_PValue Binom_Adjp_BH Hyper_Total_Genes Hyper_Expected
## 1     2.435386e-49  1.027489e-45             11129       2302.717
## 2     4.308462e-39  9.088701e-36             14268       2952.212
##   Hyper_Observed_Gene_Hits Hyper_Fold_Enrichment Hyper_Gene_Set_Coverage
## 1                     2635              1.144300               0.6865555
## 2                     3159              1.070045               0.8230849
##   Hyper_Term_Gene_Coverage Hyper_Raw_PValue Hyper_Adjp_BH
## 1                0.2367688     1.078774e-35  4.551348e-32
## 2                0.2214045     5.578685e-20  1.176824e-16

Information stored in job will be updated after retrieving enrichment tables.

job
## Submit time: 2022-06-05 16:10:27 
##   Note the results may only be avaiable on GREAT server for 24 hours.
## Version: 4.0.4 
## Species: hg19 
## Inputs: 3748 regions
## Mode: Basal plus extension 
##   Proximal: 5 kb upstream, 1 kb downstream,
##   plus Distal: up to 1000 kb
## Include curated regulatory domains
## 
## Enrichment tables for following ontologies have been downloaded:
##   GO Biological Process
##   GO Cellular Component
##   GO Molecular Function

You can get results by either specifying the ontologies or by the pre-defined categories (categories already contains pre-defined sets of ontologies):

tbl = getEnrichmentTables(job, ontology = c("GO Molecular Function", "Human Phenotype"))
tbl = getEnrichmentTables(job, category = c("GO"))

As you have seen in the previous messages and results, The enrichment tables contain no associated genes. However, you can set download_by = 'tsv' in getEnrichmentTables() to download the complete tables, but due to the restriction from GREAT web server, only the top 500 regions can be retreived (check the last two columns of tbl2[["GO Molecular Function"]] in the following example).

tbl2 = getEnrichmentTables(job, download_by = "tsv")
nrow(tbl2[["GO Molecular Function"]])
## [1] 115
head(tbl2[["GO Molecular Function"]])
##                                                                                             X.meta.charset..utf.8..
## 1     <title>GREAT Input: Genomic Regions Enrichment of Annotations Tool, Bejerano Lab, Stanford University</title>
## 2                                                                              <meta name="description" content="">
## 3                                                                                   <meta name="author" content="">
## 4                                                           <!-- HTML5 shim, for IE6-8 support of HTML elements -->
## 5                                                                                                 <!--[if lt IE 9]>
## 6                                        <script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>

All available ontology names for a given species can be get by availableOntologies() and all available ontology categories can be get by availableCategories(). Here you do not need to provide species information because job already contains it.

availableOntologies(job)
## [1] "GO Molecular Function"     "GO Biological Process"    
## [3] "GO Cellular Component"     "Mouse Phenotype"          
## [5] "Mouse Phenotype Single KO" "Human Phenotype"          
## [7] "Ensembl Genes"
availableCategories(job)
## [1] "GO"        "Phenotype" "Genes"
availableOntologies(job, category = "GO")
## [1] "GO Molecular Function" "GO Biological Process" "GO Cellular Component"

Make volcano plot

In differential gene expression analysis, volcano plot is used to visualize relations between log2 fold change and (adjusted) p-values. Similarly, we can also use volcano plot to visualize relations between fold enrichment and (adjusted) p-values for the enrichment analysis. The plot is made by the function plotVolcano():

plotVolcano(job, ontology = "GO Biological Process")

As the enrichment analysis basically only looks for over-representations, it is actually half volcano.

Get region-gene associations

Association between genomic regions and genes can be plotted by plotRegionGeneAssociations(). The function will make the three plots which are same as on GREAT website.

plotRegionGeneAssociations(job)