library(edgeR)
Original Authors: Belinda Phipson, Anna Trigos, Matt Ritchie, Maria Doyle, Harriet Dashnow, Charity Law Based on the course RNAseq analysis in R delivered on May 11/12th 2016
The list of differentially expressed genes is sometimes so long that its interpretation becomes cumbersome and time consuming. A common downstream procedure is gene set testing. It aims to understand which pathways or gene networks the differentially expressed genes are implicated in.
Various ways exist to test for enrichment of biological pathways. Two types of test answer two different questions: competitive and self-contained gene set tests.
Competitive gene set tests, such as those implemented in GOseq
and camera
, ask the question whether the differentially expressed genes tend to be over-represented in the gene set, compared to all the other genes in the experiment.
Self-contained tests, which include the ROAST
procedure, ask the question “Are the genes in the set/pathway differentially expressed as a whole?”
# load DE.Rdata from Robjects/
getwd()
#load("Robjects/DE.Rdata")
setwd("Robjects/")
dir()
load("DE.Rdata")
ls()
GOseq is a method to conduct Gene Ontology (GO) analysis suitable for RNA-seq data as it accounts for the gene length bias in detection of over-representation (GOseq article)
From the GOseq vignette:
“GO analysis of RNA-seq data requires the use of random sampling in order to generate a suitable null distribution for GO category membership and calculate each category’s significance for over representation amongst DE genes. … In most cases, the Wallenius distribution can be used to approximate the true null distribution, without any significant loss in accuracy. The goseq package implements this approximation as its default option.”
Create list of DEGs:
# Retrieve list of all genes tested:
results <- as.data.frame(topTags(lrt.BvsL, n = Inf))
print(head(results))
# Derive list of DEGs by filtering on FDR:
genes <- results$FDR < 0.01
# Add gene names to that list:
names(genes) <- rownames(results)
print(head(genes))
Fit the Probability Weighting Function (PWF):
library(goseq)
#print(supportedGeneIDs())
#print(supportedGenomes())
pwf <- nullp(genes, "mm10","knownGene")
Conduct gene set enrichment analysis:
#?goseq
go.results <- goseq(pwf, "mm10","knownGene")
go.results
From the fgsea vignette “fast preranked gene set enrichment analysis (GSEA)”:
This analysis is performed by:
“After establishing the ES for each gene set across the phenotype, GSEA reiteratively randomizes the sample labels and retests for enrichment across the random classes. By performing repeated class label randomizations, the ES for each gene set across the true classes can be compared to the ES distribution from the random classes. Those gene sets that significantly outperform iterative random class permutations are considered significant.” commentary on GSEA. The article describing the original software is available here.
library(fgsea)
Create ranks:
results.ord <- results[ order(-results[,"logFC"]), ]
head(results.ord)
ranks <- results.ord$logFC
names(ranks) <- rownames(results.ord)
head(ranks)
#plot(ranks)
barplot(ranks)
Load pathways:
load("data/mouse_H_v5.rdata")
pathways <- Mm.H
Conduct analysis:
?fgsea
fgseaRes <- fgsea(pathways, ranks, minSize=15, maxSize = 500, nperm=1000)
class(fgseaRes)
dim(fgseaRes)
#head(fgseaRes)
Glance at results:
head(fgseaRes[order(padj), ])
Plot outcome for the ‘HALLMARK_MYOGENESIS’ pathway:
First find rank of the ‘HALLMARK_MYOGENESIS’ pathway genes in the sorted genes:
# We will create a barplot of logFC for the sorted genes and add one vertical red bar for each gene in the 'HALLMARK_MYOGENESIS' pathway
#pathways[["HALLMARK_MYOGENESIS"]]
tmpInd <- match(pathways[["HALLMARK_MYOGENESIS"]],names(ranks))
tmpInd <- tmpInd[!is.na(tmpInd)]
#tmpInd
ranks2 <- rep(0,length(ranks))
ranks2[tmpInd] <- ranks[tmpInd]
barplot(ranks2)
Create enrichment score plot:
plotEnrichment(pathways[["HALLMARK_MYOGENESIS"]],
ranks)
Remember to check the GSEA article for the complete explanation.
Select top pathways and plot outcome for all these:
topPathwaysUp <- fgseaRes[ES > 0][head(order(pval), n=10), pathway]
topPathwaysDown <- fgseaRes[ES < 0][head(order(pval), n=10), pathway]
topPathways <- c(topPathwaysUp, rev(topPathwaysDown))
plotGseaTable(pathways[topPathways], ranks, fgseaRes,
gseaParam = 0.5)
?plotGseaTable
Other databases of gene sets that are available come from the Broad Institute’s Molecular Signatures Database (MSigDB). CAMERA is good option for testing a very large number of gene sets such as the MSigDB sets, as it is very fast. It has the advantage of accounting for inter-gene correlation within each gene set (Wu and Smyth 2012).
Here we will be using the C2 gene sets for mouse, available as .rdata files from the WEHI bioinformatics page http://bioinf.wehi.edu.au/software/MSigDB/index.html. The C2 gene sets contain 4725 curated gene sets collected from a variety of places: BioCarta, KEGG, Pathway Interaction Database, Reactome as well as some published studies. It doesn’t include GO terms.
# ?camera.DGEList
# Load in the mouse c2 gene sets
# The R object is called Mm.c2
#load("data/mouse_c2_v5.rdata")
setwd("./data")
load("mouse_c2_v5.rdata")
# Have a look at the first few gene sets
names(Mm.c2)[1:5]
# Number of gene sets in C2
length(Mm.c2)
The gene identifiers are Entrez Gene ID, as are the rownames of our DGEList object ‘dgeObj’. We need to map the Entrez gene ids between the list of gene sets and our DGEList object. We can do this using the ids2indices
function.
c2.ind <- ids2indices(Mm.c2, rownames(dgeObj$counts))
CAMERA takes as input the DGEList object dgeObj
, the indexed list of gene sets c2.ind
, the design matrix, the contrast being tested, as well as some other arguments. By default, CAMERA can estimate the correlation for each gene set separately. However, in practise, it works well to set a small inter-gene correlation of about 0.05 using the inter.gene.cor
argument.
# Conduct analysis for the luminal-vs-basal contrast:
group <- as.character(group)
type <- sapply(strsplit(group, ".", fixed=T), function(x) x[1])
status <- sapply(strsplit(group, ".", fixed=T), function(x) x[2])
# Specify a design matrix without an intercept term
design <- model.matrix(~ type + status)
#design
# Check contrasts:
print(colnames(design))
# Run analysis:
gst.camera <- camera.DGEList(dgeObj,index=c2.ind,design=design,contrast=2,inter.gene.cor=0.05)
CAMERA outputs a dataframe of the resulting statistics, with each row denoting a different gene set. The output is ordered by p-value so that the most significant should be at the top. Let’s look at the top 5 gene sets:
gst.camera[1:5,]
The total number of significant gene sets at 5% FDR is:
table(gst.camera$FDR < 0.05)
You can write out the camera results to a csv file to open in excel.
write.csv(gst.camera,file="gst_LumVsBas.csv")
Challenge 1
- Run
camera
on the pregnant vs lactating contrast.- Run
camera
on a different set of MSigDB gene sets, the hallmark datasets,mouse_H_v5.rdata
. You will need to load in the hallmark gene sets, and the object will be calledMm.H
in R.
ROAST is an example of a self-contained gene set test (Wu et al. 2010). It asks the question, “Do the genes in my set tend to be differentially expressed between my conditions of interest?”. ROAST does not use information on the other genes in the experiment, unlike camera
. ROAST is a good option for when you’re interested in a specific set, or a few sets. It is not really used to test thousands of sets at one time.
From the Hallmark gene sets, two MYC pathways were most significant for the pregnant vs lactating contrast.
H.camera[1:10,]
Let’s see if there are any MYC signalling pathways in MsigDB C2 collection. We can do this with the grep
command on the names of the gene sets.
grep("MYC_",names(c2.ind))
# Let's save these so that we can subset c2.ind to test all gene sets with MYC in the name
myc <- grep("MYC_",names(c2.ind))
# What are these pathways called?
names(c2.ind)[myc]
Let’s use ROAST to see if these MYC related gene sets tend to be differentially expressed. Note that the syntax for camera
and roast
is almost identical.
myc.rst <- roast(dgeObj,index=c2.ind[myc],design=design,contrast=3,nrot=999)
myc.rst[1:15,]
Each row corresponds to a single gene set.
The NGenes column gives the number of genes in each set.
The PropDown and PropUp columns contain the proportions of genes in the set that are down- and up-regulated, respectively, with absolute fold changes greater than 2.
The net direction of change is determined from the significance of changes in each direction, and is shown in the Direction column.
The PValue provides evidence for whether the majority of genes in the set are DE in the specified direction
The PValue.Mixed provides evidence for whether the majority of genes in the set are DE in any direction.
FDRs are computed from the corresponding p-values across all sets.
Challenge 2
- Test whether the MYC signalling pathways tend to be differentially expressed between basal virgin vs lactating.
- Look for gene sets containing “WNT” in the name and see whether they tend to be differentially expressed in basal pregnant vs lactating.
Notes
References
Wu, D, and G K Smyth. 2012. “Camera: a competitive gene set test accounting for inter-gene correlation.” Nucleic Acids Research 40 (17). Oxford University Press: e133—–e133.
Wu, D, E Lim, F Vaillant, M L Asselin-Labat, J E Visvader, and G K Smyth. 2010. “ROAST: rotation gene set tests for complex microarray experiments.” Bioinformatics 26 (17). Oxford Univ Press: 2176–82.