Skip to content

Add QQ plot to the statistical-analysis page#216

Merged
tonywu1999 merged 2 commits into
develfrom
MSstatsShiny/work/20260528_qq-plots-stat-analysis
Jun 16, 2026
Merged

Add QQ plot to the statistical-analysis page#216
tonywu1999 merged 2 commits into
develfrom
MSstatsShiny/work/20260528_qq-plots-stat-analysis

Conversation

@swaraj-neu

@swaraj-neu swaraj-neu commented Jun 15, 2026

Copy link
Copy Markdown
Contributor

Motivation and Context

The pull request adds QQ (Quantile-Quantile) plot visualization support to the statistical-analysis module, enabling users to assess the normality of data distributions in group comparison analyses. This enhancement expands the visualization options available on the statistical-analysis page alongside existing plot types like Volcano plots, Heatmaps, Comparison plots, and Response Curves.

Changes

Constants and Configuration

  • Added new plot type constant plot_type_qq_plot = "QQPlots" to CONSTANTS_STATMODEL in R/constants.R to map the plot type identifier to the MSstats function parameter
  • Minor formatting adjustment to plot_type_response_curve constant comment

Core Visualization Logic

  • Modified statmodelServer() in R/module-statmodel-server.R to:
    • Use default_template_plot_type_choices() helper for determining available plot type options instead of hardcoded values
    • Added explicit rendering branch for QQ plots using MSstats::groupComparisonQCPlots with proper error handling via tryCatch, modal spinner display during computation, and spinner cleanup in finally block
    • Maintains response curve rendering via renderPlotly and fallback generic plot rendering for other types

UI Components and Options

  • Created new create_qq_plot_options(ns) function in R/statmodel-ui-options-visualization.R to render QQ plot-specific UI options (protein selection via uiOutput)
  • Updated create_plot_type_selector() to include "QQ Plot" option in the plot type dropdown mapped to the QQPlots constant
  • Modified plot options conditional panel in R/statmodel-server-visualization.R to recognize qq_plot plot type and render its options

Download and Export Functionality

  • Added default_template_plot_type_choices(n_comparisons = 0) helper function in R/statmodel-server-visualization.R to dynamically determine available plot types:
    • Includes "Heatmap" option only when n_comparisons >= 2
    • Always includes "Volcano Plot", "Comparison Plot", and "QQ Plot"
  • Updated get_download_plot_filename() to generate QQPlot-<date>.zip filenames for QQ plot exports
  • Enhanced create_download_plot_handler() in R/statmodel-server-visualization.R to:
    • Generate Ex_QQPlot.pdf via MSstats::groupComparisonQCPlots(type="QQPlots") for the selected protein
    • Properly handle which.Comparison parameter based on plot type (uses "all" for heatmap)
    • Integrate QQ plot PDF into existing zip/copy download workflow
  • Updated generate_analysis_code() in R/statmodel-server-download-code.R to generate reproducible R code for QQ plot creation via MSstats::groupComparisonQCPlots() when non-PTM template is selected

Unit Tests

New tests in tests/testthat/test-module-statmodel-server.R:

  • Verified get_download_plot_filename() returns QQ plot-specific filenames (starting with QQPlot- and ending with .zip)
  • Tested default_template_plot_type_choices() for:
    • Correct exclusion of Heatmap when n_comparisons < 2 and inclusion when n_comparisons >= 2
    • Proper binding of "QQ Plot" label to CONSTANTS_STATMODEL$plot_type_qq_plot with value "QQPlots"
    • Default behavior when n_comparisons parameter is omitted (treats as 0)

Updated tests in tests/testthat/test-statmodel-ui-options-visualization.R:

  • Added tests for create_qq_plot_options() UI output containing expected namespace for protein selection control
  • Expanded create_plot_type_selector() tests to verify "QQ Plot" option presence in rendered selector UI

Coding Guidelines Compliance

The implementation adheres to the established codebase patterns and best practices:

  • R conventions: Uses appropriate R/Shiny idioms (reactive values, observers, rendering functions)
  • Namespace management: Consistently uses NAMESPACE_STATMODEL for UI element IDs and CONSTANTS_STATMODEL for constant values
  • Error handling: Implements tryCatch with user-visible error notifications for robustness
  • Asynchronous operations: Uses modal spinners to provide user feedback during computation
  • Code organization: Follows the modular structure pattern (separate UI, server, options files)
  • Function documentation: Includes @noRd roxygen tags for internal helper functions
  • Test coverage: Adds appropriate unit tests for new functionality
  • Consistency: Reuses existing patterns like create_*_plot_options() functions and download/export handlers

@swaraj-neu swaraj-neu requested a review from tonywu1999 June 15, 2026 21:30
@swaraj-neu swaraj-neu self-assigned this Jun 15, 2026
@swaraj-neu swaraj-neu added the enhancement New feature or request label Jun 15, 2026
@coderabbitai

coderabbitai Bot commented Jun 15, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@swaraj-neu, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 41 minutes and 3 seconds. Learn how PR review limits work.

Your organization has used up its prepaid credits, and credit purchases are no longer available. Enable the review add-on in the billing tab to keep reviews running — you're only billed for reviews past your plan's rate limits ($0.25/file).

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 20416352-1ccf-44c5-adf4-71ab4ace0856

📥 Commits

Reviewing files that changed from the base of the PR and between 0279f4c and 2e25acf.

