| Example Program Supermaximal Repeats Example for using the SuperMaxRepeats Iterator. Given a sequences, a repeat is a substring that occurs at at least 2 different positions. A supermaximal repeat is a repeat that is not part of any longer repeat. The following example demonstrates how to iterate over all supermaximal repeats and output them. File "index_supermaxrepeats.cpp"
1 | #include <iostream>
2 | #include <seqan/index.h>
3 |
4 | using namespace std;
5 | using namespace seqan;
6 |
7 | int main ()
8 | {
We begin with a String to store our sequence.
9 | String<char> myString = "How many wood would a woodchuck chuck.";
10 |
Then we create an Index of this StringSet
11 | typedef Index< String<char> > TMyIndex;
12 | TMyIndex myIndex(myString);
13 |
To find supermaximal repeats, we use SeqAn's SuperMaxRepeats Iterator and set the minimum repeat length to 3.
14 | Iterator< TMyIndex, SuperMaxRepeats >::Type myRepeatIterator(myIndex, 3);
15 |
16 | while (!atEnd(myRepeatIterator))
17 | {
A repeat can be represented by its length and positions it occurs at. getOccurrences returns an unordered sequence of these positions The length of this sequence, i.e. the repeat abundance can be obtained from countOccurrences.
18 | for(unsigned i = 0; i < countOccurrences(myRepeatIterator); ++i)
19 | cout << getOccurrences(myRepeatIterator)[i] << ", ";
20 |
repLength returns the length of the repeat string.
21 | cout << repLength(myRepeatIterator) << " ";
22 |
The repeat string itself can be determined with representative
23 | cout << "\t\"" << representative(myRepeatIterator) << '\"' << endl;
24 |
25 | ++myRepeatIterator;
26 | }
27 |
28 | return 0;
29 | }
Output The only supermaximal repeats of "How many wood would a woodchuck chuck." of length at least 3 are " wood" and "chuck". There are repeats of " wo" which are maximal (see Maximal Repeats), ut not supermaximal, as " wo" is part of the longer repeat " wood". weese@tanne:~/seqan$ cd demos weese@tanne:~/seqan/demos$ make index_supermaxrepeats weese@tanne:~/seqan/demos$ ./index_supermaxrepeats 8, 21, 5 " wood" 26, 32, 5 "chuck" weese@tanne:~/seqan/demos$ See countOccurrences, getOccurrences, Index, repLength, representative, SuperMaxRepeats Iterator SeqAn - Sequence Analysis Library - www.seqan.de