Smith–Waterman local alignment
DefinitionAuxiliary row computation for the Smith–Waterman table#✓fully proved
The cells H[i+1][j+1], H[i+1][j+2], … of a row from the remaining letters b :: ys of the
second sequence, the remaining cells up :: prev of the previous row, the previous row's cell
diag to the upper left and the cell left just computed. A previous row that is too short ends
the row early (this does not happen for rows of the table, nextRow_eq).
def nextRowAux (a : α) : List α → List ℤ → ℤ → ℤ → List ℤ
| [], _, _, _ => []
| _ :: _, [], _, _ => []
| b :: ys, up :: prev, diag, left =>
max 0 (max (max (diag + σ a b) (up + gap)) (left + gap)) ::
nextRowAux a ys prev up (max 0 (max (max (diag + σ a b) (up + gap)) (left + gap)))
Used by 2
DefinitionNext row of the Smith–Waterman table#✓fully proved
The row of the table for the prefix extended by a, from the previous row: H[i+1][0] = 0,
then the recurrence left to right.
def nextRow (a : α) (ys : List α) (prev : List ℤ) : List ℤ :=
0 :: nextRowAux σ gap a ys prev.tail (prev.headD 0) 0
def nextRowAux (a : α) : List α → List ℤ → ℤ → ℤ → List ℤ
| [], _, _, _ => []
| _ :: _, [], _, _ => []
| b :: ys, up :: prev, diag, left =>
max 0 (max (max (diag + σ a b) (up + gap)) (left + gap)) ::
nextRowAux a ys prev up (max 0 (max (max (diag + σ a b) (up + gap)) (left + gap)))
CSLibExt/Bioinformatics/Alignment/SmithWaterman.lean:69
Uses 1 · Used by 3
DefinitionRow-by-row filling of the Smith–Waterman table#✓fully proved
The Smith–Waterman table, filled row by row over the remaining letters of the first sequence:
row is the current row and best the largest cell of the earlier rows.
def swTabAux (ys : List α) : List α → List ℤ → ℤ → ℤ
| [], row, best => max best (listMax row)
| a :: xs, row, best => swTabAux ys xs (nextRow σ gap a ys row) (max best (listMax row))
def listMax (xs : List ℤ) : ℤ := xs.foldr (max ·) 0
CSLibExt/Algorithms/Lean/DynamicProgramming/SequenceAlignment.lean:1187
def nextRow (a : α) (ys : List α) (prev : List ℤ) : List ℤ :=
0 :: nextRowAux σ gap a ys prev.tail (prev.headD 0) 0
CSLibExt/Bioinformatics/Alignment/SmithWaterman.lean:78
Uses 2 · Used by 2
DefinitionThe Smith–Waterman table#✓fully proved
The largest cell of the (|xs| + 1) × (|ys| + 1) table, with
the zero row H[0][j] = 0 to start.
def swTab (xs ys : List α) : ℤ :=
swTabAux σ gap ys xs (0 :: ys.map fun _ => 0) 0
def swTabAux (ys : List α) : List α → List ℤ → ℤ → ℤ
| [], row, best => max best (listMax row)
| a :: xs, row, best => swTabAux ys xs (nextRow σ gap a ys row) (max best (listMax row))
CSLibExt/Bioinformatics/Alignment/SmithWaterman.lean:83
Uses 1 · Used by 2
TheoremOne row of the table#✓fully proved
From the row of the prefix px, nextRow computes the row of
px ++ [a]: the cells H[i+1][j] = swCellScore σ gap (px ++ [a]) py for the prefixes py of
ys, shortest first.
theorem nextRow_eq (a : α) (px ys : List α) :
nextRow σ gap a ys (ys.inits.map (swCellScore σ gap px)) =
ys.inits.map (swCellScore σ gap (px ++ [a]))
def nextRow (a : α) (ys : List α) (prev : List ℤ) : List ℤ :=
0 :: nextRowAux σ gap a ys prev.tail (prev.headD 0) 0
CSLibExt/Bioinformatics/Alignment/SmithWaterman.lean:78
def swCellScore (xs ys : List α) : ℤ :=
swCellFront σ gap (xs.length + ys.length) xs.reverse ys.reverse
CSLibExt/Algorithms/Lean/DynamicProgramming/SequenceAlignment.lean:988
Uses 5 · Used by 1
TheoremThe table computes the Smith–Waterman score#✓fully proved
swTab is the largest cell
swCellScore σ gap px py over all pairs of prefixes.
theorem swTab_eq_swScore (xs ys : List α) : swTab σ gap xs ys = swScore σ gap xs ys
def swTab (xs ys : List α) : ℤ :=
swTabAux σ gap ys xs (0 :: ys.map fun _ => 0) 0
CSLibExt/Bioinformatics/Alignment/SmithWaterman.lean:89
def swScore (σ : α → α → ℤ) (gap : ℤ) (xs ys : List α) : ℤ :=
listMax ((prefixPairs xs ys).map (fun p => swCellScore σ gap p.1 p.2))
CSLibExt/Algorithms/Lean/DynamicProgramming/SequenceAlignment.lean:1568
Uses 11 · Used by 1
TheoremThe table computes the optimal local alignment score#✓fully proved
The table computes the optimal local alignment score (Smith–Waterman 1981, gap ≤ 0):
swTab is the maximum, over all pairs of infixes of xs and ys (including the empty ones,
which give the floor 0), of their optimal global alignment score nwScore.
theorem swTab_eq_localScore (hgap : gap ≤ 0) (xs ys : List α) :
swTab σ gap xs ys = localScore σ gap xs ys
def swTab (xs ys : List α) : ℤ :=
swTabAux σ gap ys xs (0 :: ys.map fun _ => 0) 0
CSLibExt/Bioinformatics/Alignment/SmithWaterman.lean:89
def localScore (σ : α → α → ℤ) (gap : ℤ) (xs ys : List α) : ℤ :=
listMax ((infixPairs xs ys).map (fun p => nwScore σ gap p.1 p.2))
CSLibExt/Algorithms/Lean/DynamicProgramming/SequenceAlignment.lean:1539
Uses 5
Loading dependency explorer…
The dependency explorer needs JavaScript and its graph data.