When the algorithm is a table

The zero that moves the answer out of the corner

One extra term in the recurrence — a floor at zero — and the answer stops being in the last cell. It becomes a maximum over all 1,040 of them, the traceback's starting point is a search, and the whole mode is meaningless unless a randomly matched pair of characters scores negative on average. That last condition is on the scoring scheme, not on the sequences.

Three modes of one rectangle have appeared in this field and two of them have been measured. A global alignment runs both strings end to end and reads the answer from the corner. A search sets the top row to zero, which makes a prefix of the text free, and reads the answer from the minimum of the last row. The third is local, and it is the one where the change is not one line but four.

The question it answers is different from either. Not how far apart are these two sequences and not where in this text does this pattern nearly occur, but which region of one resembles which region of the other — with both ends of both regions unknown and to be discovered.

A local alignment stops being local at a reward of 3.0The same two sequences, 39 and 25 characters, aligned locally at eight settings of what a matching character is worth. Below the rule the expected score of a randomly matched pair is negative, an alignment that wanders is punished for wandering, and the reported region is the 13 characters the two sequences genuinely share. Above it the expectation is positive, extending pays wherever you are, and the reported region grows to 87% of the longer sequence. The condition is on the scoring scheme, not on the sequences.0%25%50%75%100%11.522.533.545what a matching character is worthreported as the shared region, of the longer sequencea random pair scores zero hereunit cost, alphabet acgtthe region found: 13 characters at the left, 34 at the right
Fig. 1 The mode’s precondition, swept. The same two sequences aligned locally at eight settings of what a matching character is worth, with the fraction of the longer sequence the reported region covers on the vertical axis. Below the rule a randomly matched pair scores negative on average, wandering is punished, and the region found is the fifteen characters the two sequences genuinely share. Above it the expectation is positive, extending pays wherever the alignment happens to be, and the region grows to 87% of the sequence. Nothing about the sequences changed across the plate.

That difference in question is what makes the mode worth a page of its own rather than a paragraph. A global alignment asked of two sequences that share a short region and nothing else will report the whole of both, aligned badly, because it has no permission to stop — and the number it returns will be dominated by the parts that do not correspond. Run on the two sequences the plate above uses, a global alignment under unit cost costs twenty across a table of 1,040 cells, and that twenty says almost nothing about the fifteen characters they actually have in common.

Four lines, and what each of them does

The global recurrence over a cost model is a minimum of three ways to reach a cell. The local one is a maximum of four, and the sign flip is the first of the four changes:

H(i,j)=max(0, H(i1,j1)+s(ai,bj), H(i1,j)g, H(i,j1)g)H(i,j) = \max\big(0,\ H(i-1,j-1) + s(a_i, b_j),\ H(i-1,j) - g,\ H(i,j-1) - g\big)

The model is read as a score rather than as a cost. A match is worth something positive and everything else is negative. That is not a presentational change: a minimisation over costs and a maximisation over scores are the same computation only when the scores are the negated costs, and the term that follows makes them not.

The first row and the first column are zero. Both of them, where the search mode zeroes only the top row. That makes both a prefix of one sequence and a prefix of the other free, which is the half of “local” the search mode does not have.

Every cell is floored at zero. A running alignment whose score has fallen to nothing is abandoned and a new one may begin at that cell for free. This is the term that makes the mode local rather than merely two-sided.

And the answer is the maximum over the whole table rather than a designated cell. It is not in the corner, it is not in the last row, and finding it requires looking at all of them.

Read together, those four changes are one idea: an alignment is allowed to start and to stop. The zeroed row and column let it start anywhere, the floor lets it stop and restart anywhere, and the maximum over the table is how it is found afterwards. Everything else about the computation — the cell count, the dependency structure, the fill order, the space that a rolling frontier could save — is untouched, which is why this field’s counter reports the identical number of cells for a local and a global fill on the same pair.

