| 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" A tutorial about the use of Pizza & Chili index.
1 | #include <iostream>
2 | #include <seqan/index.h>
3 |
4 | using namespace seqan;
5 |
6 | template <typename TSpec>
7 | void testPizzaChili() {
The following code creates a Pizza & Chili index and assigns it a text.
8 | typedef Index<String<char>, PizzaChili<TSpec> > index_t;
9 | index_t index_pc;
10 | indexText(index_pc) = "This is the best test with a bast jest.";
11 |
Of course, we can access the text as usual:
12 | ::std::cout << indexText(index_pc) << ::std::endl;
13 |
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.
14 | Finder<index_t> finder(index_pc);
15 | while (find(finder, "est"))
16 | ::std::cout << "Hit at position " << position(finder) << ::std::endl;
17 |
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(.., PizzaChiliText()).
18 | typename Fibre<index_t, PizzaChiliText>::Type text = indexText(index_pc);
19 | ::std::cout << "infix(text, 12, 21): " << infix(text, 12, 21) << ::std::endl;
20 |
We can save the index structure on disk 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.
21 | save(index_pc, "pizzachili");
22 | index_t index2;
23 | open(index2, "pizzachili");
24 | ::std::cout << indexText(index2) << ::std::endl;
25 | }
26 |
27 | int main() {
28 | ::std::cout << "Test the alphabet-friendly FM index:" << ::std::endl;
29 | testPizzaChili<PizzaChiliAF>();
30 | ::std::cout << ::std::endl << "Test the compressed compact suffix array index:" << ::std::endl;
31 | testPizzaChili<PizzaChiliCcsa>();
32 | return 0;
33 | }
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

Page built @2012/03/14 16:34:46