Skip to content

fix(PTMs): Fix bugs related to PTM E2E processing#199

Merged
tonywu1999 merged 6 commits intodevelfrom
fix-ptm
Apr 24, 2026
Merged

fix(PTMs): Fix bugs related to PTM E2E processing#199
tonywu1999 merged 6 commits intodevelfrom
fix-ptm

Conversation

@tonywu1999
Copy link
Copy Markdown
Contributor

@tonywu1999 tonywu1999 commented Apr 24, 2026

Motivation and Context

This PR fixes PTM (Post-Translational Modification) handling in the QC (Quality Control) module to ensure consistent Plotly-based visualization and simplified quantification logic. Previously, the PTM code path had inconsistent plot rendering approaches and complex nested conditional logic for quantification. The fix consolidates these patterns to improve maintainability and ensure all PTM plots render consistently via Plotly.

Changes

R/module-qc-server.R

  • Plot rendering standardization: Consolidated output$showplot to consistently use renderPlotly() with plotlyOutput() wrapped in a scroll-enabled div, removing any PTM-specific renderPlot/plotOutput variants
  • PTM plotting consolidation: Modified plotresult() function to ensure PTM plots always call dataProcessPlotsPTM(..., isPlotly=TRUE) with immediate return, eliminating the previous alternative non-Plotly code path for PTM
  • Quantification logic refactoring: Simplified the abundance() function by replacing nested PTM/TMT/filetype conditions with clearer mutually exclusive cases:
    • Dedicated branch for BIO == "PTM" && DDA_DIA == "TMT" using temp$PTM with column renaming
    • Separate branch for BIO == "PTM" && DDA_DIA != "TMT" using temp$PTM
    • Branch for DDA_DIA == "TMT" (non-PTM) using temp$ProteinLevelData
    • Default case for other data types
  • Code cleanup: Removed large commented-out blocks including old plot-saving observeEvents and related commented conditions
  • Lines changed: +31/-82

R/module-qc-ui.R

  • Removed commented UI element: Deleted a previously commented "Calculation in progress..." message UI snippet that was displayed during Shiny busy states in the "Summarization Plots" tab
  • Lines changed: +0/-4

Testing

No test files were added or modified. The existing test suite includes PTM-related tests in tests/testthat/test-utils.R and tests/testthat/test-utils-statmodel-server.R that cover PTM data handling in other modules, but no dedicated tests for the QC module's PTM plotting and quantification logic were added to verify these changes.

Coding Guidelines

No obvious violations of coding guidelines are present. The refactored code improves readability by:

  • Using clearer mutually exclusive conditional branches instead of nested conditions
  • Consistently applying Plotly rendering across all plot types
  • Removing dead code (commented-out blocks)

However, the removal of commented code without commit history context may make it difficult to understand why certain approaches were previously attempted.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 24, 2026

📝 Walkthrough

Walkthrough

The module consolidates plot rendering to consistently use Plotly, refactors PTM quantification logic with an isPlotly=TRUE parameter, simplifies the abundance function's quantification branching by removing nested PTM/TMT/filetype conditions, and removes commented-out legacy code blocks.

Changes

Cohort / File(s) Summary
Server Module Logic
R/module-qc-server.R
Consolidates plot rendering to use renderPlotly/plotlyOutput consistently in output$showplot; simplifies PTM quantification logic in plotresult with isPlotly=TRUE parameter; refactors abundance quantification branching from nested PTM/TMT/filetype conditions to clearer mutually exclusive cases; removes commented-out plot-saving observeEvents.
UI Module Cleanup
R/module-qc-ui.R
Removes commented UI snippet for "Calculation in progress..." busy state message in Summarization Plots tab.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Suggested labels

Review effort 1/5

Poem

🐰 Whiskers twitch with joy so bright,
Plotly renders smooth as night,
Branching logic, clean and neat,
Old code removed—refactor's sweet!
Quantify with clearer sight!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
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.
Title check ✅ Passed The title 'fix(PTMs): Fix bugs related to PTM E2E processing' clearly summarizes the main change—consolidating PTM plotting to use Plotly consistently and simplifying PTM quantification logic in the QC module.

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

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix-ptm

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.

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/module-qc-server.R (1)

269-315: ⚠️ Potential issue | 🔴 Critical

PTM PDF export is broken: address = file with isPlotly = TRUE conflicts with the PDF wrapper.

In the PTM branch (lines 271–280), dataProcessPlotsPTM() is called with both address = file and isPlotly = TRUE. Per MSstatsPTM documentation, isPlotly = TRUE directs the function to write Plotly output directly to an HTML file via the address parameter.

However, output$saveplot (lines 435–444) wraps the result in a pdf() device that opens the same file:

content = function(file) {
  pdf(file)
  plotresult(TRUE, input$which, FALSE, TRUE, FALSE)
  dev.off()
}

This creates a file I/O conflict: the internal dataProcessPlotsPTM call attempts to write HTML to file, while the wrapper simultaneously opens file as a PDF device. The result is likely file corruption, a locked file, or a silently invalid PDF.

