Skip to main content
v2026.11,986 entries · CC-BY 4.0

samtools mpileup: Syntax, Output Symbols and Defaults

Run samtools mpileup on a region, read the symbols in the output, and see which defaults (Q13, depth 8000) differ from samtools depth.

Written and maintained by CASRAI Editorial Board

Published

On this page

samtools mpileup reads one or more coordinate-sorted BAM files and writes a textual pileup: one line per reference position, showing how many reads cover it, which bases those reads carry and their base qualities. It does not call variants and does not write VCF. For VCF or BCF output the samtools manual points you to bcftools mpileup instead, which is covered in the bcftools guide.

What samtools mpileup is used for in research

A pileup is the position-by-position view of an alignment. Where a BAM file stores each read as one record, mpileup turns the data on its side so that each reference coordinate becomes a row. That makes it useful for checking the evidence behind a single locus, counting alleles at a site, inspecting low-coverage regions, and feeding simple downstream scripts that parse text.

The manual describes the command as generating a textual pileup for one or multiple BAM files. Reads are grouped into samples by the SM field of the @RG header lines; if no read-group information is present, each input file is treated as its own sample.

samtools mpileup or bcftools mpileup?

The two commands share a name and are routinely confused. The samtools command produces the text pileup described on this page. The bcftools command produces genotype likelihoods as VCF/BCF and is the route into variant calling. If your goal is a variant call set, use bcftools mpileup. If your goal is to read, count or filter evidence at specific positions, or to feed a text parser, use samtools mpileup.

If you only need a coverage number per position, samtools depth is a lighter alternative, but its defaults differ from mpileup in ways that change the numbers; see the comparison further down and the broader discussion of depth versus breadth of coverage.

Install or access samtools

samtools is distributed from the HTSlib project site. At the time of reading, the download page lists samtools-1.25 as the current source release, and the mpileup manual page on the same site is the page for that release. The download page gives the standard source build:

  1. Unpack the source release and enter the directory, for example cd samtools-1.x.
  2. Run ./configure --prefix=/where/to/install.
  3. Run make, then make install.
  4. Add the install location to your path: export PATH=/where/to/install/bin:$PATH.

The source packages include their own copy of HTSlib, and the INSTALL file in the package has the details for other configurations. Use the manual that matches your installed version: run samtools mpileup without arguments to see the usage text for the build on your machine, because options and defaults have changed between releases.

Step-by-step: run samtools mpileup on a region

The synopsis in the manual is:

samtools mpileup [-EB] [-C capQcoef] [-r reg] [-f in.fa] [-l list] [-Q minBaseQ] [-q minMapQ] in.bam [in2.bam [...]]

  1. Index the alignment file. The -r region option needs a BAM index. See the guide to the BAM index (.bai) file for what the index contains. Create one with samtools index in.bam.
  2. Index the reference, if you will pass one. The -f option takes a reference FASTA that has been indexed with faidx (it may be bgzip-compressed). Create the index with samtools faidx ref.fasta. Supplying the reference does two things: the third output column shows the real reference base, and base alignment quality (BAQ) adjustment is enabled.
  3. Run the command on a region. The example given in the manual is: samtools mpileup -f ref.fasta -r chr3:1,000-2,000 in1.bam in2.bam. This writes the pileup for chr3 positions 1,000 to 2,000 across two BAM files, grouped by sample.
  4. Set the quality thresholds you intend to use. Add -q for the minimum mapping quality and -Q for the minimum base quality, for example -q 20 -Q 20. State these values in any methods section, because the defaults are not zero for base quality (see below).
  5. Write to a file. Use -o FILE to write the pileup to a file instead of the terminal.

To restrict the run to a set of positions rather than a single region, use -l (also written --positions) with a BED file or a position list. If you give both -r and -l, the two are intersected. To pass many BAM files, list them in a file and give it with -b (--bam-list).

Output and how to read it

Each output line has at least three fixed columns, then a block of columns for every input BAM file.

  1. The reference sequence (chromosome) name.
  2. The 1-based position.
  3. The reference base. If you did not pass -f, this is N on every line.

Then, for each input file: the read depth; the read bases; the base qualities as ASCII characters; and, only when requested with -s, the mapping qualities. Further optional columns appear if you ask for read positions (-O), extra read fields (--output-extra), 5′-to-3′ positions or tag values. Columns with nothing to report are written as a single asterisk.

The read-bases column

The second block is where most readers get stuck. The manual defines each symbol:

