Skip to content

Tweaks for FileInfo on FASTA files - #8135

Merged
timosachsenberg merged 6 commits into
OpenMS:developfrom
cbielow:fix_FileInf
Jul 28, 2025
Merged

timosachsenberg merged 6 commits into
OpenMS:developfrom
cbielow:fix_FileInf

Conversation

@cbielow

@cbielow cbielow commented Jul 25, 2025 •

Copy link
Copy Markdown
Contributor

Description

  • reports J instead of I as ambiguous AA's.
  • reports the number of sequences that contain ambiguous AA's
  • adds some convenience Math functions related to rounding

e.g.

Number of sequences   : 573661
Number of sequences with ambiguous amino acids: 2386 (0.42%)                 <------------------
# duplicated headers  : 0 (0%)
# duplicated sequences: 88238 (15.38%) [by exact string matching]
Total amino acids     : 207922125

Amino acid counts:
  A:    17167220
  B:    276
  C:    2887411
  D:    11357879
  E:    13965640
  F:    8045007
  G:    14706671
  H:    4737923
  I:    12282073
  K:    12055904
  L:    20063163
  M:    5014787
  N:    8449025
  O:    29
  P:    9872018
  Q:    8175904
  R:    11494856
  S:    13847373
  T:    11156248
  U:    331
  V:    14255518
  W:    2298067
  X:    7993
  Y:    6080560
  Z:    249
Ambiguous amino acids (B/Z/X)  : 8518 (0%)
                      (B/Z/X/J): 8518 (0%)                                              <---------------- J, instead of I

How can I get additional information on failed tests during CI

Click to expand If your PR is failing you can check out

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.
  • setting the label "NoJenkins" will skip tests for this PR on jenkins (saves resources e.g., on edits that do not affect tests)
  • commenting with rebuild jenkins will retrigger Jenkins-based CI builds

⚠️ Note: Once you opened a PR try to minimize the number of pushes to it as every push will trigger CI (automated builds and test) and is rather heavy on our infrastructure (e.g., if several pushes per day are performed).

Summary by CodeRabbit

  • New Features

    • Added reporting of the number and percentage of sequences with ambiguous amino acids in FASTA files.
    • Output now includes detailed statistics on ambiguous amino acids, including specific counts and percentages.
    • Introduced new rounding and percentage calculation functions to improve numerical reporting.
  • Bug Fixes

    • Improved percentage calculations in output by using a consistent rounding utility for clearer results.
  • Tests

    • Expanded test coverage for new rounding and percentage calculation functions.
    • Enhanced clarity of existing tests with improved assertions.

@coderabbitai

coderabbitai Bot commented Jul 25, 2025 •

Copy link
Copy Markdown
Contributor

"""

Walkthrough

The 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

File(s) Change Summary
src/openms/include/OpenMS/MATH/MathFunctions.h Simplified round implementation, added roundTo and percentOf template functions.
src/tests/class_tests/openms/source/MathFunctions_test.cpp Updated test macros for clarity, added tests for roundTo and percentOf, improved test coverage.
src/topp/FileInfo.cpp Integrated percentOf for percentage calculations, added ambiguous amino acid sequence stats, improved output formatting.
src/tests/topp/FileInfo_17_output.txt Updated output formatting and ambiguous amino acid reporting in test output.
src/tests/topp/FileInfo_18_input.fasta Modified test input sequences to include ambiguous amino acids and reduced number of entries.
src/tests/topp/FileInfo_18_output.txt Updated test output reflecting new input, ambiguous amino acid counts, and formatting 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
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

Oh, how we round and count anew,
With digits set and percents in view!
Ambiguous AAs now stand tall,
Their numbers clear for one and all.
Math made neat, the tests refined—
A bunny’s work, precision aligned!
🐇✨
"""

Note

⚡️ Unit Test Generation is now available in beta!

Learn more here, or try it out under "Finishing Touches" below.


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 5d8c92a and 731f2ad.

📒 Files selected for processing (4)
  • src/tests/topp/FileInfo_17_output.txt (1 hunks)
  • src/tests/topp/FileInfo_18_input.fasta (2 hunks)
  • src/tests/topp/FileInfo_18_output.txt (1 hunks)
  • src/topp/FileInfo.cpp (2 hunks)
✅ Files skipped from review due to trivial changes (2)
  • src/tests/topp/FileInfo_17_output.txt
  • src/tests/topp/FileInfo_18_output.txt
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/topp/FileInfo.cpp
⏰ 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-13, xcode, 14.2)
  • 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 (windows-2022, cl.exe, 14.36)
  • GitHub Check: build-and-test (macos-14, xcode, 15.0.1)
🔇 Additional comments (4)
src/tests/topp/FileInfo_18_input.fasta (4)

32-32: LGTM! Header modification supports test objectives.

The addition of 'X' characters to the accession number creates a useful test case while maintaining the FASTA format structure.


33-33: LGTM! Strategic introduction of ambiguous amino acid 'X'.

The replacement of 'E' with 'X' at position 7 provides a clear test case for the new ambiguous amino acid detection functionality.


43-43: LGTM! Perfect test case for the key PR objective.

The introduction of 'J' characters directly tests the core functionality change where 'J' is now reported as an ambiguous amino acid instead of 'I'.


50-50: LGTM! Comprehensive test for extensive sequence masking.

The replacement of a long amino acid stretch with 'X' characters creates a realistic test scenario for sequences with extensive ambiguous regions, ensuring robust handling of multiple consecutive ambiguous amino acids.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need 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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@coderabbitai coderabbitai Bot left a comment

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.

Actionable comments posted: 0

🧹 Nitpick comments (3)
src/openms/include/OpenMS/MATH/MathFunctions.h (2)

224-254: Consider using std::pow for 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 roundTo for 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() or count() 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

📥 Commits

Reviewing files that changed from the base of the PR and between b886c44 and 5d8c92a.

📒 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::round is 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::round calls improve code clarity and prevent potential ambiguity with other round functions.


133-141: Comprehensive test coverage for roundTo function.

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_TRUE and TEST_FALSE for boolean functions is more semantically correct than TEST_EQUAL with 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::percentOf with 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.

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