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