Skip to content

Test/coverage improvements#213

Merged
devonjkohler merged 3 commits into
develfrom
test/coverage-improvements
Jul 16, 2026
Merged

Test/coverage improvements#213
devonjkohler merged 3 commits into
develfrom
test/coverage-improvements

Conversation

@devonjkohler

@devonjkohler devonjkohler commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

Motivation and Context

The current test coverage is very low (below 50%). This PR adds many tests to bring the coverage above 80%

Changes

  • Fix a couple bugs that arose from adding unit tests
  • Added units tests across many functions, particularly across plots

Testing

Please describe any unit tests you added or modified to verify your changes.

Checklist Before Requesting a Review

  • I have read the MSstats contributing guidelines
  • My changes generate no new warnings
  • Any dependent changes have been merged and published in downstream modules
  • I have run the devtools::document() command after my changes and committed the added files

Motivation and Context

The change set significantly increases unit test coverage (especially for plotting/export behavior) from under 50% to above 80%, while also addressing bugs uncovered by the added tests—most notably around SDRF fraction column handling and graphics-device handling in Plotly vs non-Plotly plot modes.

Changes

  • Updated R/SDRFconverter.R:
    • SDRFtoAnnotation(): builds the renamed output columns dynamically so the Fraction column is only added/renamed when a fraction input column is requested, preventing column name mismatches.
    • extractSDRF(): fixes column renaming when fraction = NULL by using the correct source column order so run_name, condition_name, and biological_replicate apply to the intended columns.
  • Updated R/groupComparisonPlots.R:
    • .plotHeatmap, .plotVolcano, .plotComparison: only call dev.off() when address != FALSE and the output is not Plotly (!isPlotly), preventing graphics devices from being closed in Plotly/ZIP/HTML output scenarios.
  • Added/extended comprehensive Tinytest coverage across core workflows, utilities, and plotting:
    • SDRF conversion + metadata merging
    • Data processing + quantification plots
    • Group comparison plotting (ggplot2 and Plotly/ZIP branches)
    • Model-based QC plots
    • Quality metrics plotting
    • Design sample size / power calculations + related internal helpers
    • Quantification, feature selection, anomaly weighting
    • Common plotting/file helpers and internal output finalization
    • Additional internal validation and edge-case handling utilities

Unit Tests

  • Added inst/tinytest/test_SDRFconverter.R
    • Verifies SDRFtoAnnotation() default naming, optional Fraction handling, row counts, and error cases for invalid column inputs.
    • Verifies extractSDRF() output structure/value mapping with and without fraction, and that meta_data is merged correctly by run.
  • Added multiple new plotting and workflow test suites:
    • inst/tinytest/test_dataProcessPlots.R (ggplot2 PDF export warnings/files; Plotly list outputs and ZIP export)
    • inst/tinytest/test_groupComparisonPlots.R (error handling; PDF export; Plotly volcano + ZIP outputs)
    • inst/tinytest/test_modelBasedQCPlots.R (wrapper behavior; PDF outputs for QQ/Residual plots; error handling)
    • inst/tinytest/test_plot_quality_metrics.R (validation errors; ggplot vs Plotly object types; PDF/HTML export; factor preservation for Run)
    • inst/tinytest/test_designSampleSize.R (sample size vs power outputs, monotonicity expectations, Plotly vs non-Plotly plotting)
    • inst/tinytest/test_groupComparison_designs.R and inst/tinytest/test_groupComparison_missing.R (model-fitting branches, repeated/tech replicate detection, incomplete condition edge cases)
  • Added additional functional/unit coverage:
    • inst/tinytest/test_quantification.R (sample/group quantification shapes; case-insensitive type; error handling)
    • inst/tinytest/test_utils_anomaly_weights.R (weighting behavior across NA/outlier/normal cases; normalization behavior)
    • inst/tinytest/test_utils_feature_selection.R (selection modes, expected columns, quality/outlier fields)
    • inst/tinytest/test_utils_plots_common.R (theme helpers, protein selection utilities, savePlot() and internal saveTable() semantics)
    • inst/tinytest/test_summarization_linear.R (linear summarization path, model fitting helper behavior)
    • inst/tinytest/test_utils_checks_extra.R and inst/tinytest/test_utils_groupcomparison_checks_extra.R (validation/error branches)
    • inst/tinytest/test_utils_output_finalize.R and inst/tinytest/test_utils_summarization_isSummarizable.R (finalization logic and summarizability edge cases)

Coding Guidelines Violations

  • None reported in the provided change summary.

