library(knitr) knitr::opts_chunk$set( error = FALSE, tidy = FALSE, message = FALSE, warning = FALSE, fig.align = "center")
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 genome = "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.
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)
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)
job = readRDS(system.file("extdata", "GreatJob.rds", package = "rGREAT"))
You can get the summary of your job by directly printing job
.
job
More parameters can be set for the job:
job = submitGreatJob(gr, genome = "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. Seel the rGREAT paper for more details.
Available parameters are (following content is copied from GREAT website):
genome
: "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.
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) names(tbl) tbl[[1]][1:2, ]
Information stored in job
will be updated after retrieving enrichment tables.
job
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")
All available ontology names for a given genome can be get by availableOntologies()
and all available ontology categories can be get by availableCategories()
. Here you do not
need to provide genome information because job
already contains it.
availableOntologies(job) availableCategories(job) availableOntologies(job, category = "GO")
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.
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)
getRegionGeneAssociations()
returns a GRanges
object which contains the gene-region associations. Note the column dist_to_TSS
is based on the middle points of the input regions to TSS.
getRegionGeneAssociations(job)
Please note the two meta columns are in formats of CharacterList
and IntegerList
because a region may associate to multiple genes.
You can also choose only plotting one of the three figures.
plotRegionGeneAssociations(job, which_plot = 1)
By specifying ontology and term ID, you can get the associations in a certain term.
Here the term ID is from the first column of the data frame from
getEnrichmentTables()
.
plotRegionGeneAssociations(job, ontology = "GO Molecular Function", term_id = "GO:0004984") getRegionGeneAssociations(job, ontology = "GO Molecular Function", term_id = "GO:0004984")
shinyReport()
creates a Shiny application to view the complete results:
shinyReport(job)
sessionInfo()
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.