Before you start
- You should have a sorted, indexed BAM ready; if not, work through the samtools survival kit first.
- Any term new? The Glossary has it.
Learning objectives
By the end of this lesson you will be able to: read the key columns of a SAM/BAM record, understand what the FLAG, MAPQ, and CIGAR fields tell you, and check the coverage (depth) at a position so you know whether to trust what you see.
Making a BAM file readable
You aligned your reads and got a BAM file. Open it with samtools view and it looks like a wall of numbers and letters. It is not random: each line is one read, and a handful of columns tell you everything you need. Learn those columns and a BAM stops being scary.
Practise right here
Every command box on this page has a Run button that sends it to a real Linux terminal in your browser, with a practice sample.bam already loaded (simulated single-end reads on a 10,000-base chromosome, so flagstat shows no paired reads). No install, no account.
1The columns that matter
Every aligned read is one row. These are the fields you will actually read:
| Column | What it tells you |
|---|---|
| QNAME | The read's name (same name on both mates of a pair) |
| FLAG | A code packing yes/no facts about the read (see below) |
| RNAME, POS | Which chromosome, and the 1-based position where the aligned part of the read starts |
| MAPQ | How confident the aligner is that the read is in the right place |
| CIGAR | How the read lines up: matches, insertions, deletions, clips |
# peek at a few reads (the header is hidden without -h)
samtools view sample.bam | head2FLAG: a yes/no checklist packed into one number
The FLAG looks like a meaningless number (like 99 or 147), but it is really a set of yes/no switches added together: is the read paired? did the pair map properly? is it unmapped? is it on the reverse strand? is it a duplicate? You rarely decode it by hand, you ask samtools.
# explain what a flag value means in plain English samtools flags 99 # -> PAIRED,PROPER_PAIR,MREVERSE,READ1 # count reads, broken down by flag (mapped, duplicates, etc.) samtools flagstat sample.bam
The flags you will meet mostThe useful handful
"Properly paired" means both mates mapped the way the aligner expected, a good sign. "Unmapped" reads did not align. "Duplicate" marks PCR/optical copies (from the markdup step). "Secondary" is an alternative placement for a read that could map to several places. "Supplementary" is different: it is one piece of a split read whose parts align to different places, for example across a structural-variant breakpoint. (BWA-MEM normally reports a read that fits several places as one record with MAPQ 0, not as secondary records.) flagstat totals all of these for you.
3MAPQ: can you trust where the read landed?
MAPQ is the mapping quality: higher means the aligner is more sure the read belongs exactly here. A MAPQ near 0 is a warning, it usually means the read maps equally well to several places (a repeat), so you cannot trust its position. Many analyses filter to keep only confidently placed reads, for example samtools view -q 20.
4CIGAR: how the read lines up
The CIGAR string is a tiny recipe for how the read matches the reference. The common letters:
| Letter | Meaning |
|---|---|
| M | aligned to the reference (a match or a mismatch) |
| I | insertion: bases in the read that are not in the reference |
| D | deletion: reference bases missing from the read |
| S | soft-clip: read ends that did not align (often low quality) |
| N | skipped region (in RNA-seq, a read spanning an intron) |
| H | hard-clip: read ends removed from the stored sequence (common in split reads) |
So 100M means all 100 bases aligned with no gaps or clipping (mismatches are still possible; the NM tag counts them); 50M2D48M means 50 aligned, then 2 reference bases are deleted, then 48 more aligned; 10S90M means the first 10 bases were soft-clipped (kept in the read but not aligned) and 90 aligned.
5Coverage: how many reads back up a position
Coverage (or depth) is simply how many reads stack over a given position. It is the number that tells you whether to believe a variant: one read suggesting a change is noise; thirty good-quality reads agreeing is convincing, as long as they are not duplicates and map confidently (good MAPQ). Always sanity-check the depth before trusting a call.
# per-position depth, and a quick coverage summary per chromosome
samtools depth sample.bam | head
samtools coverage sample.bamCheck your understanding
samtools flags decodes it into plain English.N usually mean in RNA-seq?10S90M. What happened?Sources & further reading
- Li H, Handsaker B, Wysoker A, et al. The Sequence Alignment/Map format and SAMtools. Bioinformatics 25: 2078-2079, 2009. (FLAG, MAPQ and CIGAR) doi:10.1093/bioinformatics/btp352
- Danecek P, Bonfield JK, Liddle J, et al. Twelve years of SAMtools and BCFtools. GigaScience 10: giab008, 2021. doi:10.1093/gigascience/giab008
The official SAM/BAM format specification is the SAMv1 spec.
Last reviewed: October 2026.
Variant calling: from FASTQ to VCF →
Practice terminal powered by sandbox.bio (runs in your browser; your commands stay on your computer).