Skip to content

FileInfo: Add sequence length stats and nucleic acid support for FASTA - #8643

Merged
timosachsenberg merged 2 commits into
developfrom
feature/fileinfo-fasta-enhancements
Jan 13, 2026
Merged

timosachsenberg merged 2 commits into
developfrom
feature/fileinfo-fasta-enhancements

Conversation

@timosachsenberg

@timosachsenberg timosachsenberg commented Jan 12, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Add sequence length distribution reporting (Min, 25%ile, Median, 75%ile, Max)
  • Detect nucleic acid vs amino acid sequences automatically based on IUPAC character set
  • Use appropriate labels ("nucleotide" vs "amino acid") based on detected sequence type
  • Report IUPAC ambiguity codes for nucleic acid files (N count and all ambiguity codes)

Closes #8638

Example Output

Amino acid FASTA:

Number of sequences   : 11
Sequence length distribution:
  Minimum : 174
  25%ile  : 175
  Median  : 176
  75%ile  : 177
  Maximum : 177
Number of sequences with ambiguous amino acids: 0 (0%)
...
Total amino acids     : 1933
Amino acid counts:
...
Ambiguous amino acids (B/Z/X)  : 0 (0%)
                      (B/Z/X/J): 0 (0%)

Nucleic acid FASTA:

Number of sequences   : 3
Sequence length distribution:
  Minimum : 16
  25%ile  : 16
  Median  : 17
  75%ile  : 48
  Maximum : 48
Number of sequences with ambiguous nucleotides: 1 (33.33%)
...
Total nucleotides     : 81
Nucleotide counts:
...
Ambiguous nucleotides (N)      : 9 (11.11%)
All IUPAC ambiguity codes      : 9 (11.11%)

Test plan

  • Build FileInfo target
  • Test with amino acid FASTA (existing test file)
  • Test with nucleic acid FASTA (created test file with N ambiguity codes)
  • Verify correct detection and labeling for both sequence types

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features
    • Automatic sequence type detection (nucleotide vs amino acid)
    • Unified analysis for both nucleotide and amino acid sequences
    • Expanded per-residue counts to report all standard residues
    • Improved ambiguity reporting with type-specific metrics
    • Added sequence length distribution statistics (min, max, median, 25th/75th percentiles)

✏️ Tip: You can customize this high-level summary in your review settings.

- Add sequence length distribution (Min, 25%ile, Median, 75%ile, Max)
- Detect nucleic acid vs amino acid sequences automatically
- Use appropriate labels ("nucleotide" vs "amino acid")
- Report IUPAC ambiguity codes for nucleic acid files

Closes #8638

Co-Authored-By: Claude Opus 4.5 <[email protected]>
@coderabbitai

coderabbitai Bot commented Jan 12, 2026 •

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

The FileInfo tool now detects sequence type (nucleic acid vs amino acid), generalizes residue counting into a map, accumulates per-sequence lengths for distribution statistics, and adds type-specific ambiguity handling and reporting. Output and duplicate-header/sequence logic were adapted accordingly.

Changes

Cohort / File(s) Summary
FileInfo core logic
src/topp/FileInfo.cpp
Replaced amino-acid-specific counters with a generic residue_counts map and number_of_residues; added sequence_lengths collection; introduced count_residues helper; added sequence-type detection (nucleotide vs amino acid); implemented ambiguity handling for AA (B/Z/X/J) and nucleotide (N + IUPAC codes); computed length distribution (min, 25%, median, 75%, max); updated reporting and duplicate-header/sequence warning logic.
Test output updates
src/tests/topp/FileInfo_17_output.txt, src/tests/topp/FileInfo_18_output.txt
Added "Sequence length distribution" block and expanded residue count listings to include full standard residues for the detected sequence type; adjusted ambiguity and total/residue output formatting to match new logic.

Sequence Diagram(s)

(Skipped — changes are internal to a single CLI component and do not introduce multi-component interaction flows.)

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Poem

🐰
I hopped through FASTA, nose to the breeze,
Counting residues, lengths, and strange ambiguities,
Quartiles and medians tucked in my hat,
N's and X's noted — imagine that!
A tiny rabbit cheers for unified stats.

🚥 Pre-merge checks | ✅ 4 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main changes: adding sequence length stats and nucleic acid support for FASTA in FileInfo.
Linked Issues check ✅ Passed The PR addresses all primary objectives from issue #8638: sequence length distribution stats, nucleic acid detection/labeling, and IUPAC ambiguity code handling.
Out of Scope Changes check ✅ Passed All changes focus on FileInfo FASTA enhancements (sequence stats, type detection, ambiguity handling) and corresponding test output updates, with no extraneous modifications.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


