Skip to content

Fix broken bwa hybrid alignment; resolve hybrid coverage design - #3

Open
DanielSprockett wants to merge 1 commit into
pipeline-hardeningfrom
hybrid-coverage-fix
Open

DanielSprockett wants to merge 1 commit into
pipeline-hardeningfrom
hybrid-coverage-fix

Conversation

@DanielSprockett

Copy link
Copy Markdown
Contributor

Stacked on #2 (base pipeline-hardening). Resolves the hybrid coverage question from the code review (§1.2).

The two problems

  1. Real bug — the bwa hybrid path never worked. _merge_long_reads_bwa ran minimap2 via the _run helper, which captures and discards stdout, so the long-read SAM was never written; the next line open(long.sam) raised FileNotFoundError. Any hybrid (short+long) sample under a bwa aligner failed.
  2. Docs/impl mismatch — CLAUDE.md claimed coverage merging happens "in coverage.py weighted by read count," but merging actually happens at the alignment stage (both technologies → one BAM).

Resolution

  • Fix the bug: route the long-read alignment through _align_minimap2_preset (which redirects minimap2's SAM to disk), then append its records to the short SAM — one merged BAM per sample as intended.
  • Design decision: keep the merged-BAM / total-depth approach. One BAM per sample, CoverM once; because every sample is processed identically the relative cross-sample signal differential binning needs is preserved. Rejected the documented read-count-weighted-mean merge — it needs separate per-technology CoverM passes and a sample→(short_bam, long_bam) mapping for no benefit to relative coverage. The one real reason to revisit (per-technology read-identity filtering) is noted as future work.
  • Docs corrected to describe what the code does and why.

Tests

test_align_hybrid.py: the merge appends long records and doesn't duplicate the header; a regression guard for the discarded-stdout bug. 136 pass.

…tation

The bwa hybrid path was broken: _merge_long_reads_bwa ran minimap2 through the
_run helper, which captures and discards stdout, so the long-read SAM was never
written and the subsequent open(long.sam) raised FileNotFoundError. Hybrid
short+long samples under a bwa aligner therefore always failed.

- Route the long-read alignment through _align_minimap2_preset, which redirects
  minimap2's SAM to long.sam, then append its records (header skipped) to the
  short SAM — producing one merged BAM per sample as intended. Dropped the unused
  aligner_bin/samtools_bin params; minimap2 binary is now a parameter.
- Resolve the hybrid coverage design question: keep the merged-BAM total-depth
  approach (one BAM per sample, CoverM once; relative cross-sample signal
  preserved because every sample is processed identically). Reject the
  previously-documented read-count-weighted-mean merge, which needs separate
  per-technology CoverM passes for no benefit to relative coverage.
- CLAUDE.md corrected: merging is at the alignment stage, not "in coverage.py
  weighted by read count"; the rejected alternative and the one real reason to
  revisit it (per-technology identity filtering) are noted.

Tests: test_align_hybrid.py covers the merge (long records appended, header not
duplicated) and is a regression guard for the discarded-stdout bug. 136 pass.
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