Skip to content

Make FeatureLinker consensus output order reproducible - #9748

Closed
jonasscheid wants to merge 3 commits into
OpenMS:developfrom
jonasscheid:fix/featurelinker-nondeterministic-consensus-order
Closed

jonasscheid wants to merge 3 commits into
OpenMS:developfrom
jonasscheid:fix/featurelinker-nondeterministic-consensus-order

Conversation

@jonasscheid

@jonasscheid jonasscheid commented Jul 16, 2026 •

Copy link
Copy Markdown
Collaborator

What: FeatureLinkerUnlabeled{KD,QT,…} can output the consensus features in a different order on every run for the same input — identical features, just shuffled rows. That makes the consensusXML (and anything derived from it, e.g. exported tables) non-reproducible.

Why: after grouping, FeatureGroupingAlgorithm::postprocess_ sorts the result by quality → maps → size. Many consensus features tie on all three (e.g. every singleton shares size 1 and the same quality), and for those ties the order falls back to the grouping order — which depends on the features' unique ids. Those ids are seeded from time/PID, so they differ every run. (OpenMS' own tests don't catch this because -test mode fixes the seed.)

Fix: sort by position (RT, m/z) first, so the order follows the data instead of random ids; size/maps/quality only break exact-position ties. Implemented as a single stable_sort with a composite comparator.

Regenerated the affected KD/QT/WNet test references (pure reorder — values unchanged).

@github-actions

Copy link
Copy Markdown
Contributor

@jonasscheid The following names might be missing from the AUTHORS file:

  • jonasscheid

Please consider applying the following patch:

--- AUTHORS	2026-07-16 08:41:57.220228381 +0000
+++ AUTHORS.new	2026-07-16 08:42:02.596002073 +0000
@@ -63,6 +63,7 @@
  - Johannes Veit
  - Johannes von Kleist
  - Johan Teleman
+ - jonasscheid
  - Joshua Charkow
  - Juliane Schmachtenberg
  - Julianus Pfeuffer

Comment on lines +84 to +92
out.sortByQuality();
out.sortByMaps();
out.sortBySize();
// Final sort by position makes the output order reproducible across runs.
// The sorts above tie on many consensus features (e.g. all singletons share size/quality),
// leaving their relative order to be decided by the grouping order, which depends on the
// input features' (randomly assigned) unique ids and is therefore not deterministic. Sorting
// by (RT, m/z) last makes position the primary, unique-id-independent key.
out.sortByPosition();

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.

is the old code even doing the right thing? e.g. should this be one sort with a comparator? or is everything some kind of stable sort?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Is everything a stable sort? Yes — I checked all seven ConsensusMap::sortBy* methods; every one is std::stable_sort.

Was the old code doing the right thing? Half. Because they're all stable, the quality → maps → size chain does compose into a well-defined order (chained stable sorts = one lexicographic sort, last-applied = most significant). So it wasn't broken in the compose sense. Its real defect was narrower: (size, maps, quality) isn't a total order — masses of features tie (every singleton shares size 1 and quality), and those ties fell through to the grouping order, which rides on the random unique ids. That's the non-reproducibility.

@jonasscheid
jonasscheid force-pushed the fix/featurelinker-nondeterministic-consensus-order branch from cae5123 to 5047c81 Compare July 16, 2026 12:54
FeatureGroupingAlgorithm::postprocess_ ordered the consensus features with a
chain of stable sorts (quality, maps, size). These keys tie on many consensus
features (e.g. all singletons share size and quality), so tied features kept the
grouping order, which depends on the input features' randomly assigned unique
ids and is not reproducible across runs. Replace the chain with a single
stable_sort whose comparator makes position (RT, m/z) the primary, unique-id
independent key; size/maps/quality only break exact-position ties. Ordering is
equivalent to the previous chain followed by a sortByPosition().
…tput

Reorders the consensus features in the KD/QT/WNet FeatureLinker test reference
files to match the new position-sorted output order. Values are unchanged (pure
reordering); verified against the built tools (all TOPP_FeatureLinker tests pass).
@jonasscheid
jonasscheid force-pushed the fix/featurelinker-nondeterministic-consensus-order branch from 5047c81 to 9733b14 Compare July 21, 2026 19:08
timosachsenberg added a commit that referenced this pull request Oct 20, 2026
) (#10660)

* Sort consensus map by position after grouping for reproducible output

FeatureGroupingAlgorithm::postprocess_ ordered the consensus features with a
chain of stable sorts (quality, maps, size). These keys tie on many consensus
features (e.g. all singletons share size and quality), so tied features kept the
grouping order, which depends on the input features' randomly assigned unique
ids and is not reproducible across runs. Replace the chain with a single
stable_sort whose comparator makes position (RT, m/z) the primary, unique-id
independent key; size/maps/quality only break exact-position ties. Ordering is
equivalent to the previous chain followed by a sortByPosition().

* [TEST] Update references for the position-sorted consensus output

FeatureGroupingAlgorithm now sorts the consensus features by position, so the
FeatureLinkerUnlabeledQT/KD, ProteomicsLFQ and MS1LabeledWorkflow references list
the same consensus features in a new order. Checked for each file: the set of
consensus features (and of mzTab rows) is unchanged, only the order differs.
Machine paths in the regenerated files are kept as they were.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01N27gUPMwAazeK8SAKECuCa

---------

Co-authored-by: jonasscheid <[email protected]>
Co-authored-by: Claude <[email protected]>
singjc pushed a commit to singjc/OpenMS that referenced this pull request Oct 21, 2026
…enMS#9748) (OpenMS#10660)

* Sort consensus map by position after grouping for reproducible output

FeatureGroupingAlgorithm::postprocess_ ordered the consensus features with a
chain of stable sorts (quality, maps, size). These keys tie on many consensus
features (e.g. all singletons share size and quality), so tied features kept the
grouping order, which depends on the input features' randomly assigned unique
ids and is not reproducible across runs. Replace the chain with a single
stable_sort whose comparator makes position (RT, m/z) the primary, unique-id
independent key; size/maps/quality only break exact-position ties. Ordering is
equivalent to the previous chain followed by a sortByPosition().

* [TEST] Update references for the position-sorted consensus output

FeatureGroupingAlgorithm now sorts the consensus features by position, so the
FeatureLinkerUnlabeledQT/KD, ProteomicsLFQ and MS1LabeledWorkflow references list
the same consensus features in a new order. Checked for each file: the set of
consensus features (and of mzTab rows) is unchanged, only the order differs.
Machine paths in the regenerated files are kept as they were.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01N27gUPMwAazeK8SAKECuCa

---------

Co-authored-by: jonasscheid <[email protected]>
Co-authored-by: Claude <[email protected]>

Copy link
Copy Markdown
Contributor

Closing as superseded by #10660, which landed the same change in develop (2026-10-20): the identical position-first stable_sort in FeatureGroupingAlgorithm::postprocess_, plus regenerated FeatureLinker KD/QT (and ProteomicsLFQ / MS1LabeledWorkflow) references. Thanks @jonasscheid for the fix — you're credited as co-author there.


Generated by Claude Code

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.

2 participants