3329 |
12 Oct 14 |
peter |
// $Id$ |
3329 |
12 Oct 14 |
peter |
2 |
|
3329 |
12 Oct 14 |
peter |
3 |
/* |
3417 |
25 May 15 |
peter |
Copyright (C) 2014, 2015 Peter Johansson |
3329 |
12 Oct 14 |
peter |
5 |
|
3329 |
12 Oct 14 |
peter |
This file is part of the yat library, http://dev.thep.lu.se/yat |
3329 |
12 Oct 14 |
peter |
7 |
|
3329 |
12 Oct 14 |
peter |
The yat library is free software; you can redistribute it and/or |
3329 |
12 Oct 14 |
peter |
modify it under the terms of the GNU General Public License as |
3329 |
12 Oct 14 |
peter |
published by the Free Software Foundation; either version 3 of the |
3329 |
12 Oct 14 |
peter |
License, or (at your option) any later version. |
3329 |
12 Oct 14 |
peter |
12 |
|
3329 |
12 Oct 14 |
peter |
The yat library is distributed in the hope that it will be useful, |
3329 |
12 Oct 14 |
peter |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
3329 |
12 Oct 14 |
peter |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
3329 |
12 Oct 14 |
peter |
General Public License for more details. |
3329 |
12 Oct 14 |
peter |
17 |
|
3329 |
12 Oct 14 |
peter |
You should have received a copy of the GNU General Public License |
3329 |
12 Oct 14 |
peter |
along with yat. If not, see <http://www.gnu.org/licenses/>. |
3329 |
12 Oct 14 |
peter |
20 |
*/ |
3329 |
12 Oct 14 |
peter |
21 |
|
3329 |
12 Oct 14 |
peter |
22 |
#include <config.h> |
3329 |
12 Oct 14 |
peter |
23 |
|
3329 |
12 Oct 14 |
peter |
24 |
#include "Suite.h" |
3329 |
12 Oct 14 |
peter |
25 |
|
3329 |
12 Oct 14 |
peter |
26 |
#include "yat/utility/Cigar.h" |
3336 |
24 Oct 14 |
peter |
27 |
#include "yat/utility/CigarIterator.h" |
3329 |
12 Oct 14 |
peter |
28 |
|
3329 |
12 Oct 14 |
peter |
29 |
#include <boost/cstdint.hpp> |
3329 |
12 Oct 14 |
peter |
30 |
|
3329 |
12 Oct 14 |
peter |
31 |
#include <cassert> |
3372 |
11 Feb 15 |
peter |
32 |
#include <deque> |
3372 |
11 Feb 15 |
peter |
33 |
#include <vector> |
3329 |
12 Oct 14 |
peter |
34 |
|
3329 |
12 Oct 14 |
peter |
35 |
using namespace theplu::yat; |
3329 |
12 Oct 14 |
peter |
36 |
|
3329 |
12 Oct 14 |
peter |
37 |
void test1(test::Suite& suite); |
3329 |
12 Oct 14 |
peter |
38 |
|
3329 |
12 Oct 14 |
peter |
39 |
int main(int argc, char* argv[]) |
3329 |
12 Oct 14 |
peter |
40 |
{ |
3329 |
12 Oct 14 |
peter |
41 |
test::Suite suite(argc, argv); |
3329 |
12 Oct 14 |
peter |
42 |
|
3329 |
12 Oct 14 |
peter |
43 |
test1(suite); |
3329 |
12 Oct 14 |
peter |
44 |
|
3329 |
12 Oct 14 |
peter |
45 |
return suite.return_value(); |
3329 |
12 Oct 14 |
peter |
46 |
} |
3329 |
12 Oct 14 |
peter |
47 |
|
3329 |
12 Oct 14 |
peter |
48 |
void test1(test::Suite& suite) |
3329 |
12 Oct 14 |
peter |
49 |
{ |
3329 |
12 Oct 14 |
peter |
// create a cigar 5S4M1D3M1I4M |
3329 |
12 Oct 14 |
peter |
51 |
std::vector<uint32_t> oplen; |
3329 |
12 Oct 14 |
peter |
52 |
std::vector<uint32_t> op; |
3329 |
12 Oct 14 |
peter |
53 |
oplen.push_back(5); |
3329 |
12 Oct 14 |
peter |
54 |
oplen.push_back(4); |
3329 |
12 Oct 14 |
peter |
55 |
oplen.push_back(1); |
3329 |
12 Oct 14 |
peter |
56 |
oplen.push_back(3); |
3329 |
12 Oct 14 |
peter |
57 |
oplen.push_back(1); |
3329 |
12 Oct 14 |
peter |
58 |
oplen.push_back(4); |
3329 |
12 Oct 14 |
peter |
59 |
|
3329 |
12 Oct 14 |
peter |
60 |
op.push_back(BAM_CSOFT_CLIP); |
3329 |
12 Oct 14 |
peter |
61 |
op.push_back(BAM_CMATCH); |
3329 |
12 Oct 14 |
peter |
62 |
op.push_back(BAM_CDEL); |
3329 |
12 Oct 14 |
peter |
63 |
op.push_back(BAM_CMATCH); |
3329 |
12 Oct 14 |
peter |
64 |
op.push_back(BAM_CINS); |
3329 |
12 Oct 14 |
peter |
65 |
op.push_back(BAM_CMATCH); |
3329 |
12 Oct 14 |
peter |
66 |
|
3329 |
12 Oct 14 |
peter |
67 |
assert(oplen.size()==op.size()); |
3329 |
12 Oct 14 |
peter |
68 |
std::vector<uint32_t> cigar; |
3329 |
12 Oct 14 |
peter |
69 |
std::vector<uint32_t> long_cigar; |
3329 |
12 Oct 14 |
peter |
70 |
for (size_t i=0; i<op.size(); ++i) { |
3329 |
12 Oct 14 |
peter |
71 |
cigar.push_back(bam_cigar_gen(oplen[i], op[i])); |
3329 |
12 Oct 14 |
peter |
72 |
for (size_t j=0; j<oplen[i]; ++j) |
3329 |
12 Oct 14 |
peter |
73 |
long_cigar.push_back(op[i]); |
3329 |
12 Oct 14 |
peter |
74 |
} |
3329 |
12 Oct 14 |
peter |
75 |
|
3336 |
24 Oct 14 |
peter |
76 |
typedef std::vector<uint32_t>::const_iterator Base; |
3336 |
24 Oct 14 |
peter |
77 |
utility::CigarIterator<Base> iter(cigar.begin()); |
3336 |
24 Oct 14 |
peter |
78 |
utility::CigarIterator<Base> end(cigar.end()); |
3329 |
12 Oct 14 |
peter |
79 |
std::vector<uint32_t>::const_iterator iter2 = long_cigar.begin(); |
3329 |
12 Oct 14 |
peter |
80 |
while (iter!=end) { |
3329 |
12 Oct 14 |
peter |
81 |
assert(iter2<long_cigar.end()); |
3329 |
12 Oct 14 |
peter |
82 |
if (*iter != *iter2) { |
3329 |
12 Oct 14 |
peter |
83 |
suite.add(false); |
3329 |
12 Oct 14 |
peter |
84 |
suite.err() << (iter2 - long_cigar.begin()) << " " |
3329 |
12 Oct 14 |
peter |
85 |
<< *iter << " " << *iter2 << "\n"; |
3329 |
12 Oct 14 |
peter |
86 |
} |
3329 |
12 Oct 14 |
peter |
87 |
++iter; |
3329 |
12 Oct 14 |
peter |
88 |
++iter2; |
3329 |
12 Oct 14 |
peter |
89 |
} |
3329 |
12 Oct 14 |
peter |
90 |
|
3372 |
11 Feb 15 |
peter |
// check default constructor |
3372 |
11 Feb 15 |
peter |
92 |
utility::CigarIterator<Base> iter3; |
3372 |
11 Feb 15 |
peter |
// check assignment |
3372 |
11 Feb 15 |
peter |
94 |
iter3 = utility::CigarIterator<Base>(cigar.begin()); |
3336 |
24 Oct 14 |
peter |
95 |
utility::CigarIterator<Base> iter4(cigar.begin()+3, 1); |
3329 |
12 Oct 14 |
peter |
96 |
std::advance(iter3, oplen[0]+oplen[1]+oplen[2]+1); |
3329 |
12 Oct 14 |
peter |
97 |
if (iter3 != iter4) { |
3329 |
12 Oct 14 |
peter |
98 |
suite.add(false); |
3329 |
12 Oct 14 |
peter |
99 |
suite.err() << "error: iter3!=iter4\n"; |
3329 |
12 Oct 14 |
peter |
100 |
} |
3329 |
12 Oct 14 |
peter |
// do not run compiler test |
3329 |
12 Oct 14 |
peter |
102 |
if (false) { |
3329 |
12 Oct 14 |
peter |
103 |
test::test_readable_iterator(iter3); |
3329 |
12 Oct 14 |
peter |
104 |
test::test_bidirectional_traversal_iterator(iter3); |
3372 |
11 Feb 15 |
peter |
// test default constructor |
3372 |
11 Feb 15 |
peter |
106 |
utility::CigarIterator<std::deque<uint32_t>::const_iterator> iter5; |
3372 |
11 Feb 15 |
peter |
107 |
test::avoid_compiler_warning(iter5); |
3329 |
12 Oct 14 |
peter |
108 |
} |
3329 |
12 Oct 14 |
peter |
109 |
} |