Skip to content

feat: add adapter trimming option to remove soft-clipped regions from signal - #173

Open
jayhesselberth wants to merge 1 commit into
mainfrom
feature/adapter-trimming
Open

feat: add adapter trimming option to remove soft-clipped regions from signal#173
jayhesselberth wants to merge 1 commit into
mainfrom
feature/adapter-trimming

Conversation

@jayhesselberth

@jayhesselberth jayhesselberth commented Dec 6, 2025

Copy link
Copy Markdown
Member

Summary

Add a new "Trim Adapters" checkbox in the Plot Options panel that removes soft-clipped (adapter) regions from signal data before plotting. This is useful for focusing on the aligned portion of reads without adapter noise.

Changes

Python Backend:

  • Add trim_adapters parameter to plot_read(), plot_reads(), plot_aggregate()
  • Add _apply_adapter_trimming_to_reads() helper function in squiggy/plotting.py that:
    • Trims signal based on soft-clip base positions from move table
    • Trims sequence and quality scores
    • Adjusts reference_start/reference_end coordinates
    • Adjusts query_to_ref mapping for new indices
    • Ensures move table base count matches sequence length
  • Add soft-clip fields (query_start_offset, query_end_offset) to AlignedRead dataclass

TypeScript Frontend:

  • Add trimAdapters to PlotOptionsState interface
  • Add checkbox UI in Plot Options panel (Aggregate section)
  • Wire parameter through SquiggyRuntimeAPI.generateAggregatePlot()

Tests:

  • Add tests/test_adapter_trimming.py with 13 comprehensive tests covering:
    • No soft-clipping (unchanged)
    • Soft-clip at start/end/both ends
    • Quality scores trimming
    • query_to_ref adjustment
    • Move table base count consistency
    • Edge cases

Important Note

Adapter trimming removes the actual adapter sequences that are soft-clipped in the BAM alignment. The poly-A tail that may be visible in tRNA plots is part of the reference sequence, not adapter - it will remain visible after trimming because it's part of the aligned region.

Test plan

  • All 735 Python tests pass
  • All 564 TypeScript tests pass
  • Build compiles successfully
  • Manual testing in Positron with POD5/BAM data

🤖 Generated with Claude Code

… signal

Add a new "Trim Adapters" checkbox in the Plot Options panel that removes
soft-clipped (adapter) regions from signal data before plotting. This is
useful for focusing on the aligned portion of reads without adapter noise.

Implementation:
- Add `trim_adapters` parameter to plot_read(), plot_reads(), plot_aggregate()
- Add `_apply_adapter_trimming_to_reads()` helper function that:
  - Trims signal based on soft-clip base positions from move table
  - Trims sequence and quality scores
  - Adjusts reference_start/reference_end coordinates
  - Adjusts query_to_ref mapping for new indices
  - Ensures move table base count matches sequence length
- Add trimAdapters to PlotOptionsState and wire through UI
- Add comprehensive tests for adapter trimming functionality

Note: Adapter trimming removes the actual adapter sequences that are
soft-clipped in the BAM alignment. The poly-A tail that may be visible
in plots is part of the reference sequence, not adapter.
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