Skip to content

Write the real VX tag and skip invalid barcodes in duplicate marking - #31

Merged
pdimens merged 1 commit into
mainfrom
claude/vx-barcode-validity
Oct 20, 2026
Merged

pdimens merged 1 commit into
mainfrom
claude/vx-barcode-validity

Conversation

@pdimens

@pdimens pdimens commented Oct 20, 2026

Copy link
Copy Markdown
Collaborator

Summary

Two related fixes for how barcode validity is handled on output.

  1. VX was always written as 1. buildRecord wrote VX:i:1 on every record (aligner/samwriter.go, unchanged since the initial import). The input's validity was parsed into FastQRecord.Valid but only used to decide whether to run the EM or RFA, so it never reached the output. Reads with an invalid barcode were reported as valid.
  2. Invalid barcodes were being deduplicated. markDuplicates ran unconditionally in both em.go and rfa.go, so invalid-barcoded reads got 0x400 flags. docs/usage.md already states that invalid-barcoded alignments do not go through deduplication; the code now matches that, so the docs are unchanged.

What changed

  • Alignment gets a valid_barcode field, set from the input record in GetAlignments (placeholders for unmapped or missing reads included).
  • buildRecord writes VX:i:0 or VX:i:1 from it.
  • mappedForDup (the eligibility check for duplicate marking) now also requires a valid barcode, so invalid-barcode reads are never flagged and never count as the original of a duplicate set. The check is in one place, so it applies to both the EM and RFA paths.

Behaviour to be aware of

Reads with no VX tag at all are treated as invalid, because ParseBarcodes reports "not valid" when either tag is missing. They will now get VX:i:0 and skip deduplication; before they got VX:i:1 and were deduplicated.

Testing

  • go vet, gofmt and go test ./... pass.
  • New tests: VX is written as 0 or 1 according to validity; invalid-barcode pairs at identical positions are not flagged while valid ones still are; GetAlignments carries validity onto every alignment, placeholders included. The existing duplicate-marking test helpers now set valid_barcode because the zero value means invalid.
  • End to end on simulated reads with every other barcode set to VX:i:0 and injected duplicate pairs:
    • main: all 42,416 records get VX:i:1, and 2,050 are flagged duplicate.
    • This branch: all 21,902 records of the invalid barcodes get VX:i:0 and none is flagged; the valid barcodes keep VX:i:1 and have 1,008 duplicates marked, about half the old count, as expected.
  • With every barcode valid, sorted output is identical to main for both the default EM and --rfa.

Generated by Claude Code

buildRecord wrote VX:i:1 for every record. The barcode's validity was read
from the input (FastQRecord.Valid) but only used to decide whether to run the
EM or RFA, so it never reached the output.

- Alignment carries valid_barcode, set from the input record in
  GetAlignments, and VX is written from it (0 or 1).
- Reads with an invalid barcode no longer take part in duplicate marking. They
  were deduplicated before, contrary to docs/usage.md, which already says
  invalid-barcoded alignments are not.

Output is unchanged when every barcode is valid (EM and RFA, sorted records
identical to main).

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01BUHUTLHfLoVtWa4XbCL9ZH
@pdimens
pdimens merged commit ae60f48 into main Oct 20, 2026
1 check passed
@pdimens
pdimens deleted the claude/vx-barcode-validity branch October 20, 2026 13:54
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.

2 participants