Skip to content

Docu test and review#7

Merged
VanessaBa merged 5 commits into
mainfrom
docu-test-and-review
May 29, 2026
Merged

Docu test and review#7
VanessaBa merged 5 commits into
mainfrom
docu-test-and-review

Conversation

@VanessaBa

@VanessaBa VanessaBa commented May 29, 2026

Copy link
Copy Markdown
Collaborator

Summary by CodeRabbit

  • New Features

    • Added comprehensive module documentation for Drug PK/PD and TB Infection components
    • Enhanced workflow documentation with detailed step-by-step instructions
    • Configurable simulation controls for dose sensitivity and TB scenario analyses
  • Documentation

    • Added detailed technical module descriptions
    • Updated getting started guide with simplified setup process
    • Improved reporting with standardized labeling and captions
    • Removed outdated documentation files
  • Refactor

    • Streamlined simulation workflow configuration
    • Reorganized dose sensitivity and scenario analysis scripts for better control

Review Change Stack

@coderabbitai

coderabbitai Bot commented May 29, 2026

Copy link
Copy Markdown
ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Free

Run ID: e94110b7-e41e-4b77-b1a7-a2082b0a8bd5

📥 Commits

Reviewing files that changed from the base of the PR and between ebce434 and 1e4f87e.

📒 Files selected for processing (21)
  • Code/README.md
  • Code/runDoseSensitivity.R
  • Code/runTBScenarios.R
  • Code/utils/doseSensitivity.R
  • Code/utils/simulate-scenarios.R
  • Code/utils/utils.R
  • Code/workflowConfig.R
  • Documentation/DRUGModule_ModelDescription.html
  • Documentation/DRUGModule_ModelDescription.qmd
  • Documentation/TB - PZA - mono.md
  • Documentation/TB model documentation.md
  • Documentation/TB model with generic drug.md
  • Documentation/TBModule_ModelDescription.html
  • Documentation/TBModule_ModelDescription.qmd
  • Documentation/Tuberculosis_workflow.html
  • Documentation/Tuberculosis_workflow.qmd
  • Models/PKML/Modules/Drug and resistance extension [DRUG].pkml
  • README.md
  • Reports/TBScenarios_report.qmd
  • Reports/doseSensitivity_report.qmd
  • Reports/references.bib
💤 Files with no reviewable changes (5)
  • Documentation/TB model with generic drug.md
  • Code/utils/simulate-scenarios.R
  • Documentation/TB - PZA - mono.md
  • Documentation/TB model documentation.md
  • Code/utils/doseSensitivity.R

📝 Walkthrough

Walkthrough

This PR refactors the dose-sensitivity workflow by consolidating utility functions directly into top-level R scripts with improved parameter configurability, and substantially expands documentation with comprehensive module specifications for drug PK/PD modeling and comprehensive TB immune response modeling within a MoBi QSP framework.

Changes

Dose Sensitivity and Scenario Workflow Refactoring

Layer / File(s) Summary
Dose sensitivity inline refactoring and parametrization
Code/runDoseSensitivity.R
Inlines runDoseSensitivity() and plotDoseSensitivity() logic with new configurable inputs (rerunSimulations, savePlots, loadResults, doseSensitivityResultsFolder), validation guardrails, and dynamic CSV path/folder handling. Updates observed data column schema (cols2) to include cmax/cavg fields and expands plot generation across dose/Cmax/Cavg relationships.
Scenario simulation and configuration parameter updates
Code/runTBScenarios.R, Code/workflowConfig.R
Updates runTBScenarios.R to validate outputFolder requirement and ensure resultsFolder creation before simulation. Updates workflowConfig.R to default dose sensitivity to re-running simulations, disables plot saving, narrows drugConfigs to INHf-only, and changes scenario selection to first three scenarios with pre-simulated loading disabled.
Utility helper improvements
Code/utils/utils.R
Refactors ggplot2 theme helper conditional into multi-line format for readability. Changes default resultsFolder initialization from static path to timestamped subdirectory with recursive directory creation.
Utility documentation update
Code/README.md
Explicitly documents shared helper functions in utils/utils.R: calculateEBA, format_plot, my_theme, exportPlotsToPNG with their responsibilities.

Module Documentation and Workflow Specification

