Repository navigation
[FIX] ConsensusMapNormalizer: accept maps with non-consecutive map indices - #10589
Conversation
…dices
'FileFilter -consensus:map 1 2' keeps the map indices 1 and 2. The median,
quantile and threshold normalizers used map indices as positions into
vectors with one entry per column header:
- median, median_shift and quantile threw ElementNotFound ("the element
'0' could not be found") because they looked up the headers 0 ... N-1;
- robust_regression (ConsensusMapNormalizerAlgorithmThreshold)
dereferenced getColumnHeaders().find(0) without checking it and wrote
and read its per-map vectors past their end; ConsensusMapNormalizer
crashed with a segmentation fault.
The maps are now numbered by their position among the column headers
(ConsensusMapNormalizerAlgorithmMedian::mapPositions_() and
mapPosition_(), shared like passesFilters_()), which is the map index for
maps numbered 0 ... N-1, so results for those maps do not change. A
feature handle whose map index has no column header throws
ElementNotFound.
Tests: class tests of all three classes with the map indices {1, 3, 4}
or {1, 3} give the same results as {0, 1, 2} / {0, 1} (the Quantile and
Threshold tests were placeholders); TOPP_ConsensusMapNormalizer_filtered_*
runs every algorithm on maps 1 and 2 of ConsensusMapNormalizer_input as
FileFilter writes them.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_014w9WfnJVb61NA9tyTwNbZ6
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info
📝 Walkthrough
Priority: ⬇️ Low Change: Bug fix · Severity of issue fixed: Low Merge Risk: ⚪ Minimal · up to
|
…an helpers Use ConsensusMapNormalizerAlgorithmMedian::mapPositions_() and mapPosition_() (from #10589) instead of a local copy of the same lookup; the behaviour and the ElementNotFound message are unchanged. The TOPP test on the filtered input with non-consecutive map indices now also runs rt_local. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_014w9WfnJVb61NA9tyTwNbZ6
…ocal); ProteomicsLFQ linking tolerance and RT model (#10585) * [FEATURE] ConsensusMapNormalizer: RT-local median normalization (rt_local) Runs of one LFQ experiment differ in loading, and their ion signal also drifts along the gradient. One factor per map removes the first, not the second. ConsensusMapNormalizerAlgorithmRTLocal removes both, following the run normalisation of andes (bigbio/andes #155, quant::normalize): - reference features: consensus features with intensities in at least min_maps (3) maps that pass the accession/description filters; - backfitting (5 rounds): a feature's level is its mean over its maps of log2(intensity) - offset; a reference cell's offset is the median residual of the 50 reference cells of its map before and the 50 after it in RT, leaving out its own; - other cells take the median residual of the 50 + 50 reference cells around their RT; maps with fewer than 20 reference cells are left alone. ConsensusMapNormalizer exposes it as -algorithm_type rt_local with rt_local:neighbors/min_maps/min_reference/rounds. pyOpenMS binds the class and its Settings. ProteoBench DDA ion module (QExactive, 6 runs, min 3 runs), ProteomicsLFQ -out_cxml -> ConsensusMapNormalizer -> MSstatsConverter, same precursors: arm precursors median |eps| E. coli CV IDs only, raw 42,322 0.223 0.407 0.231 IDs only, median 42,322 0.219 0.325 0.155 IDs only, rt_local 42,322 0.150 0.299 0.088 PIP-ECHO MBR, raw 46,375 0.221 0.409 0.236 PIP-ECHO MBR, median 46,375 0.223 0.362 0.159 PIP-ECHO MBR, rt_local 46,375 0.157 0.338 0.095 The estimated drift (sd 0.13-0.37 log2 along RT, levels -0.45 to +0.34) matches what andes reports on the same runs. Tests: class test (constant factors removed exactly, a linear RT drift followed exactly, a 20 % minority of changed features moves nothing, maps with too few references and zero intensities untouched, invalid settings throw) and TOPP_ConsensusMapNormalizer_2. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_014w9WfnJVb61NA9tyTwNbZ6 * [FIX] ProteomicsLFQ: linking RT tolerance from the 95th percentile; honour Alignment:model_type Linking tolerance. ProteomicsLFQ sized the RT tolerance of QT linking (and the global RT window of PIP-ECHO) as 2 x the largest post-alignment RT difference of any alignment point + 2 x FWHM, with a 2-minute floor. A few outlying points decide that maximum: on the ProteoBench DDA ion module (QExactive, 6 runs, 2 h gradients) the 100th percentile was 888 s (99 % of the points were within 150 s, 95 % within 24 s), so the tolerance became +-20 min and QT linking joined unrelated features. It now uses the 95th percentile (the largest over the runs) and no floor; the 10-minute cap stays. ProteoBench DDA ion module (QExactive, min 3 runs), same feature checkpoints: arm precursors median |eps| E. coli CV identified only 42,322 0.223 0.407 0.231 MBR, QT linking, before 48,962 0.243 0.625 0.245 MBR, QT linking, 99th pct. 47,690 0.228 0.478 0.239 MBR, QT linking, 95th pct.+floor 47,542 0.227 0.461 0.238 MBR, QT linking, 95th pct. 46,929 0.221 0.414 0.236 MBR, PIP-ECHO (local RT window) 46,375 0.221 0.409 0.236 RT model. align_() always fitted B-splines with default parameters (MapAlignerBase::getModelDefaults("b_spline")), so -Alignment:model_type and -Alignment:model:<type>:* had no effect. It now fits Alignment:model_type with its Alignment:model:<type>:* parameters. Their defaults equal the previous hard-coded ones, so default results do not change. The second, unused switch Alignment:model:type is removed. With the fix, lowess, linear and b_spline give the same ProteoBench results on this data (runs differ mostly by constant shifts); interpolated gives fewer precursors. TOPP tests: the reference consensusXML and mzTab files of the BSA tests with alignment are regenerated (consensus quality is normalised by the RT tolerance; a few features 120-150 s apart are no longer linked). The MSstats outputs are unchanged. All 83 ProteomicsLFQ TOPP tests that run without CMake scripts pass with the new references. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_014w9WfnJVb61NA9tyTwNbZ6 * ConsensusMapNormalizerAlgorithmRTLocal: cap the window buffer reservation at the number of cells A very large rt_local:neighbors (or a negative value wrapped through pyOpenMS) asked reserve() for a huge allocation; a window never holds more than the cells of the map (CodeRabbit review). Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_014w9WfnJVb61NA9tyTwNbZ6 * ConsensusMapNormalizerAlgorithmRTLocal: compute the window end without overflow With rt_local:neighbors close to the maximum of Size (possible from C++ or Python, not from the TOPP option), i + neighbors + 1 and pos + neighbors wrapped around and gave an empty or truncated window, so a cell's offset came out as 0. The upper bounds are now saturated at the end of the map. Results for all other values are unchanged. The class test checks a window larger than the map for reference and non-reference cells. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_014w9WfnJVb61NA9tyTwNbZ6 * ConsensusMapNormalizerAlgorithmRTLocal: accept non-consecutive map indices; reject min_reference 0 Map indices were used as positions into vectors of size "number of column headers". FileFilter keeps the original indices when it extracts maps, so a consistent map with headers {1, 3, 4} threw "map index 3 has no column header". The column headers are now numbered densely and the log names the original map index. min_reference = 0 (possible from C++ and Python; the TOPP option has a minimum of 1) let maps without any reference cell qualify, and the median of their empty offset list threw InvalidRange. It is now rejected like the other settings. Class tests: maps with gapped indices give the same offsets as dense ones, a handle without a column header throws, and each setting set to 0 throws. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_014w9WfnJVb61NA9tyTwNbZ6 * [TEST] ProteomicsLFQ: -Alignment:model_type selects the fitted RT model TOPP_ProteomicsLFQ_model_type aligns BSA1_F1 with a copy of itself, using unassigned IDs (use_feature_rt false), so the two runs share 12 peptides: more than the 10 points ProteomicsLFQ needs to fit a model (two BSA runs share at most 10). With -Alignment:model_type linear the debug log must read "after applying 'linear' transformation". The ProteomicsLFQ before this PR fits 'b_spline' with these options and fails the test. Requested in the review of #10585. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_014w9WfnJVb61NA9tyTwNbZ6 * ProteomicsLFQ: keep the 2-minute linking tolerance when no run has alignment points The 95th-percentile window read percentiles_after of every run. Runs without alignment points (the reference, or every run when the alignment finds no shared peptides or fails under -force) have empty statistics; the log loop before filled them with 0, so with no points at all the window became 0 s instead of develop's 2 minutes (e.g. BSA1_F1 with BSA2_F2: 0 points, window 0 s). Runs without points no longer count, and without any the window stays at 2 minutes. Results with alignment points do not change (all ProteomicsLFQ TOPP tests pass unchanged). Also fill in the $Maintainer/$Authors header fields of the RT-local normalizer files (CodeRabbit review). Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_014w9WfnJVb61NA9tyTwNbZ6 * ConsensusMapNormalizerAlgorithmRTLocal: number the maps with the Median helpers Use ConsensusMapNormalizerAlgorithmMedian::mapPositions_() and mapPosition_() (from #10589) instead of a local copy of the same lookup; the behaviour and the ElementNotFound message are unchanged. The TOPP test on the filtered input with non-consecutive map indices now also runs rt_local. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_014w9WfnJVb61NA9tyTwNbZ6 --------- Co-authored-by: Claude Opus 5.5 <[email protected]>
…zation, #10587 MS1LabeledWorkflow, #10545 Bruker .d reader) Only CHANGELOG conflicted; both sides are kept. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01B51nRFoHvZuVXD7cT8XZav
… Bruker .d streaming) #10587 maps the identifications of MS1LabeledWorkflow over the elution regions of the multiplets' channels and quantifies partial multiplets. Its new identification code reads peptide identifications of the maps, which this branch no longer has; it is ported to identification data: - MultiplexResolverAlgorithm: matchesResidues_(), createGenerator_() and expectedChannelMZs() as in develop; matchDeltaMasses_()/findMatchingPattern_() take the detected mass shift, as in develop. checkIdentifications() takes the identification data and checks the linked identifications, in the order of getLinkedIdentifications(). Test and pyOpenMS binding accordingly. - MS1LabeledFAIMS::annotate() maps identification data onto the channel features (IDMapper feature map mode, 'match_meta_value' = FAIMS CV instead of partitions per CV) and links a copy of every matched identification from the channel's multiplet, with the channel as map_index, once per multiplet; unmatched ones stay unassigned. - MS1LabeledWorkflow: attachToUndetectedChannels_() and keepConsistentIdentifications_() on identification data. Moved identifications are copies listed after all others (moveIdentifications_()), so the order of the identifications of a multiplet and of the unassigned ones is develop's (it decides ties in IDConflictResolverAlgorithm). keepMultiAssignedOnClosest_() takes the channel m/z from the identified peptidoform. Reference outputs: - MS1LabeledWorkflow_7_partial_out (new in develop) is reproduced unchanged; the workflow logs the same counts (1 identification attached, 4 channels re-quantified). - MS1LabeledWorkflow_2_out: develop's change is new unique ids only; the native port gives the same ids. The golden is this branch's previous one with those ids (the order of the unassigned identifications differs from develop, as before). - ProteomicsLFQ_{1,1_subset,2,3,3_seedRT,5}_out.{consensusXML,mzTab} and ProteomicsLFQ_strictly_unique_out.mzTab (#10585): the outputs have develop's features and identifications (one more feature, spectrum 2545 now assigned); they differ from develop's goldens only in the order of the unassigned identifications and PSM rows, in the same order as this branch's previous goldens (plus develop's own move of the two SHCIAEVEK PSMs). Whitelisted lines are kept from develop's goldens. ConsensusMapNormalizerAlgorithmMedian (#10589): develop's map positions by column header, with this branch's filters on the identification data. Bindings: develop's RST docstrings (#10600) with this branch's native overloads (IDMapper, BasicProteinInferenceAlgorithm, FeatureFinderIdentificationAlgorithm) formatted accordingly. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01B51nRFoHvZuVXD7cT8XZav
Description
FileFilter -consensus:map 1 2keeps the map indices 1 and 2. Themedian,median_shift,quantileandrobust_regressionnormalizers used map indices as positions into vectors with one entry per column header, so they could not handle such a map. This came up in #10585, which fixed the same problem in the newrt_localmethod.I extracted maps 1 and 2 of the TOPP test input
ConsensusMapNormalizer_input.consensusXMLwith FileFilter (map ids stay 1 and 2) and ranConsensusMapNormalizer:-algorithm_typerobust_regressionmedian,median_shiftquantileWith this PR, each method gives the same handle intensities as for the same maps renumbered 0 and 1.
Change
New position helpers:
ConsensusMapNormalizerAlgorithmMedian::mapPositions_()andmapPosition_()number the maps by their position among the column headers. They live next topassesFilters_(), which the normalizers already share.Per-map vectors indexed by position: Median, Quantile and Threshold now use these positions for their per-map vectors: medians, ratios and intensity vectors. For maps numbered 0 … N-1 the position equals the map index. On the full 10-map test input, all four methods write byte-identical output before and after.
Missing column header throws: a feature handle whose map index has no column header throws
ElementNotFound. Before,robust_regressionread past the end of its vectors.API note: the public per-map vectors are now indexed by column-header position instead of by map index:
computeMedians(): itsmediansand the reference index it returns;computeCorrelation(): its return value;Threshold::normalizeMaps(map, ratios);extractIntensityVectors()andsetNormalizedIntensityValues().Nothing changes for maps numbered from 0; before, other maps either threw or crashed. The header docs say this.
Tests
// TODO,NOT_TESTABLE) and now test normalization.TOPP_ConsensusMapNormalizer_filtered_{robust_regression,median,median_shift,quantile}run each method on the new inputConsensusMapNormalizer_filtered_input.consensusXML. That file holds maps 1 and 2 as FileFilter writes them, with FileFilter's data-processing entry removed. These tests check the exit code; the values are checked by the class tests.How this was validated
The three classes, their class tests and the TOPP tool were compiled against the 2026-10-14 nightly libraries (fd88028), Boost 1.83 headers.
TOPP_ConsensusMapNormalizer_1still passes.The full build and ctest suite are left to CI.
Not changed (found while testing)
quantilesegfaults when a map has a column header but no feature handle (resample()of an empty vector). This also happens for maps numbered 0 … N-1 with the unchanged code.-testadds an empty map:FileFilter -test -consensus:map 1 2writes an extra empty column headerid="0"; without-testit does not. Because of the quantile crash above, the new TOPP tests use a fixed input file instead of running FileFilter in the test.Checklist
🤖 Generated with Claude Code
https://claude.ai/code/session_014w9WfnJVb61NA9tyTwNbZ6
Generated by Claude Code
Summary by CodeRabbit