Skip to content

Fix MSExperiment::reset() to clear chromatograms, preventing data duplication on reload - #9211

Merged
timosachsenberg merged 3 commits into
developfrom
copilot/fix-filefilter-duplicate-scans
Apr 23, 2026
Merged

timosachsenberg merged 3 commits into
developfrom
copilot/fix-filefilter-duplicate-scans

Conversation

Copilot AI commented Apr 23, 2026 •

Copy link
Copy Markdown
Contributor

FileFilter produces duplicate data when using -rt start:stop with block-aware RT filtering modes. The root cause is MSExperiment::reset() clearing spectra but not chromatograms — so when applyRTBlockFiltering reloads the file via MzMLFile::load() → map.reset(), chromatograms from the first (metadata-only) load persist and get duplicated by the second load.

Changes

  • MSExperiment::reset() — Add chromatograms_.clear(), making it consistent with clear(true)
  • applyRTBlockFiltering() — Replace --exp.end() with std::next(last_spec) == exp.end() to avoid fragile temporary iterator semantics; add bounds checks before decrementing last_spec when it equals exp.begin() (previously UB in edge cases)
  • Deisotoper_input2.mzML — Remove duplicate spectrum (same native ID scan=2136 appeared twice with different charge states, artifact of the bug); fix indexed mzML byte offsets
  • MSExperiment_test.cpp — Extend reset() test to verify chromatograms are cleared
// Before: chromatograms survive reset(), causing duplication on reload
void MSExperiment::reset()
{
  spectra_.clear();
  clearRanges();
  ExperimentalSettings::operator=(ExperimentalSettings());
}

// After
void MSExperiment::reset()
{
  spectra_.clear();
  chromatograms_.clear();
  clearRanges();
  ExperimentalSettings::operator=(ExperimentalSettings());
}

Copilot AI changed the title [WIP] Fix FileFilter extracting scans twice when called with -rt start:stop Fix MSExperiment::reset() to clear chromatograms, preventing data duplication on reload Apr 23, 2026
Copilot AI requested a review from jpfeuffer April 23, 2026 09:55
@timosachsenberg

Copy link
Copy Markdown
Contributor

looks legit

@jpfeuffer

Copy link
Copy Markdown
Contributor

Feel free to merge.. I used Opus this time so not surprised it's better this time.

@jpfeuffer
jpfeuffer marked this pull request as ready for review April 23, 2026 13:49
@timosachsenberg
timosachsenberg merged commit 549d263 into develop Apr 23, 2026
42 checks passed
@timosachsenberg
timosachsenberg deleted the copilot/fix-filefilter-duplicate-scans branch April 23, 2026 13:55
timosachsenberg pushed a commit that referenced this pull request Apr 24, 2026
- Add Fix entry for MSExperiment::reset() not clearing chromatograms (#9211)

Co-authored-by: GitHub Copilot <[email protected]>
Co-authored-by: Copilot <[email protected]>
timosachsenberg pushed a commit that referenced this pull request Apr 24, 2026
…9215)

The implementation of reset() was updated in #9211 to also clear
chromatograms, preventing data duplication on reload. The Doxygen
comment on the declaration in MSExperiment.h still said only
"spectra, ranges, metadata" — update it to accurately reflect
that chromatograms are also cleared.

Co-authored-by: GitHub Copilot <[email protected]>
Co-authored-by: Copilot <[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.

FileFilter seems to extract some scans twice when called with -rt start:stop

3 participants