Skip to content

Wasp consolidation - #137

Merged
Psy-Fer merged 3 commits into
mainfrom
wasp-consolidation
Jul 27, 2026
Merged

Wasp consolidation#137
Psy-Fer merged 3 commits into
mainfrom
wasp-consolidation

Conversation

@Psy-Fer

@Psy-Fer Psy-Fer commented Jul 27, 2026

Copy link
Copy Markdown
Collaborator

WASP allele-specific-mapping filter (--waspOutputMode SAMtag) — consolidated + STAR-faithful (closes #108)

Consolidates BenjaminDEMAILLE's WASP PR, with the two review-flagged divergences from real STAR fixed and the feature validated byte-for-byte against STAR 2.7.11b.

WASP (van de Geijn et al. 2015) removes reference-mapping bias: a read overlapping a heterozygous SNV is re-mapped with the allele swapped; if it no longer maps to the same locus, it's flagged. rustar emits STAR's vW (pass/fail code) plus opt-in vA/vG tags.

Closes #108.

Fixes vs the original port (verified against ReadAlign_waspMap.cpp)

1. Re-map used relaxed filters (STAR-rs quirk) → now uses the user's params unmodified.
The port's wasp_remap_params set out_filter_match_nmin = 0, out_filter_match_nmin_over_lread = 0.0, out_filter_multimap_score_range = 1, out_filter_multimap_nmax = 10. STAR's WASP re-map is waspRA = new ReadAlign(Pin,…) sharing the same P, running the normal mapOneRead()multMapSelect()mappedFilter(); a swapped read failing mappedFilter under the user's own thresholds becomes waspType=4. Relaxing the filters lets swapped reads pass WASP that STAR would reject. Fixed: wasp_remap_params returns params.clone() verbatim.

2. Multimapper vW semantics were per-locus → now keyed off the primary alignment.
STAR computes one waspType from trBest (the primary): if the primary overlaps ≥1 variant and the read multimaps → waspType=2 stamped on all of the read's records; if the primary overlaps no variant → no vW on any record (even if a secondary locus does). The port stamped vW:2 per-record only where that record's own locus overlapped a variant. Fixed for both SE and PE (vA/vG stay per-record, matching STAR's per-alignment variationAdjust).

Integration into the current pipeline

The PR was written against the old single-threaded loop; it's now wired into the pipelined SE + PE drivers — the VCF is loaded once per run into a shared read-only WaspContext, and annotate_records_se/_pe run per mapped read/pair in the align stage. The vW/vA/vG attribute flags also collided with the recently-landed GX/GN/nM (NMM) flags; WASP tags were moved to bits 12–14.

Validation (vs STAR 2.7.11b, 10k yeast SE + a 60-SNV het VCF over covered loci)

  • vW distribution byte-exact: rustar and STAR both 236 × vW:i:1, 59 × vW:i:2, 9 × vW:i:6.
  • Per-record: 302/304 identical (QNAME + POS + FLAG + vW). The 2 differences are known SE tie-break reads that the two tools map to different loci — each correctly gets vW:2 for its own mapping; not a WASP-logic difference.
  • No regression: default SE 8788/8926 unchanged (WASP is inert without --waspOutputMode SAMtag).
  • New test_wasp_samtag integration test (synthetic genome + planted het SNV → all 10 unique overlapping reads get vW:i:1).

Gate: 569 tests pass · clippy --all-targets 0 warnings · fmt clean.

Note: STAR requires --outSAMtype BAM with --waspOutputMode; rustar also accepts SAM output.

BenjaminDEMAILLE and others added 3 commits July 27, 2026 16:07
Port STAR's WASP filter (--waspOutputMode SAMtag, --varVCFfile) from STAR-rs
`crates/star-align/src/star_wasp.rs`. A uniquely-mapped read overlapping
heterozygous SNVs is re-mapped with every alternative-allele combination; if all
re-maps land on the identical locus it passes (vW:i:1), otherwise a failure code
(2..7) is reported. Emits vW, and vA/vG when requested in --outSAMattributes.

- src/wasp/mod.rs: load_vcf, wasp_type (re-map decision), wasp_variants (vG/vA),
  and record annotation. Works in base-code space; variant/read overlap is
  computed by walking the transcript CIGAR (same convention as build_md_tag), so
  it does not depend on the exon read-coordinate frame.
- src/params: add --waspOutputMode (None|SAMtag) and --varVCFfile, validation
  (SAMtag requires a VCF), and vW/vA/vG in --outSAMattributes.
- src/lib.rs: load the VCF once per run, re-map with a WASP-relaxed parameter set
  (match_nmin=0, multimap_score_range=1, multimap_nmax=10, matching STAR), and
  stamp vW/vA/vG onto the SAM records in the single-end path.

Paired-end WASP is a follow-up. See docs-old/dev/porting-from-star-rs.md.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Complete the WASP filter for paired-end reads, the documented follow-up to the
single-end port (3e84d97). Ports STAR-rs `wasp_type_pe` / `wasp_variants_pe`
into rustar-aligner's two-transcript-per-pair model.

- src/wasp/mod.rs: add wasp_variants_pe (combined vG/vA over mate1 then mate2,
  STAR's `mate1 ++ rc(mate2)` combined-transcript order), wasp_type_pe (single
  vW code: walk each mate's variants in its SAM frame, apply every allele
  combination, map back to forward mates, and re-map the pair via
  align_paired_read with the WASP-relaxed params; a combination passes only if
  exactly one both-mapped pair lands on the same exons for both mates), and
  annotate_records_pe (both mate records share vW/vA/vG; multimapped pairs
  overlapping variants get vW:i:2).
- src/lib.rs: build the WaspContext once in align_reads_paired_end and stamp
  vW/vA/vG onto the built pair records, mirroring the single-end path.

Gate green: cargo build, clippy -D warnings, fmt, 464 tests (2 new PE
variant-frame unit tests). Byte-level validation against native STAR via the
test/ harness is a separate step.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@Psy-Fer Psy-Fer self-assigned this Jul 27, 2026
@Psy-Fer
Psy-Fer enabled auto-merge (squash) July 27, 2026 06:39
@Psy-Fer
Psy-Fer merged commit b500bfc into main Jul 27, 2026
10 checks passed
@Psy-Fer
Psy-Fer deleted the wasp-consolidation branch July 27, 2026 06:43
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