fix(ptm-tests): Fix unit tests for PTM differential analysis#204
Conversation
📝 WalkthroughWalkthroughA test assertion in the PTM validation is updated to check the row count within the Changes
Estimated code review effort🎯 1 (Trivial) | ⏱️ ~3 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 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 |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
tests/testthat/test-utils-statmodel-server.R (1)
272-291: Optional: also assertPTM.ModelandPROTEIN.Modelfiltering.Since PTM mode returns all three models, consider adding assertions for
PTM.Model(expect 2 significant:0.001,0.03) andPROTEIN.Model(expect 1 significant:0.02) to fully cover the PTM branch and guard against regressions in the other two filters.♻️ Suggested additional assertions
result <- extract_significant_proteins(data_comp, loadpage_input, 0.05) expect_equal(nrow(result$ADJUSTED.Model), 1) + expect_equal(nrow(result$PTM.Model), 2) + expect_equal(nrow(result$PROTEIN.Model), 1)🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@tests/testthat/test-utils-statmodel-server.R` around lines 272 - 291, The test is only asserting ADJUSTED.Model; update the test for extract_significant_proteins to also assert that result$PTM.Model contains 2 significant rows (adj.pvalue 0.001 and 0.03) and that result$PROTEIN.Model contains 1 significant row (adj.pvalue 0.02); locate the assertions immediately after result <- extract_significant_proteins(...) in tests/testthat/test-utils-statmodel-server.R and add expect_equal checks for nrow(result$PTM.Model) == 2 and nrow(result$PROTEIN.Model) == 1 (optionally assert specific protein IDs if desired).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@tests/testthat/test-utils-statmodel-server.R`:
- Around line 272-291: The test is only asserting ADJUSTED.Model; update the
test for extract_significant_proteins to also assert that result$PTM.Model
contains 2 significant rows (adj.pvalue 0.001 and 0.03) and that
result$PROTEIN.Model contains 1 significant row (adj.pvalue 0.02); locate the
assertions immediately after result <- extract_significant_proteins(...) in
tests/testthat/test-utils-statmodel-server.R and add expect_equal checks for
nrow(result$PTM.Model) == 2 and nrow(result$PROTEIN.Model) == 1 (optionally
assert specific protein IDs if desired).
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: f7063685-ba9b-41cf-83c8-5befb5a67d41
📒 Files selected for processing (1)
tests/testthat/test-utils-statmodel-server.R
Motivation and Context
PTM (post-translational modification) differential analysis in MSstatsShiny uses a specialized data structure that differs from standard protein analysis. When analyzing PTM data, the
extract_significant_proteinsfunction returns a list containing three separate data frames:PTM.Model,PROTEIN.Model, andADJUSTED.Model(the adjusted PTM results accounting for protein-level abundance).The issue was that unit tests for PTM differential analysis were incorrectly validating the overall structure of the returned object rather than the expected number of significant rows within the
ADJUSTED.Modeldata frame specifically. This misalignment between the test assertion and the actual function behavior prevented accurate verification of PTM result filtering.Changes Made
test-utils-statmodel-server.Rto validatenrow(result$ADJUSTED.Model)instead ofnrow(result). The corrected test now properly checks that filtering by adjusted p-value threshold produces exactly 1 significant protein (out of 2 proteins in ADJUSTED.Model where only P1 with p-value 0.04 falls below the 0.05 threshold).Unit Tests Added or Modified
Modified:
test-utils-statmodel-server.R- Test case "extract_significant_proteins filters PTM data correctly"The test validates that:
ADJUSTED.Modeldata frame with 2 proteinsexpect_equal(nrow(result$ADJUSTED.Model), 1)now properly reflects the list-based return structure of the PTM-specific extraction function