Skip to content

refactor(statmodel): Refactor namespaces for modeling and visualization options#138

Merged
tonywu1999 merged 15 commits intodevelfrom
refactor-namespaces-results
Dec 8, 2025
Merged

refactor(statmodel): Refactor namespaces for modeling and visualization options#138
tonywu1999 merged 15 commits intodevelfrom
refactor-namespaces-results

Conversation

@tonywu1999
Copy link
Copy Markdown
Contributor

@tonywu1999 tonywu1999 commented Dec 5, 2025

Summary by CodeRabbit

  • New Features

    • Added fold-change filtering controls and TMT moderation options
    • Added dedicated controls for log-pvalue base, significance cutoff, protein-name toggle, and plot-specific plot actions
  • UI Improvements

    • Reorganized and consolidated visualization plot options with plot-type–dependent conditional panels
    • Streamlined plot type selector and heatmap/volcano/comparison controls; updated start/view/download actions
  • Tests

    • Updated UI tests to reflect the new control identifiers and conditional behaviors
  • Style

    • Updated header styles for relevant action elements

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Dec 5, 2025

Walkthrough

Replaces hard-coded statmodel UI/input IDs with centralized namespaced constants across constants, server logic, UI builders, and tests; adds new modeling and visualization namespace keys and plot-type constants, and updates server/reactive wiring and UI option builders to use those constants.

Changes

