File: test_journaled_string_tree_mock.h

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 (227 lines) | stat: -rw-r--r-- 11,759 bytes parent folder | download
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
// ==========================================================================
//                 SeqAn - The Library for Sequence Analysis
// ==========================================================================
// Copyright (c) 2006-2026, Knut Reinert, FU Berlin
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
//     * Redistributions of source code must retain the above copyright
//       notice, this list of conditions and the following disclaimer.
//     * Redistributions in binary form must reproduce the above copyright
//       notice, this list of conditions and the following disclaimer in the
//       documentation and/or other materials provided with the distribution.
//     * Neither the name of Knut Reinert or the FU Berlin nor the names of
//       its contributors may be used to endorse or promote products derived
//       from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL KNUT REINERT OR THE FU BERLIN BE LIABLE
// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
// OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
// DAMAGE.
//
// ==========================================================================
// Author: Rene Rahn <rene.rahn@fu-berlin.de>
// ==========================================================================
// Mock generator for the journaled string tree.
// ==========================================================================

#ifndef TESTS_JOURNALED_STRING_TREE_TEST_JOURNALED_STRING_TREE_MOCK_H_
#define TESTS_JOURNALED_STRING_TREE_TEST_JOURNALED_STRING_TREE_MOCK_H_

#include <vector>
#include <seqan/sequence.h>

using namespace seqan2;

struct TestJstPosConfig_
{
    typedef uint16_t TDeltaPos;
    typedef Dna      TSnpValue;
    typedef uint16_t TDelValue;
    typedef String<Dna> TInsValue;
    typedef Pair<TDelValue, TInsValue> TSVValue;
};

template <typename TString, typename TRef, typename TDeltaMap>
inline void
_createJournaledStrings(StringSet<TString> & set,
                        TRef const & source,
                        TDeltaMap const & map,
                        unsigned const dim)
{

    for (unsigned seqId = 0; seqId < dim; ++seqId)
    {
        TString seq = source;
        auto it = end(map, Standard());
        auto itBegin = begin(map, Standard());

        while (it != itBegin)
        {
            --it;
            if (!getDeltaCoverage(*it)[seqId])
                continue;
            switch (getDeltaType(*it))
            {
                case DELTA_TYPE_SNP:
                {
                    erase(seq, getDeltaPosition(*it));
                    insertValue(seq, getDeltaPosition(*it), deltaValue(it, DeltaTypeSnp()));
                    break;
                }
                case DELTA_TYPE_DEL:
                {
                    if((*it).deltaTypeEnd != DeltaEndType::IS_RIGHT)
                        erase(seq, getDeltaPosition(*it), getDeltaPosition(*it)+ deltaValue(it, DeltaTypeDel()));
                    break;
                }
                case DELTA_TYPE_INS:
                {
                    insert(seq, getDeltaPosition(*it), deltaValue(it, DeltaTypeIns()));
                    break;
                }
                case DELTA_TYPE_SV:
                {
                    if((*it).deltaTypeEnd != DeltaEndType::IS_RIGHT)
                    {
                        erase(seq, getDeltaPosition(*it), getDeltaPosition(*it) + deltaValue(it, DeltaTypeSV()).i1);
                        insert(seq, getDeltaPosition(*it), deltaValue(it, DeltaTypeSV()).i2);
                    }
                    break;
                }
            }
        }
        appendValue(set, seq);
    }
}

class JstMockGenerator
{
public:
    template <typename TJst>
    static TJst _createSimpleJst()
    {
        typename Host<typename Member<TJst, JstSourceMember>::Type>::Type const seq = "AGATCGAGCGAGCTAGCGACTCAG";
        TJst jst(seq, 100);
        String<unsigned> ids;
        appendValue(ids, 0);
        appendValue(ids, 3);
        appendValue(ids, 9);
        appendValue(ids, 99);

        insert(jst, 1, 3, ids, DeltaTypeDel());
        insert(jst, 8, "CGTA", ids, DeltaTypeIns());
        insert(jst, 10, 'C', ids, DeltaTypeSnp());
        insert(jst, 15, 2, ids, DeltaTypeDel());
        insert(jst, 20, 'A', ids, DeltaTypeSnp());

        return jst;
    }

