# BulkSignalR : Inference of ligand-receptor interactions from bulk data or spatial transcriptomics

    library(BulkSignalR)

## Cluster-based differential analysis

By default, `BulkSignalR` inference of L-R interactions relies on correlation analysis across all the samples. That is, a putative L-R interaction is assessed for coherent expression of the ligand, the receptor, and target genes in a pathway below receptor across all the samples.

Alternatively, it is possible to define sample clusters based on an independent analysis (outside of `BulkSignalR`) to group similar samples. Based on cluster definitions, it is for instance possible to assess whether L-R interactions are significantly stronger in a cluster compared to all the samples, to all the samples but the chosen cluster, or in comparison with another cluster. In practice, the user must simply provide a table of differential gene or protein expression analysis that is relevant for the selected comparison.

In this mode, L-R interactions are inferred based on gene or protein regulation-associated P-values instead of P-values resulting from the correlation analysis in the default mode. As already stated, differential P-value estimations are left to the user to compute. With bulk data, commonly used libraries such as `DESeq2`, `EdgeR`, or `limma` constitute obvious options.

In the next chunk of code, we illustrate the differential mode using Salivary Duct Carcinoma (SDC) samples where we compare two clusters of patients.

We first create a BSRDataModelComp object as follows:

    data(sdc, package = "BulkSignalR")
    normal <- grep("^N", names(sdc))
    bsrdm.comp <- BSRDataModelComp(sdc[, -normal])

To make a very small example we generate random values, but user should provide his own logFC and associated pvalues from DGE ouputs.

    colA <- as.integer(1:3)
    colB <- as.integer(12:15)

    n <- nrow(ncounts(bsrdm.comp))
    stats <- data.frame(pval = runif(n),
    logFC = rnorm(n, 0, 2),
    expr = runif(n, 0, 10))
    rownames(stats) <- rownames(ncounts(bsrdm.comp))

We define the cluster comparison and add it.

    bsrcc <- BSRClusterComp(bsrdm.comp, colA, colB, stats)
    bsrdm.comp <- addClusterComp(bsrdm.comp, bsrcc, "random.example")

Finally we infer ligand-receptor interactions from the comparison. We use a subset of the reference to speed up inference in the context of the vignette.

    subset <- c("REACTOME_BASIGIN_INTERACTIONS",
    "REACTOME_SYNDECAN_INTERACTIONS",
    "REACTOME_ECM_PROTEOGLYCANS",
    "REACTOME_CELL_JUNCTION_ORGANIZATION")

    reactSubset <- BulkSignalR:::.SignalR$BulkSignalR_Reactome[
    BulkSignalR:::.SignalR$BulkSignalR_Reactome$`Reactome name` %in% subset,]

    resetPathways(dataframe = reactSubset,
    resourceName = "Reactome")

    bsrinf.comp <- BSRInferenceComp(bsrdm.comp,
    reference="REACTOME",
    max.pval = 1,
    "random.example")

    ## Warning: executing %dopar% sequentially: no parallel backend registered

    head(LRinter(bsrinf.comp))

    ##          L     R         pw.id                        pw.name         pval
    ## 4   ADAM15 ITGA9 R-HSA-3000178     REACTOME_ECM_PROTEOGLYCANS 1.014830e-02
    ## 5    ADAM2 ITGA9 R-HSA-3000178     REACTOME_ECM_PROTEOGLYCANS 1.684147e-03
    ## 50    CCL5  SDC1 R-HSA-3000170 REACTOME_SYNDECAN_INTERACTIONS 3.165758e-03
    ## 57    CHAD ITGA2 R-HSA-3000170 REACTOME_SYNDECAN_INTERACTIONS 5.092681e-05
    ## 571   CHAD ITGA2 R-HSA-3000178     REACTOME_ECM_PROTEOGLYCANS 3.425894e-04
    ## 63  COL1A1 ITGA2 R-HSA-3000170 REACTOME_SYNDECAN_INTERACTIONS 1.607012e-04
    ##             qval  L.logFC  R.logFC     LR.pval LR.corr rank len rank.pval
    ## 4   0.0118396834 2.023610 2.368799 0.287978495       1    9  17 0.2936072
    ## 5   0.0032747300 3.353043 2.368799 0.047791066       1    9  17 0.2936072
    ## 50  0.0048174581 3.978688 3.030656 0.160335464       1    6  11 0.2226152
    ## 57  0.0003564877 1.802674 2.595412 0.008211812       1    3   7 0.2127364
    ## 571 0.0013322920 1.802674 2.595412 0.008211812       1   11  20 0.2936072
    ## 63  0.0007030677 1.700530 2.595412 0.025912638       1    3   7 0.2127364
    ##     rank.corr  LR.score   L.expr   R.expr
    ## 4           1 0.1860076 3.266958 9.713744
    ## 5           1 0.1777825 2.665768 9.713744
    ## 50          1 0.1577640 2.894627 4.476829
    ## 57          1 0.2128822 6.555079 9.842844
    ## 571         1 0.2128822 6.555079 9.842844
    ## 63          1 0.2013048 4.790427 9.842844

