Skip to content

[TEST] Tests for the OpenSWATH MSExperiment spectrum-access wrappers - #9578

Merged
timosachsenberg merged 1 commit into
OpenMS:developfrom
timosachsenberg:test/openswath-spectrumaccess-openms
Jun 17, 2026
Merged

timosachsenberg merged 1 commit into
OpenMS:developfrom
timosachsenberg:test/openswath-spectrumaccess-openms

Conversation

@timosachsenberg

@timosachsenberg timosachsenberg commented Jun 16, 2026 •

Copy link
Copy Markdown
Contributor

Context

Part of the OpenMS 3.6.0 pre-release testing plan (#9460), §4 (OpenSwathWorkflow). Batched PR — two related untested data-access wrappers in one change.

SpectrumAccessOpenMS and SpectrumAccessOpenMSInMemory adapt an MSExperiment to the OpenSwath::ISpectrumAccess interface used throughout OpenSWATH; neither had a test.

Change

Both build a small 2-spectrum / 1-chromatogram experiment and verify the interface:

  • SpectrumAccessOpenMS (wraps a shared_ptr<MSExperiment>): getNrSpectra / getNrChromatograms, getSpectrumById (m/z + intensity arrays), getSpectrumMetaById (RT, MS level), getSpectraByRT (RT-window lookup), getChromatogramById (time + intensity arrays), getChromatogramNativeID, and lightClone.
  • SpectrumAccessOpenMSInMemory (pre-loads from an ISpectrumAccess): the same spectrum/chromatogram counts and per-array values are reproduced from the in-memory copy, plus getSpectrumMetaById and lightClone.

Notes

  • Both registered in executables.cmake (format_executables_list, DATAACCESS section, next to the existing SpectrumAccess tests).
  • Tests only — no production code changes.
  • The OpenSwath array values were probed against the built library before pinning.
  • Both build and pass locally; all assertions execute against real values (verbose-confirmed).

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Tests
    • Added comprehensive test suites for spectrum access functionality, including tests for spectrum and chromatogram retrieval, metadata access, and object operations.

Batches tests for two untested OpenSWATH data-access wrappers that adapt an
MSExperiment to the OpenSwath::ISpectrumAccess interface. Both build a small
2-spectrum / 1-chromatogram experiment and verify the interface:

- SpectrumAccessOpenMS (wraps a shared_ptr<MSExperiment>): getNrSpectra /
  getNrChromatograms, getSpectrumById (m/z + intensity arrays), getSpectrumMetaById
  (RT, MS level), getSpectraByRT (RT-window lookup), getChromatogramById (time +
  intensity arrays), getChromatogramNativeID, and lightClone.
- SpectrumAccessOpenMSInMemory (pre-loads from an ISpectrumAccess): the same
  spectrum/chromatogram counts and per-array values are reproduced from the
  in-memory copy, plus getSpectrumMetaById and lightClone.

Registered both in executables.cmake (format_executables_list, DATAACCESS
section). Part of the OpenMS 3.6.0 pre-release testing plan (OpenMS#9460). Tests only;
no production code changes.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@github-actions

Copy link
Copy Markdown
Contributor

@timosachsenberg The following names might be missing from the AUTHORS file:

  • Timo Sachsenberg

Please consider applying the following patch:

--- AUTHORS	2026-06-16 05:29:35.879490665 +0000
+++ AUTHORS.new	2026-06-16 05:29:41.058251812 +0000
@@ -23,8 +23,8 @@
  - Chirag Dave
  - Chris Bauer
  - Chris Bielow
- - Christie Mathews
  - Christian Ehrlich
+ - Christie Mathews
  - Clemens Groepl
  - Cornelia Friedle
  - Daniel Jameson

@coderabbitai

coderabbitai Bot commented Jun 16, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Two new C++ unit test files are added for SpectrumAccessOpenMS and SpectrumAccessOpenMSInMemory, each using a local mkExp() fixture that builds a small MSExperiment. Both test executables are registered in executables.cmake.

Changes

SpectrumAccess Unit Tests

Layer / File(s) Summary
SpectrumAccessOpenMS test suite and CMake registration
src/tests/class_tests/openms/executables.cmake, src/tests/class_tests/openms/source/SpectrumAccessOpenMS_test.cpp
Registers SpectrumAccessOpenMS_test and SpectrumAccessOpenMSInMemory_test in format_executables_list. Adds SpectrumAccessOpenMS_test.cpp with a mkExp() fixture (two spectra, one chromatogram) and a test suite covering construction/destruction, spectrum and chromatogram counts, retrieval by id, metadata (RT, ms_level), RT-based lookup with deltaRT tolerance, chromatogram arrays, native id, and lightClone().
SpectrumAccessOpenMSInMemory test suite
src/tests/class_tests/openms/source/SpectrumAccessOpenMSInMemory_test.cpp
Adds SpectrumAccessOpenMSInMemory_test.cpp with a mkExp() fixture and test sections covering construction from OpenSwath::ISpectrumAccess (with preloaded counts), destruction, getSpectrumById (m/z and intensity arrays), getSpectrumMetaById (RT), getChromatogramById (time/intensity arrays), and lightClone() (non-null, expected spectrum count).

🐇 Two new tests hop into the suite today,
Spectra and chromatograms checked all the way!
mkExp builds the peaks with care,
Clone, retrieve, and metadata there.
The rabbit stamps approval — tests are A-OK! 🌸

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.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 specifically describes the main change: adding tests for the OpenSWATH MSExperiment spectrum-access wrappers, which aligns directly with the changeset content.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with 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.

❤️ 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: 3

🧹 Nitpick comments (1)
src/tests/class_tests/openms/source/SpectrumAccessOpenMSInMemory_test.cpp (1)

24-39: 💤 Low value

Consider extracting the shared mkExp() fixture.

The mkExp() function on lines 24-39 is identical to the one in SpectrumAccessOpenMS_test.cpp (lines 23-38). Since both test files exercise related SpectrumAccess functionality, consider extracting this fixture into a shared test helper to reduce duplication and ensure consistency.

♻️ Possible refactoring approach

Create a shared test fixture header (e.g., SpectrumAccessTestFixtures.h) in the test directory with the mkExp() function, then include it in both test files. This would ensure that any future changes to the fixture are automatically consistent across both tests.

🤖 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/tests/class_tests/openms/source/SpectrumAccessOpenMSInMemory_test.cpp`
around lines 24 - 39, The mkExp() function is duplicated identically in both
SpectrumAccessOpenMSInMemory_test.cpp and SpectrumAccessOpenMS_test.cpp. Extract
this function into a shared test fixture header file (e.g.,
SpectrumAccessTestFixtures.h) in the test directory, then include this header in
both test files and remove the duplicate mkExp() function definitions from each
file. This will ensure consistency and reduce code duplication across the
related test files.
🤖 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/tests/class_tests/openms/source/SpectrumAccessOpenMSInMemory_test.cpp`:
- Around line 78-85: The test for getSpectrumMetaById in the START_SECTION block
is incomplete and only validates the RT field of the returned SpectrumMeta
object m. Add an additional assertion to validate the ms_level field of the
metadata object to ensure complete coverage, matching the validation pattern
used in the corresponding test in SpectrumAccessOpenMS_test.cpp.
- Around line 66-76: The intensity array validation in the getSpectrumById test
is incomplete. Currently, only data[1] is checked with TEST_REAL_SIMILAR for
s->getIntensityArray(), while data[0] is not validated. Add a TEST_REAL_SIMILAR
assertion for s->getIntensityArray()->data[0] before the existing data[1] check
to ensure consistent test coverage with the corresponding assertions for the mz
array and to match the validation pattern in SpectrumAccessOpenMS_test.cpp.
- Around line 98-106: The lightClone test section is missing an assertion for
chromatogram count validation. Add a TEST_EQUAL assertion for
clone->getNrChromatograms() immediately after the existing TEST_EQUAL for
clone->getNrSpectra() to ensure the cloned object fully preserves the in-memory
state, matching the assertion pattern used in the corresponding
SpectrumAccessOpenMS_test.cpp test. Determine the expected chromatogram count by
examining what the origin object contains or by checking the referenced test
file for the expected value.

---

Nitpick comments:
In `@src/tests/class_tests/openms/source/SpectrumAccessOpenMSInMemory_test.cpp`:
- Around line 24-39: The mkExp() function is duplicated identically in both
SpectrumAccessOpenMSInMemory_test.cpp and SpectrumAccessOpenMS_test.cpp. Extract
this function into a shared test fixture header file (e.g.,
SpectrumAccessTestFixtures.h) in the test directory, then include this header in
both test files and remove the duplicate mkExp() function definitions from each
file. This will ensure consistency and reduce code duplication across the
related test files.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: d2f28e3d-2316-4018-83fc-f6aefac6d426

📥 Commits

Reviewing files that changed from the base of the PR and between cfa350c and 14d9c80.

📒 Files selected for processing (3)
  • src/tests/class_tests/openms/executables.cmake
  • src/tests/class_tests/openms/source/SpectrumAccessOpenMSInMemory_test.cpp
  • src/tests/class_tests/openms/source/SpectrumAccessOpenMS_test.cpp

Comment on lines +66 to +76
START_SECTION((OpenSwath::SpectrumPtr getSpectrumById(int id)))
{
SpectrumAccessOpenMS origin(mkExp());
SpectrumAccessOpenMSInMemory sa(origin);
OpenSwath::SpectrumPtr s = sa.getSpectrumById(0);
TEST_EQUAL(s->getMZArray()->data.size(), 2)
TEST_REAL_SIMILAR(s->getMZArray()->data[0], 100.0)
TEST_REAL_SIMILAR(s->getMZArray()->data[1], 200.0)
TEST_REAL_SIMILAR(s->getIntensityArray()->data[1], 800.0)
}
END_SECTION

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.

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Incomplete assertion coverage for intensity array.

Line 74 only validates data[1] for the intensity array but omits data[0]. The corresponding test in SpectrumAccessOpenMS_test.cpp (lines 83-84) checks both indices. For completeness and consistency, add an assertion for data[0].

🧪 Suggested fix
  TEST_REAL_SIMILAR(s->getMZArray()->data[0], 100.0)
  TEST_REAL_SIMILAR(s->getMZArray()->data[1], 200.0)
+ TEST_REAL_SIMILAR(s->getIntensityArray()->data[0], 500.0)
  TEST_REAL_SIMILAR(s->getIntensityArray()->data[1], 800.0)
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
START_SECTION((OpenSwath::SpectrumPtr getSpectrumById(int id)))
{
SpectrumAccessOpenMS origin(mkExp());
SpectrumAccessOpenMSInMemory sa(origin);
OpenSwath::SpectrumPtr s = sa.getSpectrumById(0);
TEST_EQUAL(s->getMZArray()->data.size(), 2)
TEST_REAL_SIMILAR(s->getMZArray()->data[0], 100.0)
TEST_REAL_SIMILAR(s->getMZArray()->data[1], 200.0)
TEST_REAL_SIMILAR(s->getIntensityArray()->data[1], 800.0)
}
END_SECTION
START_SECTION((OpenSwath::SpectrumPtr getSpectrumById(int id)))
{
SpectrumAccessOpenMS origin(mkExp());
SpectrumAccessOpenMSInMemory sa(origin);
OpenSwath::SpectrumPtr s = sa.getSpectrumById(0);
TEST_EQUAL(s->getMZArray()->data.size(), 2)
TEST_REAL_SIMILAR(s->getMZArray()->data[0], 100.0)
TEST_REAL_SIMILAR(s->getMZArray()->data[1], 200.0)
TEST_REAL_SIMILAR(s->getIntensityArray()->data[0], 500.0)
TEST_REAL_SIMILAR(s->getIntensityArray()->data[1], 800.0)
}
END_SECTION
🤖 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/tests/class_tests/openms/source/SpectrumAccessOpenMSInMemory_test.cpp`
around lines 66 - 76, The intensity array validation in the getSpectrumById test
is incomplete. Currently, only data[1] is checked with TEST_REAL_SIMILAR for
s->getIntensityArray(), while data[0] is not validated. Add a TEST_REAL_SIMILAR
assertion for s->getIntensityArray()->data[0] before the existing data[1] check
to ensure consistent test coverage with the corresponding assertions for the mz
array and to match the validation pattern in SpectrumAccessOpenMS_test.cpp.

Comment on lines +78 to +85
START_SECTION((OpenSwath::SpectrumMeta getSpectrumMetaById(int id) const))
{
SpectrumAccessOpenMS origin(mkExp());
SpectrumAccessOpenMSInMemory sa(origin);
OpenSwath::SpectrumMeta m = sa.getSpectrumMetaById(0);
TEST_REAL_SIMILAR(m.RT, 10.0)
}
END_SECTION

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.

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Incomplete assertion coverage for spectrum metadata.

Line 83 validates only the RT field but omits the ms_level field. The corresponding test in SpectrumAccessOpenMS_test.cpp (lines 92-93) validates both. Add an assertion for ms_level to ensure metadata is fully preserved by the in-memory copy.

🧪 Suggested fix
  OpenSwath::SpectrumMeta m = sa.getSpectrumMetaById(0);
  TEST_REAL_SIMILAR(m.RT, 10.0)
+ TEST_EQUAL(m.ms_level, 1)
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
START_SECTION((OpenSwath::SpectrumMeta getSpectrumMetaById(int id) const))
{
SpectrumAccessOpenMS origin(mkExp());
SpectrumAccessOpenMSInMemory sa(origin);
OpenSwath::SpectrumMeta m = sa.getSpectrumMetaById(0);
TEST_REAL_SIMILAR(m.RT, 10.0)
}
END_SECTION
START_SECTION((OpenSwath::SpectrumMeta getSpectrumMetaById(int id) const))
{
SpectrumAccessOpenMS origin(mkExp());
SpectrumAccessOpenMSInMemory sa(origin);
OpenSwath::SpectrumMeta m = sa.getSpectrumMetaById(0);
TEST_REAL_SIMILAR(m.RT, 10.0)
TEST_EQUAL(m.ms_level, 1)
}
END_SECTION
🤖 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/tests/class_tests/openms/source/SpectrumAccessOpenMSInMemory_test.cpp`
around lines 78 - 85, The test for getSpectrumMetaById in the START_SECTION
block is incomplete and only validates the RT field of the returned SpectrumMeta
object m. Add an additional assertion to validate the ms_level field of the
metadata object to ensure complete coverage, matching the validation pattern
used in the corresponding test in SpectrumAccessOpenMS_test.cpp.

Comment on lines +98 to +106
START_SECTION((std::shared_ptr<OpenSwath::ISpectrumAccess> lightClone() const))
{
SpectrumAccessOpenMS origin(mkExp());
SpectrumAccessOpenMSInMemory sa(origin);
auto clone = sa.lightClone();
TEST_NOT_EQUAL(clone.get(), nullptr)
TEST_EQUAL(clone->getNrSpectra(), 2)
}
END_SECTION

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.

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Incomplete assertion coverage for lightClone.

Line 104 validates only getNrSpectra but omits getNrChromatograms. The corresponding test in SpectrumAccessOpenMS_test.cpp (lines 131-132) validates both counts. Add an assertion for chromatogram count to ensure the clone fully preserves the in-memory state.

🧪 Suggested fix
  auto clone = sa.lightClone();
  TEST_NOT_EQUAL(clone.get(), nullptr)
  TEST_EQUAL(clone->getNrSpectra(), 2)
+ TEST_EQUAL(clone->getNrChromatograms(), 1)
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
START_SECTION((std::shared_ptr<OpenSwath::ISpectrumAccess> lightClone() const))
{
SpectrumAccessOpenMS origin(mkExp());
SpectrumAccessOpenMSInMemory sa(origin);
auto clone = sa.lightClone();
TEST_NOT_EQUAL(clone.get(), nullptr)
TEST_EQUAL(clone->getNrSpectra(), 2)
}
END_SECTION
START_SECTION((std::shared_ptr<OpenSwath::ISpectrumAccess> lightClone() const))
{
SpectrumAccessOpenMS origin(mkExp());
SpectrumAccessOpenMSInMemory sa(origin);
auto clone = sa.lightClone();
TEST_NOT_EQUAL(clone.get(), nullptr)
TEST_EQUAL(clone->getNrSpectra(), 2)
TEST_EQUAL(clone->getNrChromatograms(), 1)
}
END_SECTION
🤖 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/tests/class_tests/openms/source/SpectrumAccessOpenMSInMemory_test.cpp`
around lines 98 - 106, The lightClone test section is missing an assertion for
chromatogram count validation. Add a TEST_EQUAL assertion for
clone->getNrChromatograms() immediately after the existing TEST_EQUAL for
clone->getNrSpectra() to ensure the cloned object fully preserves the in-memory
state, matching the assertion pattern used in the corresponding
SpectrumAccessOpenMS_test.cpp test. Determine the expected chromatogram count by
examining what the origin object contains or by checking the referenced test
file for the expected value.

@timosachsenberg
timosachsenberg merged commit 763e907 into OpenMS:develop Jun 17, 2026
41 checks passed
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.

1 participant