Skip to content

[FEATURE,FIX] Every PeptideIdentification needs its ProteinIdentification run - #10475

Merged
timosachsenberg merged 11 commits into
developfrom
feature/strict-protein-run-references
Oct 9, 2026
Merged

timosachsenberg merged 11 commits into
developfrom
feature/strict-protein-run-references

Conversation

@timosachsenberg

@timosachsenberg timosachsenberg commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

Summary: why a strict rule helps

A peptide identification is only meaningful together with the search run that produced it. The run (ProteinIdentification) holds the search engine, database, modifications, score settings and the proteins the peptide hits may point to. OpenMS let a peptide identification name a run that does not exist, and each file format and tool handled that differently, mostly by losing or bending data without telling anyone.

This PR makes it one simple rule: every peptide identification names an existing run. The run may be empty, i.e. without protein hits or a database, as in peptidomics or de novo. A violation now fails at once, with one clear message, where the data is created or written.

Cases this prevents (all found in this PR, in code or test data):

  • Results silently lost. idXML, featureXML and consensusXML dropped such identifications on writing, with only a warning. OpenSwathWorkflow featureXML outputs lost every identification this way, and so did XL-MS results read from mzIdentML. A FeatureFinderIdentification candidates file re-scored to 0 features instead of 69.
  • The wrong protein. A protein reference that did not resolve in the peptide's run was written as another protein (PH_0). The expected output of one TOPP test (IDConflictResolver_3) named the wrong protein without anyone noticing.
  • Broken files and obscure errors. mzTab export truncated the output file and then threw std::out_of_range; the OMS conversion threw it as well. Some writers produced files OpenMS itself could not read back.
  • The same file meaning different things. Loaders kept such identifications with an empty run, attached them to the first run, or invented an empty run, depending on the format.
  • Fragile downstream code. Every tool that looks up a peptide's run (search settings, score type, protein inference, mzTab export, the IdentificationData conversion in Introduce owning IdentificationData and native Parquet persistence #10423) can now rely on it being there.

For users: data that already follows the rule is read and written as before. Data that breaks it now fails with a clear message instead of being changed silently. The test and example files that broke it were fixed.

Description