## Technical notes

The three basic `BulkSignalR` S4 classes BSRDataModel, BSRInference, and BSRSignature were derived into new classes to add the functionalities required by the differential mode:

- BSRDataModelComp, denoted here as `bsrdm.comp` is a daughter class of BSRDataModel, previously denoted `bsrdm`
- BSRInferenceComp, denoted here as `bsrinf.comp` is a daughter class of BSRInference, previously denoted `bsrinf`
- BSRSignatureComp, denoted here as `bsrsig.comp` is a daughter class of BSRSignature, previously denoted `bsrsig`

The new S4 class BSRClusterComp is meant to represent the comparison between two clusters of samples. It primarily contains the results of the user-provided differential analysis in a table containing gene/protein names, P-values, and log-fold-changes (logFC).

Usually, we recommend instantiating a `BSRDataModel` object to contain the expression matrix underlying the differential analysis. Then, it is promoted into a `BSRDataModelComp` object such that cluster definitions and comparisons can be added to it. This can be for instance done with `as(bsrdm, "BSRDataModelComp")`. The `addClusterComp` method of a `BSRDataModelComp` object allows adding one or several comparisons between clusters, each added comparison being defined in a `BSRClusterComp` object.

Thank you for reading this guide and for using `BulkSignalR`.

## Session Information

    sessionInfo()

    ## R version 4.6.0 (2026-04-24)
    ## Platform: x86_64-pc-linux-gnu
    ## Running under: Ubuntu 24.04.4 LTS
    ##
    ## Matrix products: default
    ## BLAS:   /usr/lib/x86_64-linux-gnu/openblas-pthread/libblas.so.3
    ## LAPACK: /usr/lib/x86_64-linux-gnu/openblas-pthread/libopenblasp-r0.3.26.so;  LAPACK version 3.12.0
    ##
    ## 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
    ##
    ## time zone: Etc/UTC
    ## tzcode source: system (glibc)
    ##
    ## attached base packages:
    ## [1] stats     graphics  grDevices utils     datasets  methods   base
    ##
    ## other attached packages:
    ## [1] BulkSignalR_1.4.0 rmarkdown_2.31
    ##
    ## loaded via a namespace (and not attached):
    ##   [1] RColorBrewer_1.1-3          sys_3.4.3
    ##   [3] jsonlite_2.0.0              shape_1.4.6.1
    ##   [5] magrittr_2.0.5              magick_2.9.1
    ##   [7] farver_2.1.2                GlobalOptions_0.1.4
    ##   [9] fs_2.1.0                    vctrs_0.7.3
    ##  [11] multtest_2.68.0             memoise_2.0.1
    ##  [13] RCurl_1.98-1.18             ggtree_4.2.0
    ##  [15] rstatix_0.7.3               htmltools_0.5.9
    ##  [17] S4Arrays_1.12.0             curl_7.1.0
    ##  [19] broom_1.0.12                SparseArray_1.12.0
    ##  [21] Formula_1.2-5               gridGraphics_0.5-1
    ##  [23] sass_0.4.10                 bslib_0.10.0
    ##  [25] htmlwidgets_1.6.4           httr2_1.2.2
    ##  [27] plotly_4.12.0               cachem_1.1.0
    ##  [29] buildtools_1.0.0            igraph_2.3.0
    ##  [31] lifecycle_1.0.5             iterators_1.0.14
    ##  [33] pkgconfig_2.0.3             Matrix_1.7-5
    ##  [35] R6_2.6.1                    fastmap_1.2.0
    ##  [37] MatrixGenerics_1.24.0       clue_0.3-68
    ##  [39] digest_0.6.39               aplot_0.2.9
    ##  [41] colorspace_2.1-2            patchwork_1.3.2
    ##  [43] S4Vectors_0.50.0            GenomicRanges_1.64.0
    ##  [45] RSQLite_2.4.6               ggpubr_0.6.3
    ##  [47] filelock_1.0.3              httr_1.4.8
    ##  [49] abind_1.4-8                 compiler_4.6.0
    ##  [51] withr_3.0.2                 bit64_4.8.0
    ##  [53] fontquiver_0.2.1            doParallel_1.0.17
    ##  [55] S7_0.2.2                    backports_1.5.1
    ##  [57] orthogene_1.18.1            carData_3.0-6
    ##  [59] DBI_1.3.0                   homologene_1.4.68.19.3.27
    ##  [61] ggsignif_0.6.4              MASS_7.3-65
    ##  [63] rappdirs_0.3.4              DelayedArray_0.38.0
    ##  [65] rjson_0.2.23                tools_4.6.0
    ##  [67] otel_0.2.0                  ape_5.8-1
    ##  [69] glue_1.8.1                  stabledist_0.7-2
    ##  [71] nlme_3.1-169                grid_4.6.0
    ##  [73] Rtsne_0.17                  cluster_2.1.8.2
    ##  [75] generics_0.1.4              gtable_0.3.6
    ##  [77] tidyr_1.3.2                 data.table_1.18.2.1
    ##  [79] car_3.1-5                   XVector_0.52.0
    ##  [81] BiocGenerics_0.58.0         ggrepel_0.9.8
    ##  [83] RANN_2.6.2                  foreach_1.5.2
    ##  [85] pillar_1.11.1               yulab.utils_0.2.4
    ##  [87] babelgene_22.9              circlize_0.4.18
    ##  [89] splines_4.6.0               dplyr_1.2.1
    ##  [91] treeio_1.36.0               BiocFileCache_3.2.0
    ##  [93] lattice_0.22-9              survival_3.8-6
    ##  [95] bit_4.6.0                   tidyselect_1.2.1
    ##  [97] fontLiberation_0.1.0        ComplexHeatmap_2.28.0
    ##  [99] SingleCellExperiment_1.34.0 maketools_1.3.2
    ## [101] knitr_1.51                  fontBitstreamVera_0.1.1
    ## [103] gridExtra_2.3               IRanges_2.46.0
    ## [105] Seqinfo_1.2.0               SummarizedExperiment_1.42.0
    ## [107] stats4_4.6.0                xfun_0.57
    ## [109] Biobase_2.72.0              matrixStats_1.5.0
    ## [111] lazyeval_0.2.3              ggfun_0.2.0
    ## [113] yaml_2.3.12                 evaluate_1.0.5
    ## [115] codetools_0.2-20            gdtools_0.5.0
    ## [117] tibble_3.3.1                ggplotify_0.1.3
    ## [119] cli_3.6.6                   systemfonts_1.3.2
    ## [121] jquerylib_0.1.4             Rcpp_1.1.1-1.1
    ## [123] gprofiler2_0.2.4            dbplyr_2.5.2
    ## [125] png_0.1-9                   parallel_4.6.0
    ## [127] ggplot2_4.0.3               blob_1.3.0
    ## [129] ggalluvial_0.12.6           bitops_1.0-9
    ## [131] glmnet_4.1-10               SpatialExperiment_1.22.0
    ## [133] viridisLite_0.4.3           tidytree_0.4.7
    ## [135] ggiraph_0.9.6               scales_1.4.0
    ## [137] purrr_1.2.2                 crayon_1.5.3
    ## [139] GetoptLong_1.1.1            rlang_1.2.0