# Pathway activity inference from scRNA-seq

Pau Badia-i-Mompel1

1Heidelberg Universiy

#### 15 April 2025

#### Package

decoupleR 2.14.0

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.

# 1 Loading packages

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)

# 2 Loading the data-set

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()

### 2.0.1 PROGENy model

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 (other organisms are available) and we will use the top 500 responsive genes ranked by p-value. Here is a brief description of each pathway:

- Androgen: involved in the growth and development of the male reproductive organs.
- EGFR: regulates growth, survival, migration, apoptosis, proliferation, and differentiation in mammalian cells
- Estrogen: promotes the growth and development of the female reproductive organs.
- Hypoxia: promotes angiogenesis and metabolic reprogramming when O2 levels are low.
- JAK-STAT: involved in immunity, cell division, cell death, and tumor formation.
- MAPK: integrates external signals and promotes cell growth and proliferation.
- NFkB: regulates immune response, cytokine production and cell survival.
- p53: regulates cell cycle, apoptosis, DNA repair and tumor suppression.
- PI3K: promotes growth and proliferation.
- TGFb: involved in development, homeostasis, and repair of most tissues.
- TNFa: mediates haematopoiesis, immune surveillance, tumour regression and protection from infection.
- Trail: induces apoptosis.
- VEGF: mediates angiogenesis, vascular permeability, and cell migration.
- WNT: regulates organ morphogenesis during development and tissue repair.

To access it we can use `decoupleR`:

    net <- get_progeny(organism = 'human', top = 500)
    #> Warning in OmnipathR::get_annotation_resources(): 'OmnipathR::get_annotation_resources' is deprecated.
    #> Use 'annotation_resources' instead.
    #> See help("Deprecated")
    #> Warning in readLines(con = path, encoding = encoding): incomplete final line found on
    #> 'https://omnipathdb.org/resources'
    #> Warning in OmnipathR::import_omnipath_annotations(resources = name, ..., : 'OmnipathR::import_omnipath_annotations' is deprecated.
    #> Use 'annotations' instead.
    #> See help("Deprecated")
    #> Warning in readLines(con = path, encoding = encoding): incomplete final line found on
    #> 'https://omnipathdb.org/resources'
    net
    #> # A tibble: 7,000 × 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
    #> # ℹ 6,990 more rows

# 3 Activity inference with Multivariate Linear Model (MLM)

To infer pathway enrichment scores we will run the Multivariate Linear Model (`mlm`) method. For each sample in our dataset (`mat`), it fits a linear model that predicts the observed gene expression based on all pathways’ Pathway-Gene interactions weights. Once fitted, the obtained t-values of the slopes are the scores. If it is positive, we interpret that the pathway is active and if it is negative we interpret that it is inactive.

mlm

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 mlm
    acts <- run_mlm(mat=mat, net=net, .source='source', .target='target',
                    .mor='weight', minsize = 5)
    acts
    #> # A tibble: 2,240 × 5
    #>    statistic source   condition         score  p_value
    #>    <chr>     <chr>    <chr>             <dbl>    <dbl>
    #>  1 mlm       Androgen AAACATACAACCAC-1  0.559 0.576
    #>  2 mlm       EGFR     AAACATACAACCAC-1  3.63  0.000290
    #>  3 mlm       Estrogen AAACATACAACCAC-1 -0.886 0.375
    #>  4 mlm       Hypoxia  AAACATACAACCAC-1  1.22  0.224
    #>  5 mlm       JAK-STAT AAACATACAACCAC-1 -1.02  0.308
    #>  6 mlm       MAPK     AAACATACAACCAC-1 -2.74  0.00619
    #>  7 mlm       NFkB     AAACATACAACCAC-1 -0.230 0.818
    #>  8 mlm       PI3K     AAACATACAACCAC-1 -1.09  0.276
    #>  9 mlm       TGFb     AAACATACAACCAC-1  0.248 0.804
    #> 10 mlm       TNFa     AAACATACAACCAC-1  2.22  0.0264
    #> # ℹ 2,230 more rows

# 4 Visualization

