File: index_find.cpp

package info (click to toggle)
seqan2 2.4.0%2Bdfsg-16
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 224,180 kB
  • sloc: cpp: 256,886; ansic: 91,672; python: 8,330; sh: 995; xml: 570; makefile: 252; awk: 51; javascript: 21
file content (33 lines) | stat: -rw-r--r-- 1,186 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
///A tutorial about find algorithms using an index.
#include <iostream>
#include <seqan/index.h>

using namespace seqan;

int main()
{
///The following code creates an @Class.Index@ of $"tobeornottobe"$.
///As there is no second template parameter given to $Index<..>$,
///the default index based on an enhanced suffix array is used.
    Index<String<char> > index_esa("tobeornottobe");
    Finder<Index<String<char> > > finder_esa(index_esa);

    std::cout << "hit at ";
    while (find(finder_esa, "be"))
        std::cout << position(finder_esa) << " ";
    std::cout << std::endl;

///Now we explicitly create a q-gram index using an ungapped 2-gram and do the same.
///Instead of this @Spec.UngappedShape.fixed-size shape@ you can use arbitrary
///@Class.Shape.shapes@ and assign them before calling @Function.find@ via @Function.indexShape@.
    typedef Index<String<char>, IndexQGram<UngappedShape<2> > > TQGramIndex;
    TQGramIndex index_2gram("tobeornottobe");
    Finder<TQGramIndex> finder_2gram(index_2gram);

    std::cout << "hit at ";
    while (find(finder_2gram, "be"))
        std::cout << position(finder_2gram) << " ";
    std::cout << std::endl;

    return 0;
}