3194 |
22 Apr 14 |
peter |
// $Id$ |
3194 |
22 Apr 14 |
peter |
2 |
// |
3999 |
08 Oct 20 |
peter |
// Copyright (C) 2014, 2020 Peter Johansson |
3194 |
22 Apr 14 |
peter |
4 |
// |
3194 |
22 Apr 14 |
peter |
// This program is free software; you can redistribute it and/or modify |
3194 |
22 Apr 14 |
peter |
// it under the terms of the GNU General Public License as published by |
3194 |
22 Apr 14 |
peter |
// the Free Software Foundation; either version 3 of the License, or |
3194 |
22 Apr 14 |
peter |
// (at your option) any later version. |
3194 |
22 Apr 14 |
peter |
9 |
// |
3194 |
22 Apr 14 |
peter |
// This program is distributed in the hope that it will be useful, but |
3194 |
22 Apr 14 |
peter |
// WITHOUT ANY WARRANTY; without even the implied warranty of |
3194 |
22 Apr 14 |
peter |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
3194 |
22 Apr 14 |
peter |
// General Public License for more details. |
3194 |
22 Apr 14 |
peter |
14 |
// |
3194 |
22 Apr 14 |
peter |
// You should have received a copy of the GNU General Public License |
3194 |
22 Apr 14 |
peter |
// along with this program. If not, see <http://www.gnu.org/licenses/>. |
3194 |
22 Apr 14 |
peter |
17 |
|
3194 |
22 Apr 14 |
peter |
18 |
#include <config.h> |
3194 |
22 Apr 14 |
peter |
19 |
|
3883 |
24 Mar 20 |
peter |
20 |
#ifdef YAT_HAVE_HTSLIB |
3194 |
22 Apr 14 |
peter |
21 |
#include "yat/omic/BamFile.h" |
3194 |
22 Apr 14 |
peter |
22 |
#include "yat/omic/BamPairIterator.h" |
3194 |
22 Apr 14 |
peter |
23 |
#include "yat/omic/BamRead.h" |
3194 |
22 Apr 14 |
peter |
24 |
#include "yat/omic/BamReadIterator.h" |
3194 |
22 Apr 14 |
peter |
25 |
#include "yat/omic/BamWriteIterator.h" |
3194 |
22 Apr 14 |
peter |
26 |
#endif |
3194 |
22 Apr 14 |
peter |
27 |
|
3194 |
22 Apr 14 |
peter |
28 |
#include <algorithm> |
3194 |
22 Apr 14 |
peter |
29 |
#include <cassert> |
3194 |
22 Apr 14 |
peter |
30 |
#include <string> |
3194 |
22 Apr 14 |
peter |
31 |
|
3295 |
25 Jul 14 |
peter |
// include Suite.h late to expose bug #797 |
3295 |
25 Jul 14 |
peter |
33 |
#include "Suite.h" |
3295 |
25 Jul 14 |
peter |
34 |
|
3194 |
22 Apr 14 |
peter |
35 |
using namespace theplu::yat; |
3883 |
24 Mar 20 |
peter |
36 |
#ifdef YAT_HAVE_HTSLIB |
3194 |
22 Apr 14 |
peter |
37 |
using namespace omic; |
3209 |
04 May 14 |
peter |
38 |
#endif |
3194 |
22 Apr 14 |
peter |
39 |
|
3194 |
22 Apr 14 |
peter |
40 |
void test1(test::Suite& suite); |
3194 |
22 Apr 14 |
peter |
41 |
|
3194 |
22 Apr 14 |
peter |
42 |
int main(int argc, char* argv[]) |
3194 |
22 Apr 14 |
peter |
43 |
{ |
3201 |
03 May 14 |
peter |
44 |
test::Suite suite(argc, argv, true); |
3194 |
22 Apr 14 |
peter |
45 |
try { |
3194 |
22 Apr 14 |
peter |
46 |
test1(suite); |
3194 |
22 Apr 14 |
peter |
47 |
} |
3194 |
22 Apr 14 |
peter |
48 |
catch (std::runtime_error& e) { |
3194 |
22 Apr 14 |
peter |
49 |
suite.add(false); |
3194 |
22 Apr 14 |
peter |
50 |
suite.err() << "error: what: " << e.what() << "\n"; |
3194 |
22 Apr 14 |
peter |
51 |
} |
3194 |
22 Apr 14 |
peter |
52 |
return suite.return_value(); |
3194 |
22 Apr 14 |
peter |
53 |
} |
3194 |
22 Apr 14 |
peter |
54 |
|
3194 |
22 Apr 14 |
peter |
55 |
|
3194 |
22 Apr 14 |
peter |
56 |
void test1(test::Suite& suite) |
3194 |
22 Apr 14 |
peter |
57 |
{ |
3883 |
24 Mar 20 |
peter |
58 |
#ifdef YAT_HAVE_HTSLIB |
3194 |
22 Apr 14 |
peter |
59 |
std::string file = "../../data/foo.sorted.bam"; |
3194 |
22 Apr 14 |
peter |
60 |
|
3194 |
22 Apr 14 |
peter |
61 |
InBamFile in(file); |
3194 |
22 Apr 14 |
peter |
62 |
BamReadIterator iter(in); |
3194 |
22 Apr 14 |
peter |
63 |
BamReadIterator end; |
3194 |
22 Apr 14 |
peter |
64 |
|
3194 |
22 Apr 14 |
peter |
65 |
std::vector<BamPair> result; |
3194 |
22 Apr 14 |
peter |
66 |
BamPairIterator<BamReadIterator> piter(iter, end); |
3194 |
22 Apr 14 |
peter |
67 |
BamPairIterator<BamReadIterator> pend(end, end); |
3194 |
22 Apr 14 |
peter |
68 |
for (; piter!=pend; ++piter) { |
3194 |
22 Apr 14 |
peter |
69 |
result.push_back(*piter); |
3197 |
29 Apr 14 |
peter |
70 |
result.back() = *piter; |
3196 |
22 Apr 14 |
peter |
// This code doesn't work with boost 1.48 (or older). See |
3196 |
22 Apr 14 |
peter |
// https://svn.boost.org/trac/boost/ticket/5697 for details. It's |
3196 |
22 Apr 14 |
peter |
// not obvious the fix was included in v1.49, but let's test here |
3196 |
22 Apr 14 |
peter |
// and if it wasn't modify this test accordingly and update the |
3196 |
22 Apr 14 |
peter |
// docs in 'yat/omic/BamPairIterator.h'. |
3194 |
22 Apr 14 |
peter |
76 |
result.back().first() = piter->first(); |
3194 |
22 Apr 14 |
peter |
77 |
result.back().second() = piter->second(); |
3194 |
22 Apr 14 |
peter |
78 |
} |
3194 |
22 Apr 14 |
peter |
// not really doing anything since we've already iterated through |
3194 |
22 Apr 14 |
peter |
// the range, but checking that bam_pair_iterator functions compile |
3194 |
22 Apr 14 |
peter |
81 |
std::copy(bam_pair_iterator(iter, end), bam_pair_iterator(end), |
3194 |
22 Apr 14 |
peter |
82 |
result.begin()); |
3194 |
22 Apr 14 |
peter |
83 |
|
3194 |
22 Apr 14 |
peter |
84 |
in.close(); |
3194 |
22 Apr 14 |
peter |
85 |
if (!suite.add(result.size())) |
3194 |
22 Apr 14 |
peter |
86 |
suite.err() << "error: empty result\n"; |
3194 |
22 Apr 14 |
peter |
87 |
|
3878 |
12 Mar 20 |
peter |
88 |
suite.test_input_iterator(piter); |
3201 |
03 May 14 |
peter |
89 |
#endif |
3194 |
22 Apr 14 |
peter |
90 |
} |