Skip to content

slicer: keep Segments and PASEF MS/MS frames consistent with the slice (#101) - #103

Merged
pgarrett-scripps merged 6 commits into
tacular-omics:mainfrom
ritanjay:fix/slicer-segments-msms-101
Nov 27, 2026
Merged

pgarrett-scripps merged 6 commits into
tacular-omics:mainfrom
ritanjay:fix/slicer-segments-msms-101

Conversation

@ritanjay

Copy link
Copy Markdown
Contributor

What this changes

slice_d_folder now keeps Segments and the PASEF MS/MS frames in step with the frames it keeps. Fixes #101.

  • Segments.FirstFrame and LastFrame are clipped to the kept frames, and segments outside them are deleted.
  • A PASEF MS/MS frame whose precursors were all detected in an MS1 frame before the range is now dropped, instead of being kept without its PasefFrameMsMsInfo rows.
  • A slice left with no frames raises TdfpyError and removes the partial destination.

Why

Slicing frames 21..40 of tests/data/example_dda.d used to leave two problems:

  • Segments still said (1, 1, 710, 0).
  • 13 of the 18 MS/MS frames in the slice had no PasefFrameMsMsInfo rows. Their precursors had been removed because the parent MS1 frame was outside the slice, so the DDA reader could no longer reach those frames.

With this change, the same slice keeps frames 29..40, Segments is (1, 29, 40, 0), no MS/MS frame is orphaned, and DDA opens it.

How it was tested

  • just check passes locally:
    • full suite with RUN_SLOW=1: 889 passed, also with --resolution lowest-direct;
    • ruff, ty, the llms-full check and the release check are clean.
  • New or changed behaviour has a test that fails without this change: with src/ stashed, 5 tests in tests/test_slicer.py fail.
  • Public API changes are reflected in the docstrings and the docs: the slice_d_folder docstring (including Raises), and the table and a new paragraph in docs/utilities.md, with llms-full.txt regenerated.
  • CHANGELOG.md has an entry under ## [Unreleased].

New tests:

  • test_slice_not_starting_at_frame_1_keeps_tables_in_step (DDA 21..40) checks Segments, that every kept MS/MS frame keeps its rows, that no precursor has a missing parent, and that merged_peaks is unchanged for precursors whose windows all lie in the slice.
  • test_slice_whose_frames_are_all_orphaned_msms_raises_and_cleans_up (21..28).
  • test_slice_clips_segments, run on:
    • the DIA fixture, slice 101..200: gives [(1, 101, 200, 0)];
    • the PRM fixture, slice 200..300: gives [(1, 200, 254, 1), (2, 255, 300, 1)].

Notes for the maintainer

  • Drop the frames rather than keep the precursors. I dropped the orphaned MS/MS frames rather than keeping their precursors. Keeping a precursor would leave Precursors.Parent pointing at a frame that is not in the slice. DDA reads the parent frame's retention time and mobility calibration, so it cannot open that. The frames are logged at INFO level when dropped. The docs suggest starting the range at an MS1 frame to keep them.
  • Two existing tests changed:
    • test_slice_middle_range now expects the frames that can still be read in 100..110, computed from the source by _source_frames_kept, instead of all of 100..110.
    • test_slice_null_tims_id_removes_partial_dest slices 1..2 instead of 4..5 for its "range that still works". Frames 2..5 there are MS/MS frames of precursors from frame 1, so 4..5 now leaves nothing and raises.
  • Order of operations. The SQLite filtering now runs before the binary rebuild, so the binary only holds the frames that survive.

🤖 Generated with Claude Code

https://claude.ai/code/session_014d8j19vQx1tPzM6NkYxknS

@codecov

codecov Bot commented Nov 26, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 90.90909% with 2 lines in your changes missing coverage. Please review.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
src/tdfpy/slicer.py 90.90% 1 Missing and 1 partial ⚠️

📢 Thoughts on this report? Let us know!

@pgarrett-scripps
pgarrett-scripps merged commit c910acc into tacular-omics:main Nov 27, 2026
15 checks passed
@pgarrett-scripps

Copy link
Copy Markdown
Collaborator

Thanks @ritanjay. I sliced the DDA fixture at 21..40, 1..20, 700..710 and 23..23 on main and on this branch. On the branch Segments matches the kept frames, no MS/MS frame is left without PasefFrameMsMsInfo rows, and the DDA reader returns the same MS1 frames and precursors as before (2 and 25 for 21..40). Dropping the unreachable frames is the consistent choice, and the reason is clear in the docstring. Merged.

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.

slice_d_folder leaves Segments and some MS/MS frames out of step with the kept frames

2 participants