Skip to content

Add repeated shuffle to DecoyDatabase - #8339

Merged
timosachsenberg merged 8 commits into
developfrom
pr-8338
Oct 30, 2025
Merged

timosachsenberg merged 8 commits into
developfrom
pr-8338

Conversation

@timosachsenberg

@timosachsenberg timosachsenberg commented Oct 30, 2025 •

Copy link
Copy Markdown
Contributor

Description

continues #8338

Checklist

  • Make sure that you are listed in the AUTHORS file
  • Add relevant changes and new features to the CHANGELOG file
  • I have commented my code, particularly in hard-to-understand areas
  • New and existing unit tests pass locally with my changes
  • Updated or added python bindings for changed or new classes (Tick if no updates were necessary.)

How can I get additional information on failed tests during CI

Click to expand If your PR is failing you can check out

Advanced commands (admins / reviewer only)

Click to expand
  • /reformat (experimental) applies the clang-format style changes as additional commit. Note: your branch must have a different name (e.g., yourrepo:feature/XYZ) than the receiving branch (e.g., OpenMS:develop). Otherwise, reformat fails to push.
  • setting the label "NoJenkins" will skip tests for this PR on jenkins (saves resources e.g., on edits that do not affect tests)
  • commenting with rebuild jenkins will retrigger Jenkins-based CI builds

⚠️ Note: Once you opened a PR try to minimize the number of pushes to it as every push will trigger CI (automated builds and test) and is rather heavy on our infrastructure (e.g., if several pushes per day are performed).

Summary by CodeRabbit

  • New Features

    • Shuffle-based decoy generation producing multiple distinct decoy proteins.
    • New shuffle_decoy_ratio option to emit multiple decoy repeats per input; validated to prevent use with non-shuffle methods.
    • Per-repeat decoy identifiers include repetition suffixes to distinguish outputs.
  • Tests

    • Added unit and TOPP tests plus FASTA test data covering shuffle behavior, multi-repeat outputs, and expected FASTA results.

@timosachsenberg timosachsenberg changed the title Pr 8338 Add repeated shuffle to DecoyDatabase Oct 30, 2025
@coderabbitai

coderabbitai Bot commented Oct 30, 2025 •

Copy link
Copy Markdown
Contributor

Walkthrough

New shuffle-based decoy generation was added: a DecoyGenerator::shuffle API, Cython bindings, TOPP DecoyDatabase support for repeated shuffles, tests, and reference FASTA data; implementation digests proteins, shuffles peptides per-repeat with seeded generators, and assembles decoy proteins.

Changes

Cohort / File(s) Summary
DecoyGenerator header & bindings
src/openms/include/OpenMS/CHEMISTRY/DecoyGenerator.h, src/pyOpenMS/pxds/DecoyGenerator.pxd
Added public method shuffle(const AASequence& protein, const String& protease, int decoy_factor = 1) returning std::vector<AASequence> and exposed it to pyOpenMS as libcpp_vector[AASequence] shuffle(...) (nogil). Introduced libcpp_vector import.
DecoyGenerator implementation
src/openms/source/CHEMISTRY/DecoyGenerator.cpp
Implemented shuffle(...): digests protein into peptides, generates per-decoy and per-peptide seeded DecoyGenerator instances to shuffle peptides, assembles complete decoy proteins for each repetition/variant; minor refactors to caching lookups (behavior preserved).
TOPP DecoyDatabase tool
src/topp/DecoyDatabase.cpp, src/tests/topp/CMakeLists.txt
Added shuffle_decoy_ratio option (min 1) and validation preventing its use with non-shuffle methods; extended getDecoyIdentifier_ to accept a repetition suffix; changed main loop to produce and write multiple decoy repeats per entry using per-repeat seeds; added TOPP tests (DecoyDatabase_8, DecoyDatabase_9 wiring).
Tests & test data
src/tests/class_tests/openms/source/DecoyGenerator_test.cpp, src/tests/topp/DecoyDatabase_8_out.fasta
Added unit tests for DecoyGenerator::shuffle (various protease/cleavage and decoy_factor scenarios, deterministic outputs) and new FASTA expected output file for TOPP test comparisons.

