Skip to content

[FIX] OpenSearchModificationAnalysis: name the modification nearest to the cluster mass, not the lowest within the tolerance - #10644

Merged
timosachsenberg merged 1 commit into
developfrom
claude/open-search-mod-nearest
Oct 19, 2026
Merged

timosachsenberg merged 1 commit into
developfrom
claude/open-search-mod-nearest

Conversation

@timosachsenberg

Copy link
Copy Markdown
Contributor

Description

OpenSearchModificationAnalysis::mapDeltaMassesToModifications() mapped a delta mass cluster to the Unimod entries within +-effective_tol (at most 0.02 Da) by taking the entry of lowest mass in the window (lower_bound(cluster - tol)) and the entry of highest mass (the last one <= cluster + tol), and naming the cluster "A//B" after both (or after the one, if they are the same). The entry nearest to the cluster mass was never named when it lay between others, and histogram_found recorded the same two extremes.

Example: a cluster at +15.9949 Da (oxidation, +15.994915 Da). Thiocarboxylic acid (+15.977156 Da) is the lowest mass within 0.02 Da, and nothing is higher but oxidation itself:

place before after
modification summary / _OutputTable.tsv thiocarboxylic acid//Oxidation or Hydroxylation Oxidation or Hydroxylation
PTM meta value of the PSMs (first entry of histogram_found in the window) thiocarboxylic acid Oxidation or Hydroxylation
DeltaMassEntry::mapped_modification (generateDeltaMassStatistics, "the lowest mass still wins") thiocarboxylic acid Oxidation or Hydroxylation
cluster at +16.9949 Da, with both clusters found (+1 Da variant, first entry of the window around cluster - 1 Da) thiocarboxylic acid+1Da Oxidation or Hydroxylation+1Da

The new rule

  • A cluster is named after the entry nearest to its mass, if that is within the tolerance (still capped at MAX_MOD_MAPPING_TOL_ = 0.02 Da). Other entries in the window are not named.
  • "A//B" is kept for genuine ambiguity: entries whose distance to the cluster exceeds that of the nearest by at most MOD_MAPPING_AMBIGUITY_TOL_ = 0.0005 Da are named as well, in order of mass. That is the width of the delta mass histogram bins (analyzeDeltaMassPatterns rounds to 0.0005 Da), so a cluster mass is not known better than that. The precursor tolerance is not used for this, since in an open search it is capped at 0.02 Da and would make every window ambiguous again. For the midpoint between oxidation and thiocarboxylic acid the cluster is still "thiocarboxylic acid//Oxidation or Hydroxylation".
  • histogram_found records only the entries that name the cluster (the nearest one, or the equally close ones).
  • The nearest entry is used wherever histogram_found is searched: the +1 Da variant, the modification that explains a later cluster, and the PTM annotation of the PSMs.
  • generateDeltaMassStatistics names the mapped modification with the same rule.
  • The combination of two modifications ("A++B") is looked up with the nearest sum. It used lower_bound(cluster - eps), i.e. only combinations at or above the cluster mass (and the lowest of them), so a combination below the cluster, within the tolerance, was missed. This is the same kind of defect, in the same function, and is a separate hunk (easy to drop if you prefer it in another PR). Effect on data below.

I looked at the ModificationsDB lookups by mass (searchModificationsByDiffMonoMass[Sorted], getBestModificationByDiffMonoMass). They do not fit: they scan all modifications per call and include non-Unimod entries and substitutions, whereas this class works on one table (Unimod search modifications without substitutions, one name per mass) that is also the basis of the combinations and the +1 Da logic. The nearest lookup on the sorted map is O(log n) per cluster, which matters for histograms of 1e4 to 1e5 bins.

Tests

  • OpenSearchModificationAnalysis_test (new section mapDeltaMassesToModifications, extended generateDeltaMassStatistics): a cluster at 15.9949 maps to oxidation and not to the lowest entry of the window; a cluster next to thiocarboxylic acid maps to it; the midpoint (and +-0.0001 Da around it) is "A//B", +-0.001 Da is the nearer one; tolerance of 0.005 Da; ppm mode; PSM annotation of two neighbouring clusters; the +1 Da variant picks oxidation and not thiocarboxylic acid; the combination is the nearest sum, checked against a brute force over the Unimod table (a cluster whose nearest combination lies below it); unknown clusters. Run against the unfixed code the new checks fail (19 failed checks: 17 in the new section and 2 in generateDeltaMassStatistics, e.g. got "thiocarboxylic acid//Oxidation or Hydroxylation", expected "Oxidation or Hydroxylation"), with the fix they pass.
  • Native build (WITH_GUI/THERMO_RAW/OPENTIMS=OFF, Release): ctest -R "ProSE|OpenSearchModificationAnalysis" 77 of 77 passed (all TOPP_ProSE_*, ProSEAlgorithm_test, the class test), before and after the change; -R Sage 4 of 4 (1 skipped: the sage binary is not available).
  • No reference file changed. The only output that differs between the unfixed and the fixed build is the _ModificationAnalysis_OutputTable.tsv that TOPP_ProSE_12_open_* write (it is compared between the pin and nopin runs, there is no committed reference): the cluster at -114.043 Da was Unknown-114.0 and is now Loss of arginine due to transpeptidation++tri-Methylation (-114.054 Da, 0.011 Da below the cluster; the combination lookup now sees combinations below the cluster). The DeltaMassStats and PTMStats tables are identical.
  • CHANGELOG entry added.

Notes

  • Combinations of two Unimod entries are dense (about 20 within +-0.02 Da at 100 Da), so a combination name is weak evidence; the tolerance for them was not changed here.
  • Not changed: entries of equal mass share one name in the table (the last one in the sorted list wins, e.g. "Phosphorylation Decoy" for +79.9663 Da, "Ethylation" for +28.0313 Da). That is a separate question from the one fixed here.

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.) (no API change)

