Skip to content

fix(vignette): Turn off nM to M conversion in vignette#8

Merged
tonywu1999 merged 8 commits intodevelfrom
fix-vignette
Apr 20, 2026
Merged

fix(vignette): Turn off nM to M conversion in vignette#8
tonywu1999 merged 8 commits intodevelfrom
fix-vignette

Conversation

@tonywu1999
Copy link
Copy Markdown
Contributor

@tonywu1999 tonywu1999 commented Apr 16, 2026

Motivation and Context

The vignette example for MSstatsPrepareDoseResponseFit was converting nanomolar dose values to molar units by default. This PR updates the vignette to stop performing that conversion (transform_nM_to_M = FALSE) when dose_nM is already present. The PR also introduces a new public utility calculatePeptideWeights, removes selectTopNPeptides from the public API/docs, and updates several documentation examples and IC50-related tests to reflect API/behavior changes.

Summary of the solution

  • Prevents automatic nM → M conversion in the vignette example by setting transform_nM_to_M = FALSE.
  • Adds a new exported API calculatePeptideWeights with documentation and examples.
  • Removes the public/documentation surface for selectTopNPeptides.
  • Wraps multiple long examples in \dontrun{} and qualifies an internal example call to avoid execution during R CMD check.
  • Updates IC50 test call sites and expectations to match the revised helper behavior/outputs.

