1 CBNplot: Bayesian network plot for clusterProfiler results

1.1 Introduction

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/).

1.2 Installation

BiocManager::install("CBNplot")

1.3 Usage

1.3.1 Generation of data

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

1.3.2 The use of CBNplot

1.4 bngeneplot

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 
## 7.211110e-16 8.252696e-18 0.000000e+00 8.660254e-01 8.660254e-01 7.691851e-16 
##       CHST11       CHST15        CHPF2   CSGALNACT2       CHST12   CSGALNACT1 
## 9.374443e-16 0.000000e+00 7.691851e-16 5.000000e-01 6.970740e-16 5.528518e-16 
##        CHST7        XYLT1        XYLT2         CHPF       CHST14      B3GALT6 
## 6.249629e-16 0.000000e+00 1.000000e+00 1.057629e-15 5.000000e-01 8.252696e-18 
##       CHST13        CHSY3 
## 5.768888e-16 0.000000e+00

1.5 bnpathplot

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

1.6 bngeneplotCustom and bnpathplotCustom

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 version 4.4.1 (2024-06-14)
## Platform: x86_64-pc-linux-gnu
## Running under: Ubuntu 22.04.5 LTS
## 
## Matrix products: default
## BLAS:   /home/biocbuild/bbs-3.19-bioc/R/lib/libRblas.so 
## LAPACK: /usr/lib/x86_64-linux-gnu/lapack/liblapack.so.3.10.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.19.1  AnnotationDbi_1.66.0 IRanges_2.38.1      
## [4] S4Vectors_0.42.1     Biobase_2.64.0       BiocGenerics_0.50.0 
## [7] bnlearn_5.0.1        CBNplot_1.4.2        BiocStyle_2.32.1    
## 
## 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            farver_2.1.2           
##   [7] rmarkdown_2.28          fs_1.6.4                zlibbioc_1.50.0        
##  [10] vctrs_0.6.5             memoise_2.0.1           ggtree_3.12.0          
##  [13] tinytex_0.53            htmltools_0.5.8.1       distributional_0.5.0   
##  [16] AnnotationHub_3.12.0    curl_5.2.3              gridGraphics_0.5-1     
##  [19] sass_0.4.9              bslib_0.8.0             plyr_1.8.9             
##  [22] httr2_1.0.5             cachem_1.1.0            igraph_2.0.3           
##  [25] lifecycle_1.0.4         pkgconfig_2.0.3         gson_0.1.0             
##  [28] Matrix_1.7-0            R6_2.5.1                fastmap_1.2.0          
##  [31] GenomeInfoDbData_1.2.12 digest_0.6.37           aplot_0.2.3            
##  [34] enrichplot_1.24.4       colorspace_2.1-1        patchwork_1.3.0        
##  [37] ExperimentHub_2.12.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.4.1          bit64_4.5.2            
##  [46] withr_3.0.1             graphite_1.50.0         BiocParallel_1.38.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.4.1             ape_5.8                
##  [58] scatterpie_0.2.4        R.oo_1.26.0             glue_1.8.0             
##  [61] nlme_3.1-166            GOSemSim_2.30.2         grid_4.4.1             
##  [64] shadowtext_0.1.4        reshape2_1.4.4          fgsea_1.30.0           
##  [67] generics_0.1.3          gtable_0.3.5            R.methodsS3_1.8.2      
##  [70] tidyr_1.3.1             data.table_1.16.0       tidygraph_1.3.1        
##  [73] utf8_1.2.4              XVector_0.44.0          ggdist_3.3.2           
##  [76] ggrepel_0.9.6           BiocVersion_3.19.1      pillar_1.9.0           
##  [79] stringr_1.5.1           yulab.utils_0.1.7       splines_4.4.1          
##  [82] dplyr_1.1.4             tweenr_2.0.3            BiocFileCache_2.12.0   
##  [85] treeio_1.28.0           lattice_0.22-6          gmp_0.7-5              
##  [88] bit_4.5.0               tidyselect_1.2.1        GO.db_3.19.1           
##  [91] Biostrings_2.72.1       knitr_1.48              gridExtra_2.3          
##  [94] bookdown_0.40           xfun_0.47               graphlayouts_1.2.0     
##  [97] stringi_1.8.4           UCSC.utils_1.0.0        lazyeval_0.2.2         
## [100] ggfun_0.1.6             yaml_2.3.10             evaluate_1.0.0         
## [103] codetools_0.2-20        ggraph_2.2.1            tibble_3.2.1           
## [106] qvalue_2.36.0           graph_1.82.0            BiocManager_1.30.25    
## [109] ggplotify_0.1.2         cli_3.6.3               munsell_0.5.1          
## [112] jquerylib_0.1.4         Rcpp_1.0.13             GenomeInfoDb_1.40.1    
## [115] dbplyr_2.5.0            png_0.1-8               parallel_4.4.1         
## [118] ggplot2_3.5.1           blob_1.2.4              clusterProfiler_4.12.6 
## [121] DOSE_3.30.5             Rmpfr_0.9-5             viridisLite_0.4.2      
## [124] tidytree_0.4.6          scales_1.3.0            purrr_1.0.2            
## [127] crayon_1.5.3            rlang_1.1.4             cowplot_1.1.3          
## [130] fastmatch_1.1-4         KEGGREST_1.44.1