Repository navigation
[FORMAT] Add library-level FileInfo helper usable from pyOpenMS (#9596) - #9602
Conversation
Extracts the inspection logic of the FileInfo TOPP tool into a reusable
OpenMS::FileInfo library class (FORMAT/) so it can be called from C++ and
pyOpenMS, e.g. FileInfo().runAll("data.consensusXML").
- New OpenMS::FileInfo with a structured Result (ranges, counts, per-file-type
info, statistics, validation, ...) plus toText()/toTSV() renderers.
- TOPPFileInfo now delegates to the library: outputTo_ shrinks to a ~30-line
wrapper, so the library is the single implementation. The ~20 TOPP_FileInfo_*
golden CLI tests stay byte-for-byte identical (regression gate).
- nanobind bindings in bind_format.cpp (Result/Options/run/runAll/toText/toTSV
+ Math::SummaryStatistics); adds the stl/tuple caster.
- New class test (FileInfo_test) and pyOpenMS test (test_FileInfo.py).
Implementation detail: the rendering code is moved verbatim into the library
and the produced human-readable/TSV strings are cached on the Result, which
guarantees the CLI output is unchanged. Structured typed fields are populated
alongside for programmatic/pyOpenMS use.
Co-Authored-By: Claude Opus 4.8 <[email protected]>
|
@timosachsenberg The following names might be missing from the
Please consider applying the following patch: --- AUTHORS 2026-06-17 09:50:45.827754296 +0000
+++ AUTHORS.new 2026-06-17 09:50:51.216103508 +0000
@@ -22,8 +22,8 @@
- Chirag Dave
- Chris Bauer
- Chris Bielow
- - Christie Mathews
- Christian Ehrlich
+ - Christie Mathews
- Clemens Groepl
- Cornelia Friedle
- Daniel Jameson |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (2)
📝 WalkthroughWalkthroughExtracts the ChangesOpenMS::FileInfo library, Python bindings, and CLI refactor
Sequence Diagram(s)sequenceDiagram
participant CLI as TOPPFileInfo::outputTo_
participant Lib as OpenMS::FileInfo
participant Report as report_()
participant Parser as Format Parsers
participant Result as FileInfo::Result
CLI->>Lib: run(filename, options)
Lib->>Report: report_(filename, type, options, os, os_tsv, result)
Report->>Parser: load file (MSExperiment / FeatureMap / FastaFile / ...)
Parser-->>Report: parsed data
Report->>Result: populate peaks/features/ident/fasta/ranges/validation
Report-->>Result: write text + tsv streams into Result.text / Result.tsv
Report-->>Lib: return
Lib-->>CLI: Result
CLI->>Lib: toText(result) / toTSV(result)
Lib-->>CLI: Result.text / Result.tsv
CLI-->>CLI: write to file
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 6
🧹 Nitpick comments (4)
src/openms/source/FORMAT/FileInfo.cpp (3)
2385-2385: 💤 Low valuePotentially redundant
updateRanges()call.
exp.updateRanges()was already called at line 1535 andexphasn't been modified since. This call is redundant but harmless.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/openms/source/FORMAT/FileInfo.cpp` at line 2385, The `exp.updateRanges()` call at line 2385 is redundant because this method was already invoked earlier at line 1535 and the `exp` object has not been modified since that earlier call. Remove this duplicate `exp.updateRanges()` invocation to eliminate the unnecessary repeated computation.
830-830: 💤 Low valuePrefer
'\n'overstd::endlfor performance.Per coding guidelines,
std::endlforces a stream flush which is unnecessary here.♻️ Proposed fix
- os << "Checking mzML file for valid indices ... " << std::endl; + os << "Checking mzML file for valid indices ... \n";🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/openms/source/FORMAT/FileInfo.cpp` at line 830, In the output stream operation that logs "Checking mzML file for valid indices", replace the `std::endl` at the end of the statement with a newline character `'\n'` instead. This avoids the unnecessary stream flush that `std::endl` performs and improves performance in accordance with the coding guidelines.Source: Coding guidelines
1703-1703: 💤 Low valueUse const reference for read-only iteration.
The loop body only reads from
pm; using a non-const reference is misleading.♻️ Proposed fix
- for (MSSpectrum& pm : exp) + for (const MSSpectrum& pm : exp)🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/openms/source/FORMAT/FileInfo.cpp` at line 1703, The loop iteration at the for statement using MSSpectrum& pm is using a non-const reference even though the loop body only reads from pm without modifying it. Change the loop to use a const reference by updating MSSpectrum& to const MSSpectrum& to accurately reflect that pm is not being modified within the loop body.src/pyOpenMS/bindings/bind_format.cpp (1)
2884-2889: ⚡ Quick winRelease the GIL while inspecting files.
run()/runAll()can perform blocking file I/O, validation, and statistics. Holding the GIL blocks unrelated Python threads; copyOptionsfirst, then release the GIL for the actual C++ work.⚡ Proposed update
- .def("run", [](FileInfo& self, const std::string& filename, const FileInfo::Options& options){ return self.run(filename, options); }, + .def("run", [](FileInfo& self, const std::string& filename, const FileInfo::Options& options){ + FileInfo::Options local_options = options; + nb::gil_scoped_release release; + return self.run(filename, local_options); + }, "filename"_a, "options"_a, "Load the file (type auto-detected unless options.forced_type) and compute all requested information") - .def("run", [](FileInfo& self, const std::string& filename){ return self.run(filename); }, + .def("run", [](FileInfo& self, const std::string& filename){ + nb::gil_scoped_release release; + return self.run(filename); + }, "filename"_a, "Load the file with default options") - .def("runAll", [](FileInfo& self, const std::string& filename){ return self.runAll(filename); }, + .def("runAll", [](FileInfo& self, const std::string& filename){ + nb::gil_scoped_release release; + return self.runAll(filename); + }, "filename"_a, "Compute all content metrics (meta/processing/statistics on; no validation/index/detail/corrupt)")🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/pyOpenMS/bindings/bind_format.cpp` around lines 2884 - 2889, The three method bindings for FileInfo (the two overloads of run() and runAll()) perform blocking file I/O operations while holding Python's Global Interpreter Lock, which prevents other Python threads from executing. Modify each lambda function to release the GIL before performing the actual C++ work: for the run() method with Options parameter, create a copy of the options object first, then use pybind11's GIL release mechanism (such as py::gil_scoped_release) to wrap the actual self.run() or self.runAll() call, allowing other Python threads to proceed during the file inspection.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/openms/source/FORMAT/FileInfo.cpp`:
- Line 103: The string literal in the output statement contains extraneous
single quote characters surrounding the newline escape sequence, causing the
output format to include literal quote marks in the printed text. Remove the
single quote characters that wrap around the `\n` escape in the "Ranges:" string
so that the newline escape is interpreted as a whitespace character rather than
appearing as literal text in the output. The corrected format should match the
pattern used in the subsequent output statements for retention time ranges.
In `@src/pyOpenMS/bindings/bind_format.cpp`:
- Around line 2760-2761: The method binding in the FileInfo::PeakInfo class uses
camelCase naming which violates Python conventions. Rename the method from
activationMethodsFlat to activation_methods_flat to follow snake_case
conventions for Python-facing API names. Additionally, check for and rename any
other newly added method bindings mentioned in the review (such as runAll to
run_all, toText to to_text, and toTsv to to_tsv) to ensure consistent snake_case
naming throughout the bindings, and remove any duplicate camelCase aliases to
avoid introducing hard-to-change naming inconsistencies.
- Around line 2664-2883: The binding classes for SummaryStatistics,
FileInfo::Range, FileInfo::RangeSet, FileInfo::Ranges, FileInfo::FileMeta,
FileInfo::ExperimentMeta::Contact, FileInfo::ExperimentMeta,
FileInfo::ProcessingStep, FileInfo::NamedStats, FileInfo::PeakInfo,
FileInfo::FeatureInfo::MapColumn, FileInfo::FeatureInfo, FileInfo::IdentInfo,
FileInfo::FastaInfo, FileInfo::MzTabInfo, FileInfo::ValidationInfo,
FileInfo::CorruptionInfo, and FileInfo::DetailInfo are missing copy constructor
and copy hook definitions. For each of these classes that currently only has
.def(nb::init<>()), add a copy constructor with .def(nb::init<const
ClassName&>()), followed by __copy__ and __deepcopy__ method definitions using
lambda functions that return a new instance, following the same pattern already
implemented for FileInfo::Options and FileInfo classes at the end of the binding
section.
In `@src/pyOpenMS/tests/unittests/test_FileInfo.py`:
- Around line 81-87: The test_fileinfo_forced_type function uses an input file
that already has the .featureXML extension, so the test passes regardless of
whether forced_type is actually being honored. To properly test that forced_type
bypasses auto-detection, copy the test fixture to a temporary file with a
neutral extension like .tmp, then verify that calling run() with the forced_type
option set to FEATUREXML succeeds in parsing it, while calling run() without the
option fails to recognize it as featureXML. This ensures the test actually
validates that forced_type overrides auto-detection behavior.
In `@src/tests/class_tests/openms/source/FileInfo_test.cpp`:
- Around line 119-127: The test in START_SECTION((forced type bypasses
auto-detection)) currently uses a file with the correct .featureXML extension
while forcing the type to FEATUREXML, so it cannot verify that forced_type
actually bypasses auto-detection since auto-detection would work anyway. Replace
the test input file with a valid featureXML file that has an incorrect or
unknown file extension, then verify that fi.run() with opt.forced_type set to
FEATUREXML still successfully parses it and produces the expected result,
ensuring the test truly validates the forced_type bypass behavior.
In `@src/topp/FileInfo.cpp`:
- Around line 120-130: The `opt.meta` assignment is incorrectly allowing the
`-out_tsv` option to enable metadata computation. Currently, the line sets
`opt.meta = getFlag_("m") || !getStringOption_("out_tsv").empty();` which means
metadata gets enabled whenever an output TSV file is specified, even without the
`-m` flag. Since `Options::meta` is documented as the mirror of the CLI `-m`
flag, change the assignment to only check the `-m` flag by removing the OR
condition that checks the TSV output option. The corrected line should simply
set `opt.meta = getFlag_("m");` to keep TSV output selection separate from
metadata computation.
---
Nitpick comments:
In `@src/openms/source/FORMAT/FileInfo.cpp`:
- Line 2385: The `exp.updateRanges()` call at line 2385 is redundant because
this method was already invoked earlier at line 1535 and the `exp` object has
not been modified since that earlier call. Remove this duplicate
`exp.updateRanges()` invocation to eliminate the unnecessary repeated
computation.
- Line 830: In the output stream operation that logs "Checking mzML file for
valid indices", replace the `std::endl` at the end of the statement with a
newline character `'\n'` instead. This avoids the unnecessary stream flush that
`std::endl` performs and improves performance in accordance with the coding
guidelines.
- Line 1703: The loop iteration at the for statement using MSSpectrum& pm is
using a non-const reference even though the loop body only reads from pm without
modifying it. Change the loop to use a const reference by updating MSSpectrum&
to const MSSpectrum& to accurately reflect that pm is not being modified within
the loop body.
In `@src/pyOpenMS/bindings/bind_format.cpp`:
- Around line 2884-2889: The three method bindings for FileInfo (the two
overloads of run() and runAll()) perform blocking file I/O operations while
holding Python's Global Interpreter Lock, which prevents other Python threads
from executing. Modify each lambda function to release the GIL before performing
the actual C++ work: for the run() method with Options parameter, create a copy
of the options object first, then use pybind11's GIL release mechanism (such as
py::gil_scoped_release) to wrap the actual self.run() or self.runAll() call,
allowing other Python threads to proceed during the file inspection.
🪄 Autofix (Beta)
✅ Autofix completed
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 920d9114-c4c2-4e4d-b923-5a7622797e6e
📒 Files selected for processing (10)
src/openms/include/OpenMS/FORMAT/FileInfo.hsrc/openms/include/OpenMS/FORMAT/sources.cmakesrc/openms/source/FORMAT/FileInfo.cppsrc/openms/source/FORMAT/sources.cmakesrc/pyOpenMS/bindings/bind_format.cppsrc/pyOpenMS/bindings/type_casters/all_casters.hsrc/pyOpenMS/tests/unittests/test_FileInfo.pysrc/tests/class_tests/openms/executables.cmakesrc/tests/class_tests/openms/source/FileInfo_test.cppsrc/topp/FileInfo.cpp
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
|
Note Autofix is a beta feature. Expect some limitations and changes as we gather feedback and continue to improve it. Fixes Applied SuccessfullyFixed 4 file(s) based on 5 unresolved review comments. Files modified:
Commit: The changes have been pushed to the Time taken: |
Fixed 4 file(s) based on 5 unresolved review comments. Co-authored-by: CodeRabbit <[email protected]>
|
Adversarial review result:
I did not find a blocking behavior regression in the FileInfo extraction itself in this pass. I did not run the tests locally. |
- FileInfo_test.cpp: use std::string instead of OpenMS::String (the String header was not included, breaking the build on all platforms). - Rework the forced_type test (C++ and pyOpenMS): forced_type selects the parse branch and restricts allowed types but does not make the loader ignore the file (loadFeatures/loadExperiment still re-detect, falling back to content sniffing). The previous test forced FEATUREXML on a .tmp copy and then asserted plain detection yields UNKNOWN, but content sniffing recognizes the featureXML, so that assertion failed. Use a neutral .tmp extension, force FEATUREXML, and assert the feature map parses; document why a wrong-but-known extension cannot demonstrate a bypass here. Co-Authored-By: Claude Opus 4.8 <[email protected]>
Doxygen parsed '#IDs'/'#elements' in the ids_per_element doc comment as explicit link requests, failing Doxygen_Warning_test. Rephrase to plain text. Co-Authored-By: Claude Opus 4.8 <[email protected]>
|
Caution Failed to replace (edit) comment. This is likely due to insufficient permissions or the comment being deleted. Error details |
Add entries for all substantive non-test PRs merged since the last changelog update: - #9623 ThermoRawFile full mzML metadata extraction + polarity fix - #9602 New FileInfo library class usable from C++ and pyOpenMS - #9521 IMAGING multi-region support (add missing PR reference) - #9620 Deisotoper::isToleranceSupported + ProSE/SSE crash fix on low-res data - #9610 DistanceMatrix::setValue cached-minimum guard fix - #9497 DistanceMatrix::operator==, ClusteringGrid, File path guard fixes - #9583 LogStreamBuf thread-safety fix - #9514 CI Windows migration to Visual Studio 2026 Claude-Session: https://claude.ai/code/session_01YLg6pWyjyTxpWAU6mgrDzC Co-authored-by: Claude <[email protected]>
Summary
Closes #9596.
Creates a library-level
OpenMS::FileInfohelper (inFORMAT/) that performs the same file inspection as theFileInfoTOPP tool, but is callable from C++ and pyOpenMS and returns a structured result:What changed
OpenMS::FileInfo(FORMAT/FileInfo.{h,cpp}): a typedResult(file meta, ranges, per-file-type info for peaks/features/consensus/IDs/FASTA/mzTab/trafoXML/PQP, statistics, validation, ...) plusrun()/runAll()and statictoText()/toTSV()renderers. Nostd::ostream&in the public API.TOPPFileInfonow delegates to the library —outputTo_collapses to a thin wrapper, so the library is the single implementation (the tool drops from ~2300 to ~195 lines).bind_format.cpp):Result/Options/run/runAll/toText/toTSV+Math::SummaryStatistics; adds thenanobind/stl/tuple.hcaster.FileInfo_test) and a pyOpenMS test (test_FileInfo.py).Implementation note
The rendering code is moved verbatim into the library and the produced human-readable/TSV strings are cached on the
Result. This guarantees the CLI output is byte-for-byte unchanged — the ~20TOPP_FileInfo_*golden tests are the regression gate. Typed structured fields are populated alongside for programmatic/pyOpenMS use.Testing
TOPP_FileInfo_*golden CLI tests: 35/35 pass (byte-identical).FileInfo_testclass test: pass.test_FileInfo.pypyOpenMS test: 6/6 pass.Known follow-ups (info already available via
.text/.tsv)ValidationInfo::schema_version/detailare bound but not yet populated.-m/-s/-c/-dblocks are typed-struct-declared but only partially populated (full data is in.text/.tsv).FAIMSHelper::getCompensationVoltagesis computed twice in the peaks path (minor).🤖 Generated with Claude Code
Summary by CodeRabbit
Release Notes
FileInfoAPI to inspect mass-spectrometry files (e.g., mzML, featureXML/consensusXML, idXML, FASTA, mzTab) with structured metadata/statistics, optional validation/corruption checks, and cached rendering.pyOpenMS.FileInfo, including text/TSV output helpers.FileInfoCLI tool to delegate reporting to the shared library, including consistent option handling (e.g., index validation behavior).