





















Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!






















Abstract. Given a relatively short query string W of length P , a long subject string A of length N , and a threshold D , the approximate keyword search problem is to find all substrings of A that align with W with not more than D insertions, deletions, and mismatches. In typical applica- tions, such as searching a DNA sequence database, the size of the "database" A is much larger than that of the query W , e.g., N is on the order of millions or billions and P is a hundred to a thousand. In this paper we present an algorithm that given a precomputed index of the database A , finds rare matches in time that is sublinear in N , i.e. N c^ for some c < 1. The sequence A must be over a finite alphabet Σ. More precisely, our algorithm requires O ( DN pow (ε)^ log N ) expected-time where ε = D/ P is the maximum number of differences as a percentage of query length and pow (ε) is an increasing and concave function that is 0 when ε = 0. Thus the algo- rithm is superior to current O ( DN ) algorithms when ε is small enough to guarantee that pow (ε) < 1. As seen in the paper, this is true for a wide range of ε, e.g., ε up to 33% for DNA sequences (| Σ| = 4) and 56% for proteins sequences (| Σ| = 20). In preliminary practical experiments, the approach gives a 50- to 500-fold improvement over previous algorithms for problems of interest in molecular biology.
Key Words. Approximate match, Dynamic programming, Index, Word neighborhood
0. Introduction
Given a relatively short query string W of length P , a long subject string A of length N , and a threshold D , the approximate keyword search problem is to find all substrings of A that align with W with not more than D insertions, deletions, and mismatches. More precisely, if δ( V , W ) is the edit distance between V and W , and if A [ i.. j ] denotes the substring of A consisting of its i th^ through j th^ characters, then the problem is to find all pairs i , j such that δ( W , A [ i.. j ]) ≤ D. For this problem, we say that the maximum mismatch ratio is ε = D/ P and that we are searching A for ε -matches to W.
This problem has been much studied. Sellers [Sel80] presented the obvious O ( PN ) algorithm as a slight variation of the classic dynamic programming algorithm for the sequence vs. sequence comparison problem (here we are comparing a sequence vs. substrings of the other). (^1) This work was supported in part by the National Institutes of Health under Grant R01 LM04960-01 and the Aspen Center for Phy- sics. (^2) Department of Computer Science, University of Arizona, Tucson, AZ 85721, U.S.A.
In roughly the same time frame, Ukkonen and Myers [Ukk85a,MyM86] both reported practical and simple O ( DN ) expected time algorithms. Not long thereafter, Landau and Vishkin [LaV86] arrived at an O ( DN ) worst case algorithm that required O ( N ) space. At about the same time Myers [Mye86a] presented an algorithm with the same worst case time complexity but which required only O ( D^2 ) space. Recently, Galil and Park [GaP89] have reported another O ( DN ) worst-case time algorithm that takes O ( P^2 ) space.
With the advent of applications such as those in molecular biology where the database will be massive, e.g. N in the billions, the need for algorithms that are less than linear in N is becoming of paramount importance. Recently, Chang and Lawler [ChL90] devised a method that takes O ( DN log P/ P ) expected-time when the threshold D is less than P/ (log P + O (1)). It does so by quickly eliminating stretches of the "database" sequence A where a match cannot possibly occur. They term their algorithm sublinear in the sense of Boyer and Moore [BoM77], i.e., cN characters of A are examined where c < 1. Note however, that the algorithm still takes time linear in N and that as P gets larger the stringency of a match must be tightened as ε must be less than 1 / (log P + O (1)).
In this paper we present an algorithm that given a precomputed index of the database A , finds rare matches in time that is truly sublinear in N , i.e. N c^ where c < 1. More precisely, our algo- rithm requires O ( DN pow (ε)^ log N ) expected-time where pow (ε) is an increasing and concave function that is 0 when ε = 0. Thus the algorithm is superior to the O ( DN ) algorithms when ε is small enough to guarantee that pow (ε) < 1. For example pow (ε) is less than one when ε < 33% for | Σ| = 4 (DNA alphabet), and when ε < 56% for | Σ| = 20 (Protein alphabet). Figure 4 on page 9 precisely plots the curve for several choices of | Σ|. Apart from the fact that our algo- rithm is "truly" sublinear, it also has the advantage over the Chang and Lawler algorithm that the degree of sublinearity just depends on ε and not on P. On the other hand, we require a precom- puted O ( N ) space index structure, whereas their method is purely scanning based, requiring only O ( P ) working storage. The bounding argument used in proving the expected complexity of our algorithm is rather crude. Consequently, performance in practice is much superior. In prelim- inary experiments, the approach appears to represent a 100- to 500-fold improvement over the O ( DN ) search algorithms for problems of interest in molecular biology.
1. Overview
In this overview, we sketch the basic concepts and outline the algorithm embodying our result. The various sections of the paper then embellish upon the individual components.
The algorithm assumes that an index for the sequences in the database has already been con- structed. An index for a large text is a data structure that allows one to rapidly find all occurrences of a given query string in the text. In our method, queries will all be of length T = log (^) | Σ| N. Thus, each query can be uniquely encoded as an O ( N ) integer, and we can store the results of all possible queries (which are lists of indices where the corresponding strings of size T appear in A ) in an O ( N ) table. This simple structure can be built in O ( N ) time and 2 N words of space as shown in Section 2.
2 T. This step requires envisioning the result of the word generation lookups as delivering paral- lelogram shaped regions of a dynamic programming matrix or edit graph. All d -matches to a T - word of W are guaranteed to lie in one of these parallelograms. To find matches to 2 T -words it suffices to do a dynamic programming calculation over a 2 T -by-2 d parallelogram about each parallelogram of a T -word ‘‘hit’’. At the k th^ stage of this process, the number of matches is reduced by a factor of 1 /N^2 k (^) (1 − pow (ε))
. Thus while the time to extend matches grows by a fac- tor of 4 at each stage, this is overwhelmed by the reduction in the number of surviving matches. In the end, the total time consumed in expectation is O ( DN pow (ε)^ log N + HDP ) where H is the number of matches to W found.
Note that our algorithm’s expected time complexity is based on the assumption that the data- base is the result of random Bernouilli trials. In this case its expected complexity is O ( DN pow (ε)^ log N ). However, if the database is not random but preconditioned to have H matches to W , then O ( HDP ) time will be spent on each of these matches. Consequently, our algorithm does not improve upon the O ( DN ) algorithm for the sequence-vs.-sequence problem. Nonetheless, for searching problems where the database is large and ‘‘sufficiently’’ random, this algorithm can find near matches with great efficiency and no loss in sensitivity.
2. A Simple Index Data Structure
An index for a large string A = a (^) 1 a (^) 2...^ a (^) N , is a data structure that allows one to efficiently locate all occurrences of a shorter query string within A. In this work, a very simple technique based on integer encodings can be used because all queries are of length O ( log N ) and we assume that the underlying alphabet Σ is fixed and finite. From here on, let T = log (^) | Σ| N and assume all queries are of length between T − D and T + D where D < T.
Consider an arbitrary assignment (bijection) φ of the symbols in Σ to the integers 0 through | Σ| − 1. φ is naturally extended to strings with the recursive definition φ( Wa ) = | Σ| φ( W ) + φ( a ) where W is a string over Σ and a is a symbol in Σ. Essentially φ( W ) is the integer obtained when the string is viewed as a radix-| Σ| number. For n ∈ [0, | Σ| T^ − 1] ⊆ [0, N − 1], let Bucket ( n ) = { i : φ( a (^) i a (^) i + 1...^ a (^) i + T − 1 ) = n }. That is, Bucket ( n ) gives the indices of the leftmost character of each occurrence in A of the unique T -symbol string whose φ-code is n. This simple array of sets is our index structure.
Under the assumption that A is the result of equi-probable Bernouilli trials, one can use Bucket to find all the, say H (^) V , occurrences of a query V within A in O ( T + DH (^) V ) expected time as follows. If V is of length U ≤ T then the leftmost indices of the occurrences of V are exactly the contents of Bucket ( k ) for k ∈ [φ( V )| Σ| T^ −^ U^ ,(φ( V ) + 1)| Σ| T^ −^ U^ − 1]. In this case, it takes time O ( U ) to compute the integers defining the interval of codes and O ( H (^) V ) time to list the H (^) V occurrences of V in A. Thus the total time is less O ( T + DH (^) V ) as claimed. In the case where U is greater than T one knows that the occurrences of V must be a subset of those in Bucket (φ( V (^) T )) where V (^) T denotes the string consisting of the first T symbols of V. It takes O ( T ) time to compute the φ-code, and then it suffices to simply check whether the remaining U − T symbols of V match at each of the locations in the given bucket. While potentially quite
inefficient in the worst case this step works extremely well in the expected case where A is the result of equi-probable Bernouilli trials. Under this assumption the average number of coin- cidental matches to V (^) T is one and on average only 1 / (| Σ| − 1) additional symbols of such coin- cidental matches to V (^) T need be checked before they are discovered not to match V. Thus in expectation only a constant amount of time is spent investigating locations that do not match V. Moreover, O ( U − T ) = O ( D ) time is spent checking additional characters at those locations that do match V. Thus only O ( T + DH (^) V ) expected time is spent in the case where U > T.
Producing the index is also quite simple. First φ (^) i = φ( a (^) i a (^) i + 1...^ a (^) i + T − 1 ) is computed for every index i. This is easily done in an O ( N ) sweep of A using the observation that φ (^) i =
radix sort produces the list Indices = < i (^) 1 , i (^) 2 ,...^ i (^) N > such that φ (^) i (^) j ≤ φ (^) i (^) j + 1. Finally, the array
Header [ n ] = min { j : φ (^) Indices [ j ] = n } is produced in an O ( N ) sweep of Indices. The arrays, Indices and Header , together provide a realization of the Bucket sets. Namely, Bucket ( n ) = { Indices [ j ] : j ∈[ Header [ n ] , Header [ n + 1] − 1 ] }. Thus our index occupies O ( N ) space and takes O ( N ) time to construct.†
In the treatment immediately above two details were overlooked that require attention. First was the statement that T be set to log (^) | Σ| N. T must be an integer, and so in fact one must round the logarithm either up or down. Rounding up implies that as much as O (| Σ| N ) time and space are required to construct the index. Rounding down implies that while only O ( N ) space is used, long queries may take O ( T + | Σ| + DH (^) V ) expected time because the average bucket size can approach | Σ|. If the cardinality of Σ is fairly large (e.g. 20 for protein sequences) then both of
puting a code. Specifically, if W is of length T − 1 then the modified encoding ρ of Wa is given by ρ( Wa ) = φ( W )2 R^ + φ( a ) mod 2 R^. The treatment for constructing the index is as before except that φ (^) i is replaced with ρ (^) i = ρ( a (^) i a (^) i + 1...^ a (^) i + T − 1 ). With this choice of encoding, there are no more than N codes and there are no less than N/ 2. Thus the structure takes Θ( N ) time and space to construct independent of the size of Σ, and the average bucket size is between 1 and 2 so that searches using the ρ-code on the first T symbols of a query V will take no more than O ( DH (^) V ) expected time. Note that the T th^ symbol of V will have to be compared against its corresponding symbol for each bucket entry, but this does not add to the asymptotic complexity.
The second detail is that φ (^) i (ρ (^) i ) is not properly defined for i > N − T + 1 ( N − T ). This can rectified by simply adopting the convention that for i > N , a (^) i is any symbol not equal to a (^) N. This guarantees that the integer codes for indices N − T + 2 to N are all distinct and thus contri- bute at most one extra element to any particular Bucket set. Thus the expected case analysis for searching still holds, although one must additionally check each index in a bucket and reject it if it is greater than N − U where U is the length of the query.
†The structure requires exactly 2 N + O (1) integers in the range 0 to N , and may be built with σ( N ) additional space with some very careful ‘‘in-place’’ manipulations. It is thus a very space efficient and practical index.
array L [0.. T + D + 1, 0.. T ] vector V [1.. T + D + 1]