| Example Program Index Finder Example for using a Finder of an Index. This example shows how to use the Finder class for an Index search. File "index_find.cpp"
1 | #include <iostream>
2 | #include <seqan/index.h>
3 |
4 | using namespace std;
5 | using namespace seqan;
6 |
7 | int main ()
8 | {
The following code creates an Index of "tobeornottobe". As there is no second template parameter given to Index<..>, the default index based on an enhanced suffix array is used.
9 | Index< String<char> > index_esa("tobeornottobe");
10 | Finder< Index< String<char> > > finder_esa(index_esa);
11 |
12 | cout << "hit at ";
13 | while (find(finder_esa, "be"))
14 | cout << position(finder_esa) << " ";
15 | cout << endl;
16 |
Now we explicitly create a q-gram index using an ungapped 2-gram and do the same. Instead of this fixed-size shape you can use arbitrary shapes and assign them before calling find via indexShape.
17 | typedef Index< String<char>, Index_QGram< FixedShape<2> > > TQGramIndex;
18 | TQGramIndex index_2gram("tobeornottobe");
19 | Finder< TQGramIndex > finder_2gram(index_2gram);
20 |
21 | cout << "hit at ";
22 | while (find(finder_2gram, "be"))
23 | cout << position(finder_2gram) << " ";
24 | cout << endl;
25 |
26 | return 0;
27 | }
Output weese@tanne:~/seqan$ cd demos weese@tanne:~/seqan/demos$ make index_find weese@tanne:~/seqan/demos$ ./index_find hit at 11 2 hit at 2 11 weese@tanne:~/seqan/demos$ See find, Finder, Index SeqAn - Sequence Analysis Library - www.seqan.de