@coderabbitai

coderabbitai Bot commented Jul 16, 2026

Copy link
Copy Markdown

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 56837789-2a41-4a8c-8dbf-755892e591ae

📥 Commits

Reviewing files that changed from the base of the PR and between 2b08e58 and 2ddc0a4.

📒 Files selected for processing (7)
  • inst/tinytest/test_groupComparison_designs.R
  • inst/tinytest/test_groupComparison_missing.R
  • inst/tinytest/test_summarization_linear.R
  • inst/tinytest/test_utils_checks_extra.R
  • inst/tinytest/test_utils_groupcomparison_checks_extra.R
  • inst/tinytest/test_utils_output_finalize.R
  • inst/tinytest/test_utils_summarization_isSummarizable.R

📝 Walkthrough

Walkthrough

SDRF column mapping is corrected, Plotly device handling is guarded, and comprehensive Tinytest coverage is added for conversion, plotting, quantification, sample-size, group-comparison edge cases, feature-selection, linear summarization, anomaly-weighting, and validation utility workflows.

Changes

MSstats validation and behavior fixes

Layer / File(s) Summary
SDRF column mapping corrections
R/SDRFconverter.R, inst/tinytest/test_SDRFconverter.R
SDRFtoAnnotation and extractSDRF now correctly assign optional Fraction columns and reordered parameter names to their corresponding output positions, with tests for default/optional column presence, row-count preservation, and metadata merging.
Plot output branching and coverage
R/groupComparisonPlots.R, inst/tinytest/test_dataProcessPlots.R, inst/tinytest/test_groupComparisonPlots.R, inst/tinytest/test_modelBasedQCPlots.R, inst/tinytest/test_plot_quality_metrics.R
Plot helpers guard dev.off() to prevent device closure when Plotly output is selected; tests validate argument errors, PDF generation with warnings, Plotly object returns, HTML archiving, metric selection, and QC wrapper equivalence.
Group comparison design and missing-data validation
inst/tinytest/test_groupComparison_designs.R, inst/tinytest/test_groupComparison_missing.R, inst/tinytest/test_utils_groupcomparison_checks_extra.R
Tests exercise mixed-effects model fitting for repeated-measures and technical-replicate scenarios, validate edge cases for proteins with incomplete condition coverage, flag missing/complete-condition issues, and verify input validation for group-comparison matrices.
Quantification and sample-size workflows
inst/tinytest/test_quantification.R, inst/tinytest/test_designSampleSize.R
Tests cover sample and group quantification in matrix and long formats, argument case-insensitivity, power/sample-size calculation modes, ggplot2/Plotly rendering, and internal model-helper functions.
Linear summarization and processing validation
inst/tinytest/test_summarization_linear.R, inst/tinytest/test_utils_summarization_isSummarizable.R
Tests validate linear summarization for equal and unequal feature variance, direct unit tests for linear model fitting, and guard logic for degenerate summarization cases (missing abundances, zero/low observation counts, run-level filtering).
Utility, checks, and feature-selection coverage
inst/tinytest/test_utils_anomaly_weights.R, inst/tinytest/test_utils_feature_selection.r, inst/tinytest/test_utils_plots_common.R, inst/tinytest/test_utils_checks_extra.R, inst/tinytest/test_utils_output_finalize.R
Tests cover anomaly-weight calculation for edge cases, feature-selection modes and result columns, plot themes and protein selection, file-saving behavior, design/experiment validation, intensity preprocessing (sub-1 flooring), and output finalization (missingness categorization and imputation flags).

Estimated code review effort: 3 (Moderate) | ~27 minutes

Possibly related PRs

Poem

I'm a bunny with tests in my nest,
SDRF columns now line up best.
Plotly hops without closing the door,
Edge cases handled by the test floor.
From quantification to summarization's cheer—
More robust MSstats appears here! 🐰

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description covers motivation and checklist, but the Testing section is blank and the changes lack the required detailed bullets. Fill in the Testing section with the unit tests run and expand Changes into a detailed bullet list of the specific test and bug-fix updates.
Title check ❓ Inconclusive The title is too generic and does not describe the specific bug fixes and new tests in this PR. Rename it to mention the main change, such as adding extensive tests and fixing related plotting bugs.
✅ Passed checks (3 passed)
Check name Status Explanation
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 test/coverage-improvements

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.

@github-actions

Copy link
Copy Markdown

Failed to generate code suggestions for PR

@devonjkohler
devonjkohler merged commit 17b9171 into devel Jul 16, 2026
1 of 3 checks passed
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