| Function hashInit Preprocessing step of a pure hashNext loop. Overlapping q-grams can efficiently be hashed by calling hash on the first text position and hashNext on succeeding, adjacent positions. One drawback of this scenario is that for-loops cannot start with the first position directly and become more complicated. As a remedy, hashInit was introduced which initializes the Shape to be used with hashNext on the first position directly. hashInit(shape, it) Include Headers seqan/index.h Parameters
shape | Shape to be used for hashing. Types: Shape
it | Sequence iterator pointing to the first text character of the shape.
Member of Shape Examples Two hash loop examples. The first loop uses hash/hashNext while the second use hashInit/hashNext and can process all hashes within the loop. File "shape_hash_init.cpp"
1 | #include <seqan/sequence.h>
2 | #include <seqan/index.h>
3 |
4 | using namespace seqan;
5 |
6 | int main ()
7 | {
8 | DnaString text = "AAAACACAGTTTGA";
9 | Shape<Dna, UngappedShape<3> > myShape;
10 |
11 | // loop using hash() and hashNext() starts at position 1
12 | std::cout << hash(myShape, begin(text)) << '\t';
13 | for (unsigned i = 1; i < length(text) - length(myShape) + 1; ++i)
14 | std::cout << hashNext(myShape, begin(text) + i) << '\t';
15 | std::cout << std::endl;
16 |
17 | // loop using hashInit() and hashNext() starts at position 0
18 | hashInit(myShape, begin(text));
19 | for (unsigned i = 0; i < length(text) - length(myShape) + 1; ++i)
20 | std::cout << hashNext(myShape, begin(text) + i) << '\t';
21 | std::cout << std::endl;
22 |
23 | return 0;
24 | }
The two loops produce the same hash values: 0 0 1 4 17 4 18 11 47 63 62 56 0 0 1 4 17 4 18 11 47 63 62 56 See Also hashNext SeqAn - Sequence Analysis Library - www.seqan.de

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