Repository navigation
feat: NumMatchedPeaks, longest ion run, fragment annotations - #9117
Conversation
…structs Add constants for matched_b_ions, matched_y_ions, num_matched_peaks, and longest_peptide_ion_sequence. Remove dead fragment_annotations field from both AnnotatedHit_ structs and add matched_b_ions / matched_y_ions counters in preparation for per-PSM ion statistics. Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
… ion run, fragment annotations Register new annotate:PSM options (num_matched_peaks, matched_b_ions, matched_y_ions, longest_peptide_ion_sequence, fragment_annotation) and implement their annotation logic in postProcessHits_. Refactors the theoretical spectrum generation + alignment to be shared across all alignment-dependent annotations (fragment error, fragment annotations, longest ion run). Updates TOPP test reference files to include the new annotation fields. Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
…n run, fragment annotations Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
…ractions Reorder struct members (doubles, floats, int, uint16_t) to minimize padding and use float instead of double for prefix_fraction, suffix_fraction, and mean_error (summary statistics where 7 significant digits is sufficient). Reduces AnnotatedHit_ from 56 to 40 bytes (excluding AASequence/StringView), down from 72 bytes before this PR. Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
📝 WalkthroughWalkthroughThis pull request adds configurable enzyme specificity support to peptide search algorithms and enhances PSM metrics tracking. It introduces digestion specificity parameters (full/semi/none) across FragmentIndex and search engines, adds new fragment ion matching metrics (matched b-ions, y-ions, and longest consecutive ion sequence), extends the Arrow schema for dedicated fragment annotation column storage, and updates EnzymaticDigestion to handle semi-specific and non-specific cleavage modes. Changes
Sequence DiagramsequenceDiagram
participant Config as Search Config
participant SE as Search Engine
participant ED as EnzymaticDigestion
participant SA as Search Algorithm
participant PS as PSM Scoring
participant AR as Arrow Storage
Config->>SE: peptide:enzyme_specificity<br/>(full|semi|none)
SE->>ED: setSpecificity(specificity_)
ED->>ED: digest() with SPEC_FULL/<br/>SPEC_SEMI/SPEC_NONE
ED-->>SA: peptides (varying cardinality)
SA->>PS: match fragments<br/>count b/y ions<br/>compute longest run
PS->>PS: calculate metrics:<br/>matched_b_ions<br/>matched_y_ions<br/>num_matched_peaks<br/>longest_peptide_ion_sequence
PS->>PS: generate peak<br/>annotations
PS->>AR: store in PSM
AR->>AR: populate mz/intensity/<br/>charge/ion_type arrays
Possibly related issues
Possibly related PRs
Suggested reviewers
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
src/tests/class_tests/openms/source/ArrowSchemaRegistry_test.cpp (1)
760-765:⚠️ Potential issue | 🟡 MinorPlease assert the four new PSMSchema columns explicitly.
Bumping the field count to
29alone will still pass if one ofmz_array,intensity_array,charge_array, orion_type_arrayis renamed, reordered, or given the wrong type. Add direct constant/type/nullability checks for those fields so the new schema contract is actually covered.As per coding guidelines, "Write unit tests for new functionality and ensure existing tests pass before suggesting changes".
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/tests/class_tests/openms/source/ArrowSchemaRegistry_test.cpp` around lines 760 - 765, The test currently only checks PSMSchema::schema() is non-null and has num_fields()==29; update the test block to also assert the four new columns explicitly by locating the schema via PSMSchema::schema() and verifying each field: check a field exists with the exact name "mz_array", "intensity_array", "charge_array", and "ion_type_array" and assert each has the expected data type and nullability (e.g., expected field->type() and field->nullable() values) so renames, reordering, or wrong types will fail the test instead of relying only on the field count.
🧹 Nitpick comments (3)
src/openms/source/ANALYSIS/ID/PeptideSearchEngineFIAlgorithm.cpp (2)
448-451: Consider adding a defensive check for data array availability.Accessing
theoretical_spec.getStringDataArrays()[0]andgetIntegerDataArrays()[0]assumes these arrays are populated. WhileTheoreticalSpectrumGeneratorwithadd_metainfo=trueshould always create them, an empty theoretical spectrum (e.g., for a very short peptide) could potentially leave these arrays empty.💡 Optional defensive check
if (annotation_fragment_annotations || annotation_longest_ion_run) { + if (theoretical_spec.getStringDataArrays().empty() || theoretical_spec.getIntegerDataArrays().empty()) + { + // Fallback: skip annotations if metainfo arrays are missing + continue; + } const auto& ion_names = theoretical_spec.getStringDataArrays()[0]; const auto& ion_charges = theoretical_spec.getIntegerDataArrays()[0];🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/openms/source/ANALYSIS/ID/PeptideSearchEngineFIAlgorithm.cpp` around lines 448 - 451, The code assumes theoretical_spec.getStringDataArrays()[0] and getIntegerDataArrays()[0] exist when annotation_fragment_annotations or annotation_longest_ion_run is true; add a defensive check on theoretical_spec.getStringDataArrays().size() and theoretical_spec.getIntegerDataArrays().size() (and that the first array is non-empty) before indexing, and if missing skip the annotation block or fall back to safe defaults so annotation_fragment_annotations / annotation_longest_ion_run do not dereference empty arrays.
496-510: Consider extractinglongestRunas a shared utility function.This lambda is duplicated verbatim in
SimpleSearchEngineAlgorithm.cpp(lines 458-469). Extracting it to a shared location (e.g., a helper inMathFunctions.hor a static method) would reduce duplication and ensure consistent behavior.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/openms/source/ANALYSIS/ID/PeptideSearchEngineFIAlgorithm.cpp` around lines 496 - 510, The lambda longestRun used here (operating on vectors like b_ordinals and y_ordinals and producing the value stored via ph.setMetaValue with Constants::UserParam::LONGEST_PEPTIDE_ION_SEQUENCE) is duplicated in SimpleSearchEngineAlgorithm.cpp; extract it into a shared utility (e.g., add a function int longestConsecutiveRun(std::vector<int> v) in a common header like MathFunctions.h or as a static helper in a shared class) and replace the local lambda in both PeptideSearchEngineFIAlgorithm.cpp and SimpleSearchEngineAlgorithm.cpp with calls to that new function to remove duplication and keep behavior consistent.src/openms/source/ANALYSIS/ID/SimpleSearchEngineAlgorithm.cpp (1)
409-413: Same defensive check consideration as in PeptideSearchEngineFIAlgorithm.cpp.The access to
theoretical_spec.getStringDataArrays()[0]andgetIntegerDataArrays()[0]has the same potential edge case as noted in the other algorithm file.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/openms/source/ANALYSIS/ID/SimpleSearchEngineAlgorithm.cpp` around lines 409 - 413, The code reads theoretical_spec.getStringDataArrays()[0] and getIntegerDataArrays()[0] without ensuring those arrays are non-empty, which can crash if no data arrays exist; update the fragment-annotation block guarded by the flags annotation_fragment_annotations and annotation_longest_ion_run to first check that theoretical_spec.getStringDataArrays().size() > 0 and theoretical_spec.getIntegerDataArrays().size() > 0 (or that the specific array indices exist), and only then assign ion_names and ion_charges from [0]; if missing, skip annotation logic or provide a safe fallback (e.g., empty arrays) so functions using ion_names/ion_charges do not dereference out-of-range elements.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@src/openms/source/ANALYSIS/ID/FragmentIndex.cpp`:
- Around line 772-777: The early-return path in FragmentIndex::build leaves the
object marked built with bucketsize_ == 0 which breaks consumers iterating by
bucketsize_; update the empty-index branch to keep bucketsize_ non-zero (e.g.
set bucketsize_ = 1 instead of 0) while logging and setting is_build_ = true so
consumers that loop with fi_idx += bucketsize_ won’t hang; modify the block
referencing fi_fragments_, bucketsize_, and is_build_ accordingly.
In `@src/tests/class_tests/openms/source/FragmentIndex_test.cpp`:
- Around line 289-329: The cross-mode comparison uses semi_count computed with
peptide:min_size=2/max_size=100 but fi_none uses 8..12; recreate the
semi-specific baseline using the same length window before comparing: adjust the
FragmentIndex_test fi_semi parameters (via
fi_semi.getParameters()/p.setValue("peptide:min_size", 8) and
p.setValue("peptide:max_size", 12)) and rebuild fi_semi to set semi_count, or
alternatively drop the TEST_EQUAL(fi_none.getPeptides().size() > semi_count,
true) assertion; update the code around fi_semi, fi_semi.setParameters(p),
fi_semi.build(entries), and semi_count = fi_semi.getPeptides().size()
accordingly so both modes use the same 8..12 window.
---
Outside diff comments:
In `@src/tests/class_tests/openms/source/ArrowSchemaRegistry_test.cpp`:
- Around line 760-765: The test currently only checks PSMSchema::schema() is
non-null and has num_fields()==29; update the test block to also assert the four
new columns explicitly by locating the schema via PSMSchema::schema() and
verifying each field: check a field exists with the exact name "mz_array",
"intensity_array", "charge_array", and "ion_type_array" and assert each has the
expected data type and nullability (e.g., expected field->type() and
field->nullable() values) so renames, reordering, or wrong types will fail the
test instead of relying only on the field count.
---
Nitpick comments:
In `@src/openms/source/ANALYSIS/ID/PeptideSearchEngineFIAlgorithm.cpp`:
- Around line 448-451: The code assumes
theoretical_spec.getStringDataArrays()[0] and getIntegerDataArrays()[0] exist
when annotation_fragment_annotations or annotation_longest_ion_run is true; add
a defensive check on theoretical_spec.getStringDataArrays().size() and
theoretical_spec.getIntegerDataArrays().size() (and that the first array is
non-empty) before indexing, and if missing skip the annotation block or fall
back to safe defaults so annotation_fragment_annotations /
annotation_longest_ion_run do not dereference empty arrays.
- Around line 496-510: The lambda longestRun used here (operating on vectors
like b_ordinals and y_ordinals and producing the value stored via
ph.setMetaValue with Constants::UserParam::LONGEST_PEPTIDE_ION_SEQUENCE) is
duplicated in SimpleSearchEngineAlgorithm.cpp; extract it into a shared utility
(e.g., add a function int longestConsecutiveRun(std::vector<int> v) in a common
header like MathFunctions.h or as a static helper in a shared class) and replace
the local lambda in both PeptideSearchEngineFIAlgorithm.cpp and
SimpleSearchEngineAlgorithm.cpp with calls to that new function to remove
duplication and keep behavior consistent.
In `@src/openms/source/ANALYSIS/ID/SimpleSearchEngineAlgorithm.cpp`:
- Around line 409-413: The code reads theoretical_spec.getStringDataArrays()[0]
and getIntegerDataArrays()[0] without ensuring those arrays are non-empty, which
can crash if no data arrays exist; update the fragment-annotation block guarded
by the flags annotation_fragment_annotations and annotation_longest_ion_run to
first check that theoretical_spec.getStringDataArrays().size() > 0 and
theoretical_spec.getIntegerDataArrays().size() > 0 (or that the specific array
indices exist), and only then assign ion_names and ion_charges from [0]; if
missing, skip annotation logic or provide a safe fallback (e.g., empty arrays)
so functions using ion_names/ion_charges do not dereference out-of-range
elements.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 6e9353e2-0ff9-478d-a19f-812ab5a54361
📒 Files selected for processing (19)
src/openms/include/OpenMS/ANALYSIS/ID/FragmentIndex.hsrc/openms/include/OpenMS/ANALYSIS/ID/PeptideSearchEngineFIAlgorithm.hsrc/openms/include/OpenMS/ANALYSIS/ID/SimpleSearchEngineAlgorithm.hsrc/openms/include/OpenMS/CONCEPT/Constants.hsrc/openms/include/OpenMS/FORMAT/ArrowSchemaRegistry.hsrc/openms/source/ANALYSIS/ID/FragmentIndex.cppsrc/openms/source/ANALYSIS/ID/PeptideSearchEngineFIAlgorithm.cppsrc/openms/source/ANALYSIS/ID/SimpleSearchEngineAlgorithm.cppsrc/openms/source/CHEMISTRY/EnzymaticDigestion.cppsrc/openms/source/FORMAT/ArrowSchemaRegistry.cppsrc/openms/source/FORMAT/QPXFile.cppsrc/tests/class_tests/openms/source/ArrowSchemaRegistry_test.cppsrc/tests/class_tests/openms/source/EnzymaticDigestion_test.cppsrc/tests/class_tests/openms/source/FragmentIndex_test.cppsrc/tests/class_tests/openms/source/PeptideSearchEngineFIAlgorithm_test.cppsrc/tests/topp/PeptideDataBaseSearchFI_1_out.idXMLsrc/tests/topp/PeptideDataBaseSearchFI_2_out.idXMLsrc/tests/topp/SimpleSearchEngine_1_out.idXMLsrc/tests/topp/SimpleSearchEngine_2_out.idXML
Wire up PeptideHit::getPeakAnnotations() to the mz_array, intensity_array, charge_array, and ion_type_array columns in both PSMSchema and QPXPSMSchema parquet exports. Exclude the fragment_annotation metavalue (idXML string format) from the psm_metavalues bag to avoid duplication. Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
276a9f5 to
754f3f5
Compare
…i-vs-none test - FragmentIndex::build: set bucketsize_ to 1 instead of 0 for empty indexes to preserve bucket-walking loop invariants. - FragmentIndex_test: compare semi vs none using the same 8..12 length window so the assertion is not dependent on mismatched parameters. Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
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]>
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]>
CodeRabbit feedback on fdafb4a: - #4: LONGEST_PEPTIDE_ION_SEQUENCE only counted b/y ordinals but was newly exported to Percolator, systematically biasing ETD/EThcD. Generalized the classifier to a/b/c (prefix) / x/y/z (suffix) in both ProSEAlgorithm and SSE. Ordinals merged via existing std::unique, so a3 and b3 collapse to one backbone position. - #5: test coverage. Added DELTA_SCORE and MATCHED_ION_CURRENT assertions in the existing PSM-annotations section. - #3 (init-with-0.0 vs negative scores): pushback. HyperScore output is log1p + non-negative factorial terms, and score == 0 is already filtered at the scoring site, so 0.0 init is safe. New feature — matched_ion_current (MIC): Sum of experimental intensities over matched peaks. Computed in the existing postProcessHits_ alignment loop (no HyperScore changes), emitted as UserParam, and added to Percolator extra_features (ProSE only, matching how longest_peptide_ion_sequence is handled). SSE annotates but does not export. Safe today because SpectrumAlignment's default Da path produces 1-to-1 matches; documented inline. Reference idXML files regenerated — they were already stale before this branch due to float-precision drift from #9117 (matched_*_ions stored as float since 2026-04-09). The regeneration also absorbs the new delta_score and matched_ion_current UserParams. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
…atures (#9175) * feat(ProSE): delta score, renamed ion counts, expanded Percolator features Three changes bundled because they touch the same code paths: 1. Rename matched_b_ions / matched_y_ions → matched_prefix_ions / matched_suffix_ions across HyperScore, ProSE, SSE, and Constants.h. With PR #9167 enabling c/z/a/x ions, the old names were misleading — these counters track ALL prefix (a/b/c) and suffix (x/y/z) ions, not just b/y. MetaValue strings also renamed (no backward compat needed — ProSE is unreleased). 2. Fix HyperScore::computeWithDetail to count all prefix/suffix ion types in the factorial terms, not just b/y. Previously c/z ions contributed to the dot_product (intensity matching) but NOT to the ion-count factorial boost — penalizing ETD/EThcD searches. The fast path (first-char check, O(1) per ion) handles a/b/c/x/y/z; the XL-MS $-prefix fallback (single find('$'), O(N) on name length) is preserved for NuXL compatibility. 3. Add delta_score: score difference between best and second-best PSM per spectrum. Computed in a single O(N) pass over candidates BEFORE partial_sort — zero change to the existing sort (still k=top_hits). When only one candidate exists, delta = full score (same convention as Sage/MSFragger: no competition = maximum delta). Wired into extra_features for Percolator. Also wires longest_peptide_ion_sequence and matched_prefix/suffix_ions into extra_features (already computed but previously not passed to Percolator). Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]> * fix(ProSE): address CR feedback + add matched_ion_current CodeRabbit feedback on fdafb4a: - #4: LONGEST_PEPTIDE_ION_SEQUENCE only counted b/y ordinals but was newly exported to Percolator, systematically biasing ETD/EThcD. Generalized the classifier to a/b/c (prefix) / x/y/z (suffix) in both ProSEAlgorithm and SSE. Ordinals merged via existing std::unique, so a3 and b3 collapse to one backbone position. - #5: test coverage. Added DELTA_SCORE and MATCHED_ION_CURRENT assertions in the existing PSM-annotations section. - #3 (init-with-0.0 vs negative scores): pushback. HyperScore output is log1p + non-negative factorial terms, and score == 0 is already filtered at the scoring site, so 0.0 init is safe. New feature — matched_ion_current (MIC): Sum of experimental intensities over matched peaks. Computed in the existing postProcessHits_ alignment loop (no HyperScore changes), emitted as UserParam, and added to Percolator extra_features (ProSE only, matching how longest_peptide_ion_sequence is handled). SSE annotates but does not export. Safe today because SpectrumAlignment's default Da path produces 1-to-1 matches; documented inline. Reference idXML files regenerated — they were already stale before this branch due to float-precision drift from #9117 (matched_*_ions stored as float since 2026-04-09). The regeneration also absorbs the new delta_score and matched_ion_current UserParams. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> * docs: update ion-series doc comments to prefix/suffix terminology Stale ///< doc comments on `prefix_fraction`/`suffix_fraction` and `matched_prefix_ions`/`matched_suffix_ions` (in ProSEAlgorithm.h and SimpleSearchEngineAlgorithm.h) and on `LONGEST_PEPTIDE_ION_SEQUENCE` (Constants.h) still referred to "b-ions"/"y-ions" after the rename. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> --------- Co-authored-by: Claude Opus 4.6 (1M context) <[email protected]>
Summary
num_matched_peaks,matched_b_ions,matched_y_ions,longest_peptide_ion_sequence, and fullfragment_annotation(PeakAnnotation vector for TOPPView visualization)PeptideSearchEngineFIAlgorithmandSimpleSearchEngineAlgorithmmz_array,intensity_array,charge_array,ion_type_arraycolumnsfragment_annotationmetavalue excluded from parquetpsm_metavaluesbag to avoid duplicationDepends on #9112 (semi/non-specific digestion).
Addresses item #3 from #9108.
Bugfixes included
reverseProtein()(plain full reverse) whenenzyme_specificity=noneinstead of enzyme-awarereversePeptides(), so decoy search space matches the non-specific target spacesemiSpecificDigestion_()returns(start, end)pairs but twodigestUnmodified()callers consumed them as(start, length)— fixed at the call sitesImplementation details
HyperScore::PSMDetailalready computed matched b/y counts during scoring — now propagated toAnnotatedHit_asuint16_tfieldspostProcessHits_for top-N hits only (not in the scoring hot loop) by reusing the existingTheoreticalSpectrumGenerator+SpectrumAlignmentcode pathannotate:PSMparameter (included in "ALL")fragment_annotationsfield fromAnnotatedHit_; struct shrunk from 72 to 40 bytes via field reordering +floatfor fraction/error fieldsTest plan
🤖 Generated with Claude Code
Summary by CodeRabbit
Release Notes
New Features
Bug Fixes