Skip to content

fix(annotation): Enable fractions in label free experiments#118

Merged
tonywu1999 merged 2 commits intodevelfrom
lf-fraction-fix
Aug 19, 2025
Merged

fix(annotation): Enable fractions in label free experiments#118
tonywu1999 merged 2 commits intodevelfrom
lf-fraction-fix

Conversation

@tonywu1999
Copy link
Contributor

@tonywu1999 tonywu1999 commented Aug 19, 2025

Motivation and Context

we need to enable fractionation experiments with MSstatsPTM with label free https://groups.google.com/g/msstats/c/G9US-6V8uyM

Testing

  • Added unit tests

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

Summary by CodeRabbit

  • New Features
    • LF annotations now accept the Fraction column.
  • Bug Fixes
    • Added clear validation for unsupported labeling types, returning “Labeling type must be either LF or TMT” and stopping early to prevent downstream errors.
    • Improved robustness of annotation checks for LF and TMT, reducing false errors on valid inputs.
  • Tests
    • Introduced comprehensive tests covering LF/TMT annotation validation, including missing/extra columns, empty inputs, valid minimal schemas, and error message accuracy, ensuring reliable behavior across common scenarios.

@coderabbitai
Copy link

coderabbitai bot commented Aug 19, 2025

Walkthrough

Updated .checkAnnotation to include "Fraction" for LF annotations and to error on unsupported label_type values. Added a comprehensive tinytest suite covering valid/invalid LF and TMT annotation schemas, missing columns, extra columns, empty data, and unknown label_type handling.

Changes

Cohort / File(s) Summary
Annotation validation logic
R/utils_checks.R
Expanded allowed LF columns to include Fraction. Added explicit else branch validating label_type; now errors with "Labeling type must be either LF or TMT" when unsupported, preventing undefined max_columns. No public signatures changed.
Unit tests for .checkAnnotation
inst/tinytest/test_utils_checks.R
New tests covering LF/TMT scenarios: presence/absence of Run/Raw.file, extra columns errors with allowed list messaging, empty data frame handling, and explicit error on unknown label_type. Verifies silent passes and specific error messages.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  actor Caller
  participant Check as .checkAnnotation
  Caller->>Check: validate(annotation, label_type)
  alt label_type == "LF"
    Note over Check: Build allowed columns incl. Fraction
    Check->>Caller: pass or error (missing/extra cols)
  else label_type == "TMT"
    Note over Check: Build allowed TMT columns
    Check->>Caller: pass or error (missing/extra cols)
  else Invalid label_type
    Note over Check: Early stop with message<br/>"Labeling type must be either LF or TMT"
    Check-->>Caller: error
  end
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

I twitch my whiskers at columns aligned,
LF gains Fraction—how neatly defined!
TMT stands ready, checks crisp and tight,
Unknown labels? I thump in spite.
With tidy tests I hop in delight—
Data burrows safe, validations right. 🐇✅

Tip

🔌 Remote MCP (Model Context Protocol) integration is now available!

Pro plan users can now connect to remote MCP servers from the Integrations page. Connect with popular remote MCPs such as Notion and Linear to add more context to your reviews and chats.

✨ Finishing Touches
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch lf-fraction-fix

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@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: 0

🧹 Nitpick comments (4)
R/utils_checks.R (2)

12-21: Optional: normalize label_type to be case-insensitive and reduce duplication

Minor hardening: normalize label_type once (toupper) and branch on the normalized value. Keeps behavior, accepts "lf"/"tmt", and avoids repeated string literals.

Apply this localized refactor:

-  if (label_type == "LF"){
+  label_type_norm <- toupper(label_type)
+  if (label_type_norm == "LF"){
     max_columns = c("Run", "Raw.file", "Condition", 
                     "BioReplicate", "IsotopeLabelType", "Fraction")
-  } else if (label_type == "TMT"){
+  } else if (label_type_norm == "TMT"){
     max_columns = c("Run", "Raw.file", "Fraction", "TechRepMixture", "Channel", 
                     "Condition", "Mixture", "BioReplicate")
   } else {
-    msg = paste("Labeling type must be either LF or TMT")
-    stop(msg)
+    stop("Labeling type must be either LF or TMT")
   }

19-20: Nit: avoid paste() for a static string

Slight cleanup; paste() is unnecessary for a constant.

-    msg = paste("Labeling type must be either LF or TMT")
+    msg = "Labeling type must be either LF or TMT"
inst/tinytest/test_utils_checks.R (2)

87-104: Avoid brittle exact-string matching of allowed-column lists

Asserting the entire ordered list ties tests to a specific ordering of allowed columns. If order changes (semantically irrelevant), tests will fail.

Consider either:

  • Matching key tokens with looser patterns, e.g., separately asserting presence of “Fraction”, “IsotopeLabelType”, etc., or
  • Extracting the tail of the message and comparing sets (order-insensitive) by splitting on ", ".

Example approach (order-insensitive):

err <- tryCatch(MSstatsPTM:::.checkAnnotation(annotation_lf_extra, "LF"), error = identity)
allowed <- strsplit(sub(".*only include the following columns in the annotation file:\\s*", "", conditionMessage(err)), ",\\s*")[[1]]
tinytest::expect_true(all(c("Run","Raw.file","Condition","BioReplicate","IsotopeLabelType","Fraction") %in% allowed))

Also applies to: 118-123


154-156: Optional: add case-insensitive label_type tests if adopting normalization

If you implement the case-insensitive label_type normalization, add complementary tests to lock it in.

Example additions:

expect_silent(MSstatsPTM:::.checkAnnotation(annotation_basic, "lf"))
expect_silent(MSstatsPTM:::.checkAnnotation(annotation_basic, "tmt"))
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 3cf3b26 and b5c97ef.

📒 Files selected for processing (2)
  • R/utils_checks.R (1 hunks)
  • inst/tinytest/test_utils_checks.R (1 hunks)
🔇 Additional comments (6)
R/utils_checks.R (2)

12-15: LF: Allowing Fraction column is correct and unblocks fractionated LF workflows

Including "Fraction" in the LF allowed set fixes the previous omission and aligns LF with common fractionated runs.


18-21: Fail-fast on unsupported label_type is a good guardrail

Early stop with a clear message prevents downstream use of an undefined max_columns.

inst/tinytest/test_utils_checks.R (4)

1-17: Good negative-path coverage for missing Run/Raw.file

These assert the primary precondition and validate the exact error path.


43-54: Solid: Confirms LF now permits Fraction

This directly exercises the LF+Fraction allowance and will catch any regression.


132-147: Nice: Minimal valid schemas covered (only Run or only Raw.file) for both LF and TMT

This ensures subsets are accepted as intended.


157-161: Unknown label_type test validates new guard

Confirms the explicit error path and message text.

@tonywu1999 tonywu1999 merged commit 43dc051 into devel Aug 19, 2025
2 checks passed
@tonywu1999 tonywu1999 deleted the lf-fraction-fix branch August 19, 2025 18:57
@tonywu1999 tonywu1999 changed the title Lf fraction fix fix(annotation): Enable fractions in label free experiments Aug 20, 2025
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