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/).
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.
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()
.
## 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
## 5.360167e-18 0.000000e+00 0.000000e+00 8.660254e-01 8.660254e-01 0.000000e+00
## CHST11 CHST15 CHPF2 CSGALNACT2 CHST12 CSGALNACT1
## 0.000000e+00 0.000000e+00 6.124466e-17 5.000000e-01 5.620225e-17 0.000000e+00
## CHST7 XYLT1 XYLT2 CHPF CHST14 B3GALT6
## 0.000000e+00 0.000000e+00 1.000000e+00 0.000000e+00 5.000000e-01 0.000000e+00
## CHST13 CHSY3
## 4.807407e-17 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
.
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/).
## R version 4.4.2 (2024-10-31)
## Platform: x86_64-pc-linux-gnu
## Running under: Ubuntu 24.04.1 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=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: Etc/UTC
## 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.2
## [4] S4Vectors_0.45.2 Biobase_2.67.0 BiocGenerics_0.53.3
## [7] generics_0.1.3 bnlearn_5.0.1 CBNplot_1.7.0
## [10] BiocStyle_2.35.0
##
## loaded via a namespace (and not attached):
## [1] RColorBrewer_1.1-3 sys_3.4.3 jsonlite_1.8.9
## [4] pvclust_2.2-0 magrittr_2.0.3 ggtangle_0.0.6
## [7] farver_2.1.2 rmarkdown_2.29 fs_1.6.5
## [10] zlibbioc_1.52.0 vctrs_0.6.5 memoise_2.0.1
## [13] ggtree_3.15.0 htmltools_0.5.8.1 distributional_0.5.0
## [16] AnnotationHub_3.15.0 curl_6.0.1 gridGraphics_0.5-1
## [19] sass_0.4.9 bslib_0.8.0 plyr_1.8.9
## [22] cachem_1.1.0 buildtools_1.0.0 igraph_2.1.2
## [25] lifecycle_1.0.4 pkgconfig_2.0.3 Matrix_1.7-1
## [28] R6_2.5.1 fastmap_1.2.0 gson_0.1.0
## [31] GenomeInfoDbData_1.2.13 digest_0.6.37 aplot_0.2.4
## [34] enrichplot_1.27.3 colorspace_2.1-1 patchwork_1.3.0
## [37] ExperimentHub_2.15.0 RSQLite_2.3.9 labeling_0.4.3
## [40] filelock_1.0.3 httr_1.4.7 polyclip_1.10-7
## [43] compiler_4.4.2 bit64_4.5.2 withr_3.0.2
## [46] graphite_1.53.0 BiocParallel_1.41.0 viridis_0.6.5
## [49] DBI_1.2.3 ggforce_0.4.2 R.utils_2.12.3
## [52] MASS_7.3-61 rappdirs_0.3.3 tools_4.4.2
## [55] ape_5.8-1 R.oo_1.27.0 glue_1.8.0
## [58] nlme_3.1-166 GOSemSim_2.33.0 grid_4.4.2
## [61] reshape2_1.4.4 fgsea_1.33.0 gtable_0.3.6
## [64] R.methodsS3_1.8.2 tidyr_1.3.1 data.table_1.16.4
## [67] tidygraph_1.3.1 XVector_0.47.0 ggrepel_0.9.6
## [70] BiocVersion_3.21.1 pillar_1.10.0 ggdist_3.3.2
## [73] stringr_1.5.1 yulab.utils_0.1.8 splines_4.4.2
## [76] dplyr_1.1.4 tweenr_2.0.3 BiocFileCache_2.15.0
## [79] treeio_1.31.0 lattice_0.22-6 gmp_0.7-5
## [82] bit_4.5.0.1 tidyselect_1.2.1 GO.db_3.20.0
## [85] maketools_1.3.1 Biostrings_2.75.3 knitr_1.49
## [88] gridExtra_2.3 xfun_0.49 graphlayouts_1.2.1
## [91] stringi_1.8.4 UCSC.utils_1.3.0 lazyeval_0.2.2
## [94] ggfun_0.1.8 yaml_2.3.10 evaluate_1.0.1
## [97] codetools_0.2-20 ggraph_2.2.1 tibble_3.2.1
## [100] qvalue_2.39.0 graph_1.85.0 BiocManager_1.30.25
## [103] ggplotify_0.1.2 cli_3.6.3 munsell_0.5.1
## [106] jquerylib_0.1.4 Rcpp_1.0.13-1 GenomeInfoDb_1.43.2
## [109] dbplyr_2.5.0 png_0.1-8 parallel_4.4.2
## [112] ggplot2_3.5.1 blob_1.2.4 clusterProfiler_4.15.1
## [115] DOSE_4.1.0 Rmpfr_1.0-0 viridisLite_0.4.2
## [118] tidytree_0.4.6 scales_1.3.0 purrr_1.0.2
## [121] crayon_1.5.3 rlang_1.1.4 cowplot_1.1.3
## [124] fastmatch_1.1-4 KEGGREST_1.47.0