1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265
|
---
title: "Transcription factor activity inference in bulk RNA-seq"
author:
- name: Pau Badia-i-Mompel
affiliation:
- Heidelberg Universiy
output:
BiocStyle::html_document:
self_contained: true
toc: true
toc_float: true
toc_depth: 3
code_folding: show
package: "`r pkg_ver('decoupleR')`"
vignette: >
%\VignetteIndexEntry{Transcription factor activity inference in bulk RNA-seq}
%\VignetteEngine{knitr::rmarkdown}
%\VignetteEncoding{UTF-8}
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>"
)
```
Bulk RNA-seq yield many molecular readouts that are hard to interpret by
themselves. One way of summarizing this information is by inferring
transcription factor (TF) activities from prior knowledge.
In this notebook we showcase how to use `decoupleR` for transcription factor activity
inference with a bulk RNA-seq data-set where the transcription factor FOXA2 was
knocked out in pancreatic cancer cell lines.
The data consists of 3 Wild Type (WT) samples and 3 Knock Outs (KO). They are
freely available in
[GEO](https://www.ncbi.nlm.nih.gov/geo/query/acc.cgi?acc=GSE119931).
# Loading packages
First, we need to load the relevant packages:
```{r "load packages", message = FALSE}
## We load the required packages
library(decoupleR)
library(dplyr)
library(tibble)
library(tidyr)
library(ggplot2)
library(pheatmap)
library(ggrepel)
```
# Loading the data-set
Here we used an already processed bulk RNA-seq data-set. We provide the
normalized log-transformed counts, the experimental design meta-data and the
Differential Expressed Genes (DEGs) obtained using `limma`.
We can open the data like this:
```{r "load data"}
inputs_dir <- system.file("extdata", package = "decoupleR")
data <- readRDS(file.path(inputs_dir, "bk_data.rds"))
```
From `data` we can extract the mentioned information. Here we see the normalized
log-transformed counts:
```{r "counts"}
# Remove NAs and set row names
counts <- data$counts %>%
dplyr::mutate_if(~ any(is.na(.x)), ~ if_else(is.na(.x),0,.x)) %>%
column_to_rownames(var = "gene") %>%
as.matrix()
head(counts)
```
The design meta-data:
```{r "design"}
design <- data$design
design
```
And the results of `limma`, of which we are interested in extracting the
obtained t-value and p-value from the contrast:
```{r "deg"}
# Extract t-values per gene
deg <- data$limma_ttop %>%
select(ID, logFC, t, P.Value) %>%
filter(!is.na(t)) %>%
column_to_rownames(var = "ID") %>%
as.matrix()
head(deg)
```
# DoRothEA network
[DoRothEA](https://saezlab.github.io/dorothea/) is a comprehensive resource
containing a curated collection of TFs and their transcriptional targets. Since
these regulons were gathered from different types of evidence, interactions in
DoRothEA are classified in different confidence levels, ranging from A (highest
confidence) to D (lowest confidence). Moreover, each interaction is weighted by
its confidence level and the sign of its mode of regulation (activation or
inhibition).
For this example we will use the human version (mouse is also available) and we
will use the confidence levels ABC. We can use `decoupleR` to retrieve it from
`OmniPath`:
```{r "dorothea"}
net <- get_dorothea(organism='human', levels=c('A', 'B', 'C'))
net
```
# Activity inference with Weighted Mean
To infer activities we will run the Weighted Mean method (`wmean`). It infers
regulator activities by first multiplying each target feature by its associated
weight which then are summed to an enrichment score `wmean`. Furthermore,
permutations of random target features can be performed to obtain a null
distribution that can be used to compute a z-score `norm_wmean`, or a corrected
estimate `corr_wmean` by multiplying `wmean` by the minus log10 of the obtained
empirical p-value.
In this example we use `wmean` but we could have used any other.
To see what methods are available use `show_methods()`.
To run `decoupleR` methods, we need an input matrix (`mat`), an input prior
knowledge network/resource (`net`), and the name of the columns of net that we
want to use.
```{r "sample_wmean", message=FALSE}
# Run wmean
sample_acts <- run_wmean(mat=counts, net=net, .source='source', .target='target',
.mor='mor', times = 100, minsize = 5)
sample_acts
```
# Visualization
From the obtained results, we will select the `norm_wmean` activities and we
will observe the most variable activities across samples in a heat-map:
```{r "heatmap"}
n_tfs <- 25
# Transform to wide matrix
sample_acts_mat <- sample_acts %>%
filter(statistic == 'norm_wmean') %>%
pivot_wider(id_cols = 'condition', names_from = 'source',
values_from = 'score') %>%
column_to_rownames('condition') %>%
as.matrix()
# Get top tfs with more variable means across clusters
tfs <- sample_acts %>%
group_by(source) %>%
summarise(std = sd(score)) %>%
arrange(-abs(std)) %>%
head(n_tfs) %>%
pull(source)
sample_acts_mat <- sample_acts_mat[,tfs]
# Scale per sample
sample_acts_mat <- scale(sample_acts_mat)
# Choose color palette
palette_length = 100
my_color = colorRampPalette(c("Darkblue", "white","red"))(palette_length)
my_breaks <- c(seq(-3, 0, length.out=ceiling(palette_length/2) + 1),
seq(0.05, 3, length.out=floor(palette_length/2)))
# Plot
pheatmap(sample_acts_mat, border_color = NA, color=my_color, breaks = my_breaks)
```
We can observe that WT samples have higher activities for PDX1 and SIX2 than KO.
On the other hand, KO show higher activities for LYL1 and ZNF263.
We can also infer pathway activities from the t-values of the DEGs between KO
and WT:
```{r "contrast_wmean", message=FALSE}
# Run wmean
contrast_acts <- run_wmean(mat=deg[, 't', drop=FALSE], net=net, .source='source', .target='target',
.mor='mor', times = 100, minsize = 5)
contrast_acts
```
We select the `norm_wmean` activities and then we show the changes
in activity between KO and WT:
```{r "barplot"}
# Filter norm_wmean
f_contrast_acts <- contrast_acts %>%
filter(statistic == 'norm_wmean') %>%
mutate(rnk = NA)
# Filter top TFs in both signs
msk <- f_contrast_acts$score > 0
f_contrast_acts[msk, 'rnk'] <- rank(-f_contrast_acts[msk, 'score'])
f_contrast_acts[!msk, 'rnk'] <- rank(-abs(f_contrast_acts[!msk, 'score']))
tfs <- f_contrast_acts %>%
arrange(rnk) %>%
head(n_tfs) %>%
pull(source)
f_contrast_acts <- f_contrast_acts %>%
filter(source %in% tfs)
# Plot
ggplot(f_contrast_acts, aes(x = reorder(source, score), y = score)) +
geom_bar(aes(fill = score), stat = "identity") +
scale_fill_gradient2(low = "darkblue", high = "indianred",
mid = "whitesmoke", midpoint = 0) +
theme_minimal() +
theme(axis.title = element_text(face = "bold", size = 12),
axis.text.x =
element_text(angle = 45, hjust = 1, size =10, face= "bold"),
axis.text.y = element_text(size =10, face= "bold"),
panel.grid.major = element_blank(),
panel.grid.minor = element_blank()) +
xlab("Pathways")
```
As observed before, the pathways PDX1 and SIX2 are deactivated in KO when
compared to WT, while LYL1 and ZNF263 seem to be activated.
We can further visualize the most differential target genes in each TF along their
p-values to interpret the results. For example, let's see the genes that are
belong to FOXA2:
```{r "targets", warning=F}
tf <- 'FOXA2'
df <- net %>%
filter(source == tf) %>%
arrange(target) %>%
mutate(ID = target, color = "3") %>%
column_to_rownames('target')
inter <- sort(intersect(rownames(deg),rownames(df)))
df <- df[inter, ]
df[,c('logfc', 't_value', 'p_value')] <- deg[inter, ]
df <- df %>%
mutate(color = if_else(mor > 0 & t_value > 0, '1', color)) %>%
mutate(color = if_else(mor > 0 & t_value < 0, '2', color)) %>%
mutate(color = if_else(mor < 0 & t_value > 0, '2', color)) %>%
mutate(color = if_else(mor < 0 & t_value < 0, '1', color))
ggplot(df, aes(x = logfc, y = -log10(p_value), color = color, size=abs(mor))) +
geom_point() +
scale_colour_manual(values = c("red","royalblue3","grey")) +
geom_label_repel(aes(label = ID, size=1)) +
theme_minimal() +
theme(legend.position = "none") +
geom_vline(xintercept = 0, linetype = 'dotted') +
geom_hline(yintercept = 0, linetype = 'dotted') +
ggtitle(tf)
```
Here blue means that the sign of multiplying the `mor` and `t-value` is negative,
meaning that these genes are "deactivating" the TF, and red means that the sign
is positive, meaning that these genes are "activating" the TF. In this particular
case, FOXA2 target genes seem to be more under-expressed in KO than in WT,
therefore the KO worked.
# Session information
```{r session_info, echo=FALSE}
options(width = 120)
sessioninfo::session_info()
```
|