# Alignment E-value, P-value and bit score from Karlin–Altschul statistics

`seq_alignment_significance` · Runs: On the server · Level: Checked against a reference: NCBI BLAST+ 2.12.0 blastn, 24 BLAST+ runs on 18 sequence pairs (six re-runs of a pair with -searchsp; the outside comparison), with a 60-digit decimal script of our own and the tutorial's printed P values

Works out a local alignment's bit score, E-value and P-value from Karlin–Altschul statistics.

Research and education software; not medical advice, and not for diagnosis or treatment decisions. It computes from the inputs it receives. It does not check the person's data, design or sample.

[Catalogue](https://www.drybench.com/mcp/catalogue) / [Sequences](https://www.drybench.com/mcp/catalogue/sequences)

[Ask your assistant](https://www.drybench.com/mcp/connect)

```cite
Alignment E-value, P-value and bit score from Karlin–Altschul statistics (seq_alignment_significance), Drybench MCP server 1.0.0; seq-alignment-significance@2.0.0 (Checked against a reference); https://www.drybench.com/mcp/tools/seq-alignment-significance
```

## What it is

Returns a local alignment's bit score, E-value and P-value from Karlin–Altschul statistics (E = K m n e^(-λS)). Use when judging a BLAST hit from its printed score, λ, K and search lengths, or comparing hits across searches of different size. Not for aligning two sequences or scoring an alignment: use \`seq\_align\`. scoreKind, lengthBasis and, for a raw score, lambda, k and parameterSet are required, never assumed; no edge correction, sum statistics or composition adjustment is applied.

Field: [Sequences and primers](https://www.drybench.com/mcp/catalogue/sequences).

## What it does

**You give**

- `scoreKind` (required): raw-score (with lambda and k) or bit-score. Required: a bit score passed as a raw score gives a wrong E.
- `queryLength` (required): Letters of the query as the search used them (the effective length if the program corrected for edge effects). Must be at least 1 and at most 1000000000000000.
- `databaseLength` (required): Total letters of the database as the search used them, in the program's own count. Must be at least 1 and at most 1000000000000000.
- `lengthBasis` (required): effective, actual or unknown: whether the lengths are edge-corrected. Required and echoed.
- `rawScore`: With raw-score: the raw score as the program printed it, as in the bracketed number of '52.4 bits (124)'; above zero. Must be above 0 and at most 1000000000000. Optional.
- `bitScore`: With bit-score: the bit score as printed. Must be at most 1000000000000 bit. Optional.

and 3 more, listed below

No request is recorded for this tool.

**Limits**

- Research arithmetic on sequences, primers and alignment scores; it computes from the sequences and parameters it receives, and does not run a search, an alignment or a reaction, or say whether a match is real or a primer will work.
- Karlin–Altschul arithmetic for one local alignment from the score, λ, K and lengths given.
- The theory is exact only asymptotically, for ungapped local alignments of random sequences; for gapped alignments λ and K are estimates from simulation and must be the values the search program used for that scoring system; λ is never computed from a matrix, and no λ or K is assumed.
- P is derived from E as P = 1 − exp(−E), computed as −expm1(−E): the chance of at least one alignment scoring at least the given score in this search space under the random-sequence model; no other count of alignments is given.
- E and P are chances under that model, not the probability that a match is homologous or spurious, and no significance threshold is applied.
- Lengths are used as given, with their stated basis (effective, actual or unknown) echoed; edge correction is the caller's, and programs count database length differently, so the database length must be the program's own count.
- A program's reported E can differ: sum statistics over several alignments and composition-based statistics are not reproduced; low-complexity regions break the random-sequence model; E is not corrected across several queries or databases; and a bit score copied from a report is rounded, so E computed from it differs from the report's.
- BLAST+ blastp's printed E-values will not match E from Eq.
- 1 here, even for the same score, λ, K and lengths, because blastp applies Spouge's finite-size correction in place of Eq.
- 1.
- BLAST+ blastn, under the gapped scoring schemes that round (its default reward 2 and penalty −3 among them), computes E from the raw score rounded down to an even number but the bit score from the raw score as printed; no rounding is applied here, so for an odd printed raw score, E here, whether from that score or from its printed bit score, is about e^λ times below BLAST's printed E (about 1.9 times at λ 0.625).
- To reproduce BLAST's E for such a hit, give the raw score less one, with scoreKind raw-score; give the score as printed to reproduce its bit score.
- When E is below 1e-300, E and P are withheld, never given as 0; log10 E and log10 P are still given.
- 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 bit score of zero or below puts E at or above the search space, outside the regime the statistics describe.

### Every input, with its units

9 inputs

- `scoreKind` (required): raw-score (with lambda and k) or bit-score. Required: a bit score passed as a raw score gives a wrong E.
- `queryLength` (required): Letters of the query as the search used them (the effective length if the program corrected for edge effects). Must be at least 1 and at most 1000000000000000.
- `databaseLength` (required): Total letters of the database as the search used them, in the program's own count. Must be at least 1 and at most 1000000000000000.
- `lengthBasis` (required): effective, actual or unknown: whether the lengths are edge-corrected. Required and echoed.
- `rawScore`: With raw-score: the raw score as the program printed it, as in the bracketed number of '52.4 bits (124)'; above zero. Must be above 0 and at most 1000000000000. Optional.
- `bitScore`: With bit-score: the bit score as printed. Must be at most 1000000000000 bit. Optional.
- `lambda`: With raw-score: Karlin–Altschul lambda for the scoring system and parameter set used, as printed under Lambda; above zero. Must be above 0 and at most 1000000. Optional.
- `k`: With raw-score: Karlin–Altschul K (not a depth), as printed under K; above zero. Must be above 0 and at most 1000000. Optional.
- `parameterSet`: With raw-score: gapped or ungapped, the row of lambda and K given. Optional.

### Every refusal, with its code

1 refusal

| Code | When |
| --- | --- |
| `BIT_SCORE_NOT_POSITIVE` | a bit score of zero or below puts E at or above the search space, outside the regime the statistics describe. |

## The calculation

The method's equations, constants and worked example.

### [Bit score, E-value and P-value of one local alignment by Karlin-Altschul statistics](https://www.drybench.com/methods/m/seq-alignment-significance/2.0.0)

`seq-alignment-significance@2.0.0`

**Equation 1**

```text
ln E = ln K + ln m + ln n - lambda S (Eq. 1 in log space)
the search space m n is returned as given
S is used as given: BLAST+ 2.12.0 blastn, for gapped schemes whose round_down flag is set (reward 2 with penalty -3, -5 or -7, and 3 with -4), computes E from S rounded down to an even number and the bit score from S itself (blast_hits.c, "Round score down to even number for E-value calculations only", SB-2303), the tool applies no rounding: BLAST+'s E is reproduced by giving it the even score, and its bit score by giving the score as printed
order of checks: the kit's checks of each argument, then CONFLICTING_ARGUMENT for an argument the scoreKind does not use, then MISSING_ARGUMENT (rawScore, lambda, k, parameterSet
or bitScore), then BIT_SCORE_NOT_POSITIVE, in both modes, once S' is known
```

| Symbol | Meaning |
| --- | --- |
| `E` | expected number of alignments scoring at least S by chance in the search space |
| `S` | raw score, in the scoring system's units |
| `lambda` | Karlin-Altschul lambda, per raw-score unit |
| `K` | Karlin-Altschul K |
| `m` | query length as the search used it |
| `n` | database length as the search used it |

Source 1.

**Equation 2**

```text
S' = (lambda S - ln K) / ln 2 (Eq. 2)
```

| Symbol | Meaning |
| --- | --- |
| `S'` | bit score, bit |

Source 1.

**Equation 3**

```text
ln E = ln m + ln n - S' ln 2 (Eq. 3 in log space)
```

| Symbol | Meaning |
| --- | --- |
| `S'` | bit score, bit |

Source 1.

**Equation 4**

```text
P = 1 - e^(-E) (Eq. 5): the chance of at least one alignment scoring at least S in this search space under the random-sequence model
```

| Symbol | Meaning |
| --- | --- |
| `P` | P-value |

Source 1.

**Conventions**

- scoreKind = raw-score: a raw score with the lambda and K of its scoring system: the bit score by Eq. 2 and E by Eq. 1
- scoreKind = bit-score: a bit score: E by Eq. 3; no raw score is recovered
- lengthBasis = effective: the lengths are the effective lengths the program used after its edge correction
- lengthBasis = actual: the lengths are the sequences' actual lengths, with no edge correction
- lengthBasis = unknown: whether the lengths were edge-corrected is not known; the reply says what follows either way (LENGTH\_BASIS\_UNKNOWN)
- parameterSet = gapped: lambda and K are the program's gapped values; echoed only, the arithmetic is the same
- parameterSet = ungapped: lambda and K are the program's ungapped values; echoed only, the arithmetic is the same

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 seq-alignment-significance\@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**

- scoreKind = raw-score
- rawScore = 100
- lambda = 0.25
- k = 0.125
- parameterSet = gapped
- queryLength = 256
- databaseLength = 1024
- lengthBasis = effective

**Steps**

1. b = 39.067376 bit, from rawScore, lambda, k; by equation 2; gives result.bitScore.
2. e = 4.5508014e-7, from rawScore, lambda, k, queryLength, databaseLength; by equation 1; gives result.eValue.

The working, as the case writes it:

```text
ln E = ln 0.125 + ln 256 + ln 1024 - 0.25 x 100 = -14.6027922916008203587415181781
S' = (0.25 x 100 - ln 0.125) / ln 2 = 39.0673760222240851839981170250
```

**Answer**

- result.bitScore = 39.067376 bit
- result.eValue = 4.5508014e-7

Where these values came from: our own exact-arithmetic script and a hand-worked case; Worked by hand by Drybench on 11 November 2026 (R10). This is not an independent check.

At build the tool returned this answer within the tolerance the file states: E and P relative 1e-12 (exact below 1e-300, where they are withheld); bit scores absolute 1e-9 bit; log10 values absolute 1e-9; search space relative 1e-15; texts, statuses and codes exact.

Who worked this case: not recorded.

## Sources

1. Altschul SF, The Statistics of Sequence Similarity Scores, NCBI BLAST tutorial Used for: Bit score, E-value and P-value of one local alignment by Karlin-Altschul statistics. At: equation Eq. 1, 2, 3 and 5 (images, read as images), section Bit scores; P-values; Database searches; Edge effects. **Read in full, 11 November 2026**

Read by AI-assisted sessions. No person has checked these readings.

## How it is checked

**Level:** Checked against a reference.

**Checked against:** Our own exact-arithmetic script and a hand-worked case; the source's own worked example, CPython standard library (decimal), 3.13.18.

**Cases:** No case set is linked to this version.

**Not checked:** BLAST+'s public-domain notice (not yet read, held for the General Counsel); blastp, whose E-values apply Spouge's finite-size correction; how λ and K are derived for a scoring system; sum statistics and composition-based statistics (not reproduced); a program's own edge correction and database length counting.

No independent scientist has yet reviewed this.

### Changes to its methods

1 change

- [14 November 2026, seq-alignment-significance\@2.0.0](https://www.drybench.com/methods/corrections#2026-11-14-seq-alignment-significance200-1): In 2.0.0 unknown lengths get their own note, LENGTH\_BASIS\_UNKNOWN, worded conditionally; the raw-mode refusal applies once the bit score is known; log10 P is computed by log1p where P is near 1. The record states the note order and BLAST+ blastn's rule of computing E from the score rounded down to even under some schemes, and BLAST+ 2.12.0 blastn is recorded as an outside check on 24 alignments.