Detailed changes

  • vignettes/MSstatsResponse.Rmd

    • Example call changed: MSstatsPrepareDoseResponseFit(..., transform_nM_to_M = TRUE) → transform_nM_to_M = FALSE. No other vignette logic changed.
  • NAMESPACE

    • Added export: calculatePeptideWeights
    • Removed export: selectTopNPeptides
    • Added imports/uses: dplyr::across, dplyr::all_of, stats::cor
  • New/updated documentation (man/*.Rd and R roxygen changes)

    • man/calculatePeptideWeights.Rd: New roxygen-generated documentation for calculatePeptideWeights(data, protein_col = "Protein", peptide_col = "BaseSequence", time_col = "TimeVal", response_col = "H_frac", light_intensity_col = "Light", validity_threshold = 1.3, top_n_peptides = NULL). Documents produced diagnostic columns (n_obs, coverage_score, light_intensity_score, monotonicity_score, validity_flag) and combined weight; includes examples.
    • man/selectTopNPeptides.Rd: Removed the roxygen-generated documentation stub for selectTopNPeptides.
    • man/doseResponseFit.Rd: Minor whitespace change in examples (removed a blank line).
    • man/calculateTurnoverRatios.Rd, man/parse_timepoint.Rd, man/visualizeResponseProtein.Rd, and R/Visualize_Isotonic_Fit.R: Example blocks updated — several examples wrapped in \dontrun{...} and parse_timepoint example qualified as MSstatsResponse:::parse_timepoint(...). R/visualizeResponseProtein examples placed in \dontrun{}.
  • R/source changes (documentation/example guards)

    • R/protein_turnover_ratio_helper.R: Examples wrapped in \dontrun{} and parse_timepoint references qualified; calculatePeptideWeights examples wrapped in \dontrun{}.
  • Tests

    • tests/testthat/test-IC50_prediction.R
      • Updated .calcSingleIC50 call sites to include precalculated_ratios = FALSE in relevant cases.
      • Extended expected schema to include a direction column for single-pair test expectations.
    • tests/testthat/test-PredictIC50.R
      • Updated expectations to require results include a direction column alongside protein, drug, IC50, IC50_lower_bound, IC50_upper_bound.

Unit tests added or modified

  • Modified:

    • tests/testthat/test-IC50_prediction.R
      • .calcSingleIC50 invocations adjusted to pass precalculated_ratios = FALSE where applicable.
      • Single-pair test expectation extended to expect a new direction column.
    • tests/testthat/test-PredictIC50.R
      • Assertion updated to expect a direction column in predictIC50 results.
  • No new tests were added beyond the adjusted expectations and call-site changes described.

Coding guidelines

  • No coding guideline violations identified in the provided diffs. Documentation and namespace changes include roxygen docs for the newly exported function; examples that could run during checks are now wrapped in \dontrun{} where appropriate.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 16, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 5ecc2919-70c4-4f75-a2ff-20a3b081ab88

📥 Commits

Reviewing files that changed from the base of the PR and between 1875459 and 2831320.

📒 Files selected for processing (8)
  • R/Visualize_Isotonic_Fit.R
  • R/protein_turnover_ratio_helper.R
  • man/calculatePeptideWeights.Rd
  • man/calculateTurnoverRatios.Rd
  • man/parse_timepoint.Rd
  • man/visualizeResponseProtein.Rd
  • tests/testthat/test-IC50_prediction.R
  • tests/testthat/test-PredictIC50.R
✅ Files skipped from review due to trivial changes (6)
  • man/visualizeResponseProtein.Rd
  • man/parse_timepoint.Rd
  • R/Visualize_Isotonic_Fit.R
  • R/protein_turnover_ratio_helper.R
  • man/calculateTurnoverRatios.Rd
  • man/calculatePeptideWeights.Rd
🚧 Files skipped from review as they are similar to previous changes (1)
  • tests/testthat/test-IC50_prediction.R

📝 Walkthrough

Walkthrough

Adds a new exported function calculatePeptideWeights with documentation, removes the export and documentation for selectTopNPeptides, updates NAMESPACE imports (dplyr::across, dplyr::all_of, stats::cor), tweaks a vignette example (transform_nM_to_M = FALSE), and updates tests to pass precalculated_ratios = FALSE.

Changes

Cohort / File(s) Summary
Vignette
vignettes/MSstatsResponse.Rmd
Example call to MSstatsPrepareDoseResponseFit() changed: transform_nM_to_M from TRUE to FALSE.
New API & Docs
NAMESPACE, man/calculatePeptideWeights.Rd, R/protein_turnover_ratio_helper.R
Added export and man page for calculatePeptideWeights; added imports dplyr::across, dplyr::all_of, stats::cor; updated examples (wrapped in \dontrun{}) referencing the new function.
Removed API Docs & Export
NAMESPACE, man/selectTopNPeptides.Rd
Removed export and removed the roxygen-generated Rd for selectTopNPeptides.
Documentation examples (dontrun / qualification)
man/calculateTurnoverRatios.Rd, man/parse_timepoint.Rd, man/visualizeResponseProtein.Rd, R/Visualize_Isotonic_Fit.R
Wrapped example blocks in \dontrun{} and qualified parse_timepoint() examples with MSstatsResponse:::; adjusted example handling for visualization.
Tests
tests/testthat/test-IC50_prediction.R, tests/testthat/test-PredictIC50.R
Updated calls to .calcSingleIC50 to include precalculated_ratios = FALSE; tests updated to expect a new direction column in results.
Minor docs whitespace
man/doseResponseFit.Rd
Removed a single blank line in Examples (whitespace-only change).

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested labels

enhancement

Poem

🐰 A new weight wiggles on a leaf,
The old selector hops away in brief.
Vignettes whisper units turned small,
Tests listen close and answer the call.
Hooray — tiny hops, a tidy overhaul. 🥕

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Title check ⚠️ Warning The title claims to fix a vignette by turning off nM to M conversion, but the actual changeset includes substantial modifications beyond this single vignette change: a new exported function (calculatePeptideWeights), removal of an exported function (selectTopNPeptides), updated documentation across multiple files, and test updates. The title is misleading and does not reflect the primary scope of changes. Revise the title to accurately reflect the major changes, such as 'feat: Add calculatePeptideWeights function and update related documentation' or break this into focused pull requests by concern.
✅ Passed checks (2 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.

✏️ 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 fix-vignette

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.

🧹 Nitpick comments (1)
vignettes/MSstatsResponse.Rmd (1)

157-166: Document the transform_nM_to_M parameter choice and its implications.

The vignette changes transform_nM_to_M from TRUE to FALSE, but provides no explanation of what this parameter does or why FALSE is chosen. Since doses are in nanomolar (column named dose_nM, line 161) and remain in nM throughout the analysis, downstream IC50 predictions will also be reported in nM rather than molar units. This choice is appropriate given that transform_dose = TRUE (line 202) applies log10(dose + 1) transformation, which behaves more sensibly with nM-scale values (e.g., log10(1001) ≈ 3) than with molar-scale values (e.g., log10(10^-6 + 1) ≈ 0).

Consider adding explanatory text in the prose (around lines 151-156) or an inline comment to clarify:

  • What transform_nM_to_M controls (unit conversion from nM to M)
  • Why FALSE is appropriate for this dataset (doses already in nM, more intuitive IC50 values)
  • That IC50 estimates (section starting line 245) will be in nM units
📝 Suggested documentation addition

Add explanatory text before the code block:

 This function standardizes the data structure for downstream analysis. Users can either use pre-processed data as shown above (e.g., dia_normalized$ProteinLevelData) or begin at this step with their own datasets. It is important to ensure that column names are correctly matched to the expected ones when using MSstatsPrepareDoseResponseFit().
   
 The dose_column corresponds to the values on the x-axis (e.g., dose, concentration, time, or temperature). The protein_column should contain unique identifiers (e.g., protein, gene, or peptide sequence), and the log_abundance_column represents the response values on the y-axis (e.g., log intensity, expression, or growth).
+
+**Unit handling:** Since our doses are already in nanomolar units (`dose_nM`), we set `transform_nM_to_M = FALSE` to keep doses on the nanomolar scale throughout the analysis. This ensures that downstream IC50 estimates are reported in nanomolar units, which are more intuitive for typical drug concentrations. If your doses were in molar units or you prefer molar-scale outputs, set this parameter to `TRUE`.

Or add an inline comment:

   transform_nM_to_M = FALSE  
+  # Keep doses in nM; IC50 estimates will be in nM (not converted to M)
 )
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@vignettes/MSstatsResponse.Rmd` around lines 157 - 166, Document that the
parameter transform_nM_to_M in MSstatsPrepareDoseResponseFit controls conversion
of dose units from nanomolar to molar, and add a brief explanation near the
MSstatsPrepareDoseResponseFit call (or as an inline comment) stating that
transform_nM_to_M = FALSE is chosen because the input dose column "dose_nM" is
already in nM so downstream results and IC50 estimates (later IC50 section) will
be reported in nM; also mention that transform_dose = TRUE applies log10(dose +
1) and thus behaves more sensibly on nM-scale values, so leaving
transform_nM_to_M = FALSE preserves intuitive nM-scale IC50s.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@vignettes/MSstatsResponse.Rmd`:
- Around line 157-166: Document that the parameter transform_nM_to_M in
MSstatsPrepareDoseResponseFit controls conversion of dose units from nanomolar
to molar, and add a brief explanation near the MSstatsPrepareDoseResponseFit
call (or as an inline comment) stating that transform_nM_to_M = FALSE is chosen
because the input dose column "dose_nM" is already in nM so downstream results
and IC50 estimates (later IC50 section) will be reported in nM; also mention
that transform_dose = TRUE applies log10(dose + 1) and thus behaves more
sensibly on nM-scale values, so leaving transform_nM_to_M = FALSE preserves
intuitive nM-scale IC50s.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: a29b6b95-90f0-410b-b205-bfb444830509

📥 Commits

Reviewing files that changed from the base of the PR and between d4ec9bf and 461d93b.

📒 Files selected for processing (1)
  • vignettes/MSstatsResponse.Rmd

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: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@man/calculatePeptideWeights.Rd`:
- Line 40: The documentation for light_intensity_score is incorrect: update the
`@return` section in the R source (where calculatePeptideWeights / related roxygen
block is defined) to describe that light_intensity_score is a binary flag (1/0)
determined by the peptide's median-light rank within its protein and the
top_n_peptides filter (1 when top_n_peptides is NULL or when rank <=
top_n_peptides, else 0), not a normalized median intensity; then run
devtools::document() to regenerate man/calculatePeptideWeights.Rd so the help
text matches the implementation in R/protein_turnover_ratio_helper.R (reference
symbols: light_intensity_score, top_n_peptides, calculatePeptideWeights).
- Around line 50-73: The examples in the man page use an undeclared dataset
feature_data; update the examples to either use a documented dataset (e.g.,
replace feature_data with DIA_MSstats_Normalized) or wrap the entire example
block in \dontrun{} so it won't be executed during R CMD check; update the
corresponding `@examples` in R/protein_turnover_ratio_helper.R to reflect this
change and re-run roxygenize to regenerate documentation for
calculatePeptideWeights, calculateTurnoverRatios, and doseResponseFit examples.
🪄 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: 44362aed-f1b9-4467-b161-ea26fe7a4d5f

📥 Commits

Reviewing files that changed from the base of the PR and between 461d93b and 3130791.

📒 Files selected for processing (4)
  • NAMESPACE
  • man/calculatePeptideWeights.Rd
  • man/doseResponseFit.Rd
  • man/selectTopNPeptides.Rd
💤 Files with no reviewable changes (2)
  • man/doseResponseFit.Rd
  • man/selectTopNPeptides.Rd

\itemize{
\item n_obs: Number of observations for this peptide
\item coverage_score: Proportion of timepoints observed
\item light_intensity_score: Normalized median light intensity (per protein)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

light_intensity_score description doesn't match the implementation.

The doc states light_intensity_score: Normalized median light intensity (per protein), but per the implementation in R/protein_turnover_ratio_helper.R, light_intensity_score is a binary 0/1 flag: 1 when top_n_peptides is NULL (no filtering), otherwise 1 if the peptide's median-light rank within its protein is <= top_n_peptides, else 0. It is not a normalized intensity value.

Since this is a roxygen2-generated file, please update the @return item in the R source and re-run devtools::document().

📝 Proposed wording
-\item light_intensity_score: Normalized median light intensity (per protein)
+\item light_intensity_score: Binary top-N flag per protein (1 if peptide's median light intensity rank <= top_n_peptides, else 0; always 1 when top_n_peptides is NULL)
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@man/calculatePeptideWeights.Rd` at line 40, The documentation for
light_intensity_score is incorrect: update the `@return` section in the R source
(where calculatePeptideWeights / related roxygen block is defined) to describe
that light_intensity_score is a binary flag (1/0) determined by the peptide's
median-light rank within its protein and the top_n_peptides filter (1 when
top_n_peptides is NULL or when rank <= top_n_peptides, else 0), not a normalized
median intensity; then run devtools::document() to regenerate
man/calculatePeptideWeights.Rd so the help text matches the implementation in
R/protein_turnover_ratio_helper.R (reference symbols: light_intensity_score,
top_n_peptides, calculatePeptideWeights).

Comment thread man/calculatePeptideWeights.Rd
@tonywu1999 tonywu1999 merged commit bb1cade into devel Apr 20, 2026
2 checks passed
@tonywu1999 tonywu1999 deleted the fix-vignette branch April 20, 2026 18:08
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