Repository navigation
Tweaks for FileInfo on FASTA files - #8135
Conversation
|
""" WalkthroughThe changes introduce new mathematical utility functions for rounding and percentage calculations, update their usage in reporting ambiguous amino acids in FASTA files, and enhance test coverage for these utilities. Output formatting is improved for clarity, and ambiguous amino acid statistics are now more detailed and consistently calculated. Changes
Sequence Diagram(s)sequenceDiagram
participant FileInfo
participant MathFunctions
FileInfo->>MathFunctions: percentOf(value, total, digits)
MathFunctions-->>FileInfo: Rounded percentage
FileInfo->>MathFunctions: roundTo(value, digits)
MathFunctions-->>FileInfo: Rounded value
FileInfo->>FileInfo: Count ambiguous AA in FASTA
FileInfo->>FileInfo: Output number and percent of ambiguous AA sequences
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
Note ⚡️ Unit Test Generation is now available in beta!Learn more here, or try it out under "Finishing Touches" below. 📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (4)
✅ Files skipped from review due to trivial changes (2)
🚧 Files skipped from review as they are similar to previous changes (1)
⏰ 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)
🔇 Additional comments (4)
✨ 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. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (3)
src/openms/include/OpenMS/MATH/MathFunctions.h (2)
224-254: Consider usingstd::powfor better performance.The function logic is correct and handles both positive and negative digits properly. However, the manual loop-based power calculation could be optimized.
Consider this more efficient implementation:
template<typename T> T roundTo(const T value, int digits) { - T factor = 1.0; - if (digits > 0) - { - for (int i = 0; i < digits; ++i) - factor *= 10.0; - } - else if (digits < 0) - { - for (int i = 0; i < -digits; ++i) - factor /= 10.0; - } + T factor = std::pow(T(10.0), digits); return std::round(value * factor) / factor; }
256-283: Well-designed function with proper error handling.The function correctly handles input validation and division by zero. The use of
roundTofor consistent rounding is good design.Consider using a small epsilon for the zero comparison instead of exact equality:
- if (total <= 0) // avoid float equality compare + if (total <= std::numeric_limits<T>::epsilon()) { return 0.0; // avoid division by zero }This would be more robust for floating-point inputs where the total might be very close to zero but not exactly zero.
src/topp/FileInfo.cpp (1)
868-869: Well-designed lambda but consider exception safety.The lambda effectively counts ambiguous amino acids. However, using
at()assumes these amino acid keys exist in the map.Consider using the safer
find()orcount()approach to avoid potential exceptions:-auto count_AAAs = [](const auto& aacids) { return aacids.at('B') + aacids.at('Z') + aacids.at('X') + aacids.at('b') + aacids.at('z') + aacids.at('x'); }; +auto count_AAAs = [](const auto& aacids) { + auto get_count = [&](char c) { auto it = aacids.find(c); return it != aacids.end() ? it->second : 0; }; + return get_count('B') + get_count('Z') + get_count('X') + get_count('b') + get_count('z') + get_count('x'); +};
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
src/openms/include/OpenMS/MATH/MathFunctions.h(1 hunks)src/tests/class_tests/openms/source/MathFunctions_test.cpp(1 hunks)src/topp/FileInfo.cpp(2 hunks)
⏰ 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 (macos-14, xcode, 15.0.1)
- GitHub Check: build-and-test (windows-2022, cl.exe, 14.36)
- GitHub Check: build-and-test (ubuntu-22.04, g++, 11)
- GitHub Check: build-and-test (ubuntu-22.04, clang++, 15)
- GitHub Check: build-and-test (macos-13, xcode, 14.2)
🔇 Additional comments (8)
src/openms/include/OpenMS/MATH/MathFunctions.h (1)
221-222: LGTM! Clean simplification using standard library.The direct use of
std::roundis more maintainable and handles all edge cases correctly, including proper tie-breaking behavior.src/tests/class_tests/openms/source/MathFunctions_test.cpp (4)
127-130: Good improvement with explicit namespace qualification.The explicit
Math::roundcalls improve code clarity and prevent potential ambiguity with other round functions.
133-141: Comprehensive test coverage forroundTofunction.The tests effectively cover positive digits (decimal places), negative digits (tens/hundreds/thousands), and zero digits (integer rounding). All expected values appear correct.
143-154: Excellent test coverage including error conditions.The tests comprehensively cover normal percentage calculations with various precision levels and properly test exception handling for invalid negative inputs.
116-119: Good semantic improvement using appropriate test macros.Using
TEST_TRUEandTEST_FALSEfor boolean functions is more semantically correct thanTEST_EQUALwith boolean literals. This change improves test readability.Also applies to: 157-160
src/topp/FileInfo.cpp (3)
871-871: Elegant solution for tracking sequences with ambiguous amino acids.The before/after count comparison is an efficient way to determine which sequences contain ambiguous amino acids without additional sequence parsing.
Also applies to: 910-920
927-941: Excellent use of new Math utility for consistent formatting.The consistent use of
Math::percentOfwith 2 decimal places provides clean, uniform percentage reporting throughout the FASTA file statistics.
934-941: Good formatting improvements and functional enhancement.The structured binding and improved formatting enhance readability. The addition of 'J' amino acid to ambiguous counts aligns with the PR objectives to include 'J' as an ambiguous amino acid symbol.
Description
Jinstead ofIas ambiguous AA's.e.g.
How can I get additional information on failed tests during CI
Click to expand
If your PR is failing you can check outIf you click in the column that lists the failed tests you will get detailed error messages.
Advanced commands (admins / reviewer only)
Click to expand
/reformat(experimental) applies the clang-format style changes as additional commit. Note: your branch must have a different name (e.g., yourrepo:feature/XYZ) than the receiving branch (e.g., OpenMS:develop). Otherwise, reformat fails to push.rebuild jenkinswill retrigger Jenkins-based CI buildsSummary by CodeRabbit
New Features
Bug Fixes
Tests