Skip to content

Feat peptide weighting - #222

Merged
tonywu1999 merged 7 commits into
develfrom
feat-peptide-weighting
Jul 20, 2026
Merged

Feat peptide weighting#222
tonywu1999 merged 7 commits into
develfrom
feat-peptide-weighting

Conversation

@tonywu1999

@tonywu1999 tonywu1999 commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

Motivation and Context

Protein turnover analyses need optional peptide-level quality weighting while preserving existing unweighted workflows. This change adds feature-weighting controls, propagates weights through turnover preprocessing and dose-response fitting, and includes weighting in visualizations, downloads, and generated analysis scripts.

Changes

  • Added calculatePeptideWeights as an MSstatsResponse import.
  • Added QC controls for:
    • Feature subset selection.
    • Optional feature-weight assignment.
  • Added visibility logic for these controls based on workflow template and labeling mode.
  • Applied optional peptide weights to turnover ratios displayed in tables and CSV downloads.
  • Preserved existing weights during turnover preprocessing and assigned weight 1 to synthetic zero-dose rows.
  • Passed weights through dose-response fitting and turnover visualizations.
  • Added turnover-specific generated analysis code supporting weighted and unweighted workflows.
  • Updated related documentation and removed the obsolete get_download_plot_filename documentation page.

Tests

  • Added tests for turnover weight preservation, omission, and zero-dose defaults.
  • Extended analysis-code generation tests to verify turnover-ratio recalculation.
  • Added tests for weighted and unweighted generated scripts, including syntax validation and correct fraction selection.
  • Added QC rendering tests for feature-subset and feature-weight visibility predicates.

@coderabbitai

coderabbitai Bot commented Jul 20, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@tonywu1999, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 50 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

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.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: e53df0b2-35d3-4226-a5b4-8d579fb90966

📥 Commits

Reviewing files that changed from the base of the PR and between 3eca89e and b96ca2a.

📒 Files selected for processing (1)
  • R/statmodel-server-download-code.R
📝 Walkthrough

Walkthrough

Adds optional peptide feature weighting to protein-turnover QC controls, preprocessing, dose-response fitting, visualization, downloads, and generated analysis scripts. It also registers the new dependency import and updates related tests and module documentation.

Changes

Protein turnover feature weighting

Layer / File(s) Summary
QC controls and visibility
R/constants.R, R/module-qc-ui.R, R/qc-server-sidebar.R, tests/testthat/test-qc-server-rendering.R
Adds feature-subset and feature-weighting panels, template-based visibility predicates, and rendering tests.
Weight propagation and display
R/qc-server-turnover.R, R/statmodel-server-comparisons.R, R/module-statmodel-server.R, R/statmodel-server-visualization.R, tests/testthat/test-module-turnover.R
Preserves weights through synthetic turnover rows, applies optional peptide weights to displayed ratios, and passes weights to fitting and plotting paths.
Turnover analysis code generation
R/statmodel-server-download-code.R, tests/testthat/test-module-turnover.R
Adds dedicated protein-turnover script generation with optional peptide weighting, weighted fitting, visualization, tracer serialization, and syntax coverage.
Package imports and documentation
NAMESPACE, R/MSstatsShiny.R, man/loadpageServer.Rd
Registers calculatePeptideWeights and documents the loadpageServer template argument and split orchestration.

Estimated code review effort: 4 (Complex) | ~45 minutes

Sequence Diagram(s)

sequenceDiagram
  participant QC as QC controls
  participant Ratios as turnover_ratios_display
  participant Prepare as turnover preparation
  participant Fit as doseResponseFit
  participant Plot as visualizeResponseProtein
  QC->>Ratios: Enable feature weighting
  Ratios->>Ratios: calculatePeptideWeights(ratios)
  Ratios->>Prepare: Provide weighted ratios
  Prepare->>Fit: Supply prepared weights
  Prepare->>Plot: Supply prepared weights
Loading

Possibly related PRs

Suggested labels: enhancement

Suggested reviewers: swaraj-neu

Poem

I’m a rabbit with weights in my pack,
Peptide by peptide, I hop down the track.
Turnover curves rise, plots gently glow,
Zero-time anchors keep rows in a row.
Scripts bloom with tracer light—
Weighted hops make analysis right!

🚥 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 matches the main change: adding peptide weighting support.
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.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat-peptide-weighting

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.

@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

🧹 Nitpick comments (3)
R/module-qc-ui.R (2)

109-111: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Prefer paste0 for multi-line strings to avoid whitespace artifacts.

Using a backslash \ to continue a string on the next line preserves all of the leading indentation from the following line within the string literal itself. While HTML will visually collapse these spaces into one, it's safer and cleaner to use paste0 to prevent unintended large gaps in the raw text content.

♻️ Proposed refactor
-                                    div("What features to use in \
-                                     summarization. All features or a subset of \
-                                     features can be used.", class = "icon-tooltip")),
+                                    div(paste0("What features to use in ",
+                                               "summarization. All features or a subset of ",
+                                               "features can be used."), class = "icon-tooltip")),
🤖 Prompt for 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.

In `@R/module-qc-ui.R` around lines 109 - 111, Update the multi-line tooltip
string in the div call to use paste0 with separate string fragments instead of
backslash continuation, preserving the same displayed text without indentation
whitespace artifacts.

126-129: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Prefer paste0 for multi-line strings to avoid whitespace artifacts.

Similar to the previous tooltip, escaping newlines here silently pulls the indentation into the string literal.