Sequence Diagram(s)

sequenceDiagram
    participant Caller as Caller
    participant ShuffleAPI as DecoyGenerator::shuffle
    participant Digest as DigestionModule
    participant PeptideGen as Per-Peptide DecoyGenerator
    participant Assembler as ProteinAssembler

    Caller->>ShuffleAPI: call shuffle(protein, protease, decoy_factor)
    ShuffleAPI->>Digest: digest protein -> peptides[]
    Digest-->>ShuffleAPI: peptides[]

    loop for each repetition (decoy variant)
        loop for each peptide in peptides[]
            ShuffleAPI->>PeptideGen: create seeded generator (per-repeat/per-peptide)
            PeptideGen-->>ShuffleAPI: shuffled peptide
        end
        ShuffleAPI->>Assembler: concatenate shuffled peptides
        Assembler-->>ShuffleAPI: decoy_protein
    end

    ShuffleAPI-->>Caller: return vector of decoy_protein(s)
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

  • Review points:
    • src/topp/DecoyDatabase.cpp: new repetition loop, per-repeat seed computation, and updated getDecoyIdentifier_ signature and usage.
    • src/openms/source/CHEMISTRY/DecoyGenerator.cpp: correctness of per-variant seeding, peptide shuffling, and assembly; ensure deterministic behavior and no modification leakage.
    • Tests and CMake additions: verify test wiring, expected outputs, and WILL_FAIL marking.

Possibly related PRs

Suggested reviewers

  • jpfeuffer

Poem

🐰 A shuffle of peptides, neat and spry,
I seed each variant and watch them fly,
Proteins reborn in playful array,
The rabbit hops, assembling decoys today! 🎲

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 20.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The pull request title "Add repeated shuffle to DecoyDatabase" accurately reflects the primary objective of the changeset. The modifications add a new shuffle() method to the DecoyGenerator class, expose it to Python/Cython bindings, add comprehensive tests, and crucially update DecoyDatabase.cpp to introduce a shuffle_decoy_ratio parameter that enables repeated decoy generation with per-repetition seeding. The title is concise, specific, and avoids vague terminology, making it immediately clear to reviewers that the PR introduces repeated shuffle functionality to the DecoyDatabase tool.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch pr-8338

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 378798c and 054c8d4.

📒 Files selected for processing (2)
  • src/tests/topp/DecoyDatabase_8_out.fasta (1 hunks)
  • src/topp/DecoyDatabase.cpp (5 hunks)
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2025-09-03T12:58:20.032Z
Learnt from: timosachsenberg
PR: OpenMS/OpenMS#8177
File: src/tests/topp/CMakeLists.txt:1857-1865
Timestamp: 2025-09-03T12:58:20.032Z
Learning: OpenMS tests: When adding new TOPP tests in src/tests/topp/CMakeLists.txt that compare outputs via FuzzyDiff, always add set_tests_properties("<tool>_<n>_out<m>" PROPERTIES DEPENDS "<tool>_<n>") to avoid flakiness under parallel CTest runs.

Applied to files:

  • src/tests/topp/DecoyDatabase_8_out.fasta
🧬 Code graph analysis (1)
src/topp/DecoyDatabase.cpp (2)
src/openms/source/CHEMISTRY/DecoyGenerator.cpp (2)
  • shuffle (63-99)
  • shuffle (63-63)
