Example Program
Index countChildren
Example for using a countChildren and countOccurrences for indices.
This example shows how to iterate over a suffix tree and print the number of children and the number of occurrences of the node representatitves.
File "index_counting.cpp"
An example to demonstrate the functions countChildren and countOccurrences

1 | #include <iostream>
2 | #include <seqan/index.h>
3 |
4 | using namespace seqan;
5 |
6 | int main()
7 | {

We begin with a String to store our sequence.

8 | String<char> myString = "How many wood would a woodchuck chuck. A woodchuck chucks as much wood as a woodchuck could";
9 |

Then we create an Index of this StringSet.

10 | typedef Index<String<char> > TMyIndex;
11 | TMyIndex myIndex(myString);
12 |

we will use a TopDown Iterator that supports parent links, ommits empty edges and traverses the index in preorder to print out the number of children at each node (not the number of leafs in the subtree).

13 | Iterator<TMyIndex, TopDown<ParentLinks<PreorderEmptyEdges> > >::Type tdIterator(myIndex);
14 | Size<TMyIndex>::Type count;
15 |
16 | while (!atEnd(tdIterator))
17 | {

We print out the representatives of all nodes that have more than 3 children and the number of occurrences. Also, we print a message if a node is a leaf.

18 | count = countChildren(tdIterator);
19 | if (count >= 3)
20 | {
21 | std::cout << "Representative " << representative(tdIterator) << " has " << count << " children and ";
22 | std::cout << countOccurrences(tdIterator) << " occurrences " << std::endl;
23 | }
24 | if (isLeaf(tdIterator))
25 | std::cout << "The node is a leaf " << std::endl;
26 |
27 | tdIterator++;
28 | }
29 |
30 | return 0;
31 | }

Output
Representative has 17 children and 91 occurrences
Representative has 5 children and 16 occurrences
The node is a leaf
The node is a leaf
The node is a leaf
The node is a leaf
The node is a leaf
The node is a leaf
The node is a leaf
The node is a leaf
The node is a leaf
The node is a leaf
The node is a leaf
The node is a leaf
The node is a leaf
The node is a leaf
The node is a leaf
The node is a leaf
The node is a leaf
The node is a leaf
The node is a leaf
Representative a has 3 children and 5 occurrences
The node is a leaf
The node is a leaf
The node is a leaf
The node is a leaf
The node is a leaf
Representative c has 3 children and 12 occurrences
The node is a leaf
Representative chuck has 3 children and 5 occurrences
The node is a leaf
The node is a leaf
The node is a leaf
The node is a leaf
The node is a leaf
Representative ck has 3 children and 5 occurrences
The node is a leaf
The node is a leaf
The node is a leaf
The node is a leaf
The node is a leaf
The node is a leaf
Representative d has 3 children and 7 occurrences
The node is a leaf
The node is a leaf
The node is a leaf
The node is a leaf
The node is a leaf
The node is a leaf
The node is a leaf
The node is a leaf
Representative huck has 3 children and 5 occurrences
The node is a leaf
The node is a leaf
The node is a leaf
The node is a leaf
The node is a leaf
Representative k has 3 children and 5 occurrences
The node is a leaf
The node is a leaf
The node is a leaf
The node is a leaf
The node is a leaf
The node is a leaf
The node is a leaf
The node is a leaf
The node is a leaf
The node is a leaf
Representative o has 4 children and 13 occurrences
The node is a leaf
The node is a leaf
The node is a leaf
The node is a leaf
The node is a leaf
The node is a leaf
The node is a leaf
The node is a leaf
The node is a leaf
The node is a leaf
The node is a leaf
The node is a leaf
The node is a leaf
The node is a leaf
The node is a leaf
The node is a leaf
The node is a leaf
Representative uck has 3 children and 5 occurrences
The node is a leaf
The node is a leaf
The node is a leaf
The node is a leaf
The node is a leaf
The node is a leaf
The node is a leaf
The node is a leaf
The node is a leaf
The node is a leaf
The node is a leaf
The node is a leaf
The node is a leaf
The node is a leaf
The node is a leaf
See
Index, countChildren, isLeaf, countOccurrences
SeqAn - Sequence Analysis Library - www.seqan.de

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