← Về thư mục
📄 / / profiles / r-and-d / raw_evidence / OpenAI4S / skills / bioskills / bio-read-alignment-bwa-alignment / references / usage-guide.md

BWA-MEM2 Alignment - Usage Guide

Overview

bwa-mem2 is the maintained, architecture-aware reimplementation of BWA-MEM: near-identical output, ~1.5-3x faster, ~2x the memory, and a different index format. It is the standard DNA short-read aligner for WGS, WES, and germline/somatic variant-calling pipelines. The aligner itself is the easy part of the job; this skill emphasizes the decisions that actually determine whether downstream variant calling works -- read groups, the reference analysis set (decoy/ALT), the -M/-Y output flags, and the strict collate/fixmate/sort/markdup ordering.

Prerequisites

conda install -c bioconda bwa-mem2 bwa samtools

Quick Start

Tell your AI agent what you want to do: - "Align my paired-end WGS reads to the human reference with read groups for GATK" - "Build a bwa-mem2 index for my reference genome" - "Align and mark duplicates in one streaming pipeline" - "Map reads for structural-variant calling with soft-clipped supplementary alignments" - "Run bwa-mem2 with reproducible output across thread counts"

Example Prompts

Basic alignment

"Align reads_R1.fq.gz and reads_R2.fq.gz to reference.fa with bwa-mem2, add read groups for sample NA12878, and output a coordinate-sorted, indexed BAM."

WGS / variant-calling pipeline

"Run a complete WGS alignment with duplicate marking for sample NA12878, then tell me which QC numbers to check before calling variants."

Structural variants

"Map my WGS reads for split-read SV detection -- which flags keep the supplementary alignments that Manta and Delly need?"

Reproducibility and reference

"Align with reproducible results across different thread counts, and confirm I am mapping to a decoy-containing GRCh38 analysis set."

Ancient DNA

"I have short, damaged ancient-DNA reads with a low mapping rate using bwa mem -- what should I use instead and why?"

What the Agent Will Do

  1. Confirm the reference analysis set (decoy/ALT) is appropriate for the downstream caller and index it with bwa-mem2 index if needed.
  2. Align with read groups (SM/ID/PL/LB) injected at mapping time, streaming to a coordinate-sorted BAM to avoid a large intermediate SAM.
  3. For SV pipelines, add -Y (and never -M) so supplementary split reads keep their full sequence.
  4. Mark duplicates in the strict order collate -> fixmate -m -> sort -> markdup, skipping dedup entirely for amplicon/PCR data.
  5. Add -K 100000000 when bit-stable, thread-count-invariant output is required.
  6. Run the QC gate (alignment rate, properly-paired, duplicate/complexity) before handing the BAM to a variant caller, routing the stats and their interpretation to alignment-files/bam-statistics.

Read Group Fields

Field Description Example
ID unique read-group id; the BQSR error-model unit flowcell.lane
SM sample name; variant callers group by SM NA12878
PL platform; affects error modeling ILLUMINA
LB library; MarkDuplicates dedups WITHIN a library lib1
PU platform unit (optional but recommended) flowcell.lane.barcode

Tips