📜 Recent review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f5253ee and 1fa58f9.

📒 Files selected for processing (2)
  • src/tests/topp/FileInfo_17_output.txt
  • src/tests/topp/FileInfo_18_output.txt
🧰 Additional context used
📓 Path-based instructions (2)
**

📄 CodeRabbit inference engine (AGENTS.md)

File extensions must be lowercase except for ML, XML, and mzData

Files:

  • src/tests/topp/FileInfo_18_output.txt
  • src/tests/topp/FileInfo_17_output.txt
src/tests/topp/**

📄 CodeRabbit inference engine (AGENTS.md)

TOPP tests must be registered in src/tests/topp/CMakeLists.txt and placed alongside test data

Files:

  • src/tests/topp/FileInfo_18_output.txt
  • src/tests/topp/FileInfo_17_output.txt
⏰ 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). (10)
  • GitHub Check: build-and-test (ubuntu-24.04-arm, g++, 13)
  • GitHub Check: build-and-test (ubuntu-24.04, g++, 13)
  • GitHub Check: build-and-test (ubuntu-24.04, clang++, 17)
  • GitHub Check: build-and-test (windows-2025, cl.exe, 14.44)
  • GitHub Check: build-and-test (macos-14, xcode, 15.4)
  • GitHub Check: build-win
  • GitHub Check: build-lnx
  • GitHub Check: build-lnx-arm
  • GitHub Check: build-macos-arm
  • GitHub Check: cppcheck-test
🔇 Additional comments (1)
src/tests/topp/FileInfo_17_output.txt (1)

11-16: Sequence length distribution looks correct.

The statistics are properly ordered and the tight clustering (174-177) is reasonable for similar sequences. Format is consistent with other test outputs.


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

Comment @coderabbitai help to get the list of available commands and usage tips.

@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 (2)
src/topp/FileInfo.cpp (2)

894-908: Consider edge case for empty FASTA files.

The nucleic acid detection logic is correct and efficiently breaks early when a non-nucleotide character is found. However, if the FASTA file has no entries, is_nucleic_acid will remain true by default. This is a minor edge case since the subsequent output would show zero sequences anyway, but it may produce misleading labels if someone parses the output programmatically.

Optional: Handle empty FASTA explicitly
+      // Detect if sequences are nucleic acid (vs amino acid)
+      // If ANY character is not a valid nucleotide code, it's an amino acid sequence
-      bool is_nucleic_acid = true;
+      bool is_nucleic_acid = !entries.empty(); // Default to false if no entries
       for (const auto& entry : entries)
       {

1011-1017: Minor: Direct map access may insert default keys.

Using operator[] on residue_counts (line 1013) will insert keys 'N' and 'n' with value 0 if they don't exist. While this doesn't affect the correctness of the output, it modifies the map as a side effect. Consider using find() or the existing count_residues helper for consistency.

Suggested fix using count_residues helper
       if (is_nucleic_acid)
       {
-        size_t amb_N = residue_counts['N'] + residue_counts['n'];
+        size_t amb_N = count_residues(residue_counts, "Nn");
         size_t amb_all = count_residues(residue_counts, NA_AMBIGUOUS);
         os << "Ambiguous nucleotides (N)      : " << amb_N << " (" << Math::percentOf(amb_N, number_of_residues, 2) << "%)\n";
         os << "All IUPAC ambiguity codes      : " << amb_all << " (" << Math::percentOf(amb_all, number_of_residues, 2) << "%)\n\n";
       }
📜 Review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c50f0da and f5253ee.

📒 Files selected for processing (1)
  • src/topp/FileInfo.cpp
🧰 Additional context used
📓 Path-based instructions (3)
**/*.{h,cpp}

📄 CodeRabbit inference engine (AGENTS.md)