A gap of 4 characters, charged two waysThe same pair under an affine charge of 8 to open a gap and 1 for each character in it, computed twice. The upper alignment comes from three tables, which is the only way a cell can know whether the step above it was already inside a gap. The lower one comes from a single table charging 9 for every gap character, which is a valid cost model and a different one, and reports 39 where the affine cost is 19.three tables: 19 cost, 1 gap run(s), longest 4----ccagggagta|××||×××××agcacacggatcagone table charging 9 a character: 39 cost, 3 gap run(s)--c-cagggagta-|||×|||××|agcacacggatcag| identical x substituted - gap0,0,0,1,0,2,0,3,0,4,1,5,2,6,3,7,4,8,5,9,6,10,7,11,8,12,9,13,10,14 cells against 165
Fig. 2 The unit the score is expressed in, which the mode inherits rather than chooses. A gap of four characters charged as four events and as one, on the same pair — the affine question this field settled two rungs ago. A local alignment has the same choice to make and one further consequence: under a linear gap penalty an alignment can be extended through a long gap a character at a time, and each extension is tested against the zero, so the floor interacts with the gap model rather than sitting beside it.

The answer is not where it used to be, and that costs something

A global alignment’s traceback starts at (n,m)(n, m) because that is where the answer is. A local one starts wherever the maximum happened to be, and walks back until it hits a cell holding zero. So both ends of the reported region are discovered rather than given, and neither is available until the table is filled.

Three consequences follow and each is a real cost.

The maximum must be tracked as the fill proceeds, or found by a second pass over the table. Either is O(nm)O(nm) and neither is free; the fill’s inner loop gains a comparison, which is a constant on a computation that is already the dominant term.

A rolling frontier cannot answer the question at all. The table nobody has to keep showed that the number can be computed in two rows and the alignment cannot; and the alignment that fits in one line recovers the path at twice the cells. Here even the location of the answer is part of what is wanted — a region is a pair of intervals, not a score — so the two-row version keeps a number that names a place it can no longer find. The linear-space method that recovers a global alignment does adapt, at the usual doubling of the cells, and the adaptation has to be told where to recurse from.

And there is more than one answer. The table’s second-highest local maximum is a second region, the third is a third, and a search that wanted all the regions above some score has to enumerate them — with the additional difficulty that two nearby maxima can be two ends of one region rather than two regions, which no rule in the recurrence distinguishes.

A local alignment stops being local at a reward of 3.0The same two sequences, 28 and 19 characters, aligned locally at eight settings of what a matching character is worth. Below the rule the expected score of a randomly matched pair is negative, an alignment that wanders is punished for wandering, and the reported region is the 11 characters the two sequences genuinely share. Above it the expectation is positive, extending pays wherever you are, and the reported region grows to 89% of the longer sequence. The condition is on the scoring scheme, not on the sequences.0%25%50%75%100%12345what a matching character is worthreported as the shared region, of the longer sequencea random pair scores zero hereunit cost, alphabet acgtthe region found: 11 characters at the left, 25 at the right
Fig. 3 A second pair with the same shape and a different shared region: eleven characters found at the tightest setting and twenty-five at the loosest, out of a twenty-eight character sequence. The turn is in the same place, because the turn is not a property of these sequences — it is where the expected score of a randomly matched pair of characters over a four-letter alphabet changes sign, and that is arithmetic on the scoring scheme alone.

There is a fourth consequence that is easy to miss and is the one that bites in practice. A local alignment’s score cannot be compared with a global one’s, even under the same model, because the two are optimising different things over different regions. A global cost of twenty and a local score of twenty-seven on the same pair are not two measurements of one quantity; they are two quantities. This site has been insisting on that since a cost that is not one found four numbers on eighty-one cells of which only one was a count of anything, and the local mode adds a fifth.

The precondition, which is on the scoring scheme

Here is the part that no statement of the algorithm contains and that decides whether its output means anything.

Take two positions at random, one from each sequence. Under a four-letter alphabet used evenly, they agree a quarter of the time and disagree three quarters. If a match is worth +m+m and a mismatch costs 1-1, the expected score of that pair is m434\frac{m}{4} - \frac{3}{4}, which is negative for m<3m < 3, zero at m=3m = 3 and positive above it.

If the expectation is positive, extending an alignment is profitable regardless of what is being aligned. The running score drifts upward on unrelated sequence, it never falls back to the floor, and the highest-scoring local alignment is essentially the whole of both sequences. The mode has answered a question nobody asked, with a large number, and nothing in the output says so.

