This tutorial shows how to use RcisTarget to obtain the transcription factor binding motifs enriched on a gene list.
Note for development version: The database packages are still not included in Bioconductor. They can be downloaded from http://scenic.aertslab.org
RcisTarget is an R-package to identify transcription factor (TF) binding motifs over-represented on a gene list.
RcisTarget is based on the methods previously implemented in i-cisTarget (web interface, region-based) and iRegulon (Cytoscape plug-in, gene-based).
If you use RcisTarget in your research, please cite: (TO DO: Update publication)
## Aibar. et al. (2016) RcisTarget: Identify transcription factor binding motifs enriched on a gene list. R/Bioconductor package.
The function cisTarget() allows to perform the motif-enrichment analysis on a gene list. The main input parameters are the gene list and the motif databases, which should be chosen depending on the organism and the search space around the TSS of the genes. This is a sample on how to run the analysis (see the following sections for details):
library(RcisTarget)
# Load gene sets to analyze. e.g.:
geneList1 <- c("gene1", "gene2", "gene3")
geneLists <- list(geneListName=geneList1)
# Select motif database to use (i.e. organism and distance around TSS)
library(RcisTarget.hg19.motifDatabases.20k)
data(hg19_10kbpAroundTss_motifRanking)
data(hg19_direct_motifAnnotation)
motifRankings <- hg19_10kbpAroundTss_motifRanking
# Motif enrichment analysis:
motifEnrichmentTable_wGenes <- cisTarget(geneLists, motifRankings,
motifAnnot_direct=hg19_direct_motifAnnotation)
Advanced use: The cisTarget() function is enough for most simple analyses. However, for further flexibility (e.g. removing unnecessary steps on bigger analyses), RcisTarget also provides the possibility to run the inner functions individually. Running cisTarget() is equivalent to running this code:
# 1. Calculate AUC
motifs_AUC <- calcAUC(geneLists, motifRankings)
# 2. Select significant motifs, add TF annotation & format as table
motifEnrichmentTable <- addMotifAnnotation(motifs_AUC, motifAnnot_direct=hg19_direct_motifAnnotation)
# 3. Identify significant genes for each motif (i.e. genes from the gene set in the top of the ranking)
# Note: Method 'iCisTarget' is more accurate, but slower
motifEnrichmentTable_wGenes <- addSignificantGenes(motifEnrichmentTable,
geneSets=geneLists,
rankings=motifRankings,
nCores=1,
method="iCisTarget")
RcisTarget uses species-specific databases which are provided as independent R-packages. Prior to running RcisTarget, please download and install the databases for the relevant organism:
| Species | Package |
|---|---|
| Human (hg19) | SCENIC.hg19.motifDatabases.20k |
| Mouse (mm9) | SCENIC.mm9.motifDatabases.20k |
In addition, some extra packages can be installed to run RcisTarget in parallel or run the interactive examples in this tutorial:
source("http://bioconductor.org/biocLite.R")
# To support paralell execution:
biocLite(c("doMC", "doRNG"))
# For the examples in the follow-up section of the tutorial:
biocLite(c("DT", "visNetwork"))
At any time, remember you an access the help files for any function (i.e. ?cisTarget), and the other tutorials in the package with the following commands:
# Explore tutorials in the web browser:
browseVignettes(package="RcisTarget")
# Commnad line-based:
vignette(package="RcisTarget") # list
vignette("RcisTarget") # open
To generate an HTML report with your own data and comments, you can use the .Rmd file of this tutorial as template (i.e. copy the .Rmd file, and edit it as R notebook in RStudio).
vignetteFile <- paste(file.path(system.file('doc', package='RcisTarget')), "RcisTarget.Rmd", sep="/")
# Copy to edit as markdown
file.copy(vignetteFile, ".")
# Alternative: extract R code
Stangle(vignetteFile)
The main input to RcisTarget is the gene set(s) to analyze. The gene sets should be provided as a ‘named list’ in which each element is a gene-set (character vector containing gene names). The gene-set name will be used as ID in the following steps.
Note that for consistency, this format should be used even if there is only one gene set.
library(RcisTarget)
geneSet1 <- c("gene1", "gene2", "gene3")
geneLists <- list(geneSetName=geneSet1)
Some extra help:
class(geneSet1)
class(geneLists)
geneSet2 <- c("gene2", "gene4", "gene5", "gene6")
geneLists[["anotherGeneSet"]] <- geneSet2
names(geneLists)
geneLists$anotherGeneList
lengths(geneLists)
In this example we will be using a list of genes up-regulated in MCF7 cells under hypoxia conditions (PMID:16565084).
The original work highlighted the role of hypoxia-inducible factor (HIF1-alpha or HIF1A) pathways under hypoxia. This gene list is also used for the turorials in iRegulon (http://iregulon.aertslab.org/tutorial.html).
txtFile <- paste(file.path(system.file('examples', package='RcisTarget')), "hypoxiaGeneSet.txt", sep="/")
geneLists <- list(hypoxia=read.table(txtFile)[,1])
head(geneLists$hypoxia)
## [1] "ADM" "ADORA2B" "AHNAK2" "AK4" "AKAP12" "ALDOC"
Besides the gene list, RcisTarget also needs the motif databases. The databases are species-specific, so they are provided in independent packages:
| Species | Package |
|---|---|
| Human (hg19) | RcisTarget.hg19.motifDatabases.20k |
| Mouse (mm9) | RcisTarget.mm9.motifDatabases.20k |
For each species, the packages contain two types of databases: (1) the gene-motif rankings, which provides the rankings (~score) of all the genes for each motif (see iRegulon publication for details), and (2) the motif annotation to transcription factors.
For each species, there are two gene-motif rankings available: 10kb around the TSS or 500 bp upstream, which determine the search space around the transcription start site (TSS). To see the names of the rankings and annotations for each species, you can type on your console: ?RcisTarget.mm9.motifDatabases.20k or ?RcisTarget.hg9.motifDatabases.20k.
| Database | Search space |
|---|---|
hg19_500bpUpstream_motifRanking |
500 bp uptream TSS |
hg19_10kbpAroundTss_motifRanking |
10kbp upstream and 10kbp downstream of the TSS |
(Change the prefix to the relevant species, i.e. mm9_500bpUpstream_motifRanking)
# To download the rankings:
source("http://bioconductor.org/biocLite.R")
biocLite("RcisTarget.hg19.motifDatabases.20k")
library(RcisTarget.hg19.motifDatabases.20k)
data(hg19_10kbpAroundTss_motifRanking)
motifRankings <- hg19_10kbpAroundTss_motifRanking
motifRankings
## Rankings for RcisTarget.
## Organism: human (hg19)
## Number of GENES: 22284
## Number of motifs: 20003
##
## Motifs 10kbp around the TSS.
All the calculations performed by RcisTarget are motif-based. However, most users will be interested on TFs potentially regulating the gene-set. The association of motif to transcription factors are provided in two databases: one containing the TFs directly annotated to the motif (i.e. in the source motif database), and inferred annotation based on motif similarity.
These databases dan be provided as motifAnnot_direct or motifAnnot_inferred arguments to cisTarget() or addMotifAnnotation().
| Database | Motif-TF annotation |
|---|---|
hg19_direct_motifAnnotation |
Direct |
hg19_inferred_motifAnnotation |
Inferred by similarity |
(Change the prefix to the relevant species, i.e. mm9_500bpUpstream_motifRanking)
Once the gene lists and databases are loaded, they can be used by cisTarget(). cisTarget() runs sequentially the steps to perform the (1) motif enrichment analysis, (2) motif-TF annotation, and (3) selection of significant genes.
It is also possible to run these steps as individual commands. For example, to skip steps, for analyses in which the user is interested in one of the outputs, or to optimize the workflow to run it on multiple gene lists (see Advanced section for details).
motifEnrichmentTable_wGenes <- cisTarget(geneLists,
motifRankings,
motifAnnot_direct=hg19_direct_motifAnnotation,
motifAnnot_inferred=hg19_inferred_motifAnnotation)
The first step to estimate the over-representation of each motif on the gene-set is to calculate the Area Under the Curve (AUC) for each pair of motif-geneSet. This is calculated based on the recovery curve of the gene-set on the motif ranking (genes ranked decreasingly by the score of motif in its proximity, as provided in the motifRanking database).
motifs_AUC <- calcAUC(geneLists, motifRankings, nCores=1)
The AUC is provided as a matrix of Motifs by GeneSets. In principle, the AUC is mostly meant as input for the next step. However, it is also possible to explore the distribution of the scores, for example in a gene-set of interest:
hist(motifs_AUC["hypoxia",], main="hypoxia", xlab="AUC histogram",
breaks=100, col="#ff000050", border="darkred")
nes3 <- (3*sd(motifs_AUC["hypoxia",])) + mean(motifs_AUC["hypoxia",])
abline(v=nes3, col="red")
The selection of significant motifs is done based on the Normalized Enrichment Score (NES). The NES is calculated -for each motif- based on the AUC distribution of all the motifs for the gene-set [(x-mean)/sd]. Those motifs that pass the given threshold (3.0 by default) are considered significant.
Furthermore, this step also allows to add the TFs annotated to the motif.
data(hg19_direct_motifAnnotation)
data(hg19_inferred_motifAnnotation)
motifEnrichmentTable <- addMotifAnnotation(motifs_AUC, nesThreshold=3,
motifAnnot_direct=hg19_direct_motifAnnotation,
motifAnnot_inferred=hg19_inferred_motifAnnotation,
highlightTFs=list(hypoxia="HIF1A"))
class(motifEnrichmentTable)
## [1] "data.table" "data.frame"
dim(motifEnrichmentTable)
## [1] 93 8
head(motifEnrichmentTable[,-"TF_inferred", with=FALSE])
## geneSet motif NES AUC highlightedTFs TFinDB
## 1: hypoxia homer__GCACGTACCC_HIF2a 5.61 0.143 HIF1A
## 2: hypoxia hocomoco__HIF1A_HUMAN.H10MO.A 5.41 0.140 HIF1A **
## 3: hypoxia cisbp__M6275 5.38 0.139 HIF1A **
## 4: hypoxia transfac_pro__M00466 5.03 0.133 HIF1A **
## 5: hypoxia hdpi__ACO1 4.45 0.124 HIF1A
## 6: hypoxia swissregulon__hs__FOXO1_3_4.p2 4.19 0.120 HIF1A
## TF_direct
## 1: EPAS1
## 2: HIF1A
## 3: HIF1A
## 4: ARNT; HIF1A
## 5: ACO1
## 6: FOXO1; FOXO3; FOXO4
Since RcisTarget searches for enrichment of a motif within a gene list, finding a motif ‘enriched’ does not imply that all the genes in the gene-list have a high score for the motif. In this way, the third step of the workflow is to identify which genes (of the gene-set) are highly ranked for each of the significant motifs.
There are two methods to identify these genes: (1) equivalent to the ones used in iRegulon and i-cisTarget (method="iCisTarget", recommended if running time is not an issue), and (2) a faster implementation based on an approximate distribution using the average at each rank (method="aprox", useful to scan multiple gene sets).
IMPORTANT: Make sure that the motifRanking is the same as in Step 1.
motifEnrichmentTable_wGenes <- addSignificantGenes(motifEnrichmentTable,
rankings=motifRankings,
geneSets=geneLists)
dim(motifEnrichmentTable_wGenes)
## [1] 93 11
Plot for a few motifs:
geneSetName <- "hypoxia"
selectedMotifs <- c("cisbp__M6275", sample(motifEnrichmentTable$motif, 2))
par(mfrow=c(2,2))
getSignificantGenes(geneLists[[geneSetName]],
motifRankings,
signifRankingNames=selectedMotifs,
plotCurve=TRUE, maxRank=5000, genesFormat="none",
method="aprox")
The final output of RcisTarget is a data.table containing the information about the motif enrichment and its annotation organized in the following fields:
motifEnrichmentTable_wGenes_wLogo <- addLogo(motifEnrichmentTable_wGenes)
resultsSubset <- motifEnrichmentTable_wGenes_wLogo[1:20,]
library(DT)
datatable(resultsSubset[,-c("enrichedGenes", "TF_inferred"), with=FALSE],
escape = FALSE, # To show the logo
filter="top", options=list(pageLength=5))
Note that the TFs are provided based on the motif annotation. They can be used as a guide to select relevant motifs or to prioritize some TFs, but the motif annotation does not imply that all the TFs appearing in the table regulate the gene list.
anotatedTfs <- lapply(split(motifEnrichmentTable_wGenes$TF_direct, motifEnrichmentTable$geneSet),
function(x) unique(unlist(strsplit(x, "; "))))
anotatedTfs$hypoxia
## [1] "EPAS1" "HIF1A" "ARNT" "ACO1" "FOXO1" "FOXO3" "FOXO4"
## [8] "FOXJ1" "FOXJ2" "FOXJ3" "FOXP1" "FOXP2" "FOXP3" "FOXP4"
## [15] "AHR" "AHRR" "ARNT2" "CEBPE" "FOXK1" "MECP2" "FOXO6"
## [22] "CEBPB" "CEBPD" "CEBPG" "DBP" "FOXF2" "POLR2A" "TAF1"
## [29] "TBP" "TBPL2" "FOXG1" "FOXC1" "FOXC2" "ELK1" "FOXI1"
## [36] "NOC2L" "GMEB1" "SIM1" "SIM2" "CDX1" "CDX2" "CDX4"
## [43] "BRCA1" "USF2"
signifMotifNames <- motifEnrichmentTable$motif[1:3]
incidenceMatrix <- getSignificantGenes(geneLists$hypoxia,
motifRankings,
signifRankingNames=signifMotifNames,
plotCurve=TRUE, maxRank=5000,
genesFormat="incidMatrix",
method="aprox")$incidMatrix
library(reshape2)
edges <- melt(incidenceMatrix)
edges <- edges[which(edges[,3]==1),1:2]
colnames(edges) <- c("from","to")
Output not shown:
library(visNetwork)
motifs <- unique(as.character(edges[,1]))
genes <- unique(as.character(edges[,2]))
nodes <- data.frame(id=c(motifs, genes),
label=c(motifs, genes),
title=c(motifs, genes), # tooltip
shape=c(rep("diamond", length(motifs)), rep("elypse", length(genes))),
color=c(rep("purple", length(motifs)), rep("skyblue", length(genes))))
visNetwork(nodes, edges) %>% visOptions(highlightNearest = TRUE,
nodesIdSelection = TRUE)
This is the output of sessionInfo() on the system on which this document was compiled:
date()
## [1] "Tue Apr 18 15:47:16 2017"
sessionInfo()
## R version 3.2.2 (2015-08-14)
## Platform: x86_64-pc-linux-gnu (64-bit)
## Running under: Ubuntu 14.04.5 LTS
##
## locale:
## [1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C
## [3] LC_TIME=en_US.UTF-8 LC_COLLATE=en_US.UTF-8
## [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
##
## attached base packages:
## [1] stats graphics grDevices utils datasets methods base
##
## other attached packages:
## [1] data.table_1.10.4
## [2] DT_0.1
## [3] RcisTarget.hg19.motifDatabases.20k_0.1.1
## [4] RcisTarget_0.99.0
## [5] BiocStyle_1.8.0
## [6] telegram_0.6.0
## [7] BiocInstaller_1.20.3
##
## loaded via a namespace (and not attached):
## [1] Rcpp_0.12.9 knitr_1.13 magrittr_1.5
## [4] BiocGenerics_0.16.1 AUCell_0.7.3 lattice_0.20-33
## [7] R6_2.2.0 stringr_1.2.0 httr_1.1.0
## [10] tools_3.2.2 grid_3.2.2 parallel_3.2.2
## [13] htmltools_0.3.5 yaml_2.1.13 digest_0.6.12
## [16] formatR_1.2.1 codetools_0.2-14 htmlwidgets_0.6
## [19] curl_0.9.6 evaluate_0.8 rmarkdown_1.0
## [22] stringi_1.1.2 jsonlite_1.0 zoo_1.7-13