File: cyclic_shape_snippets.cpp

package info (click to toggle)
seqan2 2.5.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 228,748 kB
  • sloc: cpp: 257,602; ansic: 91,967; python: 8,326; sh: 1,056; xml: 570; makefile: 229; awk: 51; javascript: 21
file content (86 lines) | stat: -rw-r--r-- 2,954 bytes parent folder | download | duplicates (2)
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
// ==========================================================================
// Author: Sascha Meiers <meiers@inf.fu-berlin.de>
// ==========================================================================
// Snippets for CyclicShape demonstrations
// ==========================================================================


#include <seqan/sequence.h>
#include <seqan/stream.h>      // For printing SeqAn Strings.
#include <seqan/modifier.h>

using namespace seqan2;
int main(int, char const **)
{

    {
        //![Define FixedCyclicShape]
        typedef GappedShape<HardwiredShape<1, 1, 3, 2> >       TInnerShape; // 11100101
        // ^--You can also use predefied Shapes here, e.g. Patternhunter

        typedef CyclicShape<FixedShape<2, TInnerShape, 1> > TShape;     // 00111001010
        TShape shape;
        //![Define FixedCyclicShape]


        //![Define FixedCyclicShape Modified String]
        typedef ModifiedString<CharString, ModCyclicShape<TShape> > TModString;

        CharString str = "das ist das Haus vom Nikolaus";
        TModString modStr(str);

        std::cout << str << " => " << modStr << std::endl;
        //![Define FixedCyclicShape Modified String]
    }


    {
        //![Define GenericCyclicShape]
        typedef CyclicShape<GenericShape> TShape;
        TShape shape;
        stringToCyclicShape(shape, "00111001010");
        //![Define GenericCyclicShape]


        //![Define GenericCyclicShape Modified String]
        typedef ModifiedString<CharString, ModCyclicShape<TShape> > TModString;

        CharString str = "das ist das Haus vom Nikolaus";
        TModString modStr(str, shape);

        std::cout << str << " => " << modStr << std::endl;
        //![Define GenericCyclicShape Modified String]


        //![Define CyclicShape Modified Iterator]
        typedef ModifiedString<CharString, ModCyclicShape<TShape> > TModString;
        typedef Iterator<TModString>::Type TModIter;
        TModIter it = begin(modStr);
        TModIter itBeg = it;
        TModIter itEnd = end(modStr);

        // output iter position and host iter position
        for (; it != itEnd; ++it)
            std::cout << (it - itBeg) << "/" << (host(it) - begin(str)) << ", ";

        //  0/2, 1/3, 2/4, 3/7, 4/9, 5/13, 6/14, 7/15, 8/18, 9/20, 10/24, 11/25, 12/26,
        //![Define CyclicShape Modified Iterator]


        //![CyclicShape Care Positions]
        std::cout << std::endl << "relative care positions: ";
        for (unsigned i = 0; i < weight(shape); ++i)
            std::cout << (int)shape.diffs[i] << ",";    // output: 1,1,3,2,4,

        std::cout << std::endl << "absolute care positions: ";
        String<int> carePos;
        carePositions(carePos, shape);

        for (unsigned i = 0; i < weight(shape); ++i)
            std::cout << carePos[i] << ",";             // output: 2,3,4,7,9,
        std::cout << std::endl;
        //![CyclicShape Care Positions]
    }

    return 0;
}