decoupleR 2.2.2
scRNA-seq yield many molecular readouts that are hard to interpret by themselves. One way of summarizing this information is by inferring pathway activities from prior knowledge.
In this notebook we showcase how to use decoupleR
for pathway activity
inference with a down-sampled PBMCs 10X data-set. The data consists of 160
PBMCs from a Healthy Donor. The original data is freely available from 10x Genomics
here
from this webpage.
First, we need to load the relevant packages, Seurat
to handle scRNA-seq data
and decoupleR
to use statistical methods.
## We load the required packages
library(Seurat)
library(decoupleR)
# Only needed for data handling and plotting
library(dplyr)
library(tibble)
library(tidyr)
library(patchwork)
library(ggplot2)
library(pheatmap)
Here we used a down-sampled version of the data used in the Seurat
vignette.
We can open the data like this:
inputs_dir <- system.file("extdata", package = "decoupleR")
data <- readRDS(file.path(inputs_dir, "sc_data.rds"))
We can observe that we have different cell types:
DimPlot(data, reduction = "umap", label = TRUE, pt.size = 0.5) + NoLegend()
PROGENy is a comprehensive resource
containing a curated collection of pathways and their target genes, with weights
for each interaction. For this example we will use the human weights
(mouse is also available) and we will use the top 100 responsive genes ranked
by p-value. We can use decoupleR
to retrieve it from OmniPath
:
net <- get_progeny(organism = 'human', top = 100)
net
#> # A tibble: 1,400 × 4
#> source target weight p_value
#> <chr> <chr> <dbl> <dbl>
#> 1 Androgen TMPRSS2 11.5 2.38e-47
#> 2 Androgen NKX3-1 10.6 2.21e-44
#> 3 Androgen MBOAT2 10.5 4.63e-44
#> 4 Androgen KLK2 10.2 1.94e-40
#> 5 Androgen SARG 11.4 2.79e-40
#> 6 Androgen SLC38A4 7.36 1.25e-39
#> 7 Androgen MTMR9 6.13 2.53e-38
#> 8 Androgen ZBTB16 10.6 1.57e-36
#> 9 Androgen KCNN2 9.47 7.71e-36
#> 10 Androgen OPRK1 -5.63 1.11e-35
#> # … with 1,390 more rows
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.
# Extract the normalized log-transformed counts
mat <- as.matrix(data@assays$RNA@data)
# Run wmean
acts <- run_wmean(mat=mat, net=net, .source='source', .target='target',
.mor='weight', times = 100, minsize = 5)
acts
#> # A tibble: 6,720 × 5
#> statistic source condition score p_value
#> <chr> <chr> <chr> <dbl> <dbl>
#> 1 corr_wmean Androgen AAACATACAACCAC-1 0.00321 0.94
#> 2 corr_wmean Androgen AAACGCTGTTTCTG-1 -0.0147 0.34
#> 3 corr_wmean Androgen AACCTTTGGACGGA-1 0 0.0800
#> 4 corr_wmean Androgen AACGCCCTCGTACA-1 0 0.0200
#> 5 corr_wmean Androgen AACGTCGAGTATCG-1 0.0242 0.140
#> 6 corr_wmean Androgen AACTCACTCAAGCT-1 0.00672 0.0800
#> 7 corr_wmean Androgen AAGATGGAAAACAG-1 0.0250 0.62
#> 8 corr_wmean Androgen AAGATTACCGCCTT-1 0.00849 0.86
#> 9 corr_wmean Androgen AAGCCATGAACTGC-1 0.0314 0.58
#> 10 corr_wmean Androgen AAGGTCTGCAGATC-1 0 0.5
#> # … with 6,710 more rows
From the obtained results, we will select the norm_wmean
activities and store
them in our object as a new assay called pathwayswmean
:
# Extract norm_wmean and store it in pathwayswmean in data
data[['pathwayswmean']] <- acts %>%
filter(statistic == 'norm_wmean') %>%
pivot_wider(id_cols = 'source', names_from = 'condition',
values_from = 'score') %>%
column_to_rownames('source') %>%
Seurat::CreateAssayObject(.)
# Change assay
DefaultAssay(object = data) <- "pathwayswmean"
# Scale the data
data <- ScaleData(data)
data@assays$pathwayswmean@data <- data@assays$pathwayswmean@scale.data
This new assay can be used to plot activities. Here we visualize the Trail pathway, associated with apoptosis, which seems that in B and NK cells is more active.
p1 <- DimPlot(data, reduction = "umap", label = TRUE, pt.size = 0.5) +
NoLegend() + ggtitle('Cell types')
p2 <- (FeaturePlot(data, features = c("Trail")) &
scale_colour_gradient2(low = 'blue', mid = 'white', high = 'red')) +
ggtitle('Trail activity')
p1 | p2
We can also see what is the mean activity per group across pathways:
# Extract activities from object as a long dataframe
df <- t(as.matrix(data@assays$pathwayswmean@data)) %>%
as.data.frame() %>%
mutate(cluster = Idents(data)) %>%
pivot_longer(cols = -cluster, names_to = "source", values_to = "score") %>%
group_by(cluster, source) %>%
summarise(mean = mean(score))
# Transform to wide matrix
top_acts_mat <- df %>%
pivot_wider(id_cols = 'cluster', names_from = 'source',
values_from = 'mean') %>%
column_to_rownames('cluster') %>%
as.matrix()
# Choose color palette
palette_length = 100
my_color = colorRampPalette(c("Darkblue", "white","red"))(palette_length)
my_breaks <- c(seq(-2, 0, length.out=ceiling(palette_length/2) + 1),
seq(0.05, 2, length.out=floor(palette_length/2)))
# Plot
pheatmap(top_acts_mat, border_color = NA, color=my_color, breaks = my_breaks)
In this specific example, we can observe that Trail is more active in B and NK cells.
#> ─ Session info ───────────────────────────────────────────────────────────────────────────────────────────────────────
#> setting value
#> version R version 4.2.0 (2022-04-22)
#> os Ubuntu 20.04.4 LTS
#> system x86_64, linux-gnu
#> ui X11
#> language (EN)
#> collate C
#> ctype en_US.UTF-8
#> tz America/New_York
#> date 2022-05-15
#> pandoc 2.5 @ /usr/bin/ (via rmarkdown)
#>
#> ─ Packages ───────────────────────────────────────────────────────────────────────────────────────────────────────────
#> package * version date (UTC) lib source
#> abind 1.4-5 2016-07-21 [2] CRAN (R 4.2.0)
#> assertthat 0.2.1 2019-03-21 [2] CRAN (R 4.2.0)
#> backports 1.4.1 2021-12-13 [2] CRAN (R 4.2.0)
#> BiocManager 1.30.17 2022-04-22 [2] CRAN (R 4.2.0)
#> BiocParallel 1.30.2 2022-05-15 [2] Bioconductor
#> BiocStyle * 2.24.0 2022-05-15 [2] Bioconductor
#> bit 4.0.4 2020-08-04 [2] CRAN (R 4.2.0)
#> bit64 4.0.5 2020-08-30 [2] CRAN (R 4.2.0)
#> bookdown 0.26 2022-04-15 [2] CRAN (R 4.2.0)
#> bslib 0.3.1 2021-10-06 [2] CRAN (R 4.2.0)
#> cellranger 1.1.0 2016-07-27 [2] CRAN (R 4.2.0)
#> checkmate 2.1.0 2022-04-21 [2] CRAN (R 4.2.0)
#> cli 3.3.0 2022-04-25 [2] CRAN (R 4.2.0)
#> cluster 2.1.3 2022-03-28 [2] CRAN (R 4.2.0)
#> codetools 0.2-18 2020-11-04 [2] CRAN (R 4.2.0)
#> colorspace 2.0-3 2022-02-21 [2] CRAN (R 4.2.0)
#> cowplot 1.1.1 2020-12-30 [2] CRAN (R 4.2.0)
#> crayon 1.5.1 2022-03-26 [2] CRAN (R 4.2.0)
#> curl 4.3.2 2021-06-23 [2] CRAN (R 4.2.0)
#> data.table 1.14.2 2021-09-27 [2] CRAN (R 4.2.0)
#> DBI 1.1.2 2021-12-20 [2] CRAN (R 4.2.0)
#> decoupleR * 2.2.2 2022-05-15 [1] Bioconductor
#> deldir 1.0-6 2021-10-23 [2] CRAN (R 4.2.0)
#> digest 0.6.29 2021-12-01 [2] CRAN (R 4.2.0)
#> dplyr * 1.0.9 2022-04-28 [2] CRAN (R 4.2.0)
#> ellipsis 0.3.2 2021-04-29 [2] CRAN (R 4.2.0)
#> evaluate 0.15 2022-02-18 [2] CRAN (R 4.2.0)
#> fansi 1.0.3 2022-03-24 [2] CRAN (R 4.2.0)
#> farver 2.1.0 2021-02-28 [2] CRAN (R 4.2.0)
#> fastmap 1.1.0 2021-01-25 [2] CRAN (R 4.2.0)
#> fastmatch 1.1-3 2021-07-23 [2] CRAN (R 4.2.0)
#> fgsea 1.22.0 2022-05-15 [2] Bioconductor
#> fitdistrplus 1.1-8 2022-03-10 [2] CRAN (R 4.2.0)
#> future 1.25.0 2022-04-24 [2] CRAN (R 4.2.0)
#> future.apply 1.9.0 2022-04-25 [2] CRAN (R 4.2.0)
#> generics 0.1.2 2022-01-31 [2] CRAN (R 4.2.0)
#> ggplot2 * 3.3.6 2022-05-03 [2] CRAN (R 4.2.0)
#> ggrepel * 0.9.1 2021-01-15 [2] CRAN (R 4.2.0)
#> ggridges 0.5.3 2021-01-08 [2] CRAN (R 4.2.0)
#> globals 0.15.0 2022-05-09 [2] CRAN (R 4.2.0)
#> glue 1.6.2 2022-02-24 [2] CRAN (R 4.2.0)
#> goftest 1.2-3 2021-10-07 [2] CRAN (R 4.2.0)
#> gridExtra 2.3 2017-09-09 [2] CRAN (R 4.2.0)
#> gtable 0.3.0 2019-03-25 [2] CRAN (R 4.2.0)
#> highr 0.9 2021-04-16 [2] CRAN (R 4.2.0)
#> hms 1.1.1 2021-09-26 [2] CRAN (R 4.2.0)
#> htmltools 0.5.2 2021-08-25 [2] CRAN (R 4.2.0)
#> htmlwidgets 1.5.4 2021-09-08 [2] CRAN (R 4.2.0)
#> httpuv 1.6.5 2022-01-05 [2] CRAN (R 4.2.0)
#> httr 1.4.3 2022-05-04 [2] CRAN (R 4.2.0)
#> ica 1.0-2 2018-05-24 [2] CRAN (R 4.2.0)
#> igraph 1.3.1 2022-04-20 [2] CRAN (R 4.2.0)
#> irlba 2.3.5 2021-12-06 [2] CRAN (R 4.2.0)
#> jquerylib 0.1.4 2021-04-26 [2] CRAN (R 4.2.0)
#> jsonlite 1.8.0 2022-02-22 [2] CRAN (R 4.2.0)
#> KernSmooth 2.23-20 2021-05-03 [2] CRAN (R 4.2.0)
#> knitr 1.39 2022-04-26 [2] CRAN (R 4.2.0)
#> labeling 0.4.2 2020-10-20 [2] CRAN (R 4.2.0)
#> later 1.3.0 2021-08-18 [2] CRAN (R 4.2.0)
#> lattice 0.20-45 2021-09-22 [2] CRAN (R 4.2.0)
#> lazyeval 0.2.2 2019-03-15 [2] CRAN (R 4.2.0)
#> leiden 0.4.2 2022-05-09 [2] CRAN (R 4.2.0)
#> lifecycle 1.0.1 2021-09-24 [2] CRAN (R 4.2.0)
#> listenv 0.8.0 2019-12-05 [2] CRAN (R 4.2.0)
#> lmtest 0.9-40 2022-03-21 [2] CRAN (R 4.2.0)
#> logger 0.2.2 2021-10-19 [2] CRAN (R 4.2.0)
#> lubridate 1.8.0 2021-10-07 [2] CRAN (R 4.2.0)
#> magick 2.7.3 2021-08-18 [2] CRAN (R 4.2.0)
#> magrittr 2.0.3 2022-03-30 [2] CRAN (R 4.2.0)
#> MASS 7.3-57 2022-04-22 [2] CRAN (R 4.2.0)
#> Matrix 1.4-1 2022-03-23 [2] CRAN (R 4.2.0)
#> matrixStats 0.62.0 2022-04-19 [2] CRAN (R 4.2.0)
#> mgcv 1.8-40 2022-03-29 [2] CRAN (R 4.2.0)
#> mime 0.12 2021-09-28 [2] CRAN (R 4.2.0)
#> miniUI 0.1.1.1 2018-05-18 [2] CRAN (R 4.2.0)
#> munsell 0.5.0 2018-06-12 [2] CRAN (R 4.2.0)
#> nlme 3.1-157 2022-03-25 [2] CRAN (R 4.2.0)
#> OmnipathR 3.4.0 2022-05-15 [2] Bioconductor
#> parallelly 1.31.1 2022-04-22 [2] CRAN (R 4.2.0)
#> patchwork * 1.1.1 2020-12-17 [2] CRAN (R 4.2.0)
#> pbapply 1.5-0 2021-09-16 [2] CRAN (R 4.2.0)
#> pheatmap * 1.0.12 2019-01-04 [2] CRAN (R 4.2.0)
#> pillar 1.7.0 2022-02-01 [2] CRAN (R 4.2.0)
#> pkgconfig 2.0.3 2019-09-22 [2] CRAN (R 4.2.0)
#> plotly 4.10.0 2021-10-09 [2] CRAN (R 4.2.0)
#> plyr 1.8.7 2022-03-24 [2] CRAN (R 4.2.0)
#> png 0.1-7 2013-12-03 [2] CRAN (R 4.2.0)
#> polyclip 1.10-0 2019-03-14 [2] CRAN (R 4.2.0)
#> prettyunits 1.1.1 2020-01-24 [2] CRAN (R 4.2.0)
#> progress 1.2.2 2019-05-16 [2] CRAN (R 4.2.0)
#> progressr 0.10.0 2021-12-19 [2] CRAN (R 4.2.0)
#> promises 1.2.0.1 2021-02-11 [2] CRAN (R 4.2.0)
#> purrr 0.3.4 2020-04-17 [2] CRAN (R 4.2.0)
#> R6 2.5.1 2021-08-19 [2] CRAN (R 4.2.0)
#> RANN 2.6.1 2019-01-08 [2] CRAN (R 4.2.0)
#> rappdirs 0.3.3 2021-01-31 [2] CRAN (R 4.2.0)
#> RColorBrewer 1.1-3 2022-04-03 [2] CRAN (R 4.2.0)
#> Rcpp 1.0.8.3 2022-03-17 [2] CRAN (R 4.2.0)
#> RcppAnnoy 0.0.19 2021-07-30 [2] CRAN (R 4.2.0)
#> readr 2.1.2 2022-01-30 [2] CRAN (R 4.2.0)
#> readxl 1.4.0 2022-03-28 [2] CRAN (R 4.2.0)
#> RefManageR * 1.3.0 2020-11-13 [2] CRAN (R 4.2.0)
#> reshape2 1.4.4 2020-04-09 [2] CRAN (R 4.2.0)
#> reticulate 1.25 2022-05-11 [2] CRAN (R 4.2.0)
#> rgeos 0.5-9 2021-12-15 [2] CRAN (R 4.2.0)
#> rlang 1.0.2 2022-03-04 [2] CRAN (R 4.2.0)
#> rmarkdown 2.14 2022-04-25 [2] CRAN (R 4.2.0)
#> ROCR 1.0-11 2020-05-02 [2] CRAN (R 4.2.0)
#> rpart 4.1.16 2022-01-24 [2] CRAN (R 4.2.0)
#> Rtsne 0.16 2022-04-17 [2] CRAN (R 4.2.0)
#> sass 0.4.1 2022-03-23 [2] CRAN (R 4.2.0)
#> scales 1.2.0 2022-04-13 [2] CRAN (R 4.2.0)
#> scattermore 0.8 2022-02-14 [2] CRAN (R 4.2.0)
#> sctransform 0.3.3 2022-01-13 [2] CRAN (R 4.2.0)
#> sessioninfo 1.2.2 2021-12-06 [2] CRAN (R 4.2.0)
#> Seurat * 4.1.1 2022-05-02 [2] CRAN (R 4.2.0)
#> SeuratObject * 4.1.0 2022-05-01 [2] CRAN (R 4.2.0)
#> shiny 1.7.1 2021-10-02 [2] CRAN (R 4.2.0)
#> sp * 1.4-7 2022-04-20 [2] CRAN (R 4.2.0)
#> spatstat.core 2.4-2 2022-04-01 [2] CRAN (R 4.2.0)
#> spatstat.data 2.2-0 2022-04-18 [2] CRAN (R 4.2.0)
#> spatstat.geom 2.4-0 2022-03-29 [2] CRAN (R 4.2.0)
#> spatstat.random 2.2-0 2022-03-30 [2] CRAN (R 4.2.0)
#> spatstat.sparse 2.1-1 2022-04-18 [2] CRAN (R 4.2.0)
#> spatstat.utils 2.3-1 2022-05-06 [2] CRAN (R 4.2.0)
#> stringi 1.7.6 2021-11-29 [2] CRAN (R 4.2.0)
#> stringr 1.4.0 2019-02-10 [2] CRAN (R 4.2.0)
#> survival 3.3-1 2022-03-03 [2] CRAN (R 4.2.0)
#> tensor 1.5 2012-05-05 [2] CRAN (R 4.2.0)
#> tibble * 3.1.7 2022-05-03 [2] CRAN (R 4.2.0)
#> tidyr * 1.2.0 2022-02-01 [2] CRAN (R 4.2.0)
#> tidyselect 1.1.2 2022-02-21 [2] CRAN (R 4.2.0)
#> tzdb 0.3.0 2022-03-28 [2] CRAN (R 4.2.0)
#> utf8 1.2.2 2021-07-24 [2] CRAN (R 4.2.0)
#> uwot 0.1.11 2021-12-02 [2] CRAN (R 4.2.0)
#> vctrs 0.4.1 2022-04-13 [2] CRAN (R 4.2.0)
#> viridisLite 0.4.0 2021-04-13 [2] CRAN (R 4.2.0)
#> vroom 1.5.7 2021-11-30 [2] CRAN (R 4.2.0)
#> withr 2.5.0 2022-03-03 [2] CRAN (R 4.2.0)
#> xfun 0.31 2022-05-10 [2] CRAN (R 4.2.0)
#> xml2 1.3.3 2021-11-30 [2] CRAN (R 4.2.0)
#> xtable 1.8-4 2019-04-21 [2] CRAN (R 4.2.0)
#> yaml 2.3.5 2022-02-21 [2] CRAN (R 4.2.0)
#> zoo 1.8-10 2022-04-15 [2] CRAN (R 4.2.0)
#>
#> [1] /tmp/RtmpD6m20a/Rinstb65fd7f3bbb8a
#> [2] /home/biocbuild/bbs-3.15-bioc/R/library
#>
#> ──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────