That is what the plate measures. At a reward of two the region reported is fifteen characters and the sequences share fifteen characters. At a reward of four it is thirty-four, and the extra nineteen are noise the scoring scheme has made profitable to include. The sequences are the same in both runs.

The condition generalises past this toy: for an alphabet with frequencies pxp_x and a scoring matrix ss, the requirement is x,ypxpys(x,y)<0\sum_{x,y} p_x p_y\, s(x,y) < 0. Every published substitution matrix is constructed to satisfy it, and the construction is the reason those matrices are built as log-odds ratios rather than written down by hand — a log-odds score against a background distribution has negative expectation under that distribution automatically.

There is a neat way to see why the failure is total rather than gradual. A local alignment’s running score is a random walk: each column adds the score of one aligned pair, and the floor at zero reflects the walk whenever it goes negative. A random walk with negative drift, reflected at zero, has a stationary distribution and its maximum over nmnm steps grows like the logarithm of nmnm. A walk with positive drift has no stationary distribution at all: its maximum grows linearly in the number of steps, so the best local alignment is the longest one available. The two regimes are not two ends of a scale, they are two different behaviours of the same process, and the sign of the drift is the whole of what separates them.

log-odds on a drift model: what one substitution costsThe rule is the log-odds of one step of a random walk that stays put with probability 0.6 and otherwise moves, eight times more readily within a purine or pyrimidine pair than between them; a gap character costs 2. Read a row as the symbol expected and a column as the symbol seen; the entry is what the table charges for that pair, in bits. The diagonal is zero by construction so that a minimising fill can be used unchanged. Nothing here is copied from a published table: every entry is computed from the rule beside it, which is the difference between a matrix that can be checked and one that can only be quoted.acgtacgtseen ->0313303113033130a gap of k characters costs 2krows: expected · columns: seen · unit: bitslinear gaps
Fig. 4 A matrix built that way, drawn: the log-odds of one step of a stated drift model. Its diagonal is favourable and its off-diagonal entries are not, and the reason it can be used for a local alignment without further thought is that its expectation under the model it was derived from is negative by construction. A matrix somebody wrote down by intuition has no such guarantee and the failure is silent.

What the mode is worth when the precondition holds

The plate measures the failure. It is worth stating what the success looks like, because it is the reason the mode exists at all.

Two sequences that share a fifteen-character region and otherwise have nothing to do with each other are, to a global alignment, two sequences that are very different. Its answer is dominated by the twenty-odd characters of noise on either side, and no amount of care with the gap model rescues it — the alignment is forced to account for material that does not correspond, because it is forced to run to the corner.

The local mode’s answer on the same pair is the fifteen characters, their positions in both sequences, and a score that describes them and nothing else. It found both ends without being told where to look. That is a genuinely different capability rather than a refinement, and it is what makes this the mode every sequence-search tool is built on rather than the global one.

What it costs is the precondition, and the precondition is unusual in this collection because it is statistical rather than structural. Every other precondition on this site is a property that either holds or does not — a graph is acyclic or it is not, weights are non-negative or one of them is not, a cost matrix satisfies the triangle inequality or a triple breaks it. This one is a statement about an average over a distribution, it can be nearly violated, and near it the mode degrades smoothly rather than failing. The plate’s step between three and four is where that degradation stops being smooth.

What “the answer” is when the answer is a score

This field has been careful since a cost that is not one that a number produced by a table means nothing until the model is named. A local alignment sharpens that, because its output is not merely in an arbitrary unit — it is in a unit chosen to make the computation behave.

A global edit distance under unit cost is a count of edits. It has an interpretation independent of the algorithm, and two implementations that disagree about it disagree about a fact. A local alignment score of 27 is a number in a unit invented for the purpose, its magnitude depends on the reward chosen, and comparing two local scores computed under two schemes is comparing nothing at all.

What makes it usable is a second layer nobody in this field has built: a statistical model saying how large a score of 27 would be by chance on sequences of these lengths, which converts the score into a probability and makes two of them comparable. That is what a real sequence-search tool reports, it is the reason those tools quote an expectation value rather than a score, and it is a whole apparatus sitting on top of the recurrence.