**/*.{h,cpp}: Use 2-space indentation for C++ and header files; no tabs; Unix line endings (LF)
All non-template exported classes, structs, functions, and variables must use OPENMS_DLLAPI macro; templates are exempt
One class per file; class name must match file name exactly
Always pair .h header files with .cpp implementation files
Class and type names must use PascalCase; methods must use lowerCamelCase; variables must use snake_case
Private and protected member variables must end with trailing underscore _
Enum names and macro definitions must use UPPER_SNAKE_CASE; prefer enum class over C-style enums
Use OpenMS primitive types from OpenMS/CONCEPT/Types.h instead of standard C++ types
Use Size/SignedSize types for STL .size() values instead of standard integer types
Prefer references over pointers in C++ code
Use Rule-of-0 (no explicit copy/move) or Rule-of-6 (all copy/move/destroy); never use Rule-of-5
Accessor methods must use get/set pairs for protected/private members; do not return references to primitive types
All exceptions must derive from Exception::Base; throw with file, line, and OPENMS_PRETTY_FUNCTION; catch by reference
Code comments must use // style; should comprise at least ~5% of code; describe the next few lines in plain English
Use .clang-format configuration from repository root for code formatting; check with clang-format --dry-run -Werror
Use OpenMS logging macros and OpenMS::LogStream; avoid std::cout and std::cerr
Avoid std::endl; prefer \n for better performance
Prefer OpenMS::String for numeric formatting and parsing
Braces must be on their own lines and aligned; always use braces even for single-line blocks (trivial one-liners may remain single-line)
Space required after keywords (if, for, while) and around binary operators

Files:

  • src/topp/FileInfo.cpp
src/topp/*.cpp

📄 CodeRabbit inference engine (AGENTS.md)

src/topp/*.cpp: Use ProgressLogger in TOPP tools for progress reporting
TOPP tool source files must be registered in src/topp/executables.cmake and added to src/openms/source/APPLICATIONS/ToolHandler.cpp
TOPP tools must define parameters in registerOptionsAndFlags_() and read with getStringOption_ and related helpers

Files:

  • src/topp/FileInfo.cpp
**

📄 CodeRabbit inference engine (AGENTS.md)

File extensions must be lowercase except for ML, XML, and mzData

Files:

  • 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). (10)
  • GitHub Check: build-and-test (ubuntu-24.04-arm, g++, 13)
  • GitHub Check: build-lnx-arm
  • GitHub Check: build-macos-arm
  • GitHub Check: build-and-test (windows-2025, cl.exe, 14.44)
  • GitHub Check: build-win
  • GitHub Check: build-lnx
  • GitHub Check: build-and-test (macos-14, xcode, 15.4)
  • GitHub Check: build-and-test (ubuntu-24.04, g++, 13)
  • GitHub Check: build-and-test (ubuntu-24.04, clang++, 17)
  • GitHub Check: cppcheck-test
🔇 Additional comments (4)
src/topp/FileInfo.cpp (4)

858-881: LGTM!

The generalization from a fixed-size array to a map-based approach for residue counting is a clean design that supports both amino acids and nucleotides. The count_residues lambda correctly handles missing keys and uses std::string_view for efficient character set lookups.


947-970: LGTM!

The before/after comparison pattern for detecting sequences with ambiguous residues is correct. The approach efficiently determines whether each individual sequence contributed any ambiguous characters without needing a separate per-sequence counter.


1005-1008: LGTM!

The structured binding iteration over residue_counts is clean and idiomatic C++17. The alphabetical ordering from std::map provides consistent, predictable output.


980-996: The Math function signatures are verified and the code is correct. All three functions (Math::median, Math::quantile1st, and Math::quantile3rd) accept a bool sorted parameter with a default value of false. The code on line 983 sorts the data and then correctly passes true to these functions to indicate the data is pre-sorted, which is the proper usage.

Add sequence length distribution to expected output files.

Co-Authored-By: Claude Opus 4.5 <[email protected]>

@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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/tests/topp/FileInfo_17_output.txt (1)

22-44: Add nucleic acid test coverage for FileInfo.

FileInfo_17 and FileInfo_18 test amino acid FASTA files only. No nucleic acid FASTA tests exist for FileInfo. If the PR adds nucleic acid support with automatic sequence type detection, corresponding test cases are needed to validate:

  • Automatic detection of nucleic acid sequences
  • Correct "nucleotide"/"nucleic acid" labeling (vs "amino acid")
  • IUPAC nucleotide ambiguity code reporting (N and others)
📜 Review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f5253ee and 1fa58f9.

📒 Files selected for processing (2)
  • src/tests/topp/FileInfo_17_output.txt
  • src/tests/topp/FileInfo_18_output.txt
🧰 Additional context used
📓 Path-based instructions (2)
**

📄 CodeRabbit inference engine (AGENTS.md)

File extensions must be lowercase except for ML, XML, and mzData

Files:

  • src/tests/topp/FileInfo_18_output.txt
  • src/tests/topp/FileInfo_17_output.txt
src/tests/topp/**

📄 CodeRabbit inference engine (AGENTS.md)

TOPP tests must be registered in src/tests/topp/CMakeLists.txt and placed alongside test data

Files:

  • src/tests/topp/FileInfo_18_output.txt
  • src/tests/topp/FileInfo_17_output.txt
⏰ 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). (10)
  • GitHub Check: build-and-test (ubuntu-24.04-arm, g++, 13)
  • GitHub Check: build-and-test (ubuntu-24.04, g++, 13)
  • GitHub Check: build-and-test (ubuntu-24.04, clang++, 17)
  • GitHub Check: build-and-test (windows-2025, cl.exe, 14.44)
  • GitHub Check: build-and-test (macos-14, xcode, 15.4)
  • GitHub Check: build-win
  • GitHub Check: build-lnx
  • GitHub Check: build-lnx-arm
  • GitHub Check: build-macos-arm
  • GitHub Check: cppcheck-test
🔇 Additional comments (1)
src/tests/topp/FileInfo_17_output.txt (1)

11-16: Sequence length distribution looks correct.

The statistics are properly ordered and the tight clustering (174-177) is reasonable for similar sequences. Format is consistent with other test outputs.

@timosachsenberg
timosachsenberg merged commit 0e1e0cd into develop Jan 13, 2026
@timosachsenberg
timosachsenberg deleted the feature/fileinfo-fasta-enhancements branch January 13, 2026 06:44
claude Bot pushed a commit that referenced this pull request Jan 18, 2026
Added 19 missing PRs to OpenMS 3.6.0 changelog:

PyOpenMS:
- #8530: Build system modernization with py-build-cmake
- #8633: SpectrumNativeIDParser wrapper
- #8655: Arrow/Parquet export with DataFrame methods (BREAKING: method renames)
- #8661: Build dependency docs
- #8664: Biosaur2Algorithm wrap-inherits
- #8668: wrap-doc documentation
- #8674: Docstring validation tests

TOPP tools:
- #8643: FileInfo FASTA stats
- #8650: FileConverter MSP support
- #8649: PeakPickerHiRes parameter

OpenMS Library:
- #8633: SpectrumNativeIDParser class
- #8655: ArrowExport helper
- #8651, #8656, #8659, #8660, #8662: Performance optimizations

Fixes:
- #8645: DataArray handling in filters
- #8672: Test file correction
- #8678: UniqueIdGenerator seed collision fix

Build System:
- #8675, #8676: Claude CI workflows

Also reorganized misplaced entries from lines 122-129.

Co-authored-by: Timo Sachsenberg <[email protected]>
timosachsenberg added a commit that referenced this pull request Jan 18, 2026
* Add comprehensive changelog for OpenMS 3.6.0

Includes changes from 96 merged PRs since version 3.5.0:

- General: macOS Intel discontinued, Ubuntu 24.04, notarization in CI
- Dependencies: Autowrap >= 0.26.0, Eigen minimum 3.4.0
- PyOpenMS: Pythonic methods (__len__, __str__, __repr__, __hash__),
  DataFrame support, new wrappers, string handling improvements
- TOPP tools: MapAligner spectra transformation, FileInfo improvements,
  IsobaricWorkflow fixes, SageAdapter thread handling
- OpenMS Library: PeakFileOptions, ParamIterator, SpectrumAnnotator
- Breaking changes: Matrix<T> Eigen decoupling, API renames, FileWatcher move
- Bug fixes: NucleicAcidSearchEngine, LogConfigHandler, decoy generation
- Documentation: Targeted Quantitation, parameter annotations, AGENTS.md
- Build: macOS notarization, Parquet support, pytest fixtures

Co-Authored-By: Claude Opus 4.5 <[email protected]>

* Add missing changelog entries for recently merged PRs

Added 19 missing PRs to OpenMS 3.6.0 changelog:

PyOpenMS:
- #8530: Build system modernization with py-build-cmake
- #8633: SpectrumNativeIDParser wrapper
- #8655: Arrow/Parquet export with DataFrame methods (BREAKING: method renames)
- #8661: Build dependency docs
- #8664: Biosaur2Algorithm wrap-inherits
- #8668: wrap-doc documentation
- #8674: Docstring validation tests

TOPP tools:
- #8643: FileInfo FASTA stats
- #8650: FileConverter MSP support
- #8649: PeakPickerHiRes parameter

OpenMS Library:
- #8633: SpectrumNativeIDParser class
- #8655: ArrowExport helper
- #8651, #8656, #8659, #8660, #8662: Performance optimizations

Fixes:
- #8645: DataArray handling in filters
- #8672: Test file correction
- #8678: UniqueIdGenerator seed collision fix

Build System:
- #8675, #8676: Claude CI workflows

Also reorganized misplaced entries from lines 122-129.

Co-authored-by: Timo Sachsenberg <[email protected]>

---------

Co-authored-by: Claude Opus 4.5 <[email protected]>
Co-authored-by: claude[bot] <41898282+claude[bot]@users.noreply.github.com>
Co-authored-by: Timo Sachsenberg <[email protected]>
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.

FileInfo support for FASTA could include sequence lengths. Also, nucleic acids could use better support.

1 participant