string-match problem
EDIT 2开发者_运维百科: I managed to find the solution with suffix trees
Tree::Suffixperl package. Thanks to MarcoS for thetrieidea. I figured out from that, that suffix trees could be used as well. TheTree::Trieperl package is implemented as hash of hashes and I guess that's the reason it slow. I tried it and then went back toTree::Suffix. Thanks to all others for their links to different algorithms. I am already trying to write code for every algorithm mentioned here myself as a learning processEDIT 1: I changed the title from
perl string-match problemtostring-match problem.
Suppose that I have two strings, say,
S1 = ACGAGGATAGTATGCCACACAATGAGTACCCGTAC
S2 = CAGTATTGCACGTTGTAAAGTTACCCAGGTACGATGACAGTGCGTGAGCATACGAGGATAGTATGCCA
I initially wanted to check for the occurrence of string S1 (with no or 1 mismatch) in S2. And I have already written the perl code for that.
Now, I would like to develop on it to
1) Search for k-mismatches of S1 in S2.
2) Search for the occurrence of aprefix(yes, prefix, not suffix), of S1 in S2. If you look at the example, the string:ACGAGGATAGTATGCCAoccurs at the end of S2 which is the beginning of S1. 3) If possible, search for the prefix with k-mismatches.
The catch is that I have about 100 million such S2 strings. S1 however remains the same and is of a defined constant length for a given problem. Is there an efficient algorithm in the literature that I could use for this problem of mine?
S1 varies between 50 and 80 characters. Also, I am mostly interested in solving problem 2 at first.
Thank you very much.
You may be able to modify the Aho-Corasick algorithm for your purposes.
For approximate matching, have a look at http://en.wikipedia.org/wiki/Bitap_algorithm as used in agrep.
加载中,请稍侯......
精彩评论