Skip to content

fix(align): write multimappers in STAR's window order, primary is trBest - #321

Closed
BenjaminDEMAILLE wants to merge 2 commits into
fix/transcriptome-bam-recordsfrom
fix/multimapper-window-order
Closed

BenjaminDEMAILLE wants to merge 2 commits into
fix/transcriptome-bam-recordsfrom
fix/multimapper-window-order

Conversation

@BenjaminDEMAILLE

Copy link
Copy Markdown
Contributor

Summary

STAR writes a multimapper's alignments in trMult order (the window order) and flags trBest as the primary: the best score, then the shortest genomic span, then the first window (ReadAlign_stitchPieces.cpp, ReadAlign_multMapSelect.cpp, default --outMultimapperOrder Old_2.4). The primary is therefore not always HI:1. With --outSAMmultNmax set, STAR first swaps the best-scoring alignments to the top (in window order) and the first one is the primary.

rustar sorted the alignments by score, junction count and coordinate. The set of alignments was right, but the HI order and the choice of primary differed from STAR on many multimappers (the NH-aware parity check counted these as ties, so they did not show).

This PR:

  • adds star_mult_map_order (SE and PE): score range, then STAR's order and primary; star_order becomes the rank in STAR's output order, the primary stays at index 0 for the downstream consumers (filters, stats, Solo);
  • writes the genomic SAM/BAM records in star_order, with HI from that order and the SECONDARY flag on every alignment but the primary;
  • keeps the --outMultimapperOrder Random path as it was.

Stacked on #315 (it uses the star_order rank that PR introduces).

Measured

Record for record (flag, position, MAPQ, CIGAR, mate fields, NH, HI, AS, nM, in output order) against STAR 2.7.11b:

run before after
yeast 200k pairs, PE 332,462 / 337,034 mates identical 337,034 / 337,034
yeast 200k reads, SE 175,196 / 178,103 178,103 / 178,103

Human (GRCh38-2024-A index, 19,556 multimapping reads from pbmc_1k_v3): STAR 2.7.11b and STAR 2.7.2a give the same output; rustar now matches 19,555 of them (1,585 before). The one left has its two alignments in the same window, recorded in a different order.

Test plan

  • cargo test --release, cargo clippy --all-targets -D warnings, cargo fmt --check.
  • New unit tests for the order and the --outSAMmultNmax swap.
  • Strict per-record comparison above (yeast PE/SE vs STAR 2.7.11b, human multimappers vs STAR 2.7.2a and 2.7.11b).

🤖 Generated with Claude Code

BenjaminDEMAILLE and others added 2 commits October 10, 2026 07:06
STAR (2.7.2a and 2.7.11b alike) writes a multimapper's alignments in trMult
order (window order) and flags trBest as the primary: the best score, then
the shortest genomic span, then the first window (ReadAlign_stitchPieces.cpp,
ReadAlign_multMapSelect.cpp). The primary is not always HI:1. With
--outSAMmultNmax set, the best-scoring alignments are swapped to the top in
window order and the first one is the primary.

rustar sorted the alignments by score, junction count and coordinate, so the
HI order and the primary differed from STAR on most human multimappers.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Psy-Fer added a commit that referenced this pull request Oct 12, 2026
…e; (#326)

A1 alignment core: Ben's stack #295→#321 with STAR's window score gate; sparse-SA seed search; STAR multimapper order
@Psy-Fer

Psy-Fer commented Oct 13, 2026

Copy link
Copy Markdown
Collaborator

Closed by #326 (A1)

@Psy-Fer Psy-Fer closed this Oct 13, 2026
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