2895 |
10 Dec 12 |
peter |
// $Id$ |
2895 |
10 Dec 12 |
peter |
2 |
// |
3999 |
08 Oct 20 |
peter |
// Copyright (C) 2012, 2013, 2014, 2017, 2020 Peter Johansson |
2895 |
10 Dec 12 |
peter |
4 |
// |
2895 |
10 Dec 12 |
peter |
// This program is free software; you can redistribute it and/or modify |
2895 |
10 Dec 12 |
peter |
// it under the terms of the GNU General Public License as published by |
2895 |
10 Dec 12 |
peter |
// the Free Software Foundation; either version 3 of the License, or |
2895 |
10 Dec 12 |
peter |
// (at your option) any later version. |
2895 |
10 Dec 12 |
peter |
9 |
// |
2895 |
10 Dec 12 |
peter |
// This program is distributed in the hope that it will be useful, but |
2895 |
10 Dec 12 |
peter |
// WITHOUT ANY WARRANTY; without even the implied warranty of |
2895 |
10 Dec 12 |
peter |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
2895 |
10 Dec 12 |
peter |
// General Public License for more details. |
2895 |
10 Dec 12 |
peter |
14 |
// |
2895 |
10 Dec 12 |
peter |
// You should have received a copy of the GNU General Public License |
2895 |
10 Dec 12 |
peter |
// along with this program. If not, see <http://www.gnu.org/licenses/>. |
2895 |
10 Dec 12 |
peter |
17 |
|
2895 |
10 Dec 12 |
peter |
18 |
#include <config.h> |
2895 |
10 Dec 12 |
peter |
19 |
|
2895 |
10 Dec 12 |
peter |
20 |
#include "Suite.h" |
2895 |
10 Dec 12 |
peter |
21 |
|
3883 |
24 Mar 20 |
peter |
22 |
#ifdef YAT_HAVE_HTSLIB |
2895 |
10 Dec 12 |
peter |
23 |
#include "yat/omic/BamReadIterator.h" |
2895 |
10 Dec 12 |
peter |
24 |
#include "yat/omic/BamWriteIterator.h" |
2943 |
04 Jan 13 |
peter |
25 |
#include "yat/omic/config_bam.h" |
2943 |
04 Jan 13 |
peter |
26 |
#endif |
2895 |
10 Dec 12 |
peter |
27 |
|
3056 |
24 Jun 13 |
peter |
28 |
#include <yat/utility/Exception.h> |
3056 |
24 Jun 13 |
peter |
29 |
|
2895 |
10 Dec 12 |
peter |
30 |
#include <algorithm> |
2895 |
10 Dec 12 |
peter |
31 |
#include <cassert> |
2895 |
10 Dec 12 |
peter |
32 |
#include <fstream> |
2895 |
10 Dec 12 |
peter |
33 |
#include <iostream> |
2895 |
10 Dec 12 |
peter |
34 |
#include <string> |
2895 |
10 Dec 12 |
peter |
35 |
|
2895 |
10 Dec 12 |
peter |
36 |
using namespace theplu::yat; |
2895 |
10 Dec 12 |
peter |
37 |
|
2943 |
04 Jan 13 |
peter |
38 |
void test1(test::Suite& suite); |
2943 |
04 Jan 13 |
peter |
39 |
int main(int argc, char* argv[]) |
2943 |
04 Jan 13 |
peter |
40 |
{ |
3201 |
03 May 14 |
peter |
41 |
test::Suite suite(argc, argv, true); |
2943 |
04 Jan 13 |
peter |
42 |
|
2943 |
04 Jan 13 |
peter |
43 |
try { |
2943 |
04 Jan 13 |
peter |
44 |
test1(suite); |
2943 |
04 Jan 13 |
peter |
45 |
} |
2943 |
04 Jan 13 |
peter |
46 |
catch (std::runtime_error& e) { |
2943 |
04 Jan 13 |
peter |
47 |
suite.err() << "what: " << e.what() << "\n"; |
2943 |
04 Jan 13 |
peter |
48 |
suite.add(false); |
2943 |
04 Jan 13 |
peter |
49 |
} |
2943 |
04 Jan 13 |
peter |
50 |
|
2943 |
04 Jan 13 |
peter |
51 |
return suite.return_value(); |
2943 |
04 Jan 13 |
peter |
52 |
} |
2943 |
04 Jan 13 |
peter |
53 |
|
2895 |
10 Dec 12 |
peter |
54 |
void test1(test::Suite& suite) |
2895 |
10 Dec 12 |
peter |
55 |
{ |
3883 |
24 Mar 20 |
peter |
56 |
#ifdef YAT_HAVE_HTSLIB |
2943 |
04 Jan 13 |
peter |
57 |
using namespace omic; |
2895 |
10 Dec 12 |
peter |
58 |
std::string file = "../../data/foo.sorted.bam"; |
2895 |
10 Dec 12 |
peter |
59 |
|
2895 |
10 Dec 12 |
peter |
60 |
InBamFile bam_stream(file); |
2895 |
10 Dec 12 |
peter |
61 |
if (!bam_stream.is_open()) { |
2895 |
10 Dec 12 |
peter |
62 |
suite.err() << "cannot read " << file << "\n"; |
2895 |
10 Dec 12 |
peter |
63 |
suite.add(false); |
2895 |
10 Dec 12 |
peter |
64 |
return; |
2895 |
10 Dec 12 |
peter |
65 |
} |
2895 |
10 Dec 12 |
peter |
66 |
int begin = 24500; |
2895 |
10 Dec 12 |
peter |
67 |
int endpos = 24600; |
2895 |
10 Dec 12 |
peter |
68 |
BamReadIterator first(bam_stream, 1, begin, endpos); |
2895 |
10 Dec 12 |
peter |
69 |
BamReadIterator end; |
2895 |
10 Dec 12 |
peter |
70 |
|
2895 |
10 Dec 12 |
peter |
71 |
int count = 0; |
2895 |
10 Dec 12 |
peter |
72 |
while (first != end) { |
2895 |
10 Dec 12 |
peter |
73 |
if (!suite.add(first->pos() < endpos) || !suite.add(first->end() > begin)) |
2895 |
10 Dec 12 |
peter |
74 |
suite.err() << "error: " << first->pos() << "-" << first->end() << "\n"; |
2895 |
10 Dec 12 |
peter |
75 |
++count; |
2895 |
10 Dec 12 |
peter |
76 |
++first; |
2895 |
10 Dec 12 |
peter |
77 |
} |
2895 |
10 Dec 12 |
peter |
78 |
suite.out() << count << std::endl; |
2895 |
10 Dec 12 |
peter |
79 |
|
3056 |
24 Jun 13 |
peter |
80 |
if (count!=185) { |
3056 |
24 Jun 13 |
peter |
81 |
suite.err() << "count: " << count << "\nexpected: 185\n"; |
3056 |
24 Jun 13 |
peter |
82 |
suite.add(false); |
3056 |
24 Jun 13 |
peter |
83 |
} |
2895 |
10 Dec 12 |
peter |
84 |
|
3056 |
24 Jun 13 |
peter |
// test negative coordinates trigger exception |
3056 |
24 Jun 13 |
peter |
86 |
suite.out() << "test negative coordinates\n"; |
3056 |
24 Jun 13 |
peter |
87 |
try { |
3056 |
24 Jun 13 |
peter |
88 |
BamReadIterator iter(bam_stream, 1, -2, -1); |
3056 |
24 Jun 13 |
peter |
89 |
suite.add(false); |
3056 |
24 Jun 13 |
peter |
90 |
suite.err() << "error: no exception thrown\n"; |
3056 |
24 Jun 13 |
peter |
91 |
} |
3056 |
24 Jun 13 |
peter |
92 |
catch (utility::runtime_error& e) { |
3056 |
24 Jun 13 |
peter |
93 |
suite.out() << "expected exception caught with what(): '" << e.what() |
3056 |
24 Jun 13 |
peter |
94 |
<< "'\n"; |
3056 |
24 Jun 13 |
peter |
95 |
} |
3056 |
24 Jun 13 |
peter |
96 |
|
3672 |
31 Jul 17 |
peter |
97 |
{ |
3672 |
31 Jul 17 |
peter |
98 |
BamReadIterator begin(bam_stream, 1); |
3672 |
31 Jul 17 |
peter |
99 |
BamReadIterator end; |
3672 |
31 Jul 17 |
peter |
100 |
if (begin == end) { |
3672 |
31 Jul 17 |
peter |
101 |
suite.add(false); |
3672 |
31 Jul 17 |
peter |
102 |
suite.err() << "error: BamReadIterator(2): begin == end\n"; |
3672 |
31 Jul 17 |
peter |
103 |
} |
3672 |
31 Jul 17 |
peter |
104 |
} |
3672 |
31 Jul 17 |
peter |
105 |
|
2895 |
10 Dec 12 |
peter |
106 |
#endif |
2895 |
10 Dec 12 |
peter |
107 |
} |