File: test_crosscompare.h

package info (click to toggle)
seqan2 2.4.0+dfsg-11~bpo9+1
  • links: PTS, VCS
  • area: main
  • in suites: stretch-backports
  • size: 223,500 kB
  • sloc: cpp: 256,886; ansic: 91,672; python: 8,339; sh: 995; xml: 570; makefile: 251; awk: 51
file content (237 lines) | stat: -rw-r--r-- 8,106 bytes parent folder | download | duplicates (3)
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
228
229
230
231
232
233
234
235
236
237
// ==========================================================================
//                 SeqAn - The Library for Sequence Analysis
// ==========================================================================
// Copyright (c) 2006-2018, 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: David Weese <david.weese@fu-berlin.de>
// ==========================================================================

#ifndef TESTS_INDEX_TEST_CROSS_COMPARE_H
#define TESTS_INDEX_TEST_CROSS_COMPARE_H

#include <typeinfo>

#include <seqan/index.h>

//////////////////////////////////////////////////////////////////////////////

namespace seqan
{


template <typename TIter>
inline void _dumpState(TIter const it)
{
    std::cout << typeid(it).name() << std::endl;
    std::cout << "  range:            " << value(it).range << std::endl;
    std::cout << "  countOccurrences: " << countOccurrences(it) << std::endl;
    std::cout << "  representative:   " << representative(it)   << std::endl;
    std::cout << "  parentEdgeLabel:  " << parentEdgeLabel(it)  << std::endl;
    std::cout << "  Occurrences:      ";
    for(unsigned i=0;i<countOccurrences(it);++i)
        std::cout << getOccurrences(it)[i] << " ";
    std::cout << std::endl;
}

template <typename TIterSpec, typename TIndex1, typename TIndex2>
void crossBottomUp(TIndex1 &index1, TIndex2 &index2)
{
    typename Iterator<TIndex1, TIterSpec>::Type iter1(index1);
    typename Iterator<TIndex2, TIterSpec>::Type iter2(index2);

    while (!atEnd(iter1) && !atEnd(iter2))
    {
        SEQAN_ASSERT_EQ(representative(iter1), representative(iter2));
        SEQAN_ASSERT_EQ(countOccurrences(iter1), countOccurrences(iter2));
        SEQAN_ASSERT_EQ(parentEdgeLength(iter1), parentEdgeLength(iter2));
        goNext(iter1);
        goNext(iter2);
    }
    SEQAN_ASSERT_EQ(atEnd(iter1), atEnd(iter2));
}

template <typename TIndexSpec1, typename TIndexSpec2, typename TText>
void crossIndex(TText &text)
{
    Index<TText, TIndexSpec1> index1(text);
    Index<TText, TIndexSpec2> index2(text);

/*    crossBottomUp< TopDown<ParentLinks<Preorder> > > (index1, index2);
    crossBottomUp< TopDown<ParentLinks<Postorder> > > (index1, index2);
*/    crossBottomUp< TopDown<ParentLinks<PreorderEmptyEdges> > > (index1, index2);
    crossBottomUp< TopDown<ParentLinks<PostorderEmptyEdges> > > (index1, index2);
}

template <typename TIndexSpec, typename TText1, typename TText2>
void crossSameIndex(TText1 &text1, TText2 &text2)
{
    Index<TText1, TIndexSpec> index1(text1);
    Index<TText2, TIndexSpec> index2(text2);

    SEQAN_ASSERT(text1 == text2);
    SEQAN_ASSERT(indexText(index1) == indexText(index2));
    {
        typename Iterator<Index<TText1, TIndexSpec>, TopDown<ParentLinks<PreorderEmptyEdges> > >::Type iter1(index1);
        typename Iterator<Index<TText2, TIndexSpec>, TopDown<ParentLinks<PreorderEmptyEdges> > >::Type iter2(index2);
        SEQAN_ASSERT_EQ(indexSA(index1), indexSA(index2));
    }

    crossBottomUp< TopDown<ParentLinks<PreorderEmptyEdges> > > (index1, index2);
    crossBottomUp< TopDown<ParentLinks<PostorderEmptyEdges> > > (index1, index2);
}

template <typename TIndexSpec1, typename TIndexSpec2>
void crossIndicesChar()
{
/*    {
        CharString text("mississippi");
        crossIndex<TIndexSpec1,TIndexSpec2> (text);
    }
    {
        DnaString text("acaaacatat");
        crossIndex<TIndexSpec1,TIndexSpec2> (text);
    }
*/    {
        StringSet<CharString> t;
        resize(t, 6);
        t[0] = "caterpillar";
        t[1] = "catwoman";
        t[2] = "pillow";
        t[3] = "willow";
        t[4] = "ill";
        t[5] = "wow";
        crossIndex<TIndexSpec1,TIndexSpec2> (t);
  }
    /*{
        StringSet<DnaString> t;
        resize(t, 6);
        t[0] = "caggctcgcgt";
        t[1] = "caggaacg";
        t[2] = "tcgttg";
        t[3] = "tggtcg";
        t[4] = "agg";
        t[5] = "ctg";
        crossIndex<TIndexSpec1,TIndexSpec2> (t);
    }*/
}

template <typename TIndexSpec1, typename TIndexSpec2>
void crossIndicesDna()
{
/*    {
        CharString text("mississippi");
        crossIndex<TIndexSpec1,TIndexSpec2> (text);
    }
    {
        DnaString text("acaaacatat");
        crossIndex<TIndexSpec1,TIndexSpec2> (text);
    }
*//*    {
        StringSet<CharString> t;
        resize(t, 6);
        t[0] = "caterpillar";
        t[1] = "catwoman";
        t[2] = "pillow";
        t[3] = "willow";
        t[4] = "ill";
        t[5] = "wow";
        crossIndex<TIndexSpec1,TIndexSpec2> (t);
    }*/
    {
        StringSet<DnaString> t;
        resize(t, 6);
        t[0] = "caggctcgcgt";
        t[1] = "caggaacg";
        t[2] = "tcgttg";
        t[3] = "tggtcg";
        t[4] = "agg";
        t[5] = "ctg";
        crossIndex<TIndexSpec1,TIndexSpec2> (t);
    }
}

template <typename TIndexSpec, typename TStringSpec1, typename TStringSpec2>
void crossStringsDna()
{
    StringSet<String<Dna, TStringSpec1> > t;
    resize(t, 6);
    t[0] = "caggctcgcgt";
    t[1] = "caggaacg";
    t[2] = "tcgttg";
    t[3] = "tggtcg";
    t[4] = "agg";
    t[5] = "ctg";
    StringSet<String<Dna, TStringSpec2>, Owner<ConcatDirect<> > > t2 = t;
    crossSameIndex<TIndexSpec> (t, t2);
}

SEQAN_DEFINE_TEST(testIndexCrossCompareChar)
{
    crossIndicesChar<IndexEsa<>, IndexWotd<> >();
    // crossIndicesChar<IndexWotd<>, IndexWotd<Dfi<> > >();
}

SEQAN_DEFINE_TEST(testIndexCrossCompareCharDfi)
{
    // crossIndicesChar<IndexEsa<>, IndexWotd<> >();
    crossIndicesChar<IndexWotd<>, IndexWotd<Dfi<> > >();
}

SEQAN_DEFINE_TEST(testIndexCrossCompareDna)
{
    crossIndicesDna<IndexEsa<>, IndexWotd<> >();
    // crossIndicesDna<IndexWotd<>, IndexWotd<Dfi<> > >();
}


SEQAN_DEFINE_TEST(testIndexCrossCompareDnaStrings)
{
    crossStringsDna<IndexEsa<>, Alloc<>, Alloc<> >();
    crossStringsDna<IndexEsa<>, Alloc<>, Packed<> >();
    crossStringsDna<IndexEsa<>, Alloc<>, External<> >();
    crossStringsDna<IndexEsa<>, Alloc<>, MMap<> >();

    crossStringsDna<IndexWotd<>, Alloc<>, Alloc<> >();
    crossStringsDna<IndexWotd<>, Alloc<>, Packed<> >();
    crossStringsDna<IndexWotd<>, Alloc<>, External<> >();
    crossStringsDna<IndexWotd<>, Alloc<>, MMap<> >();
}

SEQAN_DEFINE_TEST(testIndexCrossCompareDnaDfi)
{
    // crossIndicesDna<IndexEsa<>, IndexWotd<> >();
    crossIndicesDna<IndexWotd<>, IndexWotd<Dfi<> > >();
}

//////////////////////////////////////////////////////////////////////////////


} //namespace seqan

#endif //#ifndef SEQAN_HEADER_...