Repository navigation
Pjones/refactor plfq - #8192
Pjones/refactor plfq#8192
Conversation
WalkthroughQuantification was refactored to perform alignment internally using a local Changes
Sequence Diagram(s)sequenceDiagram
autonumber
actor Caller
participant ProteomicsLFQ as ProteomicsLFQ::quantifyFraction_
participant FFI as FeatureFinderIdentification
participant Align as ProteomicsLFQ::alignAndLink_
Caller->>ProteomicsLFQ: quantifyFraction_(ms_files, mzfile2idfile, in_db, median_fwhm, consensus_fraction, fixed_mods, var_mods)
activate ProteomicsLFQ
note over ProteomicsLFQ: create local FeatureMap fm\ncreate local `transformations` vector
ProteomicsLFQ->>FFI: run(fm, ext_protein_ids={}, ext_peptide_ids={})
activate FFI
FFI-->>ProteomicsLFQ: fm populated
deactivate FFI
note over ProteomicsLFQ: process fm (randomize, filter, score)
ProteomicsLFQ->>Align: alignAndLink_(feature_maps, consensus_fraction, transformations, median_fwhm)
activate Align
Align-->>ProteomicsLFQ: consensus_fraction updated (no return value)
deactivate Align
ProteomicsLFQ-->>Caller: ExitCodes result
deactivate ProteomicsLFQ
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Poem
✨ Finishing Touches
🧪 Generate unit tests
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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. CodeRabbit Commands (Invoked using PR/Issue comments)Type Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (2)
src/topp/ProteomicsLFQ.cpp (2)
1016-1016: Localize or reserve transformations (minor).Declaring
transformationshere is fine. Optionally, declare it just before thealignAndLink_call (where it’s first used) or reserve capacity to the number of maps to slightly tighten lifetime/allocations.
1337-1338: Document ignored return value from alignAndLink_.The return value (max alignment diff) is intentionally unused. Cast to void to make this explicit (or consider changing the helper to return void in a follow-up).
- alignAndLink_(feature_maps, consensus_fraction, transformations, median_fwhm); + (void)alignAndLink_(feature_maps, consensus_fraction, transformations, median_fwhm);If any downstream logic depends on the max diff, confirm it’s not needed here after the refactor.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
💡 Knowledge Base configuration:
- MCP integration is disabled by default for public repositories
- Jira integration is disabled by default for public repositories
- Linear integration is disabled by default for public repositories
You can enable these sources in your CodeRabbit configuration.
📒 Files selected for processing (1)
src/topp/ProteomicsLFQ.cpp(3 hunks)
🧰 Additional context used
🧠 Learnings (4)
📚 Learning: 2025-08-05T12:43:11.681Z
Learnt from: CR
PR: OpenMS/OpenMS#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-05T12:43:11.681Z
Learning: Applies to src/openms/**/*.{cpp,h,hpp,cc,cxx} : Use appropriate OpenMS containers and algorithms
Applied to files:
src/topp/ProteomicsLFQ.cpp
📚 Learning: 2025-08-05T12:43:11.681Z
Learnt from: CR
PR: OpenMS/OpenMS#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-05T12:43:11.681Z
Learning: Applies to src/openms/**/*.{cpp,h,hpp,cc,cxx} : Use OpenMS data structures (e.g., MSExperiment, FeatureMap, PeptideIdentification)
Applied to files:
src/topp/ProteomicsLFQ.cpp
📚 Learning: 2025-08-14T10:19:54.371Z
Learnt from: jpfeuffer
PR: OpenMS/OpenMS#8167
File: src/topp/Digestor.cpp:200-226
Timestamp: 2025-08-14T10:19:54.371Z
Learning: In OpenMS (C++ bioinformatics framework), use boost random libraries instead of std library random distributions for cross-platform reproducible random number generation, as std library distributions are not reproducible across platforms.
Applied to files:
src/topp/ProteomicsLFQ.cpp
📚 Learning: 2025-08-05T12:43:11.681Z
Learnt from: CR
PR: OpenMS/OpenMS#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-05T12:43:11.681Z
Learning: Applies to src/openms/include/OpenMS/**/*.h : Add Doxygen comments for new public methods and classes
Applied to files:
src/topp/ProteomicsLFQ.cpp
🧬 Code graph analysis (1)
src/topp/ProteomicsLFQ.cpp (2)
src/topp/MapAlignerIdentification.cpp (2)
transformations(183-198)transformations(183-184)src/topp/MapAlignerTreeGuided.cpp (6)
transformations(123-135)transformations(123-123)transformations(219-219)feature_maps(108-121)feature_maps(108-108)feature_maps(181-181)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (5)
- GitHub Check: build-and-test (windows-2022, cl.exe, 14.36)
- GitHub Check: build-and-test (macos-14, xcode, 15.0.1)
- GitHub Check: build-and-test (ubuntu-22.04, clang++, 15)
- GitHub Check: build-and-test (ubuntu-22.04, g++, 11)
- GitHub Check: build-and-test (macos-13, xcode, 14.2)
🔇 Additional comments (1)
src/topp/ProteomicsLFQ.cpp (1)
1114-1131: Remove unusedfmand simplifytmpinitialization
FeatureMap tmp;replaces bothFeatureMap fm;andFeatureMap tmp = fm; // WTF?. The call toffi.run(peptide_ids, protein_ids, ext_peptide_ids, ext_protein_ids, tmp, seeds, mz_file)already matches the documented signature (features→seeds→spectra_file order)(pyopenms-docs.readthedocs.io, pyopenms.readthedocs.io).
timosachsenberg
left a comment
There was a problem hiding this comment.
look good to me. I think I once tried a few things that used the max_alignment_diff and the transfomration - but seems I forgot to remove them later
It looks like I can remove the return value from the |
aca32e8 to
ff5fe7f
Compare
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (5)
src/topp/ProteomicsLFQ.cpp (5)
701-706: Remove stale @return in doc; signature change to void looks goodThe function no longer returns a value, but the doc still claims it returns a maximum alignment difference. Please drop or update the stale comment. Call sites in this file are already adapted.
Apply this diff to clean up the doc:
- /// Align and link. - /// @return maximum alignment difference observed (to guide linking) + /// Align and link. void alignAndLink_(
1014-1014: Inline transformations into alignAndLink_ to shrink scope
transformationsis only used to feedalignAndLink_and never referenced afterwards. Create it insidealignAndLink_and drop the parameter and local inquantifyFraction_to simplify the API and avoid accidental future misuse.Apply this diff:
--- a/src/topp/ProteomicsLFQ.cpp +++ b/src/topp/ProteomicsLFQ.cpp @@ - void alignAndLink_( - vector<FeatureMap> & feature_maps, - ConsensusMap & consensus_fraction, - vector<TransformationDescription>& transformations, - const double median_fwhm) + void alignAndLink_( + vector<FeatureMap> & feature_maps, + ConsensusMap & consensus_fraction, + const double median_fwhm) { - double max_alignment_diff(0.0); + double max_alignment_diff(0.0); + vector<TransformationDescription> transformations; @@ } @@ - vector<TransformationDescription> transformations; @@ - // Align all features of this fraction - alignAndLink_(feature_maps, consensus_fraction, transformations, median_fwhm); + // Align all features of this fraction + alignAndLink_(feature_maps, consensus_fraction, median_fwhm);Also applies to: 1334-1336
1142-1147: Shuffle randomized_indices (currently never randomized)Comment says “randomize selection” but
randomized_indicesisn’t shuffled. UseMath::RandomShufflerto ensure reproducible shuffling across platforms.Apply this diff:
Math::RandomShuffler shuffler; std::vector<size_t> randomized_indices(fm.size()); std::iota(randomized_indices.begin(), randomized_indices.end(), 0); + shuffler.randomize(randomized_indices.begin(), randomized_indices.end());
1214-1262: LGTM: erase-remove filtering is correct and efficientThe lambda captures and counters are fine, and the second pass removing
OffsetPeptideis clear.Minor: consider guarding percentage prints later when denominators are zero to avoid inf/NaN in logs. No functional impact.
1334-1336: Verify linking tolerance uses an appropriate FWHM summary
median_fwhmis computed per MS file inside the loop; the last run’s value is passed to linking for all maps. Ensure this is intentional. If you want a fraction-level tolerance, consider aggregating across all runs (e.g., median of per-run medians) before callingalignAndLink_.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
💡 Knowledge Base configuration:
- MCP integration is disabled by default for public repositories
- Jira integration is disabled by default for public repositories
- Linear integration is disabled by default for public repositories
You can enable these sources in your CodeRabbit configuration.
📒 Files selected for processing (1)
src/topp/ProteomicsLFQ.cpp(10 hunks)
🧰 Additional context used
🧠 Learnings (4)
📚 Learning: 2025-08-05T12:43:11.681Z
Learnt from: CR
PR: OpenMS/OpenMS#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-05T12:43:11.681Z
Learning: Applies to src/openms/**/*.{cpp,h,hpp,cc,cxx} : Use appropriate OpenMS containers and algorithms
Applied to files:
src/topp/ProteomicsLFQ.cpp
📚 Learning: 2025-08-05T12:43:11.681Z
Learnt from: CR
PR: OpenMS/OpenMS#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-05T12:43:11.681Z
Learning: Applies to src/openms/**/*.{cpp,h,hpp,cc,cxx} : Use OpenMS data structures (e.g., MSExperiment, FeatureMap, PeptideIdentification)
Applied to files:
src/topp/ProteomicsLFQ.cpp
📚 Learning: 2025-08-14T10:19:54.371Z
Learnt from: jpfeuffer
PR: OpenMS/OpenMS#8167
File: src/topp/Digestor.cpp:200-226
Timestamp: 2025-08-14T10:19:54.371Z
Learning: In OpenMS (C++ bioinformatics framework), use boost random libraries instead of std library random distributions for cross-platform reproducible random number generation, as std library distributions are not reproducible across platforms.
Applied to files:
src/topp/ProteomicsLFQ.cpp
📚 Learning: 2025-08-05T12:43:11.681Z
Learnt from: CR
PR: OpenMS/OpenMS#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-05T12:43:11.681Z
Learning: Applies to src/openms/include/OpenMS/**/*.h : Add Doxygen comments for new public methods and classes
Applied to files:
src/topp/ProteomicsLFQ.cpp
🧬 Code graph analysis (1)
src/topp/ProteomicsLFQ.cpp (2)
src/topp/MapAlignerIdentification.cpp (2)
transformations(183-198)transformations(183-184)src/topp/MapAlignerTreeGuided.cpp (6)
transformations(123-135)transformations(123-123)transformations(219-219)feature_maps(108-121)feature_maps(108-108)feature_maps(181-181)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (6)
- GitHub Check: build-and-test (macos-13, xcode, 14.2)
- GitHub Check: build-and-test (macos-14, xcode, 15.0.1)
- GitHub Check: build-and-test (ubuntu-22.04, clang++, 15)
- GitHub Check: build-and-test (ubuntu-22.04, g++, 11)
- GitHub Check: build-and-test (windows-2022, cl.exe, 14.36)
- GitHub Check: cppcheck-test
🔇 Additional comments (5)
src/topp/ProteomicsLFQ.cpp (5)
1112-1128: Good: scoped temporaries for ffi.run and clear ownership of outputsSwitching to a local
FeatureMap fmand tightly scoping the unused ext ID containers is cleaner and reduces lifetime/aliasing risks.
1195-1198: LGTM: consistent switch from tmp→fmIndexing and assignment now consistently use
fm.
1282-1297: LGTM: metadata cleanup and subordinate/hull strippingThis reduces memory footprint and downstream I/O.
1299-1301: LGTM: resolve top-PSM policy earlyRunning
IDConflictResolverAlgorithm::resolveon the per-runfmis appropriate before grouping.
1302-1303: Nice: move-construct into feature_mapsUsing
std::move(fm)avoids an extra copy.
Two variables are created and passed to `quantifyFraction_` but then never used again. Move these variables into the function itself and remove dead code (`is_already_aligned`) since the code now knows that the `transformations` vector is always empty.
And put them in a proper scope since they are not used after the call to `ffi.run`.
ff5fe7f to
3a6688d
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (3)
src/topp/ProteomicsLFQ.cpp (3)
1281-1296: Consider retaining p_quant for diagnosticsAll meta except
OffsetPeptideis stripped; keepingp_quant(behind a debug flag) can aid QC and regressions.Example:
- unordered_set<String> keep_meta = {"OffsetPeptide"}; + unordered_set<String> keep_meta = {"OffsetPeptide" + #if 0 // set to 1 or gate on debug_level_ + , "p_quant" + #endif + };
1064-1065: Median FWHM aggregation across runs
median_fwhmis overwritten per file, then one value (from the last run) is used for the fraction’s linking tolerance. Consider aggregating over all runs in the fraction (median of medians) for more robust RT tolerance.Also applies to: 1333-1335
1139-1146: Shuffle the index vector before sampling
Afterstd::iota(randomized_indices.begin(), randomized_indices.end(), 0);, addshuffler.seed(UniqueIdGenerator::getUniqueId()); // or use the existing seed shuffler.portable_random_shuffle( randomized_indices.begin(), randomized_indices.end() );to ensure unbiased, reproducible randomization (see FFIDAlgoExternalIDHandler.cpp:332).
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
💡 Knowledge Base configuration:
- MCP integration is disabled by default for public repositories
- Jira integration is disabled by default for public repositories
- Linear integration is disabled by default for public repositories
You can enable these sources in your CodeRabbit configuration.
📒 Files selected for processing (1)
src/topp/ProteomicsLFQ.cpp(10 hunks)
🧰 Additional context used
🧠 Learnings (4)
📚 Learning: 2025-08-05T12:43:11.681Z
Learnt from: CR
PR: OpenMS/OpenMS#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-05T12:43:11.681Z
Learning: Applies to src/openms/**/*.{cpp,h,hpp,cc,cxx} : Use appropriate OpenMS containers and algorithms
Applied to files:
src/topp/ProteomicsLFQ.cpp
📚 Learning: 2025-08-05T12:43:11.681Z
Learnt from: CR
PR: OpenMS/OpenMS#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-05T12:43:11.681Z
Learning: Applies to src/openms/**/*.{cpp,h,hpp,cc,cxx} : Use OpenMS data structures (e.g., MSExperiment, FeatureMap, PeptideIdentification)
Applied to files:
src/topp/ProteomicsLFQ.cpp
📚 Learning: 2025-08-14T10:19:54.371Z
Learnt from: jpfeuffer
PR: OpenMS/OpenMS#8167
File: src/topp/Digestor.cpp:200-226
Timestamp: 2025-08-14T10:19:54.371Z
Learning: In OpenMS (C++ bioinformatics framework), use boost random libraries instead of std library random distributions for cross-platform reproducible random number generation, as std library distributions are not reproducible across platforms.
Applied to files:
src/topp/ProteomicsLFQ.cpp
📚 Learning: 2025-08-05T12:43:11.681Z
Learnt from: CR
PR: OpenMS/OpenMS#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-05T12:43:11.681Z
Learning: Applies to src/openms/include/OpenMS/**/*.h : Add Doxygen comments for new public methods and classes
Applied to files:
src/topp/ProteomicsLFQ.cpp
🧬 Code graph analysis (1)
src/topp/ProteomicsLFQ.cpp (2)
src/topp/MapAlignerIdentification.cpp (2)
transformations(183-198)transformations(183-184)src/topp/MapAlignerTreeGuided.cpp (6)
transformations(123-135)transformations(123-123)transformations(219-219)feature_maps(108-121)feature_maps(108-108)feature_maps(181-181)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (6)
- GitHub Check: build-and-test (macos-14, xcode, 15.0.1)
- GitHub Check: build-and-test (ubuntu-22.04, clang++, 15)
- GitHub Check: build-and-test (macos-13, xcode, 14.2)
- GitHub Check: build-and-test (ubuntu-22.04, g++, 11)
- GitHub Check: build-and-test (windows-2022, cl.exe, 14.36)
- GitHub Check: cppcheck-test
🔇 Additional comments (5)
src/topp/ProteomicsLFQ.cpp (5)
1111-1127: Local fm + scoped FFI run: LGTMSwitch to a local
FeatureMap fmand passing empty external ID containers intoffi.runis clear and self-contained.
1213-1216: Filtering pipeline: in-place erase is correctTwo-stage erase (thresholding then removing OffsetPeptide) is correct and efficient.
Also applies to: 1258-1261
1301-1301: Move into feature_maps: LGTM
emplace_back(std::move(fm))is appropriate; avoids extra copy.
700-705: AllalignAndLink_call-sites now void; no callers expect a return. Verified with repository-widergsearch showing only the definition and a single invocation that doesn’t use a return value.
1298-1300: Incorrect inversion; update the comment instead of the code.
The mapping is deliberate:keep_matchingis set to true whenkeep_feature_top_psm_only == "false", causing lower-ranked PSMs with the top sequence to be retained. The inline comment “keep only best peptide per feature per file” is therefore misleading—please revise it to reflect the actual behavior.Likely an incorrect or invalid review comment.
| set<String>& fixed_modifications, | ||
| set<String>& variable_modifications) | ||
| { | ||
| vector<TransformationDescription> transformations; |
There was a problem hiding this comment.
💡 Verification agent
🧩 Analysis chain
Pre-size transformations before alignment
Map aligners typically expect transformations.size() == feature_maps.size(); we currently pass an empty vector. Pre-sizing avoids API assumptions and empty-stats edge cases.
Apply right before calling alignAndLink_:
@@
- // Align all features of this fraction
- alignAndLink_(feature_maps, consensus_fraction, transformations, median_fwhm);
+ // Align all features of this fraction
+ transformations.resize(feature_maps.size());
+ alignAndLink_(feature_maps, consensus_fraction, transformations, median_fwhm);And verify aligners’ expectations in-tree:
Also applies to: 1333-1335
🏁 Script executed:
#!/bin/bash
rg -nP 'align\([^,]+,\s*std::vector<\s*TransformationDescription' -C3Length of output: 989
🏁 Script executed:
#!/bin/bash
# Locate and inspect the implementation of alignAndLink_ to see how 'transformations' is used
rg -nP 'alignAndLink_\s*\(' -C5 src/topp/ProteomicsLFQ.cppLength of output: 850
🏁 Script executed:
#!/bin/bash
# Extract the full implementation of alignAndLink_ for inspection
rg -nP 'void alignAndLink_\\s*\\(' -C200 src/topp/ProteomicsLFQ.cpp
# Search for direct indexing into transformations
rg -n 'transformations\\[' -C5 src/topp/ProteomicsLFQ.cppLength of output: 299
🏁 Script executed:
#!/bin/bash
# Extract the full implementation of alignAndLink_ for inspection
rg -nP 'void\s+alignAndLink_\s*\(' -C200 src/topp/ProteomicsLFQ.cpp
# Search for any direct indexing into transformations
rg -nF 'transformations[' -C5 src/topp/ProteomicsLFQ.cppLength of output: 17748
Pre-size transformations before each alignAndLink_ call
Insert
transformations.resize(feature_maps.size());immediately before
alignAndLink_(feature_maps, consensus_fraction, transformations, median_fwhm);at both call sites in src/topp/ProteomicsLFQ.cpp (around lines 1013 and 1334) to guarantee transformations.size() == feature_maps.size() and avoid out-of-bounds access in transform_ and during alignment statistics.
🤖 Prompt for AI Agents
In src/topp/ProteomicsLFQ.cpp around lines 1013 and 1334, the local
vector<TransformationDescription> transformations must be pre-sized to match
feature_maps before calling alignAndLink_ to avoid out-of-bounds access;
immediately before each call to alignAndLink_(feature_maps, consensus_fraction,
transformations, median_fwhm) insert a statement that resizes transformations to
feature_maps.size() (i.e., transformations.resize(feature_maps.size())) so
transformations.size() == feature_maps.size() when passed into alignAndLink_.
Description
Simple refactoring moving some variables around, removing code that is never executed (dead code), and removing variables that are never used.
Note to reviewers: It's probably easier to review each commit separately.
Checklist
Summary by CodeRabbit
Improvements
Refactor
Chores