♻️ Proposed refactor
-                               div("Compute per-peptide quality weights (coverage, \
-                                intensity, monotonicity, validity) and add them as \
-                                extra columns to the Turnover Ratios table.",
-                                   class = "icon-tooltip")),
+                               div(paste0("Compute per-peptide quality weights (coverage, ",
+                                          "intensity, monotonicity, validity) and add them as ",
+                                          "extra columns to the Turnover Ratios table."),
+                                   class = "icon-tooltip")),
🤖 Prompt for 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.

In `@R/module-qc-ui.R` around lines 126 - 129, Update the multi-line tooltip
string in the div call to use paste0, preserving the displayed wording while
preventing indentation and newline whitespace from being included in the
literal.
R/statmodel-server-download-code.R (1)

67-92: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Remove unreachable dead code.

The early return at line 18 (if (isTRUE(app_template == TEMPLATES$protein_turnover)) return(codes)) completely handles the protein-turnover case. This makes the if block at line 67 unreachable. You can safely remove it and retain only the content of the else block to simplify the function.

♻️ Proposed refactor
-    if (app_template == TEMPLATES$protein_turnover) {
-      codes = paste(codes, "visualizeResponseProtein(\n",
-                    "  data = prepared_data,\n",
-                    "  protein_name = \"Enter protein name here\",\n",
-                    "  drug_name = \"time\",\n",
-                    "  ratio_response = FALSE,\n",
-                    "  show_ic50 = TRUE,\n",
-                    "  add_ci = FALSE,\n",
-                    "  transform_dose = FALSE,\n",
-                    "  n_samples = 1000,\n",
-                    "  increasing = ", increasing, ",\n",
-                    "  precalculated_ratios = TRUE,\n",
-                    "  color_by = \"BaseSequence\",\n",
-                    "  target_response = 0.5\n)\n", sep = "")
-    } else {
-      codes = paste(codes, "visualizeResponseProtein(\n",
-                    "  data = prepared_data,\n",
-                    "  protein_name = \"Enter protein name here\",\n",
-                    "  drug_name = \"Enter drug name here\",\n",
-                    "  ratio_response = ", ratio_response, ",\n",
-                    "  show_ic50 = TRUE,\n",
-                    "  add_ci = TRUE,\n",
-                    "  transform_dose = ", transform_dose, ",\n",
-                    "  n_samples = 1000,\n",
-                    "  increasing = ", increasing, "\n)\n", sep = "")
-    }
+    codes = paste(codes, "visualizeResponseProtein(\n",
+                  "  data = prepared_data,\n",
+                  "  protein_name = \"Enter protein name here\",\n",
+                  "  drug_name = \"Enter drug name here\",\n",
+                  "  ratio_response = ", ratio_response, ",\n",
+                  "  show_ic50 = TRUE,\n",
+                  "  add_ci = TRUE,\n",
+                  "  transform_dose = ", transform_dose, ",\n",
+                  "  n_samples = 1000,\n",
+                  "  increasing = ", increasing, "\n)\n", sep = "")
🤖 Prompt for 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.

In `@R/statmodel-server-download-code.R` around lines 67 - 92, Remove the
unreachable app_template == TEMPLATES$protein_turnover branch from the
code-generation logic, including its specialized visualizeResponseProtein
construction. Retain the existing else-branch content as the sole path for this
section, preserving its current parameters and formatting.
🤖 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-download-code.R`:
- Line 194: Update the samples_per_condition check in the generated
condition-sampling logic to call any() with na.rm = TRUE, ensuring unused factor
levels producing NA do not cause a runtime error while preserving the existing >
1 condition.
- Around line 223-239: Update the generated-data subsetting in the turnover
preparation block, using keep_cols and prepared_data, to intersect the requested
columns with colnames(prepared_data) before selecting them. Preserve the
weighting-dependent column list while excluding conditionally absent columns
such as BaseSequence, preventing undefined-column errors for protein-level
turnover data.

---

Nitpick comments:
In `@R/module-qc-ui.R`:
- Around line 109-111: Update the multi-line tooltip string in the div call to
use paste0 with separate string fragments instead of backslash continuation,
preserving the same displayed text without indentation whitespace artifacts.
- Around line 126-129: Update the multi-line tooltip string in the div call to
use paste0, preserving the displayed wording while preventing indentation and
newline whitespace from being included in the literal.

In `@R/statmodel-server-download-code.R`:
- Around line 67-92: Remove the unreachable app_template ==
TEMPLATES$protein_turnover branch from the code-generation logic, including its
specialized visualizeResponseProtein construction. Retain the existing
else-branch content as the sole path for this section, preserving its current
parameters and formatting.
🪄 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: 26c41d70-8d3f-4f98-bd97-9fb0683a4b49

📥 Commits

Reviewing files that changed from the base of the PR and between 9f08e0c and 3eca89e.

📒 Files selected for processing (14)
  • NAMESPACE
  • R/MSstatsShiny.R
  • R/constants.R
  • R/module-qc-ui.R
  • R/module-statmodel-server.R
  • R/qc-server-sidebar.R
  • R/qc-server-turnover.R
  • R/statmodel-server-comparisons.R
  • R/statmodel-server-download-code.R
  • R/statmodel-server-visualization.R
  • man/get_download_plot_filename.Rd
  • man/loadpageServer.Rd
  • tests/testthat/test-module-turnover.R
  • tests/testthat/test-qc-server-rendering.R
💤 Files with no reviewable changes (1)
  • man/get_download_plot_filename.Rd

Comment thread R/statmodel-server-download-code.R Outdated
Comment thread R/statmodel-server-download-code.R Outdated
tonywu1999 and others added 2 commits July 20, 2026 17:55
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
@tonywu1999
tonywu1999 merged commit 5e560ba into devel Jul 20, 2026
1 of 2 checks passed
@tonywu1999
tonywu1999 deleted the feat-peptide-weighting branch July 20, 2026 22:03
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