| Example Program Pizza & Chili Index Using a Pizza & Chili Index for searching and the Pizza & Chili String for displaying. This demonstrates how the Pizza & Chili index libraries may be used in conjunction with Seqan. In order to run this example you have to statically link the Pizza & Chili library (found in seqan/lib/libpizzachili.a). File "pizzachili.cpp"
1 | #include <iostream>
2 | #include <seqan/index.h>
3 |
4 | using namespace std;
5 | using namespace seqan;
6 |
7 | template <typename TSpec>
8 | void testPizzaChili() {
The following code creates a Pizza & Chili index and assigns it a text.
9 | typedef Index<String<char>, PizzaChili<TSpec> > index_t;
10 | index_t index_pc;
11 | indexText(index_pc) = "This is the best test with a bast jest.";
12 |
Of course, we can access the text as usual:
13 | cout << indexText(index_pc) << endl;
14 |
Now we may create a default finder and search for a substring. The index is only now created because its evaluation is lazy. Immediately after the index has been created, the indexText is discarded to save memory. Notice that the results returned by the finder might not be in the order of their occurrence in the text.
15 | Finder<index_t> finder(index_pc);
16 | while (find(finder, "est"))
17 | cout << "Hit at position " << position(finder) << endl;
18 |
We may query the text of the index. Notice that this returns a string without any real content. The string is lazily evaluated in order to save memory. Only the substring we are actually displaying will be loaded into memory. indexText(..) is a shortcut for getFibre(.., PizzaChili_Text()).
19 | typename Fibre<index_t, PizzaChili_Text>::Type text = indexText(index_pc);
20 | cout << "infix(text, 12, 21): " << infix(text, 12, 21) << endl;
21 |
We can save the index structure on disc and load it again. Notice, however, that not all Pizza & Chili libraries support saving and loading at the moment. Please refer to the documentation of the different Pizza & Chili Index Tags for details.
22 | save(index_pc, "pizzachili");
23 | index_t index2;
24 | open(index2, "pizzachili");
25 | cout << indexText(index2) << endl;
26 | }
27 |
28 | int main() {
29 | cout << "Test the alphabet-friendly FM index:" << endl;
30 | testPizzaChili<PizzaChili_AF>();
31 | cout << endl << "Test the compressed compact suffix array index:" << endl;
32 | testPizzaChili<PizzaChili_CCSA>();
33 | return 0;
34 | }
Output ~/seqan$ cd demos/extra ~/seqan/demos/extra$ make pizzachili ~/seqan/demos/extra$ ./pizzachili Test the alphabet-friendly FM index: This is the best test with a bast jest. Hit at position 13 Hit at position 18 Hit at position 35 infix(text, 12, 21): best test This is the best test with a bast jest. Test the compressed compact suffix array index: This is the best test with a bast jest. Hit at position 13 Hit at position 18 Hit at position 35 infix(text, 12, 21): best test This is the best test with a bast jest. ~/seqan/demos/extra$ See Pizza & Chili Index, Pizza & Chili String SeqAn - Sequence Analysis Library - www.seqan.de