    template <typename TJst>
    static TJst _createComplexJst()
    {
        //    POS	TYPE	S0	S1	S2	S3	S4	S5	S6	S7	S8	S9	MOD
        //     0	SNP		0	1	0	1	0	1	1	1	0	0	C
        //     0	INS		1	0	1	0	0	0	0	0	0	0	TTG
        //     0	DEL		0	0	0	0	1	0	0	0	0	1	2
        //     1	SNP		0	1	1	1	0	0	0	1	0	0	G
        //     5	STV		1	0	0	0	1	0	0	1	0	0	3,CTC
        //     6	INS		0	1	1	0	0	0	1	0	0	0	GGTAGACAACG
        //     8	DEL		1	0	0	0	0	0	1	1	0	1	10
        //     8	DEL		0	1	0	0	1	0	0	0	0	0	5
        //    10	SNP		0	0	1	0	0	1	0	0	0	0	G
        //    13	DEL		0	1	0	0	0	0	0	0	0	0	5
        //    13	DEL		0	0	0	0	1	1	0	0	0	0	8
        //    20	SNP		1	1	0	0	0	0	1	0	0	0	T
        //    40	INS		1	0	1	0	0	0	1	0	1	0	TGAC
        //    41	INS		1	0	1	0	0	0	0	1	0	1	GTAGA
        //    41	STV		0	1	0	0	0	1	1	0	0	0	5,A
        //    58	DEL		1	0	0	0	0	0	0	0	1	1	10
        //    60	SNP		0	1	1	1	1	1	1	1	0	0	G
        //    61	STV		0	0	1	0	0	1	1	1	0	0	2,TA
        //    63	DEL		0	0	0	1	0	1	0	1	0	0	3
        //    66	INS		0	0	0	0	1	0	1	1	0	0	AGGTA
        //    90	DEL		1	0	0	0	0	0	0	0	0	0	9
        //    90	DEL		0	1	0	0	0	0	0	0	0	0	10
        //    99	SNP		0	0	1	0	0	0	0	0	0	0	T
        //    100	INS		0	0	0	1	0	0	0	0	0	0	CCT

        typename Host<typename Member<TJst, JstSourceMember>::Type>::Type const seq = "ACGTGGGATTACGGACGAGCGGACTGATTTAGGAGGACAGTACGGGACTACGGACGTACTACGAGCGACTATCGACGAGAGGAGATCAGGCATTAAGCCC";
          // 01234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890
          // 0         1         2         3         4         5         6         7         8         9         10
        TJst jst(std::move(seq), 10);

        insert(jst, 0, 'C',                                 std::vector<unsigned>{1, 3, 5, 6, 7},       DeltaTypeSnp());
        insert(jst, 0, "TTG",                               std::vector<unsigned>{0, 2},                DeltaTypeIns());
        insert(jst, 0, 2,                                   std::vector<unsigned>{4, 9},                DeltaTypeDel());
        insert(jst, 1, 'G',                                 std::vector<unsigned>{1, 2, 3, 7},          DeltaTypeSnp());
        insert(jst, 5, Pair<unsigned, DnaString>(3, "CTC"), std::vector<unsigned>{0, 4, 7},             DeltaTypeSV());
        insert(jst, 6, "GGTAGACAACG",                       std::vector<unsigned>{1, 2, 6},             DeltaTypeIns());
        insert(jst, 8, 10,                                  std::vector<unsigned>{0, 6, 7, 9},          DeltaTypeDel());
        insert(jst, 8, 5,                                   std::vector<unsigned>{1, 4},                DeltaTypeDel());
        insert(jst, 10, 'G',                                std::vector<unsigned>{2, 5},                DeltaTypeSnp());
        insert(jst, 13, 5,                                  std::vector<unsigned>{1},                   DeltaTypeDel());
        insert(jst, 13, 8,                                  std::vector<unsigned>{4, 5},                DeltaTypeDel());
        insert(jst, 20, 'T',                                std::vector<unsigned>{0, 1, 6},             DeltaTypeSnp());
        insert(jst, 40, "TGAC",                             std::vector<unsigned>{0, 2, 6, 8},          DeltaTypeIns());
        insert(jst, 41, "GTAGA",                            std::vector<unsigned>{0, 2, 7, 9},          DeltaTypeIns());
        insert(jst, 41, Pair<unsigned, DnaString>(5, "A"),  std::vector<unsigned>{1, 5, 6},             DeltaTypeSV());
        insert(jst, 58, 10,                                 std::vector<unsigned>{0, 8, 9},             DeltaTypeDel());
        insert(jst, 60, 'G',                                std::vector<unsigned>{1, 2, 3, 4, 5, 6, 7}, DeltaTypeSnp());
        insert(jst, 61, Pair<unsigned, DnaString>(2, "TA"), std::vector<unsigned>{2, 5, 6, 7},          DeltaTypeSV());
        insert(jst, 63, 3,                                  std::vector<unsigned>{3, 5, 7},             DeltaTypeDel());
        insert(jst, 66, "AGGTA",                            std::vector<unsigned>{4, 6, 7},             DeltaTypeIns());
        insert(jst, 90, 9,                                  std::vector<unsigned>{0},                   DeltaTypeDel());
        insert(jst, 90, 10,                                 std::vector<unsigned>{1},                   DeltaTypeDel());
        insert(jst, 99, 'T',                                std::vector<unsigned>{2},                   DeltaTypeSnp());
        insert(jst, 100, "CCT",                             std::vector<unsigned>{3},                   DeltaTypeIns());

        return jst;
    }

