Skip to content

feat: semi-tryptic and non-specific digestion (FragmentIndex / SimpleSearchEngine) - #9112

Merged
timosachsenberg merged 2 commits into
developfrom
feat/fi-semi-nonspecific-digestion
Apr 9, 2026
Merged

timosachsenberg merged 2 commits into
developfrom
feat/fi-semi-nonspecific-digestion

Conversation

@timosachsenberg

@timosachsenberg timosachsenberg commented Apr 9, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Implements item #1 from #9108 — semi-tryptic and non-specific (immunopeptidomics) digestion — across FragmentIndex, PeptideSearchEngineFIAlgorithm, and (per discussion) SimpleSearchEngineAlgorithm.

  • New parameter peptide:enzyme_specificity = full (default) / semi / none. Auto-exposed in PeptideDataBaseSearchFI and SimpleSearchEngine via the existing registerFullParam_() plumbing.
  • EnzymaticDigestion::digestUnmodified() now honors specificity_ in both the vector<pair> and vector<StringView> overloads — it previously silently ignored it, forcing callers to use the magic \"unspecific cleavage\" enzyme name for the non-specific path.
  • Two hardcoded SPEC_FULL literals (per engine) replaced: the idXML enzyme_term_specificity field and the PeptideIndexing re-validation step. The latter would otherwise silently drop every semi-/non-specific PSM after the search.

Bug fixes (uncovered while wiring this in)

  • Unsigned underflow in EnzymaticDigestion::digestUnmodified when sequence.size() < min_length. Real risk for immunopeptidomics FASTAs containing entries shorter than min_length (signal peptides, ORF stubs).
  • SIGFPE in FragmentIndex::build when no peptides survive filtering: bucketsize_ = sqrt(0) = 0 divides by zero in the OMP bucket loop. Now early-returns with an empty index.

Immunopeptidomics workflow

```
PeptideDataBaseSearchFI -in spectra.mzML -database proteome.fasta -out hits.idXML \
-Search:peptide:enzyme_specificity none \
-Search:peptide:min_size 8 -Search:peptide:max_size 12
```

Test plan

  • `EnzymaticDigestion_test` — new section: SPEC_NONE substring enumeration, SPEC_SEMI extras, SPEC_FULL regression, short / empty sequence guards.
  • `FragmentIndex_test` — new section: `full` / `semi` / `none` parameter wiring on the same protein, plus a tiny-protein test that previously triggered the FPE crash.
  • `PeptideSearchEngineFIAlgorithm_test`, `SimpleSearchEngineAlgorithm_test` — pass.
  • `TOPP_PeptideDataBaseSearchFI_1/2`, `TOPP_SimpleSearchEngine_1/2` — pass.
  • End-to-end smoke test: `PeptideDataBaseSearchFI -Search:peptide:enzyme_specificity semi` produces 6 PSMs / 3 proteins on `SimpleSearchEngine_1.{mzML,fasta}` and the idXML records `EnzymeTermSpecificity=semi` + `PeptideIndexer:enzyme_specificity=semi`.
  • End-to-end smoke test: `-Search:peptide:enzyme_specificity none -Search:peptide:min_size 8 -Search:peptide:max_size 12` runs cleanly (empty result is just because the existing test data is tryptic-targeted).
  • CI on Linux/Windows/macOS.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features

    • Configurable enzyme specificity for peptide searches (full, semi, none); search, decoy generation and indexing now respect this setting.
  • Bug Fixes

    • Early-exit when no fragments are generated to avoid downstream errors.
    • Guards to prevent integer underflow on very short sequences.
  • Tests

    • Added tests covering all enzyme specificity modes and related edge cases.

@coderabbitai

coderabbitai Bot commented Apr 9, 2026 •

Copy link
Copy Markdown
Contributor

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: f3131a29-2e9b-4f4e-b536-7b29a8651d70

📥 Commits

Reviewing files that changed from the base of the PR and between 4caa4bd and 74ac253.

📒 Files selected for processing (9)
  • src/openms/include/OpenMS/ANALYSIS/ID/FragmentIndex.h
  • src/openms/include/OpenMS/ANALYSIS/ID/PeptideSearchEngineFIAlgorithm.h
  • src/openms/include/OpenMS/ANALYSIS/ID/SimpleSearchEngineAlgorithm.h
  • src/openms/source/ANALYSIS/ID/FragmentIndex.cpp
  • src/openms/source/ANALYSIS/ID/PeptideSearchEngineFIAlgorithm.cpp
  • src/openms/source/ANALYSIS/ID/SimpleSearchEngineAlgorithm.cpp
  • src/openms/source/CHEMISTRY/EnzymaticDigestion.cpp
  • src/tests/class_tests/openms/source/EnzymaticDigestion_test.cpp
  • src/tests/class_tests/openms/source/FragmentIndex_test.cpp
