CBNplot
Workflows
Standard Workflow
Infer and plot a Bayesian network of genes within a specific enriched pathway using expression data.
library(CBNplot)
library(bnlearn)
library(org.Hs.eg.db)
# 1. Load User Inputs & Prepare Data
data(gaussian.test)
kegg <- org.Hs.egPATH2EG
mapped <- mappedkeys(kegg)
genes <- as.list(kegg[mapped])[["00532"]]
counts <- head(gaussian.test, length(genes))
row.names(counts) <- genes
pway <- clusterProfiler::enrichKEGG(gene = genes)
pway <- clusterProfiler::setReadable(pway, org.Hs.eg.db, keyType="ENTREZID")
# 2. Visualize the gene-level Bayesian network for the first pathway
bngeneplot(results = pway, exp = counts, pathNum = 1, expRow="ENTREZID")
# 3. Extract the underlying network structure, strength, and direction
ret <- bngeneplot(results = pway, exp = counts, pathNum = 1, returnNet=TRUE, expRow="ENTREZID")
head(ret$str)
# 4. Convert the averaged network to an igraph object and perform centrality analysis
g <- bnlearn::as.igraph(ret$av)
igraph::evcent(g)$vector
# 5. Customize the gene network visualization
bngeneplotCustom(results = pway, exp = counts, expRow="ENTREZID", pathNum=1, fontFamily="sans", glowEdgeNum=NULL, hub=1)
Inputs/Outputs: Takes an enrichment analysis result object and a normalized expression data frame as inputs, and outputs Bayesian network plots and network structure data frames.
When to Use
- To infer and visualize Bayesian networks of genes within a specific enriched pathway using expression data via
bngeneplot.
- To visualize relationships between multiple pathways as a Bayesian network using
bnpathplot.
- To customize network visualizations with glow edges or hub highlighting using
bngeneplotCustom or bnpathplotCustom.
- To extract network strength and direction or convert the inferred network to an
igraph object using bnlearn::as.igraph for centrality analysis.
When NOT to Use
- For general non-pathway-based gene regulatory network inference without prior enrichment results (use packages like
minet or GENIE3 instead).
- For static pathway diagrams without expression-based network inference (use
pathview instead).
Data Requirements
- Enrichment analysis results (e.g., from
clusterProfiler::enrichKEGG or ReactomePA).
- A normalized expression matrix or data frame (e.g.,
counts) where row names match the gene identifier type (e.g., ENTREZID) specified in the enrichment results.
Key Parameters
- results: Enrichment analysis result object (e.g., from
clusterProfiler::enrichKEGG).
- exp: Normalized expression data frame or matrix.
- pathNum (1): The pathway number in the enrichment results to plot.
- expRow ("ENTREZID"): The column/row identifier type for expression data.
- returnNet (FALSE): Logical indicating whether to return the network structure, strength, and direction.
- nCategory (5): Number of pathways to include in
bnpathplot.
- glowEdgeNum (NULL): Parameter in custom plots to highlight edges of interest.
- hub (1): Parameter in custom plots to highlight hub nodes.
Best Practices
- Ensure gene identifiers in the expression matrix match the
keyType of the enrichment results (e.g., convert using clusterProfiler::setReadable).
- Use
mappedkeys to map pathway identifiers to genes when preparing test or custom pathway gene lists.
- Set
returnNet = TRUE in bngeneplot to inspect the underlying network strength and direction before relying solely on the visual plot.
Common Pitfalls
- Mismatched gene identifier types between expression data and enrichment results. Fix: Use
clusterProfiler::setReadable to align key types (e.g., to "ENTREZID").
- Providing raw, unnormalized count data to network inference. Fix: Supply normalized expression values (e.g., log-transformed or normalized counts).
Alternatives
pathview for overlaying expression data onto static KEGG pathway diagrams.
enrichplot for standard enrichment visualizations (e.g., cnetplot, emapplot) without Bayesian network inference.
bnlearn for general Bayesian network inference without direct integration with enrichment results.
Citations
- Scutari M (2010). Learning Bayesian Networks with the bnlearn R Package. Journal of Statistical Software.
- Yu G, Wang LG, Han Y, He QY (2012). clusterProfiler: an R Package for Comparing Biological Themes Among Gene Clusters. OMICS.
References
1---2name: cbnplot3description: CBNplot4---56# CBNplot78## Workflows910### Standard Workflow1112Infer and plot a Bayesian network of genes within a specific enriched pathway using expression data.1314```r15library(CBNplot)16library(bnlearn)17library(org.Hs.eg.db)1819# 1. Load User Inputs & Prepare Data20data(gaussian.test)21kegg <- org.Hs.egPATH2EG22mapped <- mappedkeys(kegg)23genes <- as.list(kegg[mapped])[["00532"]]24counts <- head(gaussian.test, length(genes))25row.names(counts) <- genes2627pway <- clusterProfiler::enrichKEGG(gene = genes)28pway <- clusterProfiler::setReadable(pway, org.Hs.eg.db, keyType="ENTREZID")2930# 2. Visualize the gene-level Bayesian network for the first pathway31bngeneplot(results = pway, exp = counts, pathNum = 1, expRow="ENTREZID")3233# 3. Extract the underlying network structure, strength, and direction34ret <- bngeneplot(results = pway, exp = counts, pathNum = 1, returnNet=TRUE, expRow="ENTREZID")35head(ret$str)3637# 4. Convert the averaged network to an igraph object and perform centrality analysis38g <- bnlearn::as.igraph(ret$av)39igraph::evcent(g)$vector4041# 5. Customize the gene network visualization42bngeneplotCustom(results = pway, exp = counts, expRow="ENTREZID", pathNum=1, fontFamily="sans", glowEdgeNum=NULL, hub=1)43```44*Inputs/Outputs:* Takes an enrichment analysis result object and a normalized expression data frame as inputs, and outputs Bayesian network plots and network structure data frames.4546## When to Use47- To infer and visualize Bayesian networks of genes within a specific enriched pathway using expression data via `bngeneplot`.48- To visualize relationships between multiple pathways as a Bayesian network using `bnpathplot`.49- To customize network visualizations with glow edges or hub highlighting using `bngeneplotCustom` or `bnpathplotCustom`.50- To extract network strength and direction or convert the inferred network to an `igraph` object using `bnlearn::as.igraph` for centrality analysis.5152## When NOT to Use53- For general non-pathway-based gene regulatory network inference without prior enrichment results (use packages like `minet` or `GENIE3` instead).54- For static pathway diagrams without expression-based network inference (use `pathview` instead).5556## Data Requirements57- Enrichment analysis results (e.g., from `clusterProfiler::enrichKEGG` or `ReactomePA`).58- A normalized expression matrix or data frame (e.g., `counts`) where row names match the gene identifier type (e.g., `ENTREZID`) specified in the enrichment results.5960## Key Parameters61- **results**: Enrichment analysis result object (e.g., from `clusterProfiler::enrichKEGG`).62- **exp**: Normalized expression data frame or matrix.63- **pathNum** (1): The pathway number in the enrichment results to plot.64- **expRow** ("ENTREZID"): The column/row identifier type for expression data.65- **returnNet** (FALSE): Logical indicating whether to return the network structure, strength, and direction.66- **nCategory** (5): Number of pathways to include in `bnpathplot`.67- **glowEdgeNum** (NULL): Parameter in custom plots to highlight edges of interest.68- **hub** (1): Parameter in custom plots to highlight hub nodes.6970## Best Practices71- Ensure gene identifiers in the expression matrix match the `keyType` of the enrichment results (e.g., convert using `clusterProfiler::setReadable`).72- Use `mappedkeys` to map pathway identifiers to genes when preparing test or custom pathway gene lists.73- Set `returnNet = TRUE` in `bngeneplot` to inspect the underlying network strength and direction before relying solely on the visual plot.7475## Common Pitfalls76- Mismatched gene identifier types between expression data and enrichment results. Fix: Use `clusterProfiler::setReadable` to align key types (e.g., to "ENTREZID").77- Providing raw, unnormalized count data to network inference. Fix: Supply normalized expression values (e.g., log-transformed or normalized counts).7879## Alternatives80- `pathview` for overlaying expression data onto static KEGG pathway diagrams.81- `enrichplot` for standard enrichment visualizations (e.g., cnetplot, emapplot) without Bayesian network inference.82- `bnlearn` for general Bayesian network inference without direct integration with enrichment results.8384## Citations85- Scutari M (2010). Learning Bayesian Networks with the bnlearn R Package. Journal of Statistical Software.86- Yu G, Wang LG, Han Y, He QY (2012). clusterProfiler: an R Package for Comparing Biological Themes Among Gene Clusters. OMICS.8788## References89- Homepage: bioconductor.org/packages/cbnplot90- Vignette: https://bioconductor.org/packages/release/bioc/vignettes/cbnplot/inst/doc/CBNplot.html