How rockwillck/cbn2path works
Project Type and Purpose
• CBN2Path is an R/Bioconductor package (open-source tool) that unifies multiple Conjunctive Bayesian Network (CBN) models—CT-CBN, H-CBN, B-CBN, R-CBN—into a single interface.
• It provides functions for data import (cross-sectional genomic patterns), model fitting (R/C code), pathway analysis, and visualization of cancer progression.
File Structure Analysis
Top level:
• DESCRIPTION, NAMESPACE, LICENSE*, CITATION.cff – standard R package metadata
• R/ – R functions and wrappers (user interface, model orchestration)
• src/ – core C implementations (bcbn.c, ctcbn.c, queue.c, etc.), headers, Makevars
• inst/extdata/ – example data files (patterns, posets, time data)
• inst/scripts/ – helper scripts (R and Python) for data provenance and raw data parsing/enumeration
• man/ – Rd documentation for each function
• tests/ – testthat suite verifying R-C interface and algorithm correctness
• vignettes/ – usage tutorials and example workflows
• configure / configure.ac – autoconf scripts for locating GSL library
Patterns & architectural choices:
• R/C hybrid: R functions call compiled C code (via .Call or .C)
• Data layer: inst/extdata holds static inputs; inst/scripts transforms raw sources into standardized formats
• Modularity: each CBN variant has its own C module and an R wrapper function
README Insights
• External dependency on GNU Scientific Library (GSL)
• Instructions for building vignettes, platform support notes
• “robust quantification, analysis, and visualization”
Main Components & Interactions
a. Components
1. User Interface Layer (R functions in R/):
– Model fitters (bcbn(), ctcbn(), hcbn(), rcbn())
– Helper utilities (readPattern(), readPoset(), visualizeCBNModel(), etc.)
2. Computation Engine (C code in src/):
– Core algorithms for each CBN variant
– Supporting modules: random number generation, queues, poset enumeration
3. Data Layer (inst/extdata, inst/scripts/raw_data):
– Raw data parsers (Python, R scripts) → processed R-readable files
4. External Libraries & Build Tools:
– GSL (via autoconf/configure, Makevars)
– R CMD build/install
5. Visualization & Reporting:
– ggplot2, ggraph, sysfonts (implicit via DESCRIPTION)
– Vignettes (vignettes/CBN2Path.Rmd)
6. Quality Assurance:
– tests/testthat/ (unit tests)
b. Relationships / Data Flow
1. User → R API calls
2. R wrappers (.C/.Call) → C modules
3. C modules → GSL routines for numerical computation
4. Results → R for post-processing → Visualization functions
5. Static example data read from inst/extdata or generated via inst/scripts
6. Tests invoke R API and verify C-level results
Architectural Patterns & Principles
• Layered architecture: clear separation of R interface, C computation, and data
• Modular CBN variants: each model isolated in its own source/h header files
• Data provenance: scripts maintain reproducibility of input generation
• Standard R package conventions: ease of installation, documentation, testing