✅ Files skipped from review due to trivial changes (3)
  • src/openms/include/OpenMS/ANALYSIS/ID/SimpleSearchEngineAlgorithm.h
  • src/openms/source/ANALYSIS/ID/SimpleSearchEngineAlgorithm.cpp
  • src/tests/class_tests/openms/source/EnzymaticDigestion_test.cpp
🚧 Files skipped from review as they are similar to previous changes (3)
  • src/openms/include/OpenMS/ANALYSIS/ID/FragmentIndex.h
  • src/openms/source/ANALYSIS/ID/PeptideSearchEngineFIAlgorithm.cpp
  • src/openms/source/ANALYSIS/ID/FragmentIndex.cpp

📝 Walkthrough

Walkthrough

Adds configurable enzyme specificity (full / semi / none) across digestion, fragment-index building, and FI-based search: new specificity members/params, EnzymaticDigestion handling for semi/none, propagation into FragmentIndex and search algorithms (decoy/indexing), early-exit guards, and tests for all modes.

Changes

Cohort / File(s) Summary
Header files — specificity members
src/openms/include/OpenMS/ANALYSIS/ID/FragmentIndex.h, src/openms/include/OpenMS/ANALYSIS/ID/PeptideSearchEngineFIAlgorithm.h, src/openms/include/OpenMS/ANALYSIS/ID/SimpleSearchEngineAlgorithm.h
Added #include <OpenMS/CHEMISTRY/EnzymaticDigestion.h> and a member EnzymaticDigestion::Specificity (default SPEC_FULL) to store peptide enzyme specificity.
FragmentIndex implementation
src/openms/source/ANALYSIS/ID/FragmentIndex.cpp
Added peptide:enzyme_specificity parameter (full/semi/none), parse via EnzymaticDigestion::getSpecificityByName(), call digestor.setSpecificity(...), and early-return from build() when no fragments to avoid downstream bucketing on zero size.
Search algorithms implementation
src/openms/source/ANALYSIS/ID/PeptideSearchEngineFIAlgorithm.cpp, src/openms/source/ANALYSIS/ID/SimpleSearchEngineAlgorithm.cpp
Threaded peptide:enzyme_specificity into search setup: set search_parameters.enzyme_term_specificity, use specificity-aware decoy generation (reverseProtein for SPEC_NONE vs reversePeptides otherwise), set digestor specificity for scoring, and pass specificity string into peptide-indexing parameters.
Digestion core
src/openms/source/CHEMISTRY/EnzymaticDigestion.cpp
Handle SPEC_NONE as non-specific path and SPEC_SEMI by invoking semi-specific digestion and accumulating results; add early return when sequence shorter than min_length to avoid unsigned underflow.
Tests
src/tests/class_tests/openms/source/EnzymaticDigestion_test.cpp, src/tests/class_tests/openms/source/FragmentIndex_test.cpp
Added tests exercising SPEC_FULL/SPEC_SEMI/SPEC_NONE: counts, length bounds, superset behavior, and regression guards for short sequences and empty fragment outputs.

Sequence Diagram(s)

sequenceDiagram
    actor User
    participant Params as ParameterSystem
    participant FI as FragmentIndex/SearchAlg
    participant Dig as EnzymaticDigestion
    participant Index as PeptideIndexing/DecoyGen

    User->>Params: set peptide:enzyme_specificity (full/semi/none)
    Params->>FI: update members -> parse specificity
    FI->>Dig: digestor.setSpecificity(specificity)
    FI->>Dig: request peptide generation

    rect rgba(100,150,200,0.5)
        alt SPEC_FULL
            Dig->>Dig: full-specific digestion (tokenize & missed cleavages)
            Dig->>FI: full-specific peptides
        else SPEC_SEMI
            Dig->>Dig: full-specific digestion
            Dig->>Dig: semiSpecificDigestion_() -> extra peptides
            Dig->>FI: full + semi peptides
        else SPEC_NONE
            Dig->>Dig: generate all substrings in [min,max]
            Dig->>FI: all possible peptides
        end
    end

    FI->>Index: pass specificity for indexing/decoys
    Index->>User: indexed peptides / decoy DB
Loading

Possibly related PRs

Suggested reviewers

  • jpfeuffer
  • cbielow
  • jcharkow