📒 Files selected for processing (3)
  • R/module-statmodel-server.R
  • R/statmodel-server-visualization.R
  • tests/testthat/test-module-statmodel-server.R
📝 Walkthrough

Walkthrough

Adds QQ plot as a new group-comparison visualization type. A plot_type_qq_plot constant is registered, the plot-type dropdown and options UI are extended, default_template_plot_type_choices() is introduced to compute available choices dynamically, and the server rendering, download handler, and analysis code generation each gain a dedicated qq_plot branch calling MSstats::groupComparisonQCPlots.

Changes

QQ Plot visualization feature

Layer / File(s) Summary
Constant and UI selector additions
R/constants.R, R/statmodel-ui-options-visualization.R
Registers plot_type_qq_plot = "QQPlots" in CONSTANTS_STATMODEL, adds "QQ Plot" to create_plot_type_selector, and introduces create_qq_plot_options(ns) for protein selection.
default_template_plot_type_choices helper and dropdown wiring
R/statmodel-server-visualization.R, R/module-statmodel-server.R
Adds default_template_plot_type_choices(n_comparisons=0) that dynamically includes QQ Plot and conditionally includes Heatmap; replaces hardcoded choice sets in both render_group_comparison_plot_inputs and statmodelServer.
QQ plot server rendering
R/module-statmodel-server.R
Adds a qq_plot branch in the visualization reactive that calls MSstats::groupComparisonQCPlots via renderPlot, with modal spinner, tryCatch error notification, and finally spinner removal.
Download handler and filename generation
R/statmodel-server-visualization.R
Extends get_download_plot_filename() to return QQPlot-<date>.zip; adds a qq_plot branch writing Ex_QQPlot.pdf via groupComparisonQCPlots; updates PTM and non-PTM which.Comparison logic for heatmap vs. selected comparison.
Analysis code generation
R/statmodel-server-download-code.R
Reads plot_type from input and emits MSstats::groupComparisonQCPlots in the non-PTM branch when plot_type matches the QQ plot constant.
Unit tests
tests/testthat/test-module-statmodel-server.R, tests/testthat/test-statmodel-ui-options-visualization.R
Covers get_download_plot_filename QQ output, default_template_plot_type_choices heatmap inclusion/exclusion and constant binding, create_qq_plot_options HTML, and create_plot_type_selector option presence.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • Vitek-Lab/MSstatsShiny#118: Refactors R/module-statmodel-server.R and extends tests/testthat/test-module-statmodel-server.R, the same files this PR modifies with QQ plot rendering and tests.
  • Vitek-Lab/MSstatsShiny#180: Both PRs add new analysis-generation branches in generate_analysis_code() inside R/statmodel-server-download-code.R.
  • Vitek-Lab/MSstatsShiny#138: Modifies create_plot_type_selector and the statmodelServer plot-type rendering path in the same UI and server files this PR extends with the QQ plot branch.

Suggested reviewers

  • tonywu1999
  • sszvetecz

Poem

🐇 Hop hop, a new plot appears today,
QQ points aligned in a graceful display!
The rabbit typed constants and branches with care,
Modal spinners spin softly up into the air.
With zip files and PDFs neatly tucked in,
The QQ plot feature is ready to win! 🎉

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and specifically describes the main change: adding QQ plot functionality to the statistical-analysis page. It is concise, avoids vague terms, and accurately reflects the primary objective of the changeset across all modified files.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch MSstatsShiny/work/20260528_qq-plots-stat-analysis

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.

@coderabbitai coderabbitai 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.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@R/statmodel-server-visualization.R`:
- Around line 23-26: The QQ plot choice is being unconditionally included for
all flows through the updateSelectInput call at line 25, but PTM flows do not
support QQ plotting and this creates a broken user path. Add a conditional check
before the updateSelectInput call to filter out QQ from the choices when
loadpage_input()$BIO equals "PTM". Additionally, update the
default_template_plot_type_choices() function (lines 162-172) to accept a
parameter indicating the BIO type (or check loadpage_input()$BIO internally) and
exclude QQ from the returned choices when the BIO type is "PTM", ensuring that
both the initial choices and the updated choices remain consistent with this
rule.
- Around line 320-327: The pdf() device opened at the start of the QQ download
branch is not guaranteed to be closed if MSstats::groupComparisonQCPlots()
throws an error, which can leak graphics devices and break subsequent plot
generation. Wrap the pdf() call and the MSstats::groupComparisonQCPlots() call
in a tryCatch or try-finally construct to ensure dev.off() is always executed
regardless of whether an exception is thrown by the groupComparisonQCPlots
function.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: eade200f-2a8a-4eea-a299-d1391e054903

📥 Commits

Reviewing files that changed from the base of the PR and between 3ae58ae and 0279f4c.

📒 Files selected for processing (7)
  • R/constants.R
  • R/module-statmodel-server.R
  • R/statmodel-server-download-code.R
  • R/statmodel-server-visualization.R
  • R/statmodel-ui-options-visualization.R
  • tests/testthat/test-module-statmodel-server.R
  • tests/testthat/test-statmodel-ui-options-visualization.R

Comment thread R/statmodel-server-visualization.R
Comment thread R/statmodel-server-visualization.R Outdated
@tonywu1999 tonywu1999 merged commit e4342c9 into devel Jun 16, 2026
2 checks passed
@tonywu1999 tonywu1999 deleted the MSstatsShiny/work/20260528_qq-plots-stat-analysis branch June 16, 2026 14:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants