Let ∑ be the alphabet (e.g., {A, C, G, T}). Let L ⊆ ∑* be the set of short library sequences. Compute a minimum-state DFA (Q, ∑, ∂, q0, F) for L*.
We scan the long sequence x ∈ ∑* one letter at a time. Let x' be the prefix of x that has been consumed. We maintain, for every state q ∈ Q, the minimum cq(x') over [every sequence y ∈ ∑* such that ∂(q0, y) = q] of the Levenshtein distance between x' and y.
For the empty prefix ε, for every state q ∈ Q, it holds that cq(ε) = min {|y|: y ∈ ∑*, ∂(q0, y) = q}, since the distance between y and ε is the length of y. Compute the initial table with breadth-first search on the transition graph.
Given the table for x' and a letter s, we compute cq(x) as the minimum over several possibilities for y, where x = x' s.
Strings y = y' s z, aligning the s's. The cost in this case is minq', z: ∂(q', s z) = q (cq'(x') + |z|), which can be computed by |Q| breadth-first searches.
Strings y = y', deleting the s in x. The cost in this case is cq(x') + 1.
Strings y = y' t where t is a letter, substituting s for t (or vice versa). The cost in this case is minq', t: ∂(q', t) = q (cq'(x') + 1).
At the end, the optimal alignment cost is minq ∈ F cq(x). The alignment can be reconstructed in the usual way for dynamic programs.