The honest position for this page is therefore narrow. The recurrence is measured here. The interpretation of its output is not, and the number is a score rather than a quantity. That is the same distinction a guarantee names its model draws throughout this collection, arriving in the case where the model is a distribution over inputs rather than a machine.

A local alignment stops being local at a reward of 3.0The same two sequences, 39 and 25 characters, aligned locally at eight settings of what a matching character is worth. Below the rule the expected score of a randomly matched pair is negative, an alignment that wanders is punished for wandering, and the reported region is the 13 characters the two sequences genuinely share. Above it the expectation is positive, extending pays wherever you are, and the reported region grows to 87% of the longer sequence. The condition is on the scoring scheme, not on the sequences.0%25%50%75%100%122.533.54what a matching character is worthreported as the shared region, of the longer sequencea random pair scores zero hereunit cost, alphabet acgtthe region found: 13 characters at the left, 34 at the right
Fig. 5 The same sweep sampled more closely around the sign change, where the transition can be seen to be a step rather than a slope. Between two and three the reported region hardly moves; between three and four it nearly doubles. A condition that is satisfied or not, rather than satisfied to a degree, is what a threshold looks like when it is measured — and the measured location agrees with the arithmetic to the setting drawn.

It also puts a familiar defect in a new place. A distance that is not a distance found that a stated substitution matrix can break the triangle inequality, which takes with it every structure that prunes by distance. A local alignment score is not a distance at all and never claimed to be — it is not symmetric in the way a cost is, it does not vanish on identical inputs, and it grows rather than shrinks with similarity. So the pruning structures were never available here in the first place, and a system that indexes local alignment scores has to do something else entirely, usually a filter on shared short substrings.

Where the third mode sits beside the other two

Setting the three modes side by side makes the family visible, and the family is small.

mode top row left column floor answer read from
global 0,g,2g,0, g, 2g, \dots 0,g,2g,0, g, 2g, \dots none the corner
search all zero 0,g,2g,0, g, 2g, \dots none minimum of the last row
local all zero all zero zero maximum of the table

Four columns, three rows, and every difference between the three modes is in this table. The search row is the one the filter that feeds the table is built on, and its single zeroed row is what makes a pattern free to begin anywhere in a text. The fill is identical, the cell count is identical, and the transitions per cell go from three to four in the last row.

That is worth stating plainly because the three are usually taught as three algorithms with three names attached to three people. They are one rectangle with three initialisations and two places to read from, and this field’s counter reports the same number of cells for all three — which is the strongest argument available that the distinction is about the question rather than about the method.

log-odds on a keyboard walk: 32 of 336 triples break the triangle inequalityFor each triple of distinct symbols, the cost of going straight from the first to the third against the cost of going by way of the second. Under the log-odds of one step of a random walk over the twenty-six letters that stays put with probability 0.5 and otherwise moves, twenty times more readily to a key adjacent on a QWERTY keyboard than to any other; a gap character costs 3. A model in which the direct cost can exceed the detour is not a metric, and the answer it produces is a score rather than a distance — which matters the moment anything tries to index by it, because a metric tree prunes on exactly the inequality these rows break.direct / by way ofq to e, by way of w3 against 2 — brokenq to d, by way of w3 against 2 — brokenq to e, by way of s3 against 2 — brokenq to d, by way of s3 against 2 — brokenw to r, by way of e3 against 2 — brokenw to f, by way of e4 against 2 — brokenw to r, by way of d3 against 2 — brokenw to f, by way of d4 against 2 — brokenupper bar: direct · lower bar: the detourlog-odds on a keyboard walk, in bits
Fig. 6 The triangle inequality under a stated matrix, drawn for the same reason it is relevant here and not for the same conclusion. A local score is not a metric, was never offered as one, and cannot be indexed by anything that assumes one — so the failure this plate reports for a distance is, for the mode on this page, a starting condition rather than a discovery.

What the mode costs to search with

Local alignment is not usually run once on two sequences. It is run once per candidate against a database of millions, and the arithmetic of that is what turned the mode from a recurrence into an industry.

The cost of one comparison is nmnm cells, which for a query of three hundred characters against a sequence of a thousand is three hundred thousand — trivial. Against a database of a million such sequences it is 3×10113\times 10^{11}, which is not.

