Use when expanding BWA `XA:Z` alternate-alignment tags in SAM records into separate secondary SAM alignments for downstream tools.
Tiny Perl filter for BWA SAM output. For every alignment line containing XA:Z:..., it prints the original line unchanged and appends one extra SAM record per alternate hit, marking those records as secondary alignments and copying the mismatch count into NM:i.
xa2multi.pl [input.sam]/home/vimalinx/miniforge3/envs/bio/bin/xa2multi.plXA:Z tags into explicit SAM recordsXA optional fields# Expand XA-tagged alignments from a SAM file
xa2multi.pl input.sam > expanded.sam
# Stream from stdin into another SAM/BAM step
samtools view -h input.bam | xa2multi.pl | samtools view -b -o expanded.bam
Observed in local testing:
primary line: unchanged
alternate hits: emitted with flags 256 / 272 and NM:i copied from the XA field
XA:Z tags.xa2multi.pl before downstream tools that expect each alignment as its own SAM record.-h or --version; it simply reads stdin or filenames via Perl's <> operator.XA:Z:. All other lines, including SAM headers, are printed unchanged.0x100 set, MAPQ forced to 0, and TLEN forced to 0.# FIXME: TLEN/ISIZE is not calculated!, so do not treat inferred template length as trustworthy after expansion.