Skip to content

Make setReadString("*") go through setReadBases so BAMRecord sees it - #1951

Merged
tfenne merged 1 commit into
masterfrom
tf_set_read_string_star_bam
Nov 15, 2026
Merged

tfenne merged 1 commit into
masterfrom
tf_set_read_string_star_bam

Conversation

@tfenne

@tfenne tfenne commented Oct 30, 2026 •

Copy link
Copy Markdown
Member

setReadString("*") on a record read from BAM was ignored when the record was written back to BAM; it now takes effect.

  • SAMRecord.setReadString assigned mReadBases directly for "*" rather than calling setReadBases, so BAMRecord's override, which marks the stored bytes stale and the cached read length invalid, never ran. The record reported its old read length and BAMRecordCodec wrote its original bases.
  • It now calls setReadBases(NULL_SEQUENCE).
  • Behaviour change: a BAM record that still has qualities after only its bases are cleared now fails on write with the read-length and qualities mismatch, as a record built in memory always has. Clearing both with setBaseQualityString("*") too, as is usual, was never affected.

Found while reading broadinstitute/picard#2063.

Fixes #1947

Summary by CodeRabbit

  • Bug Fixes
    • Setting a BAM record’s read sequence to * now clears its reported read length and is preserved when the record is written and read back.
    • Writing fails if quality data remains and its length no longer matches the cleared read length.

@coderabbitai

coderabbitai Bot commented Oct 30, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 38 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used all 2 included reviews currently available.

Learn how review limits work.

Review configuration:

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 4de94f5b-acb1-4953-a1f9-6fb2aa977b81
Commits

Reviewing files that changed from the base of the PR and between 69ca376 and def7a37.

Files selected for processing: 3

  • CHANGELOG.md
  • src/main/java/htsjdk/samtools/SAMRecord.java
  • src/test/java/htsjdk/samtools/SAMRecordUnitTest.java
Walkthrough

setReadString("*") now calls setReadBases(NULL_SEQUENCE). New BAM-backed tests check that the read length becomes zero and that a BAM round trip preserves the null-sequence value. The 6.0.1 changelog entry also describes the quality-length mismatch case.

Changes: BAM read-string clearing

Layer / File(s) Summary
Clear and verify the BAM read sequence
src/main/java/htsjdk/samtools/SAMRecord.java, src/test/java/htsjdk/samtools/SAMRecordUnitTest.java, CHANGELOG.md
setReadString("*") now calls setReadBases(NULL_SEQUENCE). BAM-backed tests check the read length and the null-sequence value after a round trip. The changelog describes the write failure when retained qualities no longer match the cleared read length.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix · Severity of issue fixed: Low

Merge Risk: Minimal · previous review 69ca3

This change makes clearing a read's bases take effect on records read from BAM, so the cleared read length and sequence are written back. No actionable merge-blocking risk remains after review.

Pre-merge checks: Passed 5

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title names the main change: SAMRecord.setReadString("*") now routes through setReadBases so BAMRecord's override sees the cleared bases. The changeset does exactly this: it changes setReadString …
Linked Issues check Passed Issue #1947 requires that setReadString("*") take effect on a BAM-read record. The fix must call setReadBases(NULL_SEQUENCE) so that BAMRecord's override runs. At head, SAMRecord.setReadString now cal…
Out of Scope Changes check Passed The changes are a one-line change in SAMRecord.setReadString, a CHANGELOG.md entry, and BAM-backed unit tests in SAMRecordUnitTest.java. The SAMRecord change is the fix that #1947 requests. The CHANGE…
Docstring Coverage Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentat…
Full details: Title check

Explanation

The title names the main change: SAMRecord.setReadString("*") now routes through setReadBases so BAMRecord's override sees the cleared bases. The changeset does exactly this: it changes setReadString in SAMRecord.java, adds BAM-backed tests, and adds a 6.0.1 changelog entry describing the behavior. The title is specific and matches the linked issue's requested fix.

Full details: Linked Issues check

Explanation

Issue #1947 requires that setReadString("") take effect on a BAM-read record. The fix must call setReadBases(NULL_SEQUENCE) so that BAMRecord's override runs. At head, SAMRecord.setReadString now calls setReadBases(NULL_SEQUENCE) in the "" branch instead of assigning mReadBases directly. The diff shows this is the only change to SAMRecord.java. BAMRecord.java at head overrides setReadBases to set mBinaryDataStale = true and mReadLengthValid = false. The override therefore runs for the "*" case. This invalidates the cached read length, so getReadLength() reflects the cleared bases. It also stops BAMRecordCodec from writing the original variable-length data. The issue's stated behaviour is met: with qualities still present, writing fails on the read-length and qualities mismatch. The PR description and the PR objectives agree with the issue. The SAMRecordUnitTest.java diff could not be read in this review. The test additions are therefore described only by the raw summary, which reports BAM-backed tests for the read length and the round trip. The test verdict relies on that summary and on the source change. The body of SAMRecord.setReadBases was not read. The one-line change assumes it stores the value the same way the removed direct assignment did.

Full details: Out of Scope Changes check

Explanation

The changes are a one-line change in SAMRecord.setReadString, a CHANGELOG.md entry, and BAM-backed unit tests in SAMRecordUnitTest.java. The SAMRecord change is the fix that #1947 requests. The CHANGELOG entry documents the behaviour change that the fix introduces: a BAM-read record with cleared bases and remaining qualities now fails on write. Documentation of a required behaviour change supports the objective. The unit tests cover the same issue behaviour and are supporting material for it. No unrelated source changes appear in the reviewed evidence. The test file diff could not be read, so its exact content is taken from the raw summary only. The raw summary describes the tests as limited to setting the null-sequence read string on a decoded BAMRecord and checking the read length and round trip.

Full details: Docstring Coverage

Explanation

Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 1 functions across 2 files. (1 skipped: 1 unsupported.)

Finishing Touches

🧪 Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

setReadString assigned NULL_SEQUENCE to mReadBases directly for "*",
bypassing BAMRecord's setReadBases override, which marks the stored
binary data stale and the cached read length invalid. A record read
from BAM then reported its old read length and, when written back to
BAM, wrote its original bases. Changing the qualities too hid the bug,
since setBaseQualities marks the data stale.
@tfenne
tfenne force-pushed the tf_set_read_string_star_bam branch from 69ca376 to def7a37 Compare November 15, 2026 21:16
@tfenne
tfenne merged commit aec2bfd into master Nov 15, 2026
4 checks passed
@tfenne
tfenne deleted the tf_set_read_string_star_bam branch November 15, 2026 21:24
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.

SAMRecord.setReadString("*") is ignored when a BAMRecord is written

1 participant