Poem

🐰 I nibble peptides, full, semi, or none,
Hopping through cleavages till the counting is done.
From substrings to tryptic delight,
Indexes hum and decoys take flight,
Frolic, enzyme — the search is fun!

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 15.79% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main feature: adding semi-tryptic and non-specific digestion support to FragmentIndex and SimpleSearchEngine with the new peptide:enzyme_specificity parameter.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/fi-semi-nonspecific-digestion

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[bot]

This comment was marked as outdated.

timosachsenberg and others added 2 commits April 9, 2026 10:32
…leSearchEngine

Implements item #1 from #9108. Adds a `peptide:enzyme_specificity`
parameter (`full` / `semi` / `none`) to FragmentIndex, PeptideSearchEngineFIAlgorithm,
and SimpleSearchEngineAlgorithm — enabling immunopeptidomics-style 8..12mer non-specific
search and semi-tryptic search.

EnzymaticDigestion::digestUnmodified() previously silently ignored `specificity_`,
forcing every caller to use the magic `"unspecific cleavage"` enzyme name for the
non-specific path. Both StringView and pair overloads now honor SPEC_NONE (substring
enumeration) and SPEC_SEMI (full + semiSpecificDigestion_ variants).

Also fixes two pre-existing crashes that the immunopeptidomics workflow exposed:
  - EnzymaticDigestion::digestUnmodified unsigned underflow when `sequence.size() <
    min_length` (e.g. signal peptides in HLA proteomes).
  - FragmentIndex SIGFPE when no peptides survive filtering and bucketsize_ becomes
    sqrt(0) = 0, dividing by zero in the OMP bucket loop.

Replaces hardcoded `SPEC_FULL` literals at four sites (idXML records and the
PeptideIndexer re-validation step in both search engines) which would otherwise
silently drop semi/non-specific PSMs after the search.

New tests in EnzymaticDigestion_test (SPEC_NONE/SEMI/FULL semantics, short / empty
sequence guards) and FragmentIndex_test (full/semi/none parameter wiring +
tiny-protein crash regression).

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
…ormat

- Decoy generation: use reverseProtein() (plain full reverse) when
  enzyme_specificity is "none" instead of enzyme-aware reversePeptides(),
  so decoy search space matches the non-specific target space. Applies to
  both PeptideSearchEngineFIAlgorithm and SimpleSearchEngineAlgorithm.

- EnzymaticDigestion: semiSpecificDigestion_() returns (start, end) pairs
  (matching ProteaseDigestion convention). Fix the two digestUnmodified()
  call sites to convert to the format each needs:
  - StringView overload: substr(start, end - start) instead of substr(start, end)
  - pair<Size,Size> overload: store (start, end - start) instead of raw (start, end)

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
@timosachsenberg
timosachsenberg force-pushed the feat/fi-semi-nonspecific-digestion branch from 4caa4bd to 74ac253 Compare April 9, 2026 08:36
@timosachsenberg
timosachsenberg merged commit c41f129 into develop Apr 9, 2026
41 checks passed
@timosachsenberg
timosachsenberg deleted the feat/fi-semi-nonspecific-digestion branch April 9, 2026 10:15
github-actions Bot pushed a commit that referenced this pull request Apr 10, 2026
Add missing entries for three features merged after last changelog sync:
- PeptideDataBaseSearchFI multi-file search with shared fragment index (#9109)
- Semi-tryptic and non-specific digestion in PeptideDataBaseSearchFI and
  SimpleSearchEngine via new peptide:enzyme_specificity parameter (#9112)
- New PSM annotation options (num_matched_peaks, matched_b_ions,
  matched_y_ions, longest_peptide_ion_sequence, fragment_annotation)
  in PeptideDataBaseSearchFI and SimpleSearchEngine, with parquet export (#9117)

Co-authored-by: Copilot <[email protected]>
timosachsenberg pushed a commit that referenced this pull request Apr 10, 2026
Add missing entries for three features merged after last changelog sync:
- PeptideDataBaseSearchFI multi-file search with shared fragment index (#9109)
- Semi-tryptic and non-specific digestion in PeptideDataBaseSearchFI and
  SimpleSearchEngine via new peptide:enzyme_specificity parameter (#9112)
- New PSM annotation options (num_matched_peaks, matched_b_ions,
  matched_y_ions, longest_peptide_ion_sequence, fragment_annotation)
  in PeptideDataBaseSearchFI and SimpleSearchEngine, with parquet export (#9117)

Co-authored-by: GitHub Copilot <[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.

1 participant