Example Program
Maximal Repeats
Example for using the MaxRepeats Iterator.
Given a sequences, a repeat is a substring that occurs at at least 2 different positions. A maximal repeat is a repeat that cannot be extended to the left or to right to a longer repeat. The following example demonstrates how to iterate over all maximal repeats and output them.
File "index_maxrepeats.cpp"
A tutorial about finding maximal repeats.

1 | //![includes]
2 | #include <iostream>
3 | #include <seqan/index.h>
4 |
5 | using namespace seqan;
6 |
7 | //![includes]
8 | //![init]
9 | int main ()
10 | {
11 |
12 | String<char> myString = "How many wood would a woodchuck chuck.";
13 |
14 | typedef Index< String<char> > TMyIndex;
15 | TMyIndex myIndex(myString);
16 |
17 | //![init]
18 | //![iteration]
19 | typedef Iterator< TMyIndex, MaxRepeats >::Type TMaxRepeatIterator;
20 | TMaxRepeatIterator myRepeatIterator(myIndex, 3);
21 |
22 | while (!atEnd(myRepeatIterator))
23 | {
24 | Iterator<TMaxRepeatIterator>::Type myRepeatPair(myRepeatIterator);
25 | while (!atEnd(myRepeatPair)) {
26 | std::cout << *myRepeatPair << ", ";
27 | ++myRepeatPair;
28 | }
29 |
30 | std::cout << repLength(myRepeatIterator) << " ";
31 | std::cout << "\t\"" << representative(myRepeatIterator) << '\"' << std::endl;
32 |
33 | ++myRepeatIterator;
34 | }
35 |
36 | return 0;
37 | }
38 | //![iteration]

Output
As all supermaximal repeats (see Supermaximal Repeats) are also maximal repeats, " wood" and "chuck" are outputted. In "How many wood would a woodchuck chuck." " wo" is a repeat of length 3 that occurs at two pairs of positions which are maximal repeats (" a wood", "od woul" and "ny wood", "od woul"). Beside these there are no other maximal repeats of length at least 3.
weese@tanne:~/seqan$ cd demos
weese@tanne:~/seqan/demos$ make index_maxrepeats
weese@tanne:~/seqan/demos$ ./index_maxrepeats
< 8 , 21 >, 5 " wood"
< 21 , 13 >, < 8 , 13 >, 3 " wo"
< 26 , 32 >, 5 "chuck"
weese@tanne:~/seqan/demos$
See
Index, MaxRepeats Iterator, representative, orderOccurrences
SeqAn - Sequence Analysis Library - www.seqan.de

Page built @2014/10/13 16:12:57