    static StringSet<DnaString> _createComplexTestSet()
    {
        StringSet<DnaString> set;
        appendValue(set, "TTGACGTGCTCGCTGACTGATTTAGGAGGACAGTGACTGTAGAACGGGACTACGGACGTACTATCGACGAGAGGAGATCAGGC");
        appendValue(set, "CGGTGGGGTAGACAACGGAGCTGACTGATTTAGGAGGACAGTAACTACGGACGTACTGCGAGCGACTATCGACGAGAGGAGATCAGG");
        appendValue(set, "TTGAGGTGGGGTAGACAACGGATTGCGGACGAGCGGACTGATTTAGGAGGACAGTGACTGTAGAACGGGACTACGGACGTACTGTAAGCGACTATCGACGAGAGGAGATCAGGCATTAAGCCT");
        appendValue(set, "CGGTGGGATTACGGACGAGCGGACTGATTTAGGAGGACAGTACGGGACTACGGACGTACTGCGGACTATCGACGAGAGGAGATCAGGCATTAAGCCCCCT");
        appendValue(set, "GTGCTCGACTGATTTAGGAGGACAGTACGGGACTACGGACGTACTGCGAGCAGGTAGACTATCGACGAGAGGAGATCAGGCATTAAGCCC");
        appendValue(set, "CCGTGGGATTGCGGACTGATTTAGGAGGACAGTAACTACGGACGTACTGTAGACTATCGACGAGAGGAGATCAGGCATTAAGCCC");
        appendValue(set, "CCGTGGGGTAGACAACGGAGCTGACTGATTTAGGAGGACAGTGACTAACTACGGACGTACTGTAAGCAGGTAGACTATCGACGAGAGGAGATCAGGCATTAAGCCC");
        appendValue(set, "CGGTGCTCGCGGACTGATTTAGGAGGACAGTGTAGAACGGGACTACGGACGTACTGTAAGGTAGACTATCGACGAGAGGAGATCAGGCATTAAGCCC");
        appendValue(set, "ACGTGGGATTACGGACGAGCGGACTGATTTAGGAGGACAGTGACTACGGGACTACGGACGTACTATCGACGAGAGGAGATCAGGCATTAAGCCC");
        appendValue(set, "GTGGGAGCGGACTGATTTAGGAGGACAGTGTAGAACGGGACTACGGACGTACTATCGACGAGAGGAGATCAGGCATTAAGCCC");
        return set;
    }

    static StringSet<DnaString> generateNeedles()
    {
        std::vector<unsigned> ndlLengths = {5, 12, 23, 32, 66};
        StringSet<DnaString> ndlSet;

        auto set = _createComplexTestSet();
        for (unsigned id = 0; id < length(set); ++id)
        {
            for (unsigned pos = 0; pos < length(set[id]) - 5; ++pos)
            {
                auto ndlSize = ndlLengths[pos % length(ndlLengths)];
                ndlSize = _min(ndlSize, length(set[id]) - pos);
                appendValue(ndlSet, infix(set[id], pos, pos + ndlSize));
            }
        }
        return ndlSet;
    }
};

#endif // TESTS_JOURNALED_STRING_TREE_TEST_JOURNALED_STRING_TREE_MOCK_H_