Enforces on develop the contract the IdentificationData stack (#10423) relies on: every PeptideIdentification names an existing ProteinIdentification run (the search run, which may have no protein hits or database, e.g. peptidomics or de novo). Data and code conform before the stack lands; the error wording matches the IdentificationData import.

Central check

ProteinRunReferences (new, METADATA/, bound in pyOpenMS) throws Exception::InvalidParameter:

Peptide identification has no matching protein run: ''. Every peptide identification needs the protein identification run (search run) with its identifier, which may have no protein hits.

Writers: check before the file is opened

Format Before
idXML, featureXML, consensusXML silently omitted the identification (warning only)
pepXML, xQuest, idparquet, featureparquet, consensusparquet, QPX views wrote the dangling reference
mzIdentML logged an error, dropped the result, still wrote its Peptide entries
mzTab, OMS std::out_of_range (mzTab after truncating the file)

Loaders: refuse dangling references (strict)

  • featureXML/consensusXML: unknown identification_run_ref (was a warning, kept with an empty identifier).
  • featureparquet (kept silently), idparquet/consensusparquet (silently added an empty run), mzIdentML (silently attached to run 0).

Protein references

  • featureXML/consensusXML wrote protein_refs="PH_0" (another protein) for an accession that is no protein hit of the run, so the file could not be read back or named the wrong protein. ProteinRunReferences::checkProteinAccessions() now throws ElementNotFound before the file is opened, in the same single pass as the run check.
  • featureXML/consensusXML also keyed protein hit ids by run identifier and accession joined with _. Run A with accession B_C and run A_B with accession C shared a key, so a peptide hit referenced the other run's protein. The ids are now kept per run.
  • idXML resolved such an accession to the protein hit of an earlier run. Its lookup is now per run, and it throws ElementNotFound as for an unknown accession.
  • Loaders: idXML, featureXML and consensusXML resolved protein_refs file-wide. A reference to another run's protein hit is now a parse error.

Producers fixed at the root

  • mzIdentML / xQuest XL-MS: OPXLHelper::removeBetaPeptideHits dropped the run identifier, and only the last cross-link match of a spectrum got one. Every XL-MS identification loaded from mzIdentML was then silently dropped by the idXML writer. Hits are now grouped by run and spectrum.
  • featureparquet: run identifiers of subordinate features' identifications were not renamed on load.
  • OpenSwathWorkflow: the featureXML output had no run, so every identification was dropped; scorePeakgroups() never adds it. The new static MRMFeatureFinderScoring::addProteinIdentificationRun() (pyOpenMS too) adds the run with the transition list's proteins, or merges them into an existing run. performExtraction() calls it once, from the full transition list: no per-batch runs, deterministic order, no cost in .osw mode.
  • OpenSwathAnalyzer added one run per SWATH file with the same identifier, so several files could not be stored. It now adds one run.
  • FeatureFinderIdentification:
    • -candidates_out was written before the runs were set. With the old file, -candidates_in re-scoring found 0 features; it now finds 69.
    • Seed/offset placeholder identifications carry a run (one is added if there is none, and removed with them). They are removed by their SeedFeatureID marker, also when re-scoring candidates.
    • Placeholders rejected by the PSM score cutoff are no longer reported as unassigned identifications.
  • IDMerger -add_to: kept a peptide without its run, tracked accessions per file instead of per run, and kept a peptide whose protein is missing from its run (now an error).
  • FeatureFinderAlgorithmMetaboIdent (FAIMS: the run came only from the first group), ConsensusMap::split (non-isobaric: no runs), ProteomicsLFQ (warning → error), FileHandler OMSSA loading (overwrote run 0 and added an empty run).

Test data and expected outputs (investigated one by one, additions only)

  • Expected outputs regenerated: 19 OpenSwathWorkflow expected featureXML files and FeatureFinderIdentification_5_candidates.featureXML now contain the run and the identifications the writer used to drop. IDConflictResolver_3_output.consensusXML now names VIMSS15048, the protein its input references, instead of VIMSS14219 (PH_0).
  • Inputs with cross-run protein references fixed: the referenced protein is added to the peptide's own run, or taken from it when it is already there. Files: IDConflictResolver_3, ProteinResolver_1, Epifany_2, IDMerger_6, MzTabExporter_5, TextExporter_5 and examples/FRACTIONS/BSA_linked.consensusXML. These leave all other test outputs unchanged.

Tests

  • New tests:
    • ProteinRunReferences_test;
    • store/load cases in the IdXMLFile, FeatureXMLFile, ConsensusXMLFile, MzTabFile, PSMArrowIO, FeatureMapArrowIO, ConsensusMap and OPXLHelper class tests, including the A/B_C vs. A_B/C round trip in featureXML and consensusXML;
    • TOPP tests FeatureFinderIdentification_6 and _7 (placeholder identifications) and IDMerger_7;
    • test_protein_run_references.py, including FeatureFinderIdentification with seeds and no runs.
  • Fixtures that built identifications without a run were fixed: IdXMLFile, ConsensusMapArrowExport, ProteinGroupArrowExport and QPXFile class tests, and test_restored_call_forms.py::_identified_run.

Locally on head 79252bc, merged with develop d5709a1 (Ubuntu 24.04 system packages, Arrow 25.0.1, OPENMS_USE_VCPKG=OFF, Thermo RAW off, THIRDPARTY engines on PATH):

  • full ctest: 3073/3073 passed;
  • full pyOpenMS suite: 6589 passed, 19 skipped, 10 xfailed, 7 xpassed.

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

🤖 Generated with Claude Code

https://claude.ai/code/session_01Pxi3mzoptivbseUeJHjy2C

claude added 5 commits October 8, 2026 22:17
…tion run

Enforce the contract that a peptide identification's identifier names an
existing protein identification run (the search run, which may have no
protein hits or database). ProteinRunReferences::check() throws
Exception::InvalidParameter ("Peptide identification has no matching protein
run: '<id>'. ...") and is used by all writers before the file is opened
(idXML/featureXML/consensusXML no longer silently omit such identifications;
pepXML, mzIdentML, xQuest, mzTab, OMS and the Parquet formats check, too) and
by the loaders, which refuse dangling references (featureXML/consensusXML
identification_run_ref, featureparquet, idparquet/consensusparquet shell runs,
mzIdentML lists without a SpectrumIdentification).

Producers fixed at the root: OPXLHelper::removeBetaPeptideHits and the
mzIdentML XL-MS loader lost run identifiers; FeatureMapArrowIO did not rename
subordinate identifications; OpenSwathWorkflow's featureXML output had no run
(MRMFeatureFinderScoring::addProteinIdentificationRun); FeatureFinderIdentification
stored candidates before setting runs and kept pseudo IDs once they carry a run;
FeatureFinderAlgorithmMetaboIdent (FAIMS), ConsensusMap::split, IDMerger -add_to,
ProteomicsLFQ and the FileHandler OMSSA loader.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Pxi3mzoptivbseUeJHjy2C
…ropped

FeatureFinderIdentification_5_candidates and the OpenSwathWorkflow featureXML
outputs gain their protein identification run and the peptide identifications
of the features, which featureXML storing silently omitted before (no run).
Additions only; the feature ids differ (whitelisted) since the new run takes
unique ids.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Pxi3mzoptivbseUeJHjy2C
The writers looked protein references up with operator[], so a peptide evidence
whose protein is no protein hit of the peptide identification's run was written
as "PH_0": a file that cannot be read back, or that names another protein.
ProteinRunReferences::checkProteinAccessions() throws Exception::ElementNotFound
before the file is opened (the handlers throw, too), as idXML does.

Found by it: OpenSwathWorkflow kept only the first batch's proteins in its run
(the proteins of each batch's transitions are added now), and the
IDConflictResolver_3 input referenced a protein of another run in two runs
(the expected output named VIMSS14219 instead of VIMSS15048).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Pxi3mzoptivbseUeJHjy2C
…ther run

The loaders resolved protein_refs file-wide, so a peptide hit could reference
a protein hit of another run (e.g. 'PH_0' written by the former fallback for
unknown accessions) and silently get that protein. Such a reference is now a
parse error.

Test and example data with such references are fixed: the referenced protein
is added to (or, if present, taken from) the peptide identification's own run
(ProteinResolver_1, Epifany_2, IDMerger_6, MzTabExporter_5 and TextExporter_5
inputs, examples/FRACTIONS/BSA_linked.consensusXML). Test outputs are unchanged.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Pxi3mzoptivbseUeJHjy2C

@timosachsenberg timosachsenberg left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Review of head afaee72 (83 files vs. merge-base ea2175b). I read every code hunk plus the enclosing functions, and traced the callers of the changed writers/loaders, scorePeakgroups/pickExperiment, QPXFile::importFromArrow, and the idXML/featureXML/consensusXML handlers.

The strict run-scoped protein references are a sound direction. Inline comments, most severe first:

  1. IdXMLFile: writer still resolves protein_refs file-wide while the new loader rejects cross-run refs, so this version can write a file it cannot read.
  2. IDMerger -add_to: a "not found … Skipping" accession keeps the peptide, which now makes store throw or emit a cross-run ref.
  3. MRMFeatureFinderScoring::addProteinIdentificationRun: early return drops proteins of every batch after the first; documented pyOpenMS usage then fails in FeatureXMLFile::store.
  4. FeatureFinderIdentificationAlgorithm: the pseudo-ID placeholder run is never removed and has a fixed identifier.
  5. OpenSwathWorkflow: protein hit order is non-deterministic with -threads > 1.
    6–9. Minor: accession set rebuilt per batch inside the critical section; size-diff dangling-run detection duplicated across Arrow importers; redundant XL-MS identifier assignment; double up-front traversal in featureXML/consensusXML store; no ConsensusMap test for checkProteinAccessions.

Checked and not flagged: fatalError throws so the run->second dereferences after it are safe; the XML handlers set the run identifier before the ProteinHit elements, so proteinid_to_run_ is consistent; ConsensusXMLHandler is constructed per load so its new map needs no clear; mzIdentML parses SpectrumIdentification before protocols so runOfList_ is populated when first used; ProteomicsLFQ already enforces one run per ID file so its new throw is correct; offset peptides carry SeedFeatureID so isEmptyPseudoID_ removes both kinds.


Generated by Claude Code

Comment thread src/openms/source/FORMAT/IdXMLFile.cpp Resolved
Comment thread src/topp/IDMerger.cpp Resolved
claude added 6 commits October 9, 2026 09:53
…th runs

Fixes from the review of #10475:
- IdXMLFile::store wrote a reference to the protein hit of an earlier run for an
  accession missing from the peptide identification's run, which the strict loader
  rejects; the lookup is per run now (ElementNotFound). The run check moved out of
  the function-try-block that notes a partial file (storeFile_()).
- FeatureFinderIdentification: pseudo IDs of seeds and offset peptides rejected by
  the PSM score cutoff (or as decoys) are not reported as unassigned
  identifications (they had no run); re-scoring candidates removes pseudo IDs.
- IDMerger -add_to: protein accessions are tracked per run, not per file.
- MRMFeatureFinderScoring::addProteinIdentificationRun (static) merges the proteins
  into an existing run. OpenSwathWorkflow adds the run once per performExtraction,
  from the full transition list (no per-batch runs: deterministic protein order,
  no cost in .osw mode); OpenSwathAnalyzer adds one run for all SWATH files.
- OPXLHelper::removeBetaPeptideHits groups the hits by run and spectrum.
- MzIdentMLDOMHandler: look up the run once per new protein hit.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Pxi3mzoptivbseUeJHjy2C
…l idXML file

TOPP_FeatureFinderIdentification_6 stores offset peptides rejected by the PSM
score cutoff; _7 checks that the candidates keep the pseudo IDs while the output
and the output re-scored from the candidates have none. IdXMLFile_test removes the
partial file a failed store() leaves (it does not validate).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Pxi3mzoptivbseUeJHjy2C
… check

From the review threads on #10475:
- FeatureFinderIdentification removes the run it adds for the pseudo IDs of seeds
  and offset peptides (without other runs) together with them; it was left in the
  output as an empty run with a fixed identifier.
- IDMerger -add_to: a peptide whose protein is missing from its run is an error
  (ElementNotFound) instead of a logged "Skipping" that kept a peptide that
  cannot be written.
- ProteinRunReferences::checkProteinAccessions also reports a peptide
  identification without its run (InvalidParameter), so featureXML/consensusXML
  storing checks both in one pass.
- MzIdentMLDOMHandler: no second run assignment in the XL-MS branch.
- Tests: ConsensusMap overload of checkProteinAccessions (feature, unassigned,
  missing run); pyOpenMS: seeds without runs leave no placeholder run.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Pxi3mzoptivbseUeJHjy2C
…oined key

The writers keyed the protein hit ids by run identifier and accession joined
with '_', so (run 'A', accession 'B_C') and (run 'A_B', accession 'C') shared
the key 'A_B_C': a peptide hit of one run was written with a reference to the
other run's protein, which the loaders now refuse. The ids are now kept per run
(run identifier -> accession -> id). Round-trip regression in the FeatureXMLFile
and ConsensusXMLFile class tests.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Pxi3mzoptivbseUeJHjy2C
@jpfeuffer

jpfeuffer commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

Yeah makes sense. Cant think of anything where you would NOT need one.
The other way round might be possible. E.g. in merged runs, you can have a canonical merged protein run and then the "unused" original runs with the subset of proteins in each subrun.
Not even sure if this really needs to be kept but we do right now AFAIK.

Copy link
Copy Markdown
Contributor Author

@jpfeuffer Thanks. The rule only goes one way, so that case stays valid: a protein identification run without any peptide identification is not checked or rejected anywhere. ProteinRunReferences throws in exactly two cases:

  • a peptide identification names no existing run;
  • a peptide evidence names a protein that is not a protein hit of the peptide identification's own run.

A merged run next to the original per-file runs, which keep their subsets of proteins and no peptide identifications, is written and loaded as before. The same holds for a run whose PSMs were all filtered out. The featureXML/consensusXML class tests cover a round trip with such a run: run other, protein hit PROT_B, no peptide identifications.


Generated by Claude Code

@timosachsenberg
timosachsenberg marked this pull request as ready for review October 9, 2026 15:36
@timosachsenberg
timosachsenberg merged commit 10b0a7a into develop Oct 9, 2026
31 of 32 checks passed
@timosachsenberg
timosachsenberg deleted the feature/strict-protein-run-references branch October 9, 2026 15:37
timosachsenberg pushed a commit that referenced this pull request Oct 12, 2026
Brings in develop up to dac9590 (89 commits since #10446). Conflicts and ports:

- #10517 (modification-aware RNA digestion): RNaseDigestion keeps the run digest of
  this branch next to develop's coordinate-bearing digest, getFragmentPositions,
  inferCleavageSensitiveMods and digestWithCleavageSensitiveMods. The candidate
  and evidence merge of the run digest is RNaseDigestion::DigestedOligo::addEvidence,
  which NucleicAcidSearchEngine also uses: it applies internal fixed modifications
  before the cleavage and places cleavage-sensitive variable modifications during
  the digestion, on the database sequences of its run (evidence refers to the
  unmodified database sequence). A digest input (-digest) uses only the enzyme it
  records (rna_enzyme) to classify cleavage-sensitive modifications. The m2,2G
  digestion check and NASEDigestion_test use the owning model and a native digest
  bundle instead of .oms; bindings keep the run digest and add develop's API.
- #10515 (RNA adduct mass): the mzTab export of oligonucleotide matches without a
  calculated m/z includes the adduct, computed as NucleicAcidSearchEngine does
  (AdductInfo::getMZ; the adduct of a match is that of the ion). The regression
  test uses the owning model with the adduct NucleicAcidSearchEngine stores and
  develop's formula as the expected value.
- #10475 (every peptide identification needs its run): the Arrow writers check
  both the native links and the protein runs; the consensus Parquet loader checks
  both as well. The adapter reports a missing run with ProteinRunReferences'
  message. The converter keeps this branch's implementation, which enforces the
  run contract on import.
- FileHandler: imaging includes from #10439; CHANGELOG: both sides.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01B51nRFoHvZuVXD7cT8XZav
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