Layer / File(s) Summary
Drug PK/PD and Resistance Module specification
Documentation/DRUGModule_ModelDescription.qmd
Comprehensive module description covering metadata, biological background, module assumptions and interfaces, global compartment definitions (Organism/Lung/Interstitial/Lesion), three state variables (DRUG, Be_r_DRUG, Bi_r_DRUG), and detailed sections on pharmacokinetics (first-order clearance with induction), pharmacodynamics (bacteriostatic/bactericidal mechanisms), resistant dynamics (fitness costs, immune processes), spontaneous resistance emergence, dosing/transport mechanisms, spatial-structure mappings, PBPK integration notes, calibration parameters, and known limitations.
TB Infection and Immune Response Module specification
Documentation/TBModule_ModelDescription.qmd
Complete QSP immune scaffold module specification with metadata, biological background, 17 state variables, detailed sections on macrophage dynamics, T-helper priming, cytokine dynamics, dendritic-cell dynamics, and bacterial dynamics/clearance, scenario tables, drug PK/PD module integration notes, limitations, and appendices (compact reaction reference, spatial structure, changelog, compliance checklist).
Workflow guide and repository structure documentation
Documentation/Tuberculosis_workflow.qmd, Documentation/Tuberculosis_workflow.html, README.md
Updates Tuberculosis_workflow.qmd with conditional ProjectConfiguration restoration, reorganized drug module PKML generation step, and expanded input/output tables. Generates corresponding HTML output. Replaces README.md "Getting started" with ProjectConfiguration JSON restoration and rewrites "Repository structure" section with updated directory descriptions.
Report formatting and bibliography updates
Reports/TBScenarios_report.qmd, Reports/doseSensitivity_report.qmd, Reports/references.bib
Adds stable Quarto chunk labels (`#

🎯 4 (Complex) | ⏱️ ~60 minutes


Note

🎁 Summarized by CodeRabbit Free

Your organization is on the Free plan. CodeRabbit will generate a high-level summary and a walkthrough for each pull request. For a comprehensive line-by-line review, please upgrade your subscription to CodeRabbit Pro by visiting https://app.coderabbit.ai/login.

Comment @coderabbitai help to get the list of available commands and usage tips.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request refactors the TB modelling platform by introducing dynamic results and output folder management, cleaning up unused utility functions, and adding comprehensive mathematical model descriptions for the TB disease and drug PK/PD modules. The workflow documentation and README have also been updated to reflect these structural changes. The reviewer feedback highlights a critical bug in Code/utils/utils.R where simulation results are saved to a hardcoded directory instead of the dynamic resultsFolder. Additionally, the default settings in Code/workflowConfig.R are noted as fragile due to hardcoded scenario indices and commented-out drug configurations. Finally, several typos, copy-paste errors, and an undefined citation key were identified across the documentation and report files.

Comment thread Code/utils/utils.R
Comment on lines +128 to +131
resultsFolder <- file.path(
'./Results/doseSensitivity/',
format(Sys.time(), "%Y-%m-%d %H-%M")
)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

While resultsFolder is correctly initialized here to a timestamped directory (or passed from the caller), the actual simulation results and CSV exports inside calculateEBA (when loadResults is FALSE) are hardcoded to ./Results/doseSensitivity/ (see lines 190 and 197 of Code/utils/utils.R). This means the files are saved in the parent directory rather than the specific resultsFolder, causing loadScenarioResults to fail when loadResults is TRUE because it looks inside resultsFolder.

Comment thread Code/workflowConfig.R
# Set scenariosToRun to NULL to run all (or all except scenariosNotToRun).
# scenariosToRun takes priority over scenariosNotToRun when both are set.
scenariosToRun <- NULL
scenariosToRun <- c(1:3)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Using a hardcoded numeric index range like c(1:3) as the default for scenariosToRun is fragile. If the user's ProjectConfiguration.xlsx contains fewer than 3 scenarios, names(scenarioConfigurations)[c(1:3)] will introduce NA values. This will propagate into selectedConfigurations as NULL elements, causing downstream functions like createScenarios or loadScenarioResults to crash. It is safer to default to NULL (to run all scenarios) or use explicit scenario names.

Comment thread Code/workflowConfig.R
dosePath = "Events|MOX PO|Tablet|Application_1|ProtocolSchemaItem|Dose",
doseUnit = "mg"
)
) #,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Most of the drug configurations in drugConfigs have been commented out, leaving only INHf active. While this might be useful for local testing, committing these commented-out blocks to the repository limits the default execution of the dose sensitivity analysis for other users. Consider keeping the full list active by default.

- **EBA~0–5~**: covers the first five days of treatment.
- **EBA~0–14~**: integrates bactericidal activity over the full 14-day early phase.
- **EBA~2–5~**: reflects activity against the semi-dormant population that becomes prominent after the initial rapid kill.
Early Bactericidal Activity (EBA) is a key pharmacodynamic endpoint in tuberculosis (TB) drug development. It quantifies the rate of decline of viable *Mycobacterium tuberculosis* colony-forming units (CFU) in sputum during the early phase of monotherapy, expressed as the daily log~10~ reduction in CFU per mL. EBA measurements over different time windows capture distinct aspects of drug action, e.g. **EBA~0–2~** (rapid killiing (days 0–2)), **EBA~2–5~** (delayed effect), or **EBA~0–14~** (overall score/ more longterm effect).

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

There is a typo in this line: "killiing" should be "killing". Also, "longterm" is more commonly written as "long-term".

Early Bactericidal Activity (EBA) is a key pharmacodynamic endpoint in tuberculosis (TB) drug development. It quantifies the rate of decline of viable *Mycobacterium tuberculosis* colony-forming units (CFU) in sputum during the early phase of monotherapy, expressed as the daily log~10~ reduction in CFU per mL. EBA measurements over different time windows capture distinct aspects of drug action, e.g. **EBA~0–2~** (rapid killing (days 0–2)), **EBA~2–5~** (delayed effect), or **EBA~0–14~** (overall score/ more long-term effect). 

| A3 | Resistant bacteria carry a fixed fitness cost (`resistanceFitness` = 0.8 relative to wild type) | Biological | Compensatory mutations that restore fitness are not represented |
| A4 | Drug concentrations in Interstitial and Lesion compartments are provided exogenously via spatial parameters (`DRUG_compartment_e`, `DRUG_compartment_i`) | Pharmacokinetic | Tissue distribution kinetics must be supplied by a companion PBPK or effect-compartment module |
| A5 | Drug clearance from the central compartment follows first-order kinetics with linear induction over time up to `tmax` days | Pharmacokinetic | Non-linear autoinduction or saturable elimination are not captured in the simple PK model |
| A6 | Only mono-resistant strain are modelled | Pharmacological/Evolutionary |mulit-resistant strains are not captured although they are known to exist |

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

There are typos in this line: "strain" should be plural "strains" to match "are modelled", and "mulit-resistant" should be "multi-resistant".

| A6 | Only mono-resistant strains are modelled | Pharmacological/Evolutionary |multi-resistant strains are not captured although they are known to exist |

immune killing. The net killing rate parameter `K_Be_total` is assembled in the
Spatial Structure and drives this reaction.

`K_Be_total` is defined as a sum over `K_Be_fast` or `K_Be_slow` of the implmented drugs depending on the growth phase of the bacteria.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

There is a typo in this line: "implmented" should be "implemented".

`K_Be_total` is defined as a sum over `K_Be_fast` or `K_Be_slow` of the implemented drugs depending on the growth phase of the bacteria.

Comment on lines +784 to +785

The reaction contains the following local parameter definitions:

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

This sentence is a copy-paste error from the DRUG module documentation. The base TB Immune Scaffold module does not contain the drug-resistant species Be_r_DRUG and Bi_r_DRUG. This second sentence should be removed.

The macrophage passive transport building blocks are shared with the TB Immune Scaffold.


`Code/utils/transformDrugParams.R` reads drug parameter text files from the
reference model implementation and converts them to the Excel format expected
reference model implementation @Fors and converts them to the Excel format expected

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The citation key @Fors is not defined in references.bib. It should be @fors2020 to match the correct reference.

reference model implementation @fors2020 and converts them to the Excel format expected

@VanessaBa
VanessaBa merged commit e86b0e0 into main May 29, 2026
2 checks passed
@VanessaBa
VanessaBa deleted the docu-test-and-review branch May 29, 2026 15:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[QSP TB-model] Model documentation

1 participant