
Quick answer: Read mapping (read alignment) takes the millions of short sequences a sequencer produced and determines where each one originates in a known reference genome. Modern mappers do this with a fast seed-and-extend strategy — find exact short matches first, then score the alignment around them — rather than comparing every read against every position. The output is a SAM/BAM file where every read carries its position, a mapping-quality score, and flags describing how it aligned; filtering and trusting those fields is where most downstream results quietly succeed or fail.
Companion to the NGS quality control and variant calling guides on this blog: mapping is the middle step that both of those depend on.
Table of Contents
What mapping is actually answering
After sequencing you hold a bag of reads: strings of 50–300 bases with no coordinates attached. Every downstream analysis — variant calling, differential expression, ChIP-seq peak calling — needs to know where each read came from. Mapping answers one question per read: given this sequence, which location(s) in the reference are the most plausible origin, and how confident am I?
That “how confident” matters more than beginners expect. A read that maps equally well to ten places (repeats, paralogs, segmental duplications) carries almost no information, yet a naive analysis counts it like any other. Mapping quality is the field’s mechanism for separating evidence from noise.
Two clarifications on vocabulary:
- Alignment vs mapping. Strictly, alignment is the alignment-scoring problem (edit distances, substitution matrices); mapping is the genome-scale search that assigns coordinates. Tools do both; the community uses the words interchangeably.
- Reference-based, not de novo. Mapping presumes a reference genome exists for the species. When none exists, reads are assembled first instead — the territory of the genome assembly article.
Why exact search is impossible, and what seed-and-extend does
A human genome is 3 billion positions; a lane of sequencing produces hundreds of millions of reads. Testing every read against every position with dynamic programming is arithmetically out of the question. The trick every modern mapper shares:
- Seed. Chop the read into short exact matches (or near-exact ones) and find where those short strings occur in the reference, using an FM-index or hash table — the same family of index ideas that made database search fast, rebuilt to span an entire genome.
- Extend. Around each seed hit, run a local alignment (banded dynamic programming) that tolerates mismatches, indels, and sequencing errors, and score the resulting candidate.
- Rank. Keep the best-scoring location(s); report alternatives when several candidates score comparably.
The dominant tools encode this pattern differently. BWA-MEM (and its successor bwa-mem2) uses short exact seeds then long-gap extension, making it the default for 70–250 bp genomic reads. Bowtie2 uses a different index (FMD-index) with a configurable seed strategy and is tuned for shorter reads and offers explicit end-to-end or local modes. HISAT2 adds a graph of known variants into the index so reads spanning known SNPs map more accurately — the reason it is the RNA-seq default for splice-aware alignment alongside STAR, which seeds from the read’s split segments to jump across introns.
Choosing a mapper is rarely the hard part: the defaults are good. Knowing what the outputs mean is where analysis quality lives.
Reading a SAM/BAM record: the fields that matter
Mappers write SAM (text) or BAM (compressed binary; samtools view converts between them). Each record is one read, with a fixed core:
- QNAME — read identifier.
- FLAG — a single integer encoding paired-end status, strand, whether the read is unmapped, secondary, supplementary, duplicate, and more. Learn to decompose it (
flag 99= paired, proper pair, mate reverse, first in pair); it answers most “why is this read weird” questions. - RNAME / POS — reference sequence and 1-based start position.
- MAPQ — mapping quality, −10·log₁₀(P(wrong)). MAPQ 60 means roughly 1-in-1,000,000 confidence in most conventions; MAPQ 0 means the read could equally live elsewhere. Many pipelines hard-filter below 20 or 30.
- CIGAR — the run-length encoding of matches, mismatches, insertions and deletions (
45M2I51M). It tells you the alignment’s shape, including soft-clips (S) at the ends, which often mark adapter contamination or structural breakpoints. - Tags — most usefully
NM(edit distance from reference),MD(mismatch string),AS(alignment score), and for RNA-seq,XS(second-best strand score, the splice-site evidence).
A BAM is then sorted by coordinate and indexed (.bai or .csi), which is what lets tools — and genome browsers like IGV — jump to any region instantly instead of rescanning the file.
The filters between a raw BAM and a trustworthy one
Raw alignments are a starting inventory, not analysis-ready data. The standard conditioning steps:
- Sort and index.
samtools sort, thensamtools index. Everything downstream assumes this. - Mark duplicates. PCR or optical duplicates produce identical start/end coordinates from distinct molecules; left in, they inflate depth and fake allele fractions.
samtools markdupor Picard marks them (flags them rather than deleting, so you can reverse the decision). - Filter by MAPQ and flags. Remove unmapped, secondary, and supplementary records for simple analyses; keep them for structural-variant or splice-aware work where they are the signal. A typical variant-calling prefilter:
samtools view -b -q 20 -F 0x904. - Check the numbers.
samtools flagstat(mapping rate, proper-pair rate),samtools stats(insert-size distribution, mismatch rate),samtools idxstats(per-chromosome depth). A mapping rate that fell from 97% to 78% versus the last run is a contamination, adapter, or wrong-reference problem that no downstream test will fix. - Recalibration (GATK-style). Base-quality recalibration rewrites quality scores using known-sites resources — optional for exploratory work, standard in clinical-grade germline pipelines.
Where mapping quietly goes wrong
- Wrong reference build. GRCh37 vs GRCh38 vs a custom genome: reads still map (with depressed rates and shifted coordinates), producing plausible-looking garbage. Verify the reference FASTA matches your annotation and known-sites files before anything else.
- Multi-mapping reads treated as real. Repeat-rich regions, rRNA, and paralogous gene families generate MAPQ-0 pileups. Deciding whether to keep or discard them is a per-analysis choice: discard for variant calling, often keep (with care) for quantification.
- RNA-seq mapped to the genome without splice awareness. Reads spanning junctions get soft-clipped or forced into mismatches, and junction-spanning genes lose most of their counts. Use a splice-aware aligner or a pseudoaligner such as Salmon for quantification-only work.
- Paired-end expectations violated. Anomalous insert sizes or wrong-orientation pairs are the standard evidence for structural variants — but in a low-quality library they are just noise, and tools that assume proper pairs will drop half the data.
- Duplicates removed too eagerly. In low-input libraries (single-cell, amplicon), identical coordinates can be genuine independent molecules; aggressive duplicate removal deletes real depth. Mark, measure, then decide.
What a completed mapping step should hand over
A defensible mapping deliverable is a coordinate-sorted, indexed BAM plus its QC: mapping rate, proper-pair rate, coverage distribution, duplication rate, and the exact reference and mapper versions used. Anything less — an unsorted BAM with no stats file — forces the next person (including future you) to redo the step to trust the analysis.
Key takeaways
- Mapping assigns each read to a reference coordinate with a confidence score; it is the hinge between raw sequencing and every downstream analysis.
- Seed-and-extend over an FM-index is why genome-scale alignment is seconds instead of years; BWA-MEM, Bowtie2, HISAT2, and STAR are variations on that idea.
- The BAM fields worth knowing by heart are FLAG, MAPQ, CIGAR, and NM — they explain most anomalies you will ever debug.
- Raw BAMs need sorting, indexing, duplicate marking, MAPQ filtering, and a QC summary before they are analysis-ready.
- Wrong-reference builds, multi-mapping reads, and splice-unaware RNA-seq alignment are the classic silent failures.
- Mapping QC numbers belong in the methods section of any report; a mapping rate without context is not a result.
Challenge
Take a public BAM (the 1000 Genomes or ENCODE portals host them) and open it in IGV alongside its reference. Find one read with MAPQ 0, decompose its FLAG by hand, and locate its CIGAR soft-clips. Then run samtools flagstat and samtools stats and see whether the numbers agree with what you observed visually. The loop of “look at the pileup, check the statistic, explain the discrepancy” is the working skill of every alignment QC session.
Want guided practice turning alignment QC into a defensible analysis? Ampersand Academy offers one-to-one mentoring in bioinformatics — part of Mahadhi, a development and digital marketing company.
FAQ
What is the difference between SAM and BAM?
SAM is the plain-text alignment format; BAM is the same content gzip-compressed and binary-indexed. They are interchangeable via samtools view; virtually all pipelines store BAM for size and speed, with a .bai index alongside for random access.
What does mapping quality (MAPQ) actually mean?
It is a phred-scaled estimate that the read is placed in the wrong location: MAPQ 20 implies roughly a 1-in-100 chance of misplacement, MAPQ 60 roughly 1-in-1,000,000. Values of 0 mean the read matches multiple locations equally well, so its position carries no information.
Should I remove secondary and supplementary alignments?
For variant calling and simple quantification, yes — keep primary alignments only. For structural-variant detection, splice-aware analysis, or long-read workflows, secondary and supplementary records are the evidence itself and must be kept.
BWA-MEM or Bowtie2 — which should I use?
For standard 100 bp+ paired-end genomic DNA, BWA-MEM2 is the default choice. Bowtie2 remains excellent for short reads and for its explicit end-to-end vs local modes. RNA-seq needs a splice-aware option (HISAT2 or STAR) rather than either.
Does duplicate marking delete my reads?
No. It sets a flag on records with identical coordinates, so the reads stay in the BAM and the decision is reversible. Removal (if wanted) happens later as an explicit filtering step, which matters in low-input libraries where duplicates can be real molecules.
Why did my mapping rate drop after switching references?
A mismatched reference build (or an unmasked contaminant sequence) reduces exact seed matches and MAPQ, even though many reads still place somewhere. Always confirm the FASTA build matches the annotation and known-sites resources before comparing mapping rates across runs.
How does read mapping differ from de novo assembly?
Mapping places reads against an existing reference; assembly reconstructs a genome without one by overlapping reads into contigs. Use mapping when a trustworthy reference exists, assembly when it does not — or when divergence from the reference is too great for reliable placement.
Last updated on · Written by Dinesh Kumar R

