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).
A tutorial about the use of Pizza & Chili index.
1#include <iostream>
2#include <seqan/index.h>
4using namespace seqan;
6template <typename TSpec>
7void 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.";
Of course, we can access the text as usual:
12    ::std::cout << indexText(index_pc) << ::std::endl;
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;
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;
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;
27int 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;
~/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 - Sequence Analysis Library - www.seqan.de

Page built @2011/02/08 21:37:01