Skip to content

Error probability from Phred quality, and expected errors per read

ngs_phred_quality

Converts between Phred qualities and error probabilities, with the expected errors per read.

Runs
On the server
Level
Checked against a reference: Biopython 1.88's FASTQ decoders on the offsets and ranges (the outside comparison), with the SAM v1.6 Phred scale at 60 digits in a script of our own
Ask your assistant

What it is

Converts between Phred quality and base-call error probability (Q = -10 log10 p), with expected errors per read. Use when reading qualities, a FASTQ qualityString with its encoding, or errorProbabilities: each gives per-base values and the expected errors Σp, the mean error and its quality. Not for depth from a read count: use `ngs_coverage_depth`. The encoding is required, never inferred; refuses Q above 93 and characters outside the encoding. A qualityString is at most 3000 characters (the reply limit); split a longer read and add the parts' expectedErrors.

Field: Sequencing and genomics.

What it does

You give

  • qualities: Per-base Phred qualities. Optional.
  • errorProbabilities: Per-base error probabilities. Optional.
  • qualityString: A FASTQ quality line, one character per base. Leading and trailing white space is removed before the pattern is checked. Optional.
  • encoding: The quality string's encoding: phred+33 (Sanger, Illumina 1.8+) or phred+64 (Illumina 1.3 to 1.7). Required with a quality string. Optional.

No request is recorded for this tool.

Limits

  • Research arithmetic for planning sequencing libraries and runs and for genomic coordinate bookkeeping; it does arithmetic on the inputs it receives, and does not measure the library, the instrument or the data.
  • Expected errors Σp are exact only if the reported qualities are calibrated error probabilities; binned or uncalibrated scores make it an estimate, and no distribution of the error count is given.
  • The mean of the Qs overstates quality relative to the quality of the mean error (they agree only when every Q is the same).
  • Solexa scores are not decoded; the encoding is never inferred from the characters.
  • A quality string longer than 3,000 characters is declined, not truncated, so a longer read gets no per-base figures from one call; Σp is additive, so the expected errors of a split read are the sum over its parts.
  • Every computed number a reply returns, other than an integer or an exact decimal, is rounded once to 12 significant figures: to the nearest, a change of at most 5 × 10⁻¹² of its value, except that a lower bound is rounded down and an upper bound up, a change of less than 1 × 10⁻¹¹; the method computes, and decides any pass or fail, on the unrounded value.

It will not answer when

  • a given quality is above the top of what Sanger (phred+33) FASTQ can encode.
  • a character of the quality string lies outside the stated encoding, often data in the other encoding.
Every input, with its units4 inputs
  • qualities: Per-base Phred qualities. Optional.
  • errorProbabilities: Per-base error probabilities. Optional.
  • qualityString: A FASTQ quality line, one character per base. Leading and trailing white space is removed before the pattern is checked. Optional.
  • encoding: The quality string's encoding: phred+33 (Sanger, Illumina 1.8+) or phred+64 (Illumina 1.3 to 1.7). Required with a quality string. Optional.
Every refusal, with its code2 refusals
CodeWhen
QUALITY_ABOVE_RANGEa given quality is above the top of what Sanger (phred+33) FASTQ can encode.
CHARACTER_OUTSIDE_ENCODINGa character of the quality string lies outside the stated encoding, often data in the other encoding.

The calculation

The method's equations, constants and worked example.

Phred quality and base-call error probability, with expected errors per readngs-phred-quality@2.0.0

Equation 1

p=10^(-Q/10)
Q=-10log10p

Q rounded = floor(Q + 1/2)

within the phred+33 range when Q rounded <= 93 (126 - 33): SAMv1 §1.2 defines Q = -10 log10 p "rounded to the closest integer" and §1.4 gives QUAL as ASCII Q + 33 in [!-~]

the inverse p = 10^(-Q/10) follows from the definition, and halves upward is the record's choice, since the source states no tie rule

SymbolMeaning
pbase-call error probability
QPhred quality, phred

Source 1.

Equation 2

Q = ASCII code - offset, offset 33 (phred+33) or 64 (phred+64)

a code below the offset or above 126 is outside the encoding (Cock et al. 2010)