Fix: For the save path, either use isPlotly = FALSE (reverting to PDF-compatible ggplot output) or omit the address parameter when the plotting function is wrapped in an external device handler.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@R/module-qc-server.R` around lines 269 - 315, The PTM branch in plotresult
(dataProcessPlotsPTM) is passing address = file together with isPlotly = TRUE
which causes the internal function to write HTML while output$saveplot opens a
PDF device; change plotresult to detect the saveFile flag (the first parameter)
and when saving (saveFile == TRUE) call dataProcessPlotsPTM with isPlotly =
FALSE and do not pass address (or set address = NULL), otherwise keep isPlotly =
TRUE and pass address = file; update the PTM branch in plotresult (and similarly
any other branches that use address/isPlotly) so PDF export uses
non-Plotly/ggplot output while interactive uses Plotly.
🧹 Nitpick comments (1)
R/module-qc-server.R (1)

498-512: Optional: collapse the two PTM branches to reduce duplication.

The only difference between the PTM+TMT and PTM+non-TMT branches is the setnames call; the quantification(temp$PTM, ...) call is identical. Consider merging:

♻️ Proposed refactor
-    if (loadpage_input()$BIO == "PTM" && loadpage_input()$DDA_DIA == "TMT"){
-      temp = copy(preprocess_data())
-      setnames(temp$PTM$ProteinLevelData, 
-               c("Abundance", "Condition", "BioReplicate"), 
-               c("LogIntensities", "GROUP", "SUBJECT"))
-      abundant$results = quantification(temp$PTM,
-                                        type = input$typequant,
-                                        format = input$format,
-                                        use_log_file = FALSE)
-    } else if (loadpage_input()$BIO == "PTM" && loadpage_input()$DDA_DIA != "TMT"){
-      temp = copy(preprocess_data())
-      abundant$results =quantification(temp$PTM,
-                                       type = input$typequant,
-                                       format = input$format,
-                                       use_log_file = FALSE)
-    } else if (loadpage_input()$DDA_DIA == "TMT"){
+    if (loadpage_input()$BIO == "PTM") {
+      temp = copy(preprocess_data())
+      if (loadpage_input()$DDA_DIA == "TMT") {
+        setnames(temp$PTM$ProteinLevelData,
+                 c("Abundance", "Condition", "BioReplicate"),
+                 c("LogIntensities", "GROUP", "SUBJECT"))
+      }
+      abundant$results = quantification(temp$PTM,
+                                        type = input$typequant,
+                                        format = input$format,
+                                        use_log_file = FALSE)
+    } else if (loadpage_input()$DDA_DIA == "TMT"){
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@R/module-qc-server.R` around lines 498 - 512, Collapse the duplicated PTM
branches by calling setnames only when loadpage_input()$DDA_DIA == "TMT" and
then performing the single quantification call; specifically, inside the
conditional for loadpage_input()$BIO == "PTM" obtain temp <-
copy(preprocess_data()), if DDA_DIA == "TMT" call setnames on
temp$PTM$ProteinLevelData (referencing the same column names currently used),
then assign abundant$results <- quantification(temp$PTM, type = input$typequant,
format = input$format, use_log_file = FALSE). This removes the duplicated
quantification call and preserves the unique renaming step.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@R/module-qc-server.R`:
- Around line 513-521: preprocess_data() returns a list containing data.tables,
but copy(preprocess_data()) only clones the list structure so the subsequent
setnames(temp$ProteinLevelData, ...) mutates the original; to fix, deep-copy the
nested data.table(s) before modifying them (e.g., after temp =
copy(preprocess_data()) do an explicit copy of temp$ProteinLevelData) so
setnames changes only the local temp used to compute abundant$results via
quantification; apply the same pattern if there are other nested tables in temp.

---

Outside diff comments:
In `@R/module-qc-server.R`:
- Around line 269-315: The PTM branch in plotresult (dataProcessPlotsPTM) is
passing address = file together with isPlotly = TRUE which causes the internal
function to write HTML while output$saveplot opens a PDF device; change
plotresult to detect the saveFile flag (the first parameter) and when saving
(saveFile == TRUE) call dataProcessPlotsPTM with isPlotly = FALSE and do not
pass address (or set address = NULL), otherwise keep isPlotly = TRUE and pass
address = file; update the PTM branch in plotresult (and similarly any other
branches that use address/isPlotly) so PDF export uses non-Plotly/ggplot output
while interactive uses Plotly.

---

Nitpick comments:
In `@R/module-qc-server.R`:
- Around line 498-512: Collapse the duplicated PTM branches by calling setnames
only when loadpage_input()$DDA_DIA == "TMT" and then performing the single
quantification call; specifically, inside the conditional for
loadpage_input()$BIO == "PTM" obtain temp <- copy(preprocess_data()), if DDA_DIA
== "TMT" call setnames on temp$PTM$ProteinLevelData (referencing the same column
names currently used), then assign abundant$results <- quantification(temp$PTM,
type = input$typequant, format = input$format, use_log_file = FALSE). This
removes the duplicated quantification call and preserves the unique renaming
step.
🪄 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: 10d3259b-fd05-4537-a518-82370e7407e1

📥 Commits

Reviewing files that changed from the base of the PR and between 83156ff and 762832e.

📒 Files selected for processing (2)
  • R/module-qc-server.R
  • R/module-qc-ui.R
💤 Files with no reviewable changes (1)
  • R/module-qc-ui.R

Comment thread R/module-qc-server.R
@tonywu1999 tonywu1999 changed the title Fix ptm fix(PTMs): Fix bugs related to PTM E2E processing Apr 24, 2026
@tonywu1999 tonywu1999 merged commit ccd22d3 into devel Apr 24, 2026
1 of 2 checks passed
@tonywu1999 tonywu1999 deleted the fix-ptm branch April 24, 2026 20:20
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