Symbol Meaning
. Base matches the reference, forward strand
, Base matches the reference, reverse strand
A C G T N Mismatch on the forward strand
a c g t n Mismatch on the reverse strand
> and < Reference skip (CIGAR N) on the forward and reverse strand
* Deleted base (CIGAR D); by default used for both strands
# Deleted base on the reverse strand, only with --reverse-del
^ Start of a read; the next character encodes the mapping quality
$ End of a read
+<len><seq> Insertion of that length and sequence after this base
-<len><seq> Deletion of that length and sequence after this base; later lines show *

Base quality characters run from ! to ~. To get the numeric quality, take the ASCII code of the character and subtract 33.

A constructed line, read from the symbol rules

The line below is an illustrative construction built only from the symbol rules above, not output from a real dataset:

chr3 1000 A 4 .,.^F. IIHI

The columns are chromosome chr3, position 1000, reference base A, depth 4, then four read bases and four quality characters. The read-bases column shows a forward match, a reverse match, a forward match, and a fourth read that starts here (^F) and matches the reference on the forward strand. The qualities I, I, H and I convert to 40, 40, 39 and 40 after subtracting 33. The number of base symbols equals the depth because the ^ marker and its following quality character are not counted as reads.

Options that change what you see

Most surprises come from filters that act before any line is written. These are the defaults stated in the manual:

  • Minimum base quality (-Q, --min-BQ): 13. Bases below this are not counted.
  • Minimum mapping quality (-q, --min-MQ): 0.
  • Maximum depth (-d, --max-depth): 8000, applied per input file. Setting 0 removes the limit.
  • Excluded read flags (--ff, --excl-flags): SECONDARY, QCFAIL and DUP. The option replaces the default list rather than adding to it, so if you set it you must restate everything you still want excluded. For the meaning of each flag, see decoding SAM flags.
  • Overlap removal: on by default, so the overlapping part of a read pair is not double counted. Turn it off with -x (--ignore-overlaps-removal).
  • Orphan reads (-A): not counted unless you ask for them.
  • BAQ: computed when a reference is supplied. -B (--no-BAQ) disables it and -E (--redo-BAQ) recomputes it.
  • Mapping quality adjustment (-C): 0, meaning disabled.

Options that change the output text include:

  • -a prints all positions including those with zero depth, and -aa also prints reference sequences that no read used.
  • -s adds the mapping quality column; -O adds the 1-based position within the read.
  • --output-QNAME and --output-extra add read name and other fields.
  • -M (--output-mods) reports base modifications, for example in the form C[+m179+h40].
  • --no-output-ins, --no-output-del and --no-output-ends shorten the read-bases column by dropping insertion detail, deletion detail, or the ^ and $ markers.
  • --output-empty changes the placeholder used for empty columns (the default is an asterisk).

samtools mpileup versus samtools depth

Both commands report coverage, and it is common to assume they agree. The samtools depth manual lists the differences in a caveats section; they are compiled in the data table below. The practical consequence is that the same BAM file can give two different depth values at the same position unless you align the options. The quality options are the sharpest trap: the meanings of -q and -Q are swapped between the two commands, so copying a filter from one command to the other silently filters on the wrong quantity.

Choose mpileup when you need the bases, qualities or indels at each position, or when BAQ and overlap handling matter. Choose depth when you only need a per-position count and want a simple, fast summary; it also offers -a, a BED restriction with -b, a region with -r, a header line with -H and a deletion-counting switch -J.

Troubleshooting

The reference column shows N on every line

You did not pass -f. The manual states that without a reference the third column is N throughout. Supply the faidx-indexed FASTA. Doing so also enables BAQ.

The region option fails or returns nothing

The -r option needs an index on the BAM file. Create it with samtools index and check that the contig name in your region exactly matches the name in the BAM header. Remember that -r and -l intersect when used together.

Positions are missing from the output

Without -a, positions with zero depth after filtering are not printed. Add -a for every position in the region, or -aa to also include reference sequences no read touched.

Depth never exceeds 8000

The default --max-depth is 8000 per input file. In very deep data, such as amplicon or targeted panels, set -d 0 to remove the cap or choose a higher value deliberately.

Depth is lower than expected

Check the filters in order: base quality 13, secondary, QC-fail and duplicate reads excluded, overlap removal, and orphan reads not counted. If you changed --ff, remember that it replaced the default list. A depth comparison with another tool is only meaningful once these settings match.

Deletions look different between tools