the rest of this item is the record's, not the source's: the kit trims whitespace from both ends of the string before any check, so a space, tab or line break at either end is dropped and never decoded (none is a quality character), whitespace inside is CHARACTER_OUTSIDE_ENCODING, and a string that is empty or all whitespace is the kit's INVALID_STRING

a quality string is at most 3,000 characters after that trim, counted as UTF-16 code units, which equal characters for any valid quality character (ASCII 33 to 126), so that the worst-case reply stays under the 2 MB reply cap (1,638,340 bytes as served at 3,000 characters, a margin of 22 %)

order of checks: the kit's checks of each argument (a quality above 93 is QUALITY_ABOVE_RANGE, checked before the whole-number test, so Q 93.5 is refused QUALITY_ABOVE_RANGE), then one of the three input forms, then the whole-number test of qualities (NOT_AN_INTEGER), then CHARACTER_OUTSIDE_ENCODING

SymbolMeaning
offset33 or 64

Source 2.

Equation 3

expected errors = Σ p_i (linearity of expectation, whatever the dependence)

mean error = Σ p_i / n

quality of the mean error = -10 log10(mean error)

mean of Q = Σ Q_i / n >= quality of the mean error (the arithmetic mean of p is at least its geometric mean, and -10 log10 is decreasing): the record's own arithmetic, not SAMv1's, which is cited for the scale only (§1.2, Phred scale)

Σp, the mean error and its quality are returned for every input form, qualities, quality strings and error probabilities alike, and the mean of the Qs for qualities and quality strings

the sums run in input order in double precision

SymbolMeaning
nbases in the read

Source not recorded.

A definition, not a model: the equation states what the quantity means. A different convention gives a different number.

Worked example

Worked example: one case of ngs-phred-quality@2.0.0, from its inputs through each step to the answer. Values are written as a person writes them; the working carries more digits, so your own figure may differ in the last digit shown.

Inputs

  • errorProbabilities[0] = 0.001

Steps

  1. Q = 30 phred, from errorProbabilities[0]; by equation 1; gives result.bases[0].quality.

The working, as the case writes it:

-10 log10(0.0010000000000000000208166817) = 30.000000000000

closest integer 30

Answer

result.bases[0].quality = 30 phred

Where these values came from: our own exact-arithmetic script and a hand-worked case; SAM v1.6 section 1.2, Terminologies and Concepts: the Phred scale of p is -10 log10 p, rounded to the closest integer; halves upward (towards larger Q) is the record's choice, since SAMv1 states no tie rule, and no finite decimal p reaches a tie.

At build the tool returned this answer within the tolerance the file states: qualities absolute 1e-9 phred; probabilities and expected errors relative 1e-12 (exact below 1e-300); statuses, codes, flags and counts exact.

Sources

  1. Sequence Alignment/Map Format Specification v1.6, samtools/hts-specs, SAMv1.tex

    Used for: Phred quality and base-call error probability, with expected errors per read. At: section 1.2 Terminologies and Concepts: Phred scale; 1.4 The alignment section: mandatory fields, field 11 QUAL.

    Read in full, 11 November 2026
  2. Cock PJA, Fields CJ, Goto N, Heuer ML, Rice PM (2010), The Sanger FASTQ file format for sequences with quality scores, and the Solexa/Illumina FASTQ variants, Nucleic Acids Research 38:1767-1771

    Used for: Phred quality and base-call error probability, with expected errors per read. At: section FASTQ variants: Sanger offset 33, Phred 0 to 93; Illumina 1.3+ offset 64.

    Read in full, 11 November 2026

How it is checked

Level

Checked against a reference.

Checked against

Our own exact-arithmetic script and a hand-worked case.

Cases

No case set is linked to this version.

Not checked

Whether the qualities are calibrated (binned or uncalibrated scores make Σp an estimate); the distribution of the error count; Solexa scores (their formula unread); FASTQ files themselves (strings only).

What this project's records still lack1 thing
  • The source's location for each equation for ngs-phred-quality@2.0.0.
Changes to its methods1 change
  • 14 November 2026, ngs-phred-quality@2.0.0: In 2.0.0 a quality string is at most 3,000 characters, where the worst-case reply is 1,638,340 bytes; a longer read is split and the parts' expected errors added. Error probabilities also return the expected errors, the mean error probability and its quality. The record labels the per-read sums as its own arithmetic, states the order of checks and the value the rounding is decided on, and records Biopython 1.88's decoders as checks.