🤖 Generated with Claude Code

…o the cluster mass, not the lowest within the tolerance

mapDeltaMassesToModifications() took the entry of lowest mass within +-tolerance of a
cluster (lower_bound) and the entry of highest mass (the last one <= cluster + tolerance),
and named the cluster "A//B" after both, or after the one if they were the same. The entry
nearest to the cluster mass was never named when it lay between others. With the Unimod
table, +15.9949 Da (oxidation) was "thiocarboxylic acid//Oxidation or Hydroxylation":
thiocarboxylic acid (+15.9772 Da) is the lowest mass within 0.02 Da. histogram_found
recorded the same two extremes, and the later lookups took the lowest entry of their window:

- the PTM meta value of the PSMs of the oxidation cluster was "thiocarboxylic acid"
  (first entry of histogram_found within the tolerance),
- DeltaMassEntry::mapped_modification of generateDeltaMassStatistics() was "thiocarboxylic
  acid" (the lowest mass still wins),
- a cluster at +16.9949 Da was "thiocarboxylic acid+1Da" (first entry in the window around
  cluster - 1 Da) instead of "Oxidation or Hydroxylation+1Da".

Now a cluster is named after the entry nearest to its mass if that is within the tolerance
(still capped at 0.02 Da). "A//B" is kept for genuine ambiguity: entries whose distance to
the cluster exceeds that of the nearest by at most 0.0005 Da, the width of the delta mass
histogram bins, are named as well (in order of mass), as a cluster mass is not known better
than that. Only the entries that name the cluster go into histogram_found. The nearest entry
is also used wherever histogram_found is searched (the +1 Da variant, a modification found
before, the PTM annotation of the hits), by generateDeltaMassStatistics() (same naming), and
for the combination of two modifications, which was looked up at or above the cluster mass
only (lower_bound(cluster)), so that a combination below it, within the tolerance, was missed
(a cluster of -114.043 Da was "Unknown" with a combination 0.011 Da below it).

The ModificationsDB lookups by mass (searchModificationsByDiffMonoMass*, getBest...) do not
fit: the table here is the Unimod search modifications, one name per mass, and is also the
basis of the combinations and the +1 Da logic; the sorted-map lookup is O(log n) per cluster
for histograms of 1e4-1e5 bins.

Tests: OpenSearchModificationAnalysis_test maps clusters at oxidation, thiocarboxylic acid
and between them, with the tolerance, in ppm mode, with PSM annotation, the +1 Da variant,
the combination (against a brute force over the Unimod table) and generateDeltaMassStatistics.
No reference file changes; the ModificationAnalysis tables of TOPP_ProSE_12_open_* gain one
combination name for a cluster that was "Unknown" (-114.043 Da).

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
@timosachsenberg

Copy link
Copy Markdown
Contributor Author

important fix

@timosachsenberg
timosachsenberg marked this pull request as ready for review October 19, 2026 12:57
@timosachsenberg
timosachsenberg merged commit 8528cf2 into develop Oct 19, 2026
33 checks passed
@timosachsenberg
timosachsenberg deleted the claude/open-search-mod-nearest branch October 19, 2026 14:39
timosachsenberg pushed a commit that referenced this pull request Oct 19, 2026
ConsensusID.cpp, which this branch had changed to clear the score software record, is removed
with the tool (#10619); ProcessingStep.h, which develop changed in a comment, stays removed with the
reference graph. PercolatorAdapter is now the only tool that records itself as search engine and
clears score software records (CHANGELOG and identification-data.md updated).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01B51nRFoHvZuVXD7cT8XZav
timosachsenberg pushed a commit that referenced this pull request Oct 19, 2026
…10563 HiGHS, #10644, #10648)

ConsensusID.cpp is removed with the tool (#10619), and with it this branch's bridge for feature and
consensus maps: the tool exported the identifications that a feature links to peptide
identifications, combined them with ConsensusIDAlgorithm and imported the consensus as a new run.
No other code of this branch used ConsensusID.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01B51nRFoHvZuVXD7cT8XZav
timosachsenberg pushed a commit that referenced this pull request Oct 20, 2026
…sm-prose-webapp

Brings in develop (with #10578 + #10602 as squash 2ef8693 and #10644 as
8528cf2) through the updated #10564 branch. This branch had carried a
pre-squash version of #10578/#10602 (claude/prose-merged-in-library) and a
cherry-pick of #10644.

Resolution: every library path is develop's version plus only the library
commits of this branch that develop does not have (ProSEAlgorithm::
pinEnzymeName() and modMatchTolerance() public, ML::PEPTDEEP_DEFAULT_BATCH_SIZE,
the joined reader thread, peptdeep:batch_size 128 in WebAssembly, the
PeptDeepRescoring NCE fix, ONNXPredictorBase without the memory pattern, the
ONNX environment changes for WebAssembly threads).
- ProSEAlgorithm.h, ProSEAlgorithm_test.cpp, src/tests/topp/CMakeLists.txt
  (conflicts) and ProSEAlgorithm.cpp (auto-merged, but with
  rescoreWithPercolator(), applyDeferredPsmFDR() and applyPsmFDR_() twice,
  since the squash moved them): develop's version with those commits on top.
- src/tests/topp/ProSE_13_prepare.cmake: removed; develop's Test 13 copies
  its inputs with add_test(... -E copy) instead.
- CHANGELOG: develop's text with this branch's entries.
- #10644 (7abcb28): identical to develop's, no difference left.

Co-Authored-By: Claude Opus 5.5 <[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