src/openms/source/CONCEPT/Exception.cpp (1)
  • InvalidParameter (230-233)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (7)
  • GitHub Check: build-and-test (ubuntu-22.04-arm, g++, 11)
  • GitHub Check: build-and-test (ubuntu-22.04, clang++, 15)
  • GitHub Check: build-and-test (ubuntu-22.04, g++, 11)
  • GitHub Check: build-and-test (windows-2022, cl.exe, 14.36)
  • GitHub Check: Analyze (ruby)
  • GitHub Check: Analyze (python)
  • GitHub Check: cppcheck-test
🔇 Additional comments (5)
src/tests/topp/DecoyDatabase_8_out.fasta (1)

1-60: Test reference data looks good.

The FASTA file correctly demonstrates the shuffle_decoy_ratio=2 feature with proper formatting:

  • Each target protein has two distinct decoy variants with _1 and _2 suffixes
  • FASTA headers and sequences are well-formed
  • Decoy sequences appear properly shuffled and distinct from targets and from each other

This aligns with the maintainer approval in past review comments.

src/topp/DecoyDatabase.cpp (4)

100-101: LGTM! Parameter registration is correct.

The shuffle_decoy_ratio parameter is properly configured with sensible defaults (1) and constraints (minimum 1), and correctly marked as advanced.


138-148: LGTM! Function signature update is correct.

The addition of the suffix_string parameter to getDecoyIdentifier_ properly supports per-repeat decoy naming, correctly appending the suffix in both prefix and suffix placement modes.


162-169: LGTM! Parameter validation is well-implemented.

The validation correctly prevents using shuffle_decoy_ratio > 1 with the reverse method, which wouldn't make sense (reverse is deterministic). The error message is clear and the exception type is appropriate.


403-496: LGTM! Per-repeat decoy generation is correctly implemented.

The implementation properly addresses the critical issue from the previous review about generating identical decoys. Key improvements:

  • Line 407: repeat_seed = seed + num_repeat ensures each repeat uses a distinct seed
  • All shuffle code paths correctly use repeat_seed:
    • Line 436: RNA shuffle via shuffler.seed(repeat_seed)
    • Line 466: Protein peptide shuffle via m.shufflePeptide(..., repeat_seed, ...)
    • Line 477: Whole-protein shuffle via shuffler.seed(repeat_seed)
  • Line 409: Suffix computation correctly generates _1, _2, etc. for shuffle_ratio > 1
  • Lines 490-495: Each decoy is written per repetition, supporting multiple output targets

The structure ensures distinct, deterministic decoys for each repetition while maintaining reproducibility within a repetition.

Verify test dependencies were configured per coding guidelines.

The AI summary indicates new TOPP tests (DecoyDatabase_8 and DecoyDatabase_9) were added. Based on learnings, when adding new TOPP tests in src/tests/topp/CMakeLists.txt that compare outputs via FuzzyDiff, you should add set_tests_properties("<tool>_<n>_out<m>" PROPERTIES DEPENDS "<tool>_<n>") to avoid flakiness under parallel CTest runs. Please confirm this was done for the new tests.

Based on learnings


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 and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🧹 Nitpick comments (1)
src/tests/topp/CMakeLists.txt (1)

2710-2712: Add explicit -decoy_string and -decoy_string_position for consistency.

The test setup is correct (deterministic seed, FuzzyDiff DEPENDS), and the reference file is present. However, tests 2–4 that also use shuffle/reverse methods with FuzzyDiff comparisons explicitly set -decoy_string "DECOY_SEQ_" -decoy_string_position "prefix". For consistency and to avoid brittleness if defaults change, align test 8 with this pattern:

add_test("TOPP_DecoyDatabase_8" ${TOPP_BIN_PATH}/DecoyDatabase -test -in ${DATA_DIR_TOPP}/DecoyDatabase_1.fasta -out DecoyDatabase_8.tmp.fasta -decoy_string "DECOY_SEQ_" -decoy_string_position "prefix" -method shuffle -shuffle_decoy_ratio 2 -seed 42)
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between bc88568 and 378798c.

