Ruzzo–Tompa algorithm
The Ruzzo-Tompa algorithm is a linear time algorithm for finding all non-overlapping, contiguous, maximal scoring subsequences in a sequence of real numbers.[1] This algorithm is an improvement over previously known quadratic time algorithms. The maximum scoring subsequence from the set produced by the algorithm is also a solution to the Maximum subarray problem.
The Ruzzo-Tompa algorithm has applications in Bioinformatics, Web scraping, and Information retrieval.
Applications
Bioinformatics
The Ruzzo-Tompa algorithm has been used in Bioinformatics tools to study biological data. The problem of finding disjoint maximal subsequences is of practical importance in the analysis of DNA. Maximal subsequences algorithms have been used in the identification of transmembrane segments and the evaluation of sequence homology[2]
Problem Definition
The problem of finding all maximal subsequences is defined as follows: Given a list of real numbered scores , find the list of contiguous subsequences that gives the great total score, where the score of each subsequence . The subsequences must be disjoint (non-overlapping) and have a positive score.
Algorithm
There are several approaches to solving the all maximal scoring subsequences problem. A natural approach is to use existing, linear time algorithms to find the maximum subsequence (see maximum subarray problem) and then recursively find the maximal subsequences to the left and right of the maximum subsequence. The analysis of this algorithm is similar to that of Quicksort: The maximum subsequence could be small in comparison to the rest of sequence, leading to a running time of in the worst case.
The standard implementation of the Ruzzo-Tompa algorithm runs in time and uses space, where is the length of the list of scores. The algorithm uses dynamic programming to progressively build the final solution by incrementally solving progressively larger subsets of the problem. The description of the algorithm provided by Ruzzo and Tompa is as follows:
- Read the scores left to right and maintain the cumulative sum of the scores read. Maintain an ordered list of disjoint subsequences. For each subsequence , record the cumulative total of all scores up to but not including the leftmost score of , and the total up to and including the rightmost score of .
- The lists are initially empty. Scores are read from left to right and are processed as follows. Nonpositive scores are require no special processing, so the next score is read. A positive score is incorporated into a new sub-sequence of length one that is then integrated into the list by the following process.
- The list is searched from right to left for the maximum value of satisfying
- If there is no such , then add to the end of the list.
- If there is such a , and , then add to the end of the list.
- Otherwise (i.e., there is such a j, but ), extend the subsequence to the left to encompass everything up to and including the leftmost score in . Delete subsequences from the list, and append to the end of the list. Reconsider the newly extended subsequence (now renumbered ) as in step 1.
- Once the end of the input is reached, all subsequences remaining on the list are maximal.[2]
As example of the algorithm running, consider the input score list . On input in step 1, no satisfying is found so step 2 applies and is appended to , so . The input is skipped and the input is read. In step 1, no satisfying is found so is appended to , so . The input is skipped and the input is read. In step 1, a value of is found to satisfy , so step 3 applies. In step 3, , so is appended to , and now . On input in step 1 a value of is found to satisfy , so step 3 applies. In step 3, , so step 4 applies. In step 4, the elements of are inserted into and is removed from , so now . Now we consider the input . In step 1, a value of is found to satisfy , so step 3 applies. In step 3, , so step 4 applies. In step 4, the elements of are inserted into and is removed from , so now . Now we consider the input . In step 1, so satisfying value of is found, so is appended to . The end of the input has been reached, so the final value of is .
The following Python code implements the Ruzzo-Tompa algorithm:
def RuzzoTompa(scores):
k=0
total = 0;
# Allocating arrays of size n
I,L,R,Lidx = [[0]*len(scores) for _ in range(4)]
for i,s in enumerate(scores):
total += s
if s > 0:
# store I[k] by (start,end) indices of scores
I[k] = (i,i+1)
Lidx[k] = i
L[k] = total-s
R[k] = total
while(True):
maxj = None
for j in range(k-1,-1,-1):
if L[j] < L[k]:
maxj = j
break;
if maxj != None and R[maxj] < R[k]:
I[maxj] = (Lidx[maxj],i+1)
R[maxj] = total
k = maxj
else:
k+=1
break;
# Getting maximal subsequences using stored indices
return [scores[I[l][0]:I[l][1]] for l in range(k)]
References
- ^ Ruzzo, Walter L.; Martin, Tompa (1999). "A Linear Time Algorithm for Finding All Maximal Scoring Subsequences". Proceedings. International Conference on Intelligent Systems for Molecular Biology: 234–241. PMID 10786306.
- ^ a b Karlin, S; Altschul, SF (Jun 15, 1993). "Applications and statistics for multiple high-scoring segments in molecular sequences". Proceedings of the National Academy of Sciences of the United States of America. 90 (12): 5873–5877. PMID 8390686.
This article has not been added to any content categories. Please help out by adding categories to it so that it can be listed with similar articles. (May 2018) |