Repository navigation
refactor(summarization): Rename ref regression covariate to ref_covariate for SRM experiments - #190
Conversation
📝 WalkthroughWalkthroughReplaces the Changes
Sequence Diagram(s)(omitted) Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 inconclusive)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Comment |
PR Reviewer Guide 🔍Here are some key observations to aid the review process:
|
PR Code Suggestions ✨Explore these optional code suggestions:
|
There was a problem hiding this comment.
🧹 Nitpick comments (1)
inst/tinytest/test_utils_summarization.R (1)
75-78: Strengthen the assertion to require a non-aliasedref_covariateeffect.Right now the test passes if the term name exists even when all
ref_covariatecoefficients areNA(aliased). Consider asserting at least one non-NAref_covariatecoefficient.Suggested test hardening
-expect_true( - any(grepl("ref_covariate", names(coef(lm_fit)))), - info = "ref_covariate: model coefficients must include 'ref_covariate' terms" -) +coef_vals <- coef(lm_fit) +ref_terms <- coef_vals[grepl("^ref_covariate", names(coef_vals))] +expect_true( + length(ref_terms) > 0 && any(!is.na(ref_terms)), + info = "ref_covariate: model must retain at least one estimable ref_covariate coefficient" +)🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@inst/tinytest/test_utils_summarization.R` around lines 75 - 78, The test currently only checks that a term named "ref_covariate" appears in coef(lm_fit); change the assertion to require at least one non-NA coefficient for that effect by extracting coef(lm_fit)[grepl("ref_covariate", names(coef(lm_fit)))], checking its length > 0 and that any(!is.na(...)) is true, and update the expect_* call (e.g., expect_true or expect_false with appropriate info) so the test fails when all ref_covariate coefficients are aliased (NA).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@inst/tinytest/test_utils_summarization.R`:
- Around line 75-78: The test currently only checks that a term named
"ref_covariate" appears in coef(lm_fit); change the assertion to require at
least one non-NA coefficient for that effect by extracting
coef(lm_fit)[grepl("ref_covariate", names(coef(lm_fit)))], checking its length >
0 and that any(!is.na(...)) is true, and update the expect_* call (e.g.,
expect_true or expect_false with appropriate info) so the test fails when all
ref_covariate coefficients are aliased (NA).
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: d7c2ee8c-e026-4c58-bd0e-d712a2f45273
📒 Files selected for processing (6)
R/dataProcess.RR/utils_imputation.RR/utils_summarization.RR/utils_summarization_prepare.Rinst/tinytest/test_dataProcess.Rinst/tinytest/test_utils_summarization.R
There was a problem hiding this comment.
🧹 Nitpick comments (3)
inst/tinytest/test_utils_imputation.R (2)
19-20: Consider extracting sharedref_covariateconstruction.The same transformation is repeated in three fixtures. A tiny helper would reduce drift risk in future renames.
♻️ Suggested refactor
+add_ref_covariate <- function(dt, runs) { + ref_vals <- ifelse(dt$LABEL == "L", as.character(dt$RUN), "0") + dt[["ref_covariate"]] <- factor(ref_vals, levels = c("0", runs)) + dt +} + make_surv_labeled_single <- function() { @@ - ref_vals <- ifelse(dt$LABEL == "L", as.character(dt$RUN), "0") - dt[["ref_covariate"]] <- factor(ref_vals, levels = c("0", runs)) - dt + add_ref_covariate(dt, runs) }Also applies to: 33-34, 55-56
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@inst/tinytest/test_utils_imputation.R` around lines 19 - 20, Extract the repeated construction of ref_vals and dt[["ref_covariate"]] into a small helper (e.g., make_ref_covariate) and call it from the three fixtures instead of duplicating the logic; specifically, move the logic that builds ref_vals <- ifelse(dt$LABEL == "L", as.character(dt$RUN), "0") and dt[["ref_covariate"]] <- factor(ref_vals, levels = c("0", runs)) into that helper, accept dt and runs as parameters, return the modified dt (or the factor), and replace the three inline occurrences (the blocks constructing ref_vals and setting dt[["ref_covariate"]]) with calls to make_ref_covariate.
83-133: Assertions are strong, but one branch is still untested.Given
.fitSurvivalinR/utils_imputation.Rhas a distinct unlabeled underdetermined fallback (~ RUN), add one fixture/assertion pair for that case to lock behavior.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@inst/tinytest/test_utils_imputation.R` around lines 83 - 133, Add a test case for the unlabeled underdetermined branch by calling MSstats:::.fitSurvival with a fixture like make_surv_unlabeled_underdetermined() (mirror the pattern of surv_labeled_under and surv_unlabeled_multi_wd) and assert that the resulting coef names do NOT contain "ref_covariate" and do NOT contain "^FEATURE" (i.e., add two expect_false checks similar to the other unlabeled assertions, referencing the new variable e.g. surv_unlabeled_under to locate the test).inst/tinytest/test_utils_summarization_prepare.R (1)
21-21: Add teardown to restore logging settings.
MSstatsConvert::MSstatsLogsSettings(FALSE)on line 21 changes global behavior and is never restored. This will disable logging for all subsequent tests executed in the same R session. Add a corresponding restoration call (e.g.,MSstatsConvert::MSstatsLogsSettings(TRUE)) at the end of the file to prevent unintended side effects on other tests.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@inst/tinytest/test_utils_summarization_prepare.R` at line 21, The test file calls MSstatsConvert::MSstatsLogsSettings(FALSE) which mutates global logging state and is never restored; add a teardown to reset it (e.g., call MSstatsConvert::MSstatsLogsSettings(TRUE)) at the end of the file or register a cleanup/on.exit handler so logging is restored after tests finish; reference the existing call to MSstatsConvert::MSstatsLogsSettings(FALSE) when adding the restoration to ensure the global setting is returned to TRUE.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@inst/tinytest/test_utils_imputation.R`:
- Around line 19-20: Extract the repeated construction of ref_vals and
dt[["ref_covariate"]] into a small helper (e.g., make_ref_covariate) and call it
from the three fixtures instead of duplicating the logic; specifically, move the
logic that builds ref_vals <- ifelse(dt$LABEL == "L", as.character(dt$RUN), "0")
and dt[["ref_covariate"]] <- factor(ref_vals, levels = c("0", runs)) into that
helper, accept dt and runs as parameters, return the modified dt (or the
factor), and replace the three inline occurrences (the blocks constructing
ref_vals and setting dt[["ref_covariate"]]) with calls to make_ref_covariate.
- Around line 83-133: Add a test case for the unlabeled underdetermined branch
by calling MSstats:::.fitSurvival with a fixture like
make_surv_unlabeled_underdetermined() (mirror the pattern of surv_labeled_under
and surv_unlabeled_multi_wd) and assert that the resulting coef names do NOT
contain "ref_covariate" and do NOT contain "^FEATURE" (i.e., add two
expect_false checks similar to the other unlabeled assertions, referencing the
new variable e.g. surv_unlabeled_under to locate the test).
In `@inst/tinytest/test_utils_summarization_prepare.R`:
- Line 21: The test file calls MSstatsConvert::MSstatsLogsSettings(FALSE) which
mutates global logging state and is never restored; add a teardown to reset it
(e.g., call MSstatsConvert::MSstatsLogsSettings(TRUE)) at the end of the file or
register a cleanup/on.exit handler so logging is restored after tests finish;
reference the existing call to MSstatsConvert::MSstatsLogsSettings(FALSE) when
adding the restoration to ensure the global setting is returned to TRUE.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: f5405e57-b85e-4a95-b9d6-6f7071c18424
📒 Files selected for processing (2)
inst/tinytest/test_utils_imputation.Rinst/tinytest/test_utils_summarization_prepare.R
PR Type
Bug fix, Tests
Description
Rename labeled reference term to
ref_covariateUpdate preparation, imputation, summarization models
Align
dataProcessaccepted input columnsAdd regression tests for outputs and coefficients
Diagram Walkthrough
File Walkthrough
dataProcess.R
Use `ref_covariate` in summarization inputsR/dataProcess.R
ref_covariatein summarization column subsetsutils_imputation.R
Switch AFT models to `ref_covariate`R/utils_imputation.R
refwithref_covariatein AFT modelsutils_summarization.R
Update labeled linear model covariateR/utils_summarization.R
ref_covariatein labeled linear modelsutils_summarization_prepare.R
Create `ref_covariate` during summarization preparationR/utils_summarization_prepare.R
ref_covariatefor label-based inputsRUNor0test_dataProcess.R
Add output column regression checksinst/tinytest/test_dataProcess.R
ProteinLevelDataincludesLogIntensitiesProteinLevelDataincludesGROUPtest_utils_summarization.R
Test labeled models with `ref_covariate`inst/tinytest/test_utils_summarization.R
ref_covariate.fitLinearModelon labeled inputref_covariatetermsMotivation and Context
This PR refactors the labeled reference term naming convention across the MSstats summarization and imputation pipeline. Previously, the reference indicator for labeled experiments was stored in a column named
ref. This refactoring renames this term toref_covariateto improve naming clarity and semantic consistency. The change propagates through data preparation, survival model fitting, and linear model fitting, ensuring that all downstream analyses correctly reference the renamed covariate in their formulas and data subsets.Detailed Changes
Core Implementation Changes
R/utils_summarization_prepare.R: Modified
MSstatsPrepareForSummarization()to create theref_covariatecolumn instead ofrefby storingfactor(ifelse(LABEL == "L", RUN, 0))under the new column name.R/dataProcess.R: Updated column-selection logic in
MSstatsSummarizeSingleLinear()andMSstatsSummarizeSingleTMP()to replacerefwithref_covariatein the feature-level data column intersections, ensuring downstream model-fitting data includes the correctly named covariate.R/utils_summarization.R: Updated
.fitLinearModel()to useref_covariateinstead ofrefin linear model formulas for labeled experiments (both single-feature and multi-feature cases:ABUNDANCE ~ RUN + ref_covariateandABUNDANCE ~ FEATURE + RUN + ref_covariate).R/utils_imputation.R: Updated survival regression formulas in
.fitSurvival()for labeled cases to replace therefterm withref_covariatein three labeled-case branches, resulting in formulas like~ RUN + ref_covariateand~ FEATURE + RUN + ref_covariate.Test Coverage
inst/tinytest/test_dataProcess.R: Added two regression assertions validating that
dataProcess(SRMRawData, use_log_file = FALSE)$ProteinLevelDatacontains expected columnsLogIntensitiesandGROUP.inst/tinytest/test_utils_summarization.R: Added
make_srm_input()helper function that constructs synthetic test data withref_covariateas a categorical column, along with a new test assertion verifying that.fitLinearModel()produces coefficients containing"ref_covariate"terms when fitting labeled experiments.inst/tinytest/test_utils_imputation.R: New comprehensive test file with helper functions for generating labeled and unlabeled survival model test datasets across single-feature and multi-feature scenarios:
make_surv_labeled_single(),make_surv_labeled_multi_welldetermined(),make_surv_labeled_underdetermined()for labeled casesmake_surv_unlabeled_single(),make_surv_unlabeled_multi_welldetermined()for unlabeled casescoef_names()helper for extracting coefficient names from fitted modelsref_covariateandFEATUREterms in fitted models based on scenario type.inst/tinytest/test_utils_summarization_prepare.R: New test file verifying
ref_covariatecreation inMSstatsPrepareForSummarization()for both labeled and label-free datasets, confirming the column is created as a factor with correct mappings (heavy rows →"0", light rows → correspondingRUNidentifiers) for labeled input and absent for label-free input.Unit Tests Added or Modified
ref_covariatecolumn creation and mapping for labeled and label-free datasets (72 lines added)Coding Guidelines
No coding guideline violations identified in the provided changes. The refactoring maintains consistent naming conventions, preserves existing control flow and logic, and includes comprehensive test coverage across all modified code paths.