From the obtained results, we will select the `ulm` activities and store them in our object as a new assay called `pathwaysmlm`:

    # Extract mlm and store it in pathwaysmlm in data
    data[['pathwaysmlm']] <- acts %>%
      pivot_wider(id_cols = 'source', names_from = 'condition',
                  values_from = 'score') %>%
      column_to_rownames('source') %>%
      Seurat::CreateAssayObject(.)

    # Change assay
    DefaultAssay(object = data) <- "pathwaysmlm"

    # Scale the data
    data <- ScaleData(data)
    data@assays$pathwaysmlm@data <- data@assays$pathwaysmlm@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

# 5 Exploration

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$pathwaysmlm@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.

# 6 Session information

    #> ─ Session info ───────────────────────────────────────────────────────────────────────────────────────────────────────
    #>  setting  value
    #>  version  R version 4.5.0 RC (2025-04-04 r88126 ucrt)
    #>  os       Windows Server 2022 x64 (build 20348)
    #>  system   x86_64, mingw32
    #>  ui       RTerm
    #>  language (EN)
    #>  collate  C
    #>  ctype    English_United States.utf8
    #>  tz       America/New_York
    #>  date     2025-04-15
    #>  pandoc   2.7.3 @ C:/PROGRA~1/Pandoc/ (via rmarkdown)
    #>  quarto   NA
    #>
    #> ─ Packages ───────────────────────────────────────────────────────────────────────────────────────────────────────────
    #>  package          * version   date (UTC) lib source
    #>  abind              1.4-8     2024-09-12 [2] CRAN (R 4.5.0)
    #>  backports          1.5.0     2024-05-23 [2] CRAN (R 4.5.0)
    #>  bibtex             0.5.1     2023-01-26 [2] CRAN (R 4.5.0)
    #>  BiocManager        1.30.25   2024-08-28 [2] CRAN (R 4.5.0)
    #>  BiocParallel       1.42.0    2025-04-15 [2] Bioconductor 3.21 (R 4.5.0)
    #>  BiocStyle        * 2.36.0    2025-04-15 [2] Bioconductor 3.21 (R 4.5.0)
    #>  bit                4.6.0     2025-03-06 [2] CRAN (R 4.5.0)
    #>  bit64              4.6.0-1   2025-01-16 [2] CRAN (R 4.5.0)
    #>  blob               1.2.4     2023-03-17 [2] CRAN (R 4.5.0)
    #>  bookdown           0.43      2025-04-15 [2] CRAN (R 4.5.0)
    #>  bslib              0.9.0     2025-01-30 [2] CRAN (R 4.5.0)
    #>  cachem             1.1.0     2024-05-16 [2] CRAN (R 4.5.0)
    #>  cellranger         1.1.0     2016-07-27 [2] CRAN (R 4.5.0)
    #>  checkmate          2.3.2     2024-07-29 [2] CRAN (R 4.5.0)
    #>  chromote           0.5.0     2025-03-21 [2] CRAN (R 4.5.0)
    #>  cli                3.6.4     2025-02-13 [2] CRAN (R 4.5.0)
    #>  cluster            2.1.8.1   2025-03-12 [2] CRAN (R 4.5.0)
    #>  codetools          0.2-20    2024-03-31 [2] CRAN (R 4.5.0)
    #>  colorspace         2.1-1     2024-07-26 [2] CRAN (R 4.5.0)
    #>  cowplot            1.1.3     2024-01-22 [2] CRAN (R 4.5.0)
    #>  crayon             1.5.3     2024-06-20 [2] CRAN (R 4.5.0)
    #>  curl               6.2.2     2025-03-24 [2] CRAN (R 4.5.0)
    #>  data.table         1.17.0    2025-02-22 [2] CRAN (R 4.5.0)
    #>  DBI                1.2.3     2024-06-02 [2] CRAN (R 4.5.0)
    #>  decoupleR        * 2.14.0    2025-04-15 [1] Bioconductor 3.21 (R 4.5.0)
    #>  deldir             2.0-4     2024-02-28 [2] CRAN (R 4.5.0)
    #>  digest             0.6.37    2024-08-19 [2] CRAN (R 4.5.0)
    #>  dotCall64          1.2       2024-10-04 [2] CRAN (R 4.5.0)
    #>  dplyr            * 1.1.4     2023-11-17 [2] CRAN (R 4.5.0)
    #>  evaluate           1.0.3     2025-01-10 [2] CRAN (R 4.5.0)
    #>  farver             2.1.2     2024-05-13 [2] CRAN (R 4.5.0)
    #>  fastDummies        1.7.5     2025-01-20 [2] CRAN (R 4.5.0)
    #>  fastmap            1.2.0     2024-05-15 [2] CRAN (R 4.5.0)
    #>  fastmatch          1.1-6     2024-12-23 [2] CRAN (R 4.5.0)
    #>  fgsea              1.34.0    2025-04-15 [2] Bioconductor 3.21 (R 4.5.0)
    #>  fitdistrplus       1.2-2     2025-01-07 [2] CRAN (R 4.5.0)
    #>  fs                 1.6.6     2025-04-12 [2] CRAN (R 4.5.0)
    #>  future             1.40.0    2025-04-10 [2] CRAN (R 4.5.0)
    #>  future.apply       1.11.3    2024-10-27 [2] CRAN (R 4.5.0)
    #>  generics           0.1.3     2022-07-05 [2] CRAN (R 4.5.0)
    #>  ggplot2          * 3.5.2     2025-04-09 [2] CRAN (R 4.5.0)
    #>  ggrepel          * 0.9.6     2024-09-07 [2] CRAN (R 4.5.0)
    #>  ggridges           0.5.6     2024-01-23 [2] CRAN (R 4.5.0)
    #>  globals            0.16.3    2024-03-08 [2] CRAN (R 4.5.0)
    #>  glue               1.8.0     2024-09-30 [2] CRAN (R 4.5.0)
    #>  goftest            1.2-3     2021-10-07 [2] CRAN (R 4.5.0)
    #>  gridExtra          2.3       2017-09-09 [2] CRAN (R 4.5.0)
    #>  gtable             0.3.6     2024-10-25 [2] CRAN (R 4.5.0)
    #>  hms                1.1.3     2023-03-21 [2] CRAN (R 4.5.0)
    #>  htmltools          0.5.8.1   2024-04-04 [2] CRAN (R 4.5.0)
    #>  htmlwidgets        1.6.4     2023-12-06 [2] CRAN (R 4.5.0)
    #>  httpuv             1.6.15    2024-03-26 [2] CRAN (R 4.5.0)
    #>  httr               1.4.7     2023-08-15 [2] CRAN (R 4.5.0)
    #>  httr2              1.1.2     2025-03-26 [2] CRAN (R 4.5.0)
    #>  ica                1.0-3     2022-07-08 [2] CRAN (R 4.5.0)
    #>  igraph             2.1.4     2025-01-23 [2] CRAN (R 4.5.0)
    #>  irlba              2.3.5.1   2022-10-03 [2] CRAN (R 4.5.0)
    #>  jquerylib          0.1.4     2021-04-26 [2] CRAN (R 4.5.0)
    #>  jsonlite           2.0.0     2025-03-27 [2] CRAN (R 4.5.0)
    #>  KernSmooth         2.23-26   2025-01-01 [2] CRAN (R 4.5.0)
    #>  knitr              1.50      2025-03-16 [2] CRAN (R 4.5.0)
    #>  labeling           0.4.3     2023-08-29 [2] CRAN (R 4.5.0)
    #>  later              1.4.2     2025-04-08 [2] CRAN (R 4.5.0)
    #>  lattice            0.22-7    2025-04-02 [2] CRAN (R 4.5.0)
    #>  lazyeval           0.2.2     2019-03-15 [2] CRAN (R 4.5.0)
    #>  lifecycle          1.0.4     2023-11-07 [2] CRAN (R 4.5.0)
    #>  listenv            0.9.1     2024-01-29 [2] CRAN (R 4.5.0)
    #>  lmtest             0.9-40    2022-03-21 [2] CRAN (R 4.5.0)
    #>  logger             0.4.0     2024-10-22 [2] CRAN (R 4.5.0)
    #>  lubridate          1.9.4     2024-12-08 [2] CRAN (R 4.5.0)
    #>  magick             2.8.6     2025-03-23 [2] CRAN (R 4.5.0)
    #>  magrittr           2.0.3     2022-03-30 [2] CRAN (R 4.5.0)
    #>  MASS               7.3-65    2025-02-28 [2] CRAN (R 4.5.0)
    #>  Matrix             1.7-3     2025-03-11 [2] CRAN (R 4.5.0)
    #>  matrixStats        1.5.0     2025-01-07 [2] CRAN (R 4.5.0)
    #>  memoise            2.0.1     2021-11-26 [2] CRAN (R 4.5.0)
    #>  mime               0.13      2025-03-17 [2] CRAN (R 4.5.0)
    #>  miniUI             0.1.1.1   2018-05-18 [2] CRAN (R 4.5.0)
    #>  munsell            0.5.1     2024-04-01 [2] CRAN (R 4.5.0)
    #>  nlme               3.1-168   2025-03-31 [2] CRAN (R 4.5.0)
    #>  OmnipathR          3.16.0    2025-04-15 [2] Bioconductor 3.21 (R 4.5.0)
    #>  parallelly         1.43.0    2025-03-24 [2] CRAN (R 4.5.0)
    #>  patchwork        * 1.3.0     2024-09-16 [2] CRAN (R 4.5.0)
    #>  pbapply            1.7-2     2023-06-27 [2] CRAN (R 4.5.0)
    #>  pheatmap         * 1.0.12    2019-01-04 [2] CRAN (R 4.5.0)
    #>  pillar             1.10.2    2025-04-05 [2] CRAN (R 4.5.0)
    #>  pkgconfig          2.0.3     2019-09-22 [2] CRAN (R 4.5.0)
    #>  plotly             4.10.4    2024-01-13 [2] CRAN (R 4.5.0)
    #>  plyr               1.8.9     2023-10-02 [2] CRAN (R 4.5.0)
    #>  png                0.1-8     2022-11-29 [2] CRAN (R 4.5.0)
    #>  polyclip           1.10-7    2024-07-23 [2] CRAN (R 4.5.0)
    #>  prettyunits        1.2.0     2023-09-24 [2] CRAN (R 4.5.0)
    #>  processx           3.8.6     2025-02-21 [2] CRAN (R 4.5.0)
    #>  progress           1.2.3     2023-12-06 [2] CRAN (R 4.5.0)
    #>  progressr          0.15.1    2024-11-22 [2] CRAN (R 4.5.0)
    #>  promises           1.3.2     2024-11-28 [2] CRAN (R 4.5.0)
    #>  ps                 1.9.1     2025-04-12 [2] CRAN (R 4.5.0)
    #>  purrr              1.0.4     2025-02-05 [2] CRAN (R 4.5.0)
    #>  R.methodsS3        1.8.2     2022-06-13 [2] CRAN (R 4.5.0)
    #>  R.oo               1.27.0    2024-11-01 [2] CRAN (R 4.5.0)
    #>  R.utils            2.13.0    2025-02-24 [2] CRAN (R 4.5.0)
    #>  R6                 2.6.1     2025-02-15 [2] CRAN (R 4.5.0)
    #>  RANN               2.6.2     2024-08-25 [2] CRAN (R 4.5.0)
    #>  rappdirs           0.3.3     2021-01-31 [2] CRAN (R 4.5.0)
    #>  RColorBrewer       1.1-3     2022-04-03 [2] CRAN (R 4.5.0)
    #>  Rcpp               1.0.14    2025-01-12 [2] CRAN (R 4.5.0)
    #>  RcppAnnoy          0.0.22    2024-01-23 [2] CRAN (R 4.5.0)
    #>  RcppHNSW           0.6.0     2024-02-04 [2] CRAN (R 4.5.0)
    #>  readr              2.1.5     2024-01-10 [2] CRAN (R 4.5.0)
    #>  readxl             1.4.5     2025-03-07 [2] CRAN (R 4.5.0)
    #>  RefManageR       * 1.4.0     2022-09-30 [2] CRAN (R 4.5.0)
    #>  reshape2           1.4.4     2020-04-09 [2] CRAN (R 4.5.0)
    #>  reticulate         1.42.0    2025-03-25 [2] CRAN (R 4.5.0)
    #>  rlang              1.1.6     2025-04-11 [2] CRAN (R 4.5.0)
    #>  rmarkdown          2.29      2024-11-04 [2] CRAN (R 4.5.0)
    #>  ROCR               1.0-11    2020-05-02 [2] CRAN (R 4.5.0)
    #>  RSpectra           0.16-2    2024-07-18 [2] CRAN (R 4.5.0)
    #>  RSQLite            2.3.9     2024-12-03 [2] CRAN (R 4.5.0)
    #>  Rtsne              0.17      2023-12-07 [2] CRAN (R 4.5.0)
    #>  rvest              1.0.4     2024-02-12 [2] CRAN (R 4.5.0)
    #>  sass               0.4.10    2025-04-11 [2] CRAN (R 4.5.0)
    #>  scales             1.3.0     2023-11-28 [2] CRAN (R 4.5.0)
    #>  scattermore        1.2       2023-06-12 [2] CRAN (R 4.5.0)
    #>  sctransform        0.4.1     2023-10-19 [2] CRAN (R 4.5.0)
    #>  selectr            0.4-2     2019-11-20 [2] CRAN (R 4.5.0)
    #>  sessioninfo        1.2.3     2025-02-05 [2] CRAN (R 4.5.0)
    #>  Seurat           * 5.2.1     2025-01-24 [2] CRAN (R 4.5.0)
    #>  SeuratObject     * 5.0.2     2024-05-08 [2] CRAN (R 4.5.0)
    #>  shiny              1.10.0    2024-12-14 [2] CRAN (R 4.5.0)
    #>  sp               * 2.2-0     2025-02-01 [2] CRAN (R 4.5.0)
    #>  spam               2.11-1    2025-01-20 [2] CRAN (R 4.5.0)
    #>  spatstat.data      3.1-6     2025-03-17 [2] CRAN (R 4.5.0)
    #>  spatstat.explore   3.4-2     2025-03-21 [2] CRAN (R 4.5.0)
    #>  spatstat.geom      3.3-6     2025-03-18 [2] CRAN (R 4.5.0)
    #>  spatstat.random    3.3-3     2025-03-19 [2] CRAN (R 4.5.0)
    #>  spatstat.sparse    3.1-0     2024-06-21 [2] CRAN (R 4.5.0)
    #>  spatstat.univar    3.1-2     2025-03-05 [2] CRAN (R 4.5.0)
    #>  spatstat.utils     3.1-3     2025-03-15 [2] CRAN (R 4.5.0)
    #>  stringi            1.8.7     2025-03-27 [2] CRAN (R 4.5.0)
    #>  stringr            1.5.1     2023-11-14 [2] CRAN (R 4.5.0)
    #>  survival           3.8-3     2024-12-17 [2] CRAN (R 4.5.0)
    #>  tensor             1.5       2012-05-05 [2] CRAN (R 4.5.0)
    #>  tibble           * 3.2.1     2023-03-20 [2] CRAN (R 4.5.0)
    #>  tidyr            * 1.3.1     2024-01-24 [2] CRAN (R 4.5.0)
    #>  tidyselect         1.2.1     2024-03-11 [2] CRAN (R 4.5.0)
    #>  timechange         0.3.0     2024-01-18 [2] CRAN (R 4.5.0)
    #>  tinytex            0.57      2025-04-15 [2] CRAN (R 4.5.0)
    #>  tzdb               0.5.0     2025-03-15 [2] CRAN (R 4.5.0)
    #>  utf8               1.2.4     2023-10-22 [2] CRAN (R 4.5.0)
    #>  uwot               0.2.3     2025-02-24 [2] CRAN (R 4.5.0)
    #>  vctrs              0.6.5     2023-12-01 [2] CRAN (R 4.5.0)
    #>  viridisLite        0.4.2     2023-05-02 [2] CRAN (R 4.5.0)
    #>  vroom              1.6.5     2023-12-05 [2] CRAN (R 4.5.0)
    #>  websocket          1.4.4     2025-04-10 [2] CRAN (R 4.5.0)
    #>  withr              3.0.2     2024-10-28 [2] CRAN (R 4.5.0)
    #>  xfun               0.52      2025-04-02 [2] CRAN (R 4.5.0)
    #>  XML                3.99-0.18 2025-01-01 [2] CRAN (R 4.5.0)
    #>  xml2               1.3.8     2025-03-14 [2] CRAN (R 4.5.0)
    #>  xtable             1.8-4     2019-04-21 [2] CRAN (R 4.5.0)
    #>  yaml               2.3.10    2024-07-26 [2] CRAN (R 4.5.0)
    #>  zip                2.3.2     2025-02-01 [2] CRAN (R 4.5.0)
    #>  zoo                1.8-14    2025-04-10 [2] CRAN (R 4.5.0)
    #>
    #>  [1] E:/biocbuild/bbs-3.21-bioc/tmpdir/RtmpywaJ0p/Rinst1d53462ac34e7
    #>  [2] E:/biocbuild/bbs-3.21-bioc/R/library
    #>  * ── Packages attached to the search path.
    #>
    #> ──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────