Cohort / File(s) Summary
Constants Definitions
R/constants.R
Added multiple NAMESPACE_STATMODEL keys for modeling (e.g., modeling_start, modeling_significance_level, modeling_tmt_moderation) and visualization (plot type, logp base, fold-change inputs, which comparison/protein, heatmap options, view/download). Added plot type constants in CONSTANTS_STATMODEL (VolcanoPlot, Heatmap, ComparisonPlot).
Server Module Logic
R/module-statmodel-server.R
Made UI input handling fully namespaced: updated render_group_comparison_plot_inputs signature (adds input, loadpage_input), replaced hard-coded IDs with NAMESPACE_STATMODEL constants, switched analysis trigger from calculate to modeling_start, updated reactive chains, generate/ download handlers, and added get_tmt_moderation_radio_button.
UI Headers & Styling
R/statmodel-ui-headers.R
Replaced hard-coded CSS selectors (#statmodel-calculate, #statmodel-plotresults, #statmodel-viewresults) with dynamically composed selectors using NAMESPACE_STATMODEL values.
Modeling UI Options
R/statmodel-ui-options-modeling.R
Replaced create_moderation_option with create_moderation_radio_buttons; changed Start button ID to modeling_start; renamed significance slider ID to modeling_significance_level; moderation UI now rendered via uiOutput(ns(...)).
Visualization UI Options
R/statmodel-ui-options-visualization.R
Consolidated per-plot option builders into conditional/uiOutput-driven panels; plot type selector now uses CONSTANTS_STATMODEL values; refactored volcano/heatmap/comparison option functions to emit namespaced input IDs and adjusted signatures (e.g., create_volcano_plot_options(ns, show_protein_name = TRUE)).
Unit Tests — Module UI
tests/testthat/test-module-statmodel-ui.R
Replaced hard-coded element ID strings with NAMESPACE_STATMODEL constants; removed several assertions for legacy IDs and conditional tests; updated disabled checks and core UI presence assertions to use namespaced identifiers.
Unit Tests — Visualization Options
tests/testthat/test-statmodel-ui-options-visualization.R
Added/updated tests verifying UI option builders include correct namespaced IDs and option values for fold-change, volcano, comparison, heatmap, and plot-type selector.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

  • Areas to double-check:
    • All substitutions of input/output IDs in R/module-statmodel-server.R, especially reactive triggers and dynamic condition strings
    • Correct wiring of the updated render_group_comparison_plot_inputs signature across callers
    • Integration and conditional rendering logic of get_tmt_moderation_radio_button
    • Consistency between CONSTANTS_STATMODEL plot-type values and UI option tests

Possibly related PRs

Suggested labels

Review effort 3/5

Poem

🐇 I hopped through constants, tidy and spry,

Namespaced my IDs, no more hard-coded cry.
Plots and inputs now sing in one tune—
A neat little burrow beneath the moon. ✨

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: refactoring namespaces across modeling and visualization option files throughout the codebase.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch refactor-namespaces-results

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

@tonywu1999 tonywu1999 changed the title Refactor namespaces results refactor(statmodel): Refactor namespaces for modeling and visualization options Dec 5, 2025
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Dec 5, 2025

Failed to generate code suggestions for PR

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
R/statmodel-ui-options-visualization.R (1)

92-96: Typo: "dendogram" should be "dendrogram".

The correct spelling is "dendrogram" (with an 'r'). This typo appears in three option labels for the cluster analysis select input.

Apply this diff:

   c(
-    "protein dendogram" = "protein", 
-    "comparison dendogram" = "comparison", 
-    "protein and comparison dendograms" = "both"
+    "protein dendrogram" = "protein", 
+    "comparison dendrogram" = "comparison", 
+    "protein and comparison dendrograms" = "both"
   )
🧹 Nitpick comments (1)
R/module-statmodel-server.R (1)

512-516: Verify the tryCatch without error handling.

The Rownames reactive uses tryCatch but only provides an empty error handler. This silently swallows errors, which could make debugging difficult.

Consider logging the error or returning a more informative default:

 Rownames = eventReactive(input[[NAMESPACE_STATMODEL$comparisons_submit]], {
   req(input[[NAMESPACE_STATMODEL$comparison_mode]])
   req(loadpage_input()$DDA_DIA)
-  tryCatch({ rownames(matrix_build()) }, error = function(e) {})
+  tryCatch({ 
+    rownames(matrix_build()) 
+  }, error = function(e) {
+    message("Error getting rownames: ", conditionMessage(e))
+    character(0)
+  })
 })
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 742e7df and 39aea78.

📒 Files selected for processing (7)
  • R/constants.R (1 hunks)
  • R/module-statmodel-server.R (9 hunks)
  • R/statmodel-ui-headers.R (1 hunks)
  • R/statmodel-ui-options-modeling.R (1 hunks)
  • R/statmodel-ui-options-visualization.R (3 hunks)
  • tests/testthat/test-module-statmodel-ui.R (4 hunks)
  • tests/testthat/test-statmodel-ui-options-visualization.R (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: build
🔇 Additional comments (16)
R/statmodel-ui-headers.R (1)

19-33: LGTM! Consistent namespace-based CSS selector construction.

The new styling blocks follow the same pattern as the existing comparison button styles, ensuring uniform application of the orange background color across all action buttons.

tests/testthat/test-statmodel-ui-options-visualization.R (1)

1-62: Well-structured test coverage for namespace-based UI elements.

The tests effectively validate the presence of namespaced identifiers in the generated UI HTML. Good use of descriptive test names and informative error messages.

R/statmodel-ui-options-modeling.R (2)

12-18: LGTM! Good architectural improvement.

Moving the moderation UI to a conditional uiOutput allows for dynamic rendering based on experiment type (TMT), which is more flexible than the previous inline approach.


21-32: The radio button value binding is correct. The c(True = TRUE, False = FALSE) pattern is intentional and follows the same convention as other boolean radio buttons in the codebase (e.g., c(Yes=TRUE, No=FALSE) in remove_unlocalized_peptides). The display labels ("True"/"False") and logical values (TRUE/FALSE) correctly bind to the moderated parameter in MSstatsTMT::groupComparisonTMT() with no transformation needed.

However, there is a minor UI inconsistency: the tooltip text uses all-caps "TRUE"/"FALSE" while the radio button labels use capitalized "True"/"False". Consider updating the tooltip to match the button labels for consistency: change "TRUE will moderate t statistic; FALSE (default)" to "True will moderate t statistic; False (default)".

tests/testthat/test-module-statmodel-ui.R (2)

68-89: LGTM! Thorough namespace migration in tests.

The button presence and disabled state checks have been properly updated to use the new namespace constants, maintaining test coverage while aligning with the refactored codebase.


104-122: LGTM! Clean test simplification.

The input controls test now focuses on the essential namespace-based checks, removing redundant assertions while maintaining coverage of key UI elements.

R/statmodel-ui-options-visualization.R (3)

5-16: LGTM! Improved separation of concerns.

The move to a conditional uiOutput for plot options enables dynamic rendering based on plot type selection, which is cleaner than the previous approach.


19-31: LGTM! Consistent use of plot type constants.

The plot type selector properly uses both namespace constants for the input ID and value constants for the plot type identifiers.


34-59: LGTM! Well-refactored volcano plot options.

The function signature now properly accepts the ns parameter and consistently uses namespace constants for all input IDs. The conditional protein name display based on show_protein_name parameter is a good design.

R/constants.R (2)

2-28: LGTM! Well-organized namespace constants.

The NAMESPACE_STATMODEL constants are comprehensive and well-documented with inline comments showing the old hard-coded IDs. The hierarchical naming convention (e.g., visualization_plot_type, visualization_logp_base) makes the purpose of each constant clear.


30-39: LGTM! Clean plot type constants.

The CONSTANTS_STATMODEL entries properly define the plot type values used throughout the application, with helpful comments indicating their usage context.

R/module-statmodel-server.R (5)

214-221: LGTM! Clean conditional UI helper.

The get_tmt_moderation_radio_button function properly encapsulates the logic for conditionally rendering moderation options only for TMT experiments.


228-265: LGTM! Comprehensive namespace migration in plot inputs.

The function has been successfully updated to:

  1. Accept additional parameters (input, loadpage_input) for conditional rendering
  2. Use namespace constants for all UI element IDs
  3. Implement dynamic plot options based on plot type selection
  4. Conditionally render fold change input

This is a well-structured refactoring that improves maintainability.


268-329: LGTM! Thorough namespace constant adoption in plot creation.

All input references have been systematically migrated to use namespace constants, ensuring consistency with the centralized ID management approach. The fold change cutoff handling is also properly updated.


536-560: LGTM! Comprehensive namespace migration in matrix building.

The matrix building logic has been thoroughly updated to use namespace constants for:

  • Comparison mode checks
  • Contrast building function calls
  • UI element enabling

The refactoring maintains the original logic while improving maintainability through centralized constant management.


612-645: LGTM! Namespace constants properly used in dynamic UI.

The conditional panel conditions correctly interpolate namespace constants into the JavaScript condition strings, ensuring the UI visibility logic aligns with the namespaced input IDs.

Comment thread tests/testthat/test-statmodel-ui-options-visualization.R Outdated
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (2)
R/statmodel-ui-options-visualization.R (2)

34-59: Volcano options helper is consistent; confirm shared logp/fold-change behavior + consider tiny reuse refactor

The refactored create_volcano_plot_options(ns, show_protein_name) cleanly:

  • Namespaces all inputs/outputs via NAMESPACE_STATMODEL.
  • Allows the protein-name checkbox to be toggled via show_protein_name.
  • Reuses visualization_logp_base, visualization_volcano_significance_cutoff, and create_fold_change_options(ns).

Two small follow-ups:

  • This now shares the visualization_logp_base and fold-change controls with other plot types (e.g., heatmap). That means the chosen base/cutoff can persist when switching plot types; please confirm this cross-plot state sharing is intentional from a UX perspective.
  • Since the logp-base selector is duplicated between volcano and heatmap, you could optionally extract a tiny helper (e.g., create_logp_base_input(ns)) to avoid drift if the label or choices ever change.

69-99: Heatmap options wiring looks correct; option values should stay in sync with server

Heatmap options are cleanly namespaced and reuse shared controls (logp base + fold-change) alongside a bounded numericInput for protein count and a cluster-mode selectInput. Implementation looks correct.

If the server branches on "protein", "comparison", and "both" for clustering, ensure those string literals are used consistently there; if they get reused in multiple places, consider moving them into constants to reduce coupling.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 39aea78 and fe33463.

📒 Files selected for processing (2)
  • R/statmodel-ui-options-visualization.R (2 hunks)
  • tests/testthat/test-statmodel-ui-options-visualization.R (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • tests/testthat/test-statmodel-ui-options-visualization.R
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: build
🔇 Additional comments (5)
R/statmodel-ui-options-visualization.R (5)

8-14: Namespaced plot-options container wiring looks good

Using uiOutput(ns(NAMESPACE_STATMODEL$visualization_plot_options_conditional_panel)) gives the server a single, namespaced anchor to swap volcano/heatmap/comparison option panels; layout and API usage look correct.


20-28: Selector correctly uses centralized plot-type constants

The plot-type selectInput now uses a namespaced ID and CONSTANTS_STATMODEL$plot_type_* values, which should keep UI, server logic, and tests aligned around a single source of truth for plot types. No issues spotted with ordering or defaults.


62-65: Comparison plot options simplified to a single dynamic placeholder

Returning only uiOutput(ns(NAMESPACE_STATMODEL$visualization_comparison_plot_which_protein)) keeps the comparison-plot UI flexible and server-driven. The namespacing is consistent with the rest of the refactor.


103-109: Centralized fold-change options helper is consistent

create_fold_change_options(ns) now provides a namespaced checkbox plus a uiOutput placeholder for the actual cutoff input, which matches the dynamic rendering approach described in the server changes. The shared helper should reduce duplication across plot types.


113-118: Action buttons correctly migrated to namespaced IDs

visualization_view_results and visualization_download_plot_results are now passed through ns() and pulled from NAMESPACE_STATMODEL, which should keep the header, server, and UI in sync. Button semantics remain unchanged.

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.

1 participant