📒 Files selected for processing (7)
  • src/openms/include/OpenMS/CHEMISTRY/DecoyGenerator.h (1 hunks)
  • src/openms/source/CHEMISTRY/DecoyGenerator.cpp (3 hunks)
  • src/pyOpenMS/pxds/DecoyGenerator.pxd (2 hunks)
  • src/tests/class_tests/openms/source/DecoyGenerator_test.cpp (1 hunks)
  • src/tests/topp/CMakeLists.txt (1 hunks)
  • src/tests/topp/DecoyDatabase_8_out.fasta (1 hunks)
  • src/topp/DecoyDatabase.cpp (5 hunks)
🧰 Additional context used
📓 Path-based instructions (3)
src/openms/**/*.{cpp,h,hpp,cc,cxx}

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

src/openms/**/*.{cpp,h,hpp,cc,cxx}: Follow the existing C++ coding conventions in the codebase
Use the established naming patterns for classes, methods, and variables
Use OpenMS data structures (e.g., MSExperiment, FeatureMap, PeptideIdentification)
Follow the established error handling patterns
Utilize OpenMS logging mechanisms
Be mindful of memory usage when processing large datasets
Consider algorithmic complexity for data processing operations
Use appropriate OpenMS containers and algorithms

Files:

  • src/openms/source/CHEMISTRY/DecoyGenerator.cpp
  • src/openms/include/OpenMS/CHEMISTRY/DecoyGenerator.h
src/openms/include/OpenMS/**/*.h

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

Add Doxygen comments for new public methods and classes

Files:

  • src/openms/include/OpenMS/CHEMISTRY/DecoyGenerator.h
src/tests/class_tests/openms/**/*.cpp

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

Write unit tests for new functionality

Files:

  • src/tests/class_tests/openms/source/DecoyGenerator_test.cpp
🧠 Learnings (5)
📚 Learning: 2025-08-14T10:19:54.371Z
Learnt from: jpfeuffer
PR: OpenMS/OpenMS#8167
File: src/topp/Digestor.cpp:200-226
Timestamp: 2025-08-14T10:19:54.371Z
Learning: In OpenMS (C++ bioinformatics framework), use boost random libraries instead of std library random distributions for cross-platform reproducible random number generation, as std library distributions are not reproducible across platforms.

Applied to files:

  • src/openms/source/CHEMISTRY/DecoyGenerator.cpp
📚 Learning: 2025-09-03T12:58:20.032Z
Learnt from: timosachsenberg
PR: OpenMS/OpenMS#8177
File: src/tests/topp/CMakeLists.txt:1857-1865
Timestamp: 2025-09-03T12:58:20.032Z
Learning: OpenMS tests: When adding new TOPP tests in src/tests/topp/CMakeLists.txt that compare outputs via FuzzyDiff, always add set_tests_properties("<tool>_<n>_out<m>" PROPERTIES DEPENDS "<tool>_<n>") to avoid flakiness under parallel CTest runs.

Applied to files:

  • src/tests/topp/CMakeLists.txt
  • src/tests/class_tests/openms/source/DecoyGenerator_test.cpp
📚 Learning: 2025-08-05T12:43:11.681Z
Learnt from: CR
PR: OpenMS/OpenMS#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-05T12:43:11.681Z
Learning: Applies to src/tests/class_tests/openms/**/*.cpp : Write unit tests for new functionality

Applied to files:

  • src/tests/topp/CMakeLists.txt
  • src/tests/class_tests/openms/source/DecoyGenerator_test.cpp
📚 Learning: 2025-08-05T12:43:11.681Z
Learnt from: CR
PR: OpenMS/OpenMS#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-05T12:43:11.681Z
Learning: Applies to src/tests/class_tests/openms/*Test.cpp : Follow naming convention: `ClassNameTest.cpp` for `ClassName`

Applied to files:

  • src/tests/class_tests/openms/source/DecoyGenerator_test.cpp
📚 Learning: 2025-08-05T12:43:11.681Z
Learnt from: CR
PR: OpenMS/OpenMS#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-05T12:43:11.681Z
Learning: Applies to src/pyOpenMS/**/*.h : Add Doxygen comments for new public methods and classes in pyOpenMS bindings

