Repository navigation
(feat,osw): OSW Parquet (.oswpq) format - #8813
Conversation
… Parquet library input
…r loading PQP Parquet files
…nt in parquet reading functions
…nhance array handling with utility functions
…namic library name and improved JSON structure
…nversion and generation
…cific QC counts and JSON structure
…uet library input reader
…oved metadata handling and duplicate transition detection
- Introduced MSChromatogramParquetConsumer for writing chromatograms to Parquet files. - Updated OpenSwathBase to handle new output format options including xic (Parquet). - Enhanced FileTypes to include CHROMPARQUET type for chromatogram output. - Modified output file registration in OpenSwathWorkflow to support new formats. - Added source file references for MSChromatogramParquetConsumer in CMake configurations.
- Updated OpenSwathBase.cpp to load OSWPQ files instead of PQPPARQUET. - Modified FileTypes.cpp to define OSWPQ as a readable and writable file type. - Added ParquetFile.cpp to handle Parquet file I/O operations. - Updated sources.cmake to include ParquetFile.cpp in the build. - Refactored TransitionParquetFile_test.cpp to use OSWPQ in tests. - Adjusted CMakeLists.txt for TOPP tests to use OSWPQ format. - Changed OpenSwathAssayGenerator and OpenSwathDecoyGenerator to support OSWPQ format. - Updated OpenSwathWorkflow to reflect changes in file handling and output formats. - Modified TargetedFileConverter to support OSWPQ as input and output format.
…t for Arrow support
…nd adjust tests accordingly
…andom-access reads
…on-demand parquet reads
There was a problem hiding this comment.
Actionable comments posted: 8
♻️ Duplicate comments (2)
src/openms/source/ANALYSIS/OPENSWATH/OpenSwathOSWParquetWriter.cpp (2)
398-399:⚠️ Potential issue | 🟠 MajorCleanup of
run_id=directory should cover all exceptions, not only async write failures.The rollback block at Line 1320 runs only around
waitForWriteTasks_. Exceptions thrown earlier (feature parsing/building) can leaveruns/run_id=<id>behind and block retries.🛠️ Proposed fix
File::makeDir(run_path); + bool run_committed = false; + + try + { + // ... existing run building + writing logic ... + waitForWriteTasks_(write_tasks); + // ... update runs.parquet ... + run_committed = true; + } + catch (...) + { + if (!run_committed && File::exists(run_path)) + { + File::removeDirRecursively(run_path); + } + throw; + } - try - { - waitForWriteTasks_(write_tasks); - } - catch (...) - { - if (File::exists(run_path)) - { - File::removeDirRecursively(run_path); - } - throw; - }Also applies to: 1316-1329
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/openms/source/ANALYSIS/OPENSWATH/OpenSwathOSWParquetWriter.cpp` around lines 398 - 399, The current cleanup that removes the runs/run_id=<id> directory only runs around waitForWriteTasks_ and misses exceptions thrown earlier (e.g., during feature parsing/building), so expand the rollback to cover the entire operation that begins after File::makeDir(run_path). Wrap the whole sequence from File::makeDir(run_path) through all parsing/building and waitForWriteTasks_ in a single try/catch (or use an RAII guard) that on any exception ensures deletion of run_path; reference the run_path variable and the waitForWriteTasks_ call in the cleanup to reliably remove the runs/run_id directory on all failures.
349-373:⚠️ Potential issue | 🔴 CriticalReuse on-disk library IDs when appending (
library_ready=true).Current logic validates only row counts, then rebuilds
compound_to_precursorandtransition_to_idfrom current assay order. If ordering/ID encoding differs, appended run rows can reference wrong library IDs.🛠️ Proposed fix
+ if (library_ready) + { + // Load stable IDs from on-disk library tables and reuse them. + auto prec_tbl = ParquetFile::readTable(precursors_path); + auto prec_id_col = ParquetFile::getColumn(prec_tbl, "precursor_id"); + auto prec_traml_col = ParquetFile::getColumn(prec_tbl, "traml_id"); + for (int64_t i = 0; i < prec_tbl->num_rows(); ++i) + { + compound_to_precursor[String(ParquetFile::getString(prec_traml_col, i))] = + ParquetFile::getInt64(prec_id_col, i, 0, false); + } + + auto trans_tbl = ParquetFile::readTable(transitions_path); + auto trans_id_col = ParquetFile::getColumn(trans_tbl, "transition_id"); + auto trans_traml_col = ParquetFile::getColumn(trans_tbl, "traml_id"); + for (int64_t i = 0; i < trans_tbl->num_rows(); ++i) + { + transition_to_id[String(ParquetFile::getString(trans_traml_col, i))] = + ParquetFile::getInt64(trans_id_col, i, 0, false); + } + } + else + { + // existing ID-generation path for first write + }Also applies to: 400-462
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/openms/source/ANALYSIS/OPENSWATH/OpenSwathOSWParquetWriter.cpp` around lines 349 - 373, When library_ready is true the code currently only compares row counts (existing_precursors/existing_transitions) and then rebuilds compound_to_precursor and transition_to_id from the in-memory assay_library order, which can produce incorrect IDs if on-disk ID encoding/order differs; fix by reading the existing parquet ID mappings from precursors_path and transitions_path (the stored compound->precursor_id and transition_name->transition_id columns) and populate compound_to_precursor and transition_to_id from those on-disk columns instead of regenerating from assay_library, validate that all required compounds/transitions in assay_library exist in the loaded mappings (throw a clear error if not), and only fall back to rebuilding if no ID columns are present; use getParquetRowCount_, precursors_path, transitions_path, compound_to_precursor, transition_to_id, and assay_library to locate and implement this change.
🧹 Nitpick comments (5)
src/openms/include/OpenMS/FORMAT/ZipRandomAccessFile.h (2)
38-41: Export macro should be consistent acrossWITH_PARQUETbranches.The fallback
struct ZipRandomAccessFile(Line 38) is public but lacksOPENMS_DLLAPI, while theWITH_PARQUETbranch has it. Keep visibility/export behavior consistent in both branches.As per coding guidelines: “All exported classes, structs, functions, and variables must include the
OPENMS_DLLAPImacro.”🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/openms/include/OpenMS/FORMAT/ZipRandomAccessFile.h` around lines 38 - 41, The fallback struct ZipRandomAccessFile is missing the export macro; add OPENMS_DLLAPI before the struct name to match the WITH_PARQUET branch and ensure consistent visibility/export behavior for ZipRandomAccessFile and its static Open method; update the declaration "struct ZipRandomAccessFile" to "struct OPENMS_DLLAPI ZipRandomAccessFile" (keeping the existing Open signature) so it follows the project guideline requiring OPENMS_DLLAPI on exported types.
33-35: DocumentOpenwith full Doxygen tags.Line 33 introduces a public method but lacks method-level
@param,@return, and@throwstags. Please add full Doxygen on the method declaration (not only class-level prose).As per coding guidelines: “Every public method must include a Doxygen comment with
@brief,@param[in/out/in,out] for all parameters,@returnfor return values, and@throwsfor exceptions.”🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/openms/include/OpenMS/FORMAT/ZipRandomAccessFile.h` around lines 33 - 35, Add a full Doxygen comment above the Open method in ZipRandomAccessFile.h documenting `@brief`, `@param` for archive_path (in), entry_name (in), temp_dir (in,out if modified), `@return` describing the arrow::Result containing a shared_ptr to arrow::io::RandomAccessFile, and an `@throws` describing failure cases (e.g., inability to open archive, missing entry, or other errors returned in the arrow::Result). Ensure the tags reference the exact symbol names: Open, archive_path, entry_name, and temp_dir, and describe the semantics of the returned arrow::Result and the conditions under which exceptions/errors are produced.src/openms/include/OpenMS/FORMAT/ParquetFile.h (1)
121-126: Complete Doxygen onreadTable(RandomAccessFile)overload.Line 121 method docs are missing explicit
@param,@return, and@throwstags. Please document it to the same level as the other public methods.As per coding guidelines: “Every public method must include a Doxygen comment with
@brief,@param[in/out/in,out] for all parameters,@returnfor return values, and@throwsfor exceptions.”🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/openms/include/OpenMS/FORMAT/ParquetFile.h` around lines 121 - 126, The Doxygen for the static method readTable(const std::shared_ptr<arrow::io::RandomAccessFile>& infile) is incomplete; update its comment to include `@param`[in] for infile describing that it is the Arrow RandomAccessFile to read from, `@return` describing the returned std::shared_ptr<arrow::Table> and its ownership/empty-on-failure semantics, and `@throws` documenting any exceptions (e.g., arrow::Status/IO errors or OpenMS exceptions) that can be thrown; mirror the style and level of detail used by the other public methods in this header so the readTable(RandomAccessFile) overload has full `@brief`, `@param`, `@return` and `@throws` tags.src/openms/include/OpenMS/FORMAT/ZipArchiveFile.h (1)
126-127: Add Doxygen for testing hook methods.Lines 126-127 expose public methods but currently have no method-level Doxygen. Please add brief docs (and
@returnfortestGetExtractionCount).As per coding guidelines: “Every public method must include a Doxygen comment with
@brief,@param[in/out/in,out] for all parameters,@returnfor return values, and@throwsfor exceptions.”🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/openms/include/OpenMS/FORMAT/ZipArchiveFile.h` around lines 126 - 127, Add method-level Doxygen comments for the public test hooks: add a `@brief` comment for both testResetExtractionCount() and testGetExtractionCount(), explicitly stating their purpose (resetting and returning the extraction count respectively), add an `@return` description for testGetExtractionCount() describing the int value returned, and include `@throws` tags only if these methods can throw (otherwise omit); attach the comments immediately above the function declarations for testResetExtractionCount and testGetExtractionCount.src/openms/source/ANALYSIS/OPENSWATH/TransitionParquetFile.cpp (1)
205-385: Consider decomposing both conversion methods into focused helpers.Both methods are doing schema definition, parsing, mapping, stats, and I/O orchestration in one place; extraction of table-specific read/write helpers would reduce risk and simplify future format evolution.
Also applies to: 387-720
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/openms/source/ANALYSIS/OPENSWATH/TransitionParquetFile.cpp` around lines 205 - 385, The convertParquetToTargetedExperiment function is doing too many responsibilities; split it into focused helper methods: extract/open table helper (move the open_table_from_entry lambda into a private method e.g. openTableFromEntry(const String& oswpq_dir, const String& entry, std::unique_ptr<File::TempDir>& temp_dir)), a precursor-table reader (e.g. readPrecursorsTable(std::shared_ptr<arrow::Table> -> std::unordered_map<int64_t,PrecursorInfo>) that performs the ParquetFile::getColumn calls and the loop that fills precursor_map), a helper that converts a PrecursorInfo into OpenSwath::LightCompound and populates targeted_exp.proteins/compounds (e.g. addCompoundFromPrecursor(const PrecursorInfo&, OpenSwath::LightTargetedExperiment&)), and a transition-table reader (e.g. readTransitionsTable that takes transitions_table and precursor_map and appends OpenSwath::LightTransition entries). Move the duplicate-name handling and all ParquetFile::getX calls out of the big function into these helpers (keep unique symbols: TransitionParquetFile::convertParquetToTargetedExperiment, openTableFromEntry, readPrecursorsTable, addCompoundFromPrecursor, readTransitionsTable) and update convertParquetToTargetedExperiment to orchestrate: open tables, call readPrecursorsTable -> build compounds/proteins, then call readTransitionsTable.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@CHANGELOG`:
- Line 179: The changelog line "Added Parquet-based archive (.oswpq) to store
spectral library information and multi-run feature scores.(`#8813`)" is missing a
space before the PR reference; update that string to insert a space so it reads
"...feature scores. (`#8813`)" to match the repo's formatting convention.
In `@src/openms/CMakeLists.txt`:
- Around line 169-172: The compile definition OPENMS_ENABLE_TESTING_HOOKS is
currently applied with PUBLIC scope to the OpenMS target which leaks test-only
instrumentation (e.g. ZipArchiveFile::testResetExtractionCount(),
testGetExtractionCount()) to downstream consumers; change the
target_compile_definitions call on the OpenMS target to use PRIVATE instead of
PUBLIC, and instead add the OPENMS_ENABLE_TESTING_HOOKS definition to the
specific test targets' CMakeLists.txt files that need access to those test
methods so the macro remains scoped only to tests.
In `@src/openms/source/ANALYSIS/OPENSWATH/OpenSwathOSWParquetReader.cpp`:
- Around line 137-139: The current group_id construction uses only out.run_id
and out.precursor_id (out.group_id = String(out.run_id) + "_" +
String(out.precursor_id)), causing different feature/peak groups for the same
precursor/run to collide; update both occurrences where group_id is set (the
out.group_id assignment and the similar assignment later around the feature
emission) to include the unique feature identifier (e.g., out.feature_id) in the
concatenation (for example run_precursor_feature) so each candidate peak group
gets a stable, distinct group_id.
- Around line 716-719: ZipArchiveFile::listEntries(oswpq_dir) returns empty for
directory inputs so has_ppm/has_pep become false and fetchUnscoredData() skips
peptide mapping; update the check to detect when oswpq_dir is a directory and
then test actual file existence (e.g. using std::filesystem::exists on oswpq_dir
+ "/library/precursor_peptide_mapping.parquet" and
".../library/peptides.parquet") instead of relying solely on
ZipArchiveFile::listEntries, or fall back to a directory-aware listing; adjust
the logic around has_ppm/has_pep and the conditional that follows to use these
filesystem checks so peptide mapping is discovered for directory inputs.
In `@src/openms/source/ANALYSIS/OPENSWATH/OpenSwathOSWParquetWriter.cpp`:
- Around line 323-327: The writer currently always creates a fresh temp_dir and
sets base_dir = temp_dir->getPath()+"/oswpq_output" (using File::TempDir and
base_dir) and later unconditionally removes the existing archive (around the
block that deletes the .oswpq), which drops prior runs when appending; change
the logic so that when append mode is requested you open the existing .oswpq
archive and extract or copy its contents into base_dir (or merge in-place)
before writing new runs, and do NOT remove the existing archive file prior to
merging—modify the code paths that create temp_dir/base_dir and the archive
deletion block to detect append, restore existing entries into the working
directory, and only add new run files instead of deleting the archive.
In `@src/openms/source/ANALYSIS/OPENSWATH/TransitionParquetFile.cpp`:
- Around line 696-700: The code currently removes the existing archive
(output_zip_abs) before rebuilding, which can leave users without a valid .oswpq
on partial failures; change to a safe "write to temp then atomic replace"
pattern in TransitionParquetFile.cpp by writing the new archive to a unique
temporary path in the same directory (e.g., output_zip_abs + ".tmp" or similar),
performing all entry iteration/writes against that temp file, and only after
successful completion close it and atomically rename/move it to output_zip_abs
(use File::rename or platform-appropriate atomic replace), ensuring you do not
call File::remove on the existing output before success and that any failed temp
file is cleaned up on error.
- Around line 633-635: The loop that normalizes fragment_type uses std::tolower
on a plain char which is undefined for negative char values; update the loop in
TransitionParquetFile.cpp that iterates over fragment_type (the variable named
fragment_type and the loop using std::tolower) to cast each character to
unsigned char before calling std::tolower (e.g.,
std::tolower(static_cast<unsigned char>(c))) so the behavior is well-defined;
apply the same fix to the similar occurrences in
src/pyOpenMS/bindings/arrow_zerocopy.cpp around the uses at the indicated lines.
In `@src/openms/source/FORMAT/ZipRandomAccessFile.cpp`:
- Around line 73-94: The Read methods must reject negative nbytes and must not
return buffers containing uninitialized tail bytes on short reads: validate that
nbytes is non-negative at the start of both Read(int64_t, void*) and
Read(int64_t) and return an Invalid status if negative; in Read(int64_t) only
allocate/read when nbytes > 0, call Read(int64_t, void*) to get bytes_read,
check bytes_read >= 0, and construct the Arrow buffer using exactly bytes_read
bytes (not the original requested size) so EOF short-reads produce a smaller
buffer; reference the Read(int64_t, void*) and Read(int64_t) implementations to
apply these changes.
---
Duplicate comments:
In `@src/openms/source/ANALYSIS/OPENSWATH/OpenSwathOSWParquetWriter.cpp`:
- Around line 398-399: The current cleanup that removes the runs/run_id=<id>
directory only runs around waitForWriteTasks_ and misses exceptions thrown
earlier (e.g., during feature parsing/building), so expand the rollback to cover
the entire operation that begins after File::makeDir(run_path). Wrap the whole
sequence from File::makeDir(run_path) through all parsing/building and
waitForWriteTasks_ in a single try/catch (or use an RAII guard) that on any
exception ensures deletion of run_path; reference the run_path variable and the
waitForWriteTasks_ call in the cleanup to reliably remove the runs/run_id
directory on all failures.
- Around line 349-373: When library_ready is true the code currently only
compares row counts (existing_precursors/existing_transitions) and then rebuilds
compound_to_precursor and transition_to_id from the in-memory assay_library
order, which can produce incorrect IDs if on-disk ID encoding/order differs; fix
by reading the existing parquet ID mappings from precursors_path and
transitions_path (the stored compound->precursor_id and
transition_name->transition_id columns) and populate compound_to_precursor and
transition_to_id from those on-disk columns instead of regenerating from
assay_library, validate that all required compounds/transitions in assay_library
exist in the loaded mappings (throw a clear error if not), and only fall back to
rebuilding if no ID columns are present; use getParquetRowCount_,
precursors_path, transitions_path, compound_to_precursor, transition_to_id, and
assay_library to locate and implement this change.
---
Nitpick comments:
In `@src/openms/include/OpenMS/FORMAT/ParquetFile.h`:
- Around line 121-126: The Doxygen for the static method readTable(const
std::shared_ptr<arrow::io::RandomAccessFile>& infile) is incomplete; update its
comment to include `@param`[in] for infile describing that it is the Arrow
RandomAccessFile to read from, `@return` describing the returned
std::shared_ptr<arrow::Table> and its ownership/empty-on-failure semantics, and
`@throws` documenting any exceptions (e.g., arrow::Status/IO errors or OpenMS
exceptions) that can be thrown; mirror the style and level of detail used by the
other public methods in this header so the readTable(RandomAccessFile) overload
has full `@brief`, `@param`, `@return` and `@throws` tags.
In `@src/openms/include/OpenMS/FORMAT/ZipArchiveFile.h`:
- Around line 126-127: Add method-level Doxygen comments for the public test
hooks: add a `@brief` comment for both testResetExtractionCount() and
testGetExtractionCount(), explicitly stating their purpose (resetting and
returning the extraction count respectively), add an `@return` description for
testGetExtractionCount() describing the int value returned, and include `@throws`
tags only if these methods can throw (otherwise omit); attach the comments
immediately above the function declarations for testResetExtractionCount and
testGetExtractionCount.
In `@src/openms/include/OpenMS/FORMAT/ZipRandomAccessFile.h`:
- Around line 38-41: The fallback struct ZipRandomAccessFile is missing the
export macro; add OPENMS_DLLAPI before the struct name to match the WITH_PARQUET
branch and ensure consistent visibility/export behavior for ZipRandomAccessFile
and its static Open method; update the declaration "struct ZipRandomAccessFile"
to "struct OPENMS_DLLAPI ZipRandomAccessFile" (keeping the existing Open
signature) so it follows the project guideline requiring OPENMS_DLLAPI on
exported types.
- Around line 33-35: Add a full Doxygen comment above the Open method in
ZipRandomAccessFile.h documenting `@brief`, `@param` for archive_path (in),
entry_name (in), temp_dir (in,out if modified), `@return` describing the
arrow::Result containing a shared_ptr to arrow::io::RandomAccessFile, and an
`@throws` describing failure cases (e.g., inability to open archive, missing
entry, or other errors returned in the arrow::Result). Ensure the tags reference
the exact symbol names: Open, archive_path, entry_name, and temp_dir, and
describe the semantics of the returned arrow::Result and the conditions under
which exceptions/errors are produced.
In `@src/openms/source/ANALYSIS/OPENSWATH/TransitionParquetFile.cpp`:
- Around line 205-385: The convertParquetToTargetedExperiment function is doing
too many responsibilities; split it into focused helper methods: extract/open
table helper (move the open_table_from_entry lambda into a private method e.g.
openTableFromEntry(const String& oswpq_dir, const String& entry,
std::unique_ptr<File::TempDir>& temp_dir)), a precursor-table reader (e.g.
readPrecursorsTable(std::shared_ptr<arrow::Table> ->
std::unordered_map<int64_t,PrecursorInfo>) that performs the
ParquetFile::getColumn calls and the loop that fills precursor_map), a helper
that converts a PrecursorInfo into OpenSwath::LightCompound and populates
targeted_exp.proteins/compounds (e.g. addCompoundFromPrecursor(const
PrecursorInfo&, OpenSwath::LightTargetedExperiment&)), and a transition-table
reader (e.g. readTransitionsTable that takes transitions_table and precursor_map
and appends OpenSwath::LightTransition entries). Move the duplicate-name
handling and all ParquetFile::getX calls out of the big function into these
helpers (keep unique symbols:
TransitionParquetFile::convertParquetToTargetedExperiment, openTableFromEntry,
readPrecursorsTable, addCompoundFromPrecursor, readTransitionsTable) and update
convertParquetToTargetedExperiment to orchestrate: open tables, call
readPrecursorsTable -> build compounds/proteins, then call readTransitionsTable.
ℹ️ Review info
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: f51caaee-72b8-40a7-a91f-8cf444fcaac9
📒 Files selected for processing (13)
CHANGELOGsrc/openms/CMakeLists.txtsrc/openms/include/OpenMS/FORMAT/ParquetFile.hsrc/openms/include/OpenMS/FORMAT/ZipArchiveFile.hsrc/openms/include/OpenMS/FORMAT/ZipRandomAccessFile.hsrc/openms/include/OpenMS/FORMAT/sources.cmakesrc/openms/source/ANALYSIS/OPENSWATH/OpenSwathOSWParquetReader.cppsrc/openms/source/ANALYSIS/OPENSWATH/OpenSwathOSWParquetWriter.cppsrc/openms/source/ANALYSIS/OPENSWATH/TransitionParquetFile.cppsrc/openms/source/FORMAT/ParquetFile.cppsrc/openms/source/FORMAT/ZipArchiveFile.cppsrc/openms/source/FORMAT/ZipRandomAccessFile.cppsrc/openms/source/FORMAT/sources.cmake
🚧 Files skipped from review as they are similar to previous changes (1)
- src/openms/include/OpenMS/FORMAT/sources.cmake
…enSwathOSWParquetRoundTrip test
…hOSWParquetReader
Description
Related to #8533, this PR adds an archive store for storing parquet files for spectral library information, and run-specific feature scores for OpenSwath. Briefly, the file is an uncompressed zip archive with the following structure:
Added files
@timosachsenberg , I didn't add python bindings to this PR. I tried adding bindings for the
OpenSwathOSWParquetReaderclass, but was running into issues with wrapping, so figured it would probably be easier to do that in a separate PR. Would you be able to get claude to generate the bindings in a separate PR? I think it will maybe be more successful at generating the bindings.I was thinking the bindings API would be something similar to
XICParquetFile, something like:Checklist
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
Tests