So no real system runs the recurrence against everything. It runs a filter first: find candidates sharing a short exact substring with the query, and align only those. That is the same architecture the filter that feeds the table describes for approximate string search, and it has the same two properties — the filter is one-sided, so it may propose candidates that fail, and it may in principle miss candidates the alignment would have found.

The second property is the one that matters and it is rarely stated as plainly as it should be. A filtered local-alignment search is not a search for the best local alignment; it is a search for the best local alignment among candidates the filter proposed. The recurrence is exact and the system built on it is not, and the approximation lives in a step that the recurrence knows nothing about.

That is worth carrying because it changes what a score means one more time. The number a filtered search reports is the best score found, its relationship to the best score available is governed by the filter’s sensitivity, and the sensitivity is a parameter — the length of the exact substring required — that the user usually leaves at its default.

Three ways an answer can leave the corner

Setting this rung’s move beside two others in the tables field makes the family visible, and the family is about where an answer is allowed to be.

A global alignment’s answer is at a fixed cell, the corner, and every other cell exists to get there. The traceback starts where the answer is.

A search’s answer is in a fixed row, and which column is discovered. That is one degree of freedom, it costs a scan of the last row, and it turns the same table into a different question.

A local alignment’s answer is anywhere, and both its ends are discovered. Two degrees of freedom for the end, and the start is found by walking back to a zero.

Each step outward costs something concrete: the search mode costs a scan of a row, the local mode costs a scan of the table plus the floor’s comparison in every cell, and each step makes the space-saving techniques less available — a rolling frontier can answer the first, can answer the second, and cannot answer the third at all.

The degrees of freedom in where the answer sits are a resource, and this field has been paying for them a step at a time without naming the currency.

What is not measured here

No published matrix is used. Every score here comes from a stated rule, which is this field’s practice and the reason a cost that is not one refuses to quote a table. Every score on this page comes from a stated rule, in keeping with this field’s practice: a number copied out of a published table is a number that cannot be checked. The consequence is that the precondition arithmetic is exact here and would be approximate on a real matrix, whose background frequencies are the ones its authors used rather than the ones an application has.

The gap model is linear. A cell that has to know where it is established that a gap of four is one event rather than four and that expressing it needs three tables. All three modes accept an affine gap and the local one is drawn here with a linear one, so the regions reported are a little more fragmented than an affine version would give.

The alphabet is used evenly. The precondition arithmetic above assumes each of the four symbols is equally likely, which makes the expected score a clean quarter-minus-three-quarters. Real sequence has skewed composition, and a scoring scheme tuned for one composition has a different expectation under another — so a matrix that is safely negative on one organism’s sequence can be marginal on another’s. That is the same class of failure a corpus that was not generated is about: the statistics of the input are part of the method’s precondition and the input does not come with them attached.

And the second-best region is never shown. Every plate reports one maximum. A real use of this mode wants all the regions above a threshold, the enumeration has its own difficulties, and none of them is on this page.

Where this ladder goes next: a distance divided by a length

The zero on this page changes what is optimised. The next rung changes what optimal means.

Three edits between two five-character words and thirty between two five-hundred-character ones are the same distance and are plainly not the same amount of difference. Everybody who has ever used one of these numbers has wanted to divide it by something, and the obvious division — take the optimal alignment and divide its cost by its length — is not what it appears to be.

The reason is exactly the reason the zero mattered here: changing the objective changes which alignment wins. The alignment with the lowest cost need not be the alignment with the lowest cost per column; some other alignment may cost more over a much greater length and have a better ratio. Minimising a quotient is a different optimisation from minimising a numerator, dividing afterwards does not perform it, and there is an instance on two-character strings.

That is a small, exactly checkable claim with an enumerable counter-example, which makes it the right next rung — and it lands in the same place this one did, on the observation that the recurrence computes whatever it was asked to compute and nothing in it says what was wanted.

What this makes readable

Essays that name this one as a prerequisite.

Named alongside this one

Essays reaching for the same objects. Nobody chose these; they are what the concept index makes visible.

What links here

Every essay whose body links to this one.

The objects this essay names

Each one links to every other essay that touches it.

AlignmentCost modelDynamic programmingEdit distanceExpected caseHonest limitLocal alignmentParameter choicePreconditionScoreSubstitution matrixTraceback