Applied to files:

  • src/pyOpenMS/pxds/DecoyGenerator.pxd
🧬 Code graph analysis (4)
src/openms/source/CHEMISTRY/DecoyGenerator.cpp (1)
src/topp/DecoyDatabase.cpp (1)
  • protein (151-496)
src/openms/include/OpenMS/CHEMISTRY/DecoyGenerator.h (1)
src/openms/source/CHEMISTRY/DecoyGenerator.cpp (2)
  • shuffle (63-99)
  • shuffle (63-63)
src/tests/class_tests/openms/source/DecoyGenerator_test.cpp (1)
src/openms/source/CHEMISTRY/DecoyGenerator.cpp (2)
  • shuffle (63-99)
  • shuffle (63-63)
src/topp/DecoyDatabase.cpp (2)
src/openms/source/CHEMISTRY/DecoyGenerator.cpp (2)
  • shuffle (63-99)
  • shuffle (63-63)
src/openms/source/CONCEPT/Exception.cpp (1)
  • InvalidParameter (230-233)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (7)
  • GitHub Check: build-and-test (macos-15-intel, xcode, 16.0.0)
  • GitHub Check: build-and-test (windows-2022, cl.exe, 14.36)
  • GitHub Check: build-and-test (ubuntu-22.04-arm, g++, 11)
  • GitHub Check: build-and-test (ubuntu-22.04, g++, 11)
  • GitHub Check: build-and-test (ubuntu-22.04, clang++, 15)
  • GitHub Check: build-and-test (macos-26, xcode, 26.0)
  • GitHub Check: cppcheck-test
🔇 Additional comments (2)
src/tests/topp/DecoyDatabase_8_out.fasta (1)

1-60: The test data is correct—identical decoy sequences across variants are intentional.

The review comment incorrectly identified duplicate sequences as a bug. The DecoyDatabase implementation explicitly uses the same random seed for all shuffle iterations (line 471: shuffler.seed(seed)), producing deterministic, identical shuffles. This is documented in the method description and comments:

  • "all sequences are shuffled using the same random seed, ensuring that identical sequences produce the same shuffled decoy sequences"
  • "Set the seed for shuffling always to the same number, this ensures that identical peptides get shuffled the same way every time (without keeping track of them explicitly). This will ensure that the total number of unique tryptic peptides is identical in both databases."

The shuffle_decoy_ratio parameter generates multiple database copies (not multiple different shuffles), so identical sequences with different suffix identifiers (_1, _2) is the expected test data format.

Likely an incorrect or invalid review comment.

src/tests/topp/CMakeLists.txt (1)

2714-2715: Good negative test coverage.

WILL_FAIL for reverse + shuffle_decoy_ratio is appropriate and minimal.

Comment thread src/topp/DecoyDatabase.cpp Resolved
Comment thread src/topp/DecoyDatabase.cpp Resolved
Comment thread src/topp/DecoyDatabase.cpp Resolved
@timosachsenberg
timosachsenberg enabled auto-merge (squash) October 30, 2025 16:36
@timosachsenberg
timosachsenberg merged commit 26f0b94 into develop Oct 30, 2025
@timosachsenberg
timosachsenberg deleted the pr-8338 branch October 30, 2025 17:35
@poshul

poshul commented Oct 31, 2025

Copy link
Copy Markdown
Collaborator

@timosachsenberg this looks to have broken our CI, can you take a look and see if you can isolate why?

@timosachsenberg

Copy link
Copy Markdown
Contributor Author

Ok. Strange. Here it passed all tests.

@t0mdavid-m t0mdavid-m mentioned this pull request Oct 31, 2025
8 of 13 tasks
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.

3 participants