The R package to infer and plot Bayesian networks. The network are inferred from expression data based on clusterProfiler or ReactomePA results. It makes use of libraries including clusterProfiler, ReactomePA, bnlearn, graphite and depmap. In this vignette, the description of functions and several use cases are depicted using random data. The more detailed use cases including the analysis of the dataset GSE133624, which contains RNA-Seq data of bladder cancer, can be found on the book (https://noriakis.github.io/CBNplot/).
BiocManager::install("CBNplot")
library(CBNplot)
library(bnlearn)
library(org.Hs.eg.db)
## Load data
data(gaussian.test)
## Draw genes in the KEGG pathway as DEG
kegg <- org.Hs.egPATH2EG
mapped <- mappedkeys(kegg)
genes <- as.list(kegg[mapped])[["00532"]]
## Random data
counts <- head(gaussian.test, length(genes))
row.names(counts) <- genes
## Perform enrichment analysis
pway <- clusterProfiler::enrichKEGG(gene = genes)
pway <- clusterProfiler::setReadable(pway, org.Hs.eg.db, keyType="ENTREZID")
Then use CBNplot. Basically, you need to supply the enrichment analysis result, normalized expression value and samples to be included. For bngeneplot
, the pathway number in the result
slot of enrichment analysis results must be given.
bngeneplot(results = pway,exp = counts, pathNum = 1, expRow="ENTREZID")
Data frame of raw values used in the inference, data frame containing strength and direction, averaged network, and plot can be obtained by specifying returnNet=TRUE
ret <- bngeneplot(results = pway,exp = counts, pathNum = 1, returnNet=TRUE, , expRow="ENTREZID")
head(ret$str)
FALSE from to strength direction
FALSE 1 CHST3 UST 0.25 0.4000000
FALSE 2 CHST3 B4GALT7 0.00 0.0000000
FALSE 3 CHST3 CHSY1 0.15 0.0000000
FALSE 4 CHST3 B3GAT3 0.30 0.5833333
FALSE 5 CHST3 DSE 0.10 0.5000000
FALSE 6 CHST3 CHST11 0.10 0.5000000
The resulting network can be converted to igraph
object using bnlearn::as.igraph()
.
g <- bnlearn::as.igraph(ret$av)
igraph::evcent(g)$vector
## Warning: `evcent()` was deprecated in igraph 2.0.0.
## ℹ Please use `eigen_centrality()` instead.
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.
## CHST3 UST B4GALT7 CHSY1 B3GAT3 DSE
## 0.000000e+00 1.201852e-17 0.000000e+00 8.660254e-01 8.660254e-01 0.000000e+00
## CHST11 CHST15 CHPF2 CSGALNACT2 CHST12 CSGALNACT1
## 0.000000e+00 0.000000e+00 0.000000e+00 5.000000e-01 0.000000e+00 0.000000e+00
## CHST7 XYLT1 XYLT2 CHPF CHST14 B3GALT6
## 0.000000e+00 0.000000e+00 1.000000e+00 0.000000e+00 5.000000e-01 1.201852e-17
## CHST13 CHSY3
## 0.000000e+00 0.000000e+00
The relationship between pathways can be drawn by bnpathplot
. The number to be included in the inference can be specified by nCategory
.
bnpathplot(results = pway,exp = counts, nCategory=5, shadowText = TRUE, expRow="ENTREZID")
bngeneplotCustom
and bnpathplotCustom
can be used to customize visualization with more flexibility, like highlighting the nodes and edges of interest by glowEdgeNum
and hub
.
bnpathplotCustom(results = pway, exp = counts, expRow="ENTREZID",
fontFamily="serif", glowEdgeNum=1, hub=1)
bngeneplotCustom(results = pway, exp = counts, expRow="ENTREZID",
pathNum=1, fontFamily="sans", glowEdgeNum=NULL, hub=1)
The detailed usage for the package, like including covariates to the plot and probabilistic reasoning is available in the package documentation (https://noriakis.github.io/CBNplot/).
sessionInfo()
## R Under development (unstable) (2024-10-21 r87258)
## Platform: x86_64-pc-linux-gnu
## Running under: Ubuntu 24.04.1 LTS
##
## Matrix products: default
## BLAS: /home/biocbuild/bbs-3.21-bioc/R/lib/libRblas.so
## LAPACK: /usr/lib/x86_64-linux-gnu/lapack/liblapack.so.3.12.0
##
## locale:
## [1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C
## [3] LC_TIME=en_GB LC_COLLATE=C
## [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: America/New_York
## tzcode source: system (glibc)
##
## attached base packages:
## [1] stats4 stats graphics grDevices utils datasets methods
## [8] base
##
## other attached packages:
## [1] org.Hs.eg.db_3.20.0 AnnotationDbi_1.69.0 IRanges_2.41.0
## [4] S4Vectors_0.45.0 Biobase_2.67.0 BiocGenerics_0.53.0
## [7] bnlearn_5.0.1 CBNplot_1.7.0 BiocStyle_2.35.0
##
## loaded via a namespace (and not attached):
## [1] RColorBrewer_1.1-3 jsonlite_1.8.9 pvclust_2.2-0
## [4] magrittr_2.0.3 magick_2.8.5 ggtangle_0.0.3
## [7] farver_2.1.2 rmarkdown_2.28 fs_1.6.4
## [10] zlibbioc_1.53.0 vctrs_0.6.5 memoise_2.0.1
## [13] ggtree_3.15.0 tinytex_0.53 htmltools_0.5.8.1
## [16] distributional_0.5.0 AnnotationHub_3.15.0 curl_5.2.3
## [19] gridGraphics_0.5-1 sass_0.4.9 bslib_0.8.0
## [22] plyr_1.8.9 cachem_1.1.0 igraph_2.1.1
## [25] lifecycle_1.0.4 pkgconfig_2.0.3 gson_0.1.0
## [28] Matrix_1.7-1 R6_2.5.1 fastmap_1.2.0
## [31] GenomeInfoDbData_1.2.13 digest_0.6.37 aplot_0.2.3
## [34] enrichplot_1.27.0 colorspace_2.1-1 patchwork_1.3.0
## [37] ExperimentHub_2.15.0 RSQLite_2.3.7 labeling_0.4.3
## [40] filelock_1.0.3 fansi_1.0.6 httr_1.4.7
## [43] polyclip_1.10-7 compiler_4.5.0 bit64_4.5.2
## [46] withr_3.0.2 graphite_1.53.0 BiocParallel_1.41.0
## [49] viridis_0.6.5 DBI_1.2.3 highr_0.11
## [52] ggforce_0.4.2 R.utils_2.12.3 MASS_7.3-61
## [55] rappdirs_0.3.3 tools_4.5.0 ape_5.8
## [58] R.oo_1.26.0 glue_1.8.0 nlme_3.1-166
## [61] GOSemSim_2.33.0 grid_4.5.0 reshape2_1.4.4
## [64] fgsea_1.33.0 generics_0.1.3 gtable_0.3.6
## [67] R.methodsS3_1.8.2 tidyr_1.3.1 data.table_1.16.2
## [70] tidygraph_1.3.1 utf8_1.2.4 XVector_0.47.0
## [73] ggdist_3.3.2 ggrepel_0.9.6 BiocVersion_3.21.1
## [76] pillar_1.9.0 stringr_1.5.1 yulab.utils_0.1.7
## [79] splines_4.5.0 dplyr_1.1.4 tweenr_2.0.3
## [82] BiocFileCache_2.15.0 treeio_1.31.0 lattice_0.22-6
## [85] gmp_0.7-5 bit_4.5.0 tidyselect_1.2.1
## [88] GO.db_3.20.0 Biostrings_2.75.0 knitr_1.48
## [91] gridExtra_2.3 bookdown_0.41 xfun_0.48
## [94] graphlayouts_1.2.0 stringi_1.8.4 UCSC.utils_1.3.0
## [97] lazyeval_0.2.2 ggfun_0.1.7 yaml_2.3.10
## [100] evaluate_1.0.1 codetools_0.2-20 ggraph_2.2.1
## [103] tibble_3.2.1 qvalue_2.39.0 graph_1.85.0
## [106] BiocManager_1.30.25 ggplotify_0.1.2 cli_3.6.3
## [109] munsell_0.5.1 jquerylib_0.1.4 Rcpp_1.0.13
## [112] GenomeInfoDb_1.43.0 dbplyr_2.5.0 png_0.1-8
## [115] parallel_4.5.0 ggplot2_3.5.1 blob_1.2.4
## [118] clusterProfiler_4.15.0 DOSE_4.1.0 Rmpfr_0.9-5
## [121] viridisLite_0.4.2 tidytree_0.4.6 scales_1.3.0
## [124] purrr_1.0.2 crayon_1.5.3 rlang_1.1.4
## [127] cowplot_1.1.3 fastmatch_1.1-4 KEGGREST_1.47.0