mpileup shows a deleted base as * and counts it. samtools depth ignores deletions unless you give -J. Use --reverse-del in mpileup if you want strand-specific deletion symbols (# for reverse-strand deletions).

Free alternatives

Three tools overlap with samtools mpileup. All are open documentation sources; the table states only what each project’s own manual says.

Tool Output Use it when
samtools depth Per-position depth, one column per input You only need counts and accept different defaults (quality 0, no BAQ, no overlap removal)
bcftools mpileup VCF/BCF genotype likelihoods You want variant calling rather than text evidence; see the bcftools guide
pysam AlignmentFile.pileup() Python PileupColumn objects You work in Python and want programmatic access to each column

Python: pysam pileup

The pysam documentation describes AlignmentFile.pileup(contig, start, stop, region, reference, end, **kwargs). Its stepper argument accepts all, nofilter or samtools, where the samtools stepper applies the same filtering and processing as the samtools pileup. The documented defaults are:

  • max_depth: 8000
  • min_base_quality: 13
  • min_mapping_quality: 0
  • ignore_overlaps: True
  • ignore_orphans: True
  • compute_baq: True
  • flag_filter: UNMAP, SECONDARY, QCFAIL and DUP

Each PileupColumn exposes pileups, nsegments, reference_pos (0-based) and reference_name; each PileupRead exposes alignment, indel, is_del, is_refskip and query_position. To reproduce the samtools mpileup text format with get_query_sequences(), the documentation says to set mark_matches, mark_ends and add_indels all to True. Note that the pysam position is 0-based while the mpileup text position is 1-based.

Frequently asked questions

What does samtools mpileup do?

It generates a textual pileup for one or more BAM files: one line per reference position with the depth, the read bases and the base qualities of the reads covering it.

Does samtools mpileup call variants?

No. It writes text. The manual directs you to bcftools mpileup when you want VCF or BCF output.

What is the default minimum base quality?

13, set with -Q. The default minimum mapping quality set with -q is 0.

Why is my depth capped at 8000?

The default --max-depth is 8000 per input file. Use -d 0 to remove the limit.

How do I convert a quality character to a number?

Take the ASCII value of the character and subtract 33.

How is samtools mpileup different from samtools depth?

Defaults differ in deletion handling, quality thresholds, overlap removal, depth limit and BAQ, and the -q and -Q meanings are swapped. The data table above lists each difference.

Sources

Data: samtools mpileup versus samtools depth: default behaviour

Compares how samtools mpileup and samtools depth differ by default for the same BAM input, compiled from the HTSlib samtools-mpileup and samtools-depth manual pages (samtools 1.25 documentation).

samtools mpileup versus samtools depth: default behaviour
Behavioursamtools mpileupsamtools depth
Deleted basesAlways counted; shown as * in the read-bases columnIgnored by default; counted only with -J
Meaning of -q and -Q-q is minimum mapping quality, -Q is minimum base qualityThe meanings are swapped relative to mpileup
Default minimum qualityBase quality 13 (mapping quality 0)0
Overlapping read pairsOverlap removal on by default (disable with -x)Overlap removal off by default
Maximum depth8000 per input file by default (0 removes the limit)No depth limit
Base alignment quality (BAQ)Used when a reference is supplied with -fNever used

Sources

Compiled by CASRAI from the sources above. Free to reuse under CC BY 4.0 with attribution.

Follow CASRAI

Research-administration guidance, standards updates and independent tool reviews.

Ask CASRAI · full access

Ask about samtools mpileup: Syntax, Output Symbols and Defaults

Full access: large monthly usage, up to 10 source passages behind each answer, and MCP and API access for Claude Code, Codex and other CLIs. Cancel any time.

An AI assistant for research: funder rules, compliance, methods and publishing. It links the sources behind its answers and labels answers that come from a web search.

Answers draw on CASRAI's guides and dictionary plus the federal and funder documents we index: Federal Register, Grants.gov, Regulations.gov and UKRI.

Works on this site and inside Claude, Cursor and the AI tools you already use.

Everything CASRAI publishes — this page, the dictionary, the guides and the news — stays open to read, with no account and no card.

Referenced across the research world

University of Cambridge logoColumbia University logoCrossref logoUniversity of Edinburgh logoHarvard University logoUniversity of Oxford logoPrinceton University logoStanford School of Medicine logoUniversity College London logoORCID logoUniversity of Cambridge logoColumbia University logoCrossref logoUniversity of Edinburgh logoHarvard University logoUniversity of Oxford logoPrinceton University logoStanford School of Medicine logoUniversity College London logoORCID logo
  • University of Cambridge logo
  • Columbia University logo
  • Crossref logo
  • University of Edinburgh logo
  • Harvard University logo
  • University of Oxford logo
  • Princeton University logo
  • Stanford School of Medicine logo
  • University College London logo
  • ORCID logo

View CASRAI adoption →