4345 |
19 Apr 23 |
peter |
// $Id$ |
4345 |
19 Apr 23 |
peter |
2 |
|
4345 |
19 Apr 23 |
peter |
3 |
/* |
4345 |
19 Apr 23 |
peter |
Copyright (C) 2023 Peter Johansson |
4345 |
19 Apr 23 |
peter |
5 |
|
4345 |
19 Apr 23 |
peter |
This file is part of the yat library, https://dev.thep.lu.se/yat |
4345 |
19 Apr 23 |
peter |
7 |
|
4345 |
19 Apr 23 |
peter |
The yat library is free software; you can redistribute it and/or |
4345 |
19 Apr 23 |
peter |
modify it under the terms of the GNU General Public License as |
4345 |
19 Apr 23 |
peter |
published by the Free Software Foundation; either version 3 of the |
4345 |
19 Apr 23 |
peter |
License, or (at your option) any later version. |
4345 |
19 Apr 23 |
peter |
12 |
|
4345 |
19 Apr 23 |
peter |
The yat library is distributed in the hope that it will be useful, |
4345 |
19 Apr 23 |
peter |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
4345 |
19 Apr 23 |
peter |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
4345 |
19 Apr 23 |
peter |
General Public License for more details. |
4345 |
19 Apr 23 |
peter |
17 |
|
4345 |
19 Apr 23 |
peter |
You should have received a copy of the GNU General Public License |
4345 |
19 Apr 23 |
peter |
along with yat. If not, see <https://www.gnu.org/licenses/>. |
4345 |
19 Apr 23 |
peter |
20 |
*/ |
4345 |
19 Apr 23 |
peter |
21 |
|
4345 |
19 Apr 23 |
peter |
22 |
#include <config.h> |
4345 |
19 Apr 23 |
peter |
23 |
|
4345 |
19 Apr 23 |
peter |
24 |
#include "Suite.h" |
4345 |
19 Apr 23 |
peter |
25 |
|
4345 |
19 Apr 23 |
peter |
26 |
#ifdef YAT_HAVE_HTSLIB |
4345 |
19 Apr 23 |
peter |
27 |
#include "yat/omic/BamFile.h" |
4345 |
19 Apr 23 |
peter |
28 |
#include "yat/omic/BamRead.h" |
4345 |
19 Apr 23 |
peter |
29 |
#include "yat/omic/BamReadSequenceIterator.h" |
4345 |
19 Apr 23 |
peter |
30 |
#endif |
4345 |
19 Apr 23 |
peter |
31 |
|
4345 |
19 Apr 23 |
peter |
32 |
using namespace theplu::yat; |
4345 |
19 Apr 23 |
peter |
33 |
|
4345 |
19 Apr 23 |
peter |
34 |
void test1(test::Suite& suite); |
4345 |
19 Apr 23 |
peter |
35 |
|
4345 |
19 Apr 23 |
peter |
36 |
int main(int argc, char* argv[]) |
4345 |
19 Apr 23 |
peter |
37 |
{ |
4345 |
19 Apr 23 |
peter |
38 |
test::Suite suite(argc, argv, true); |
4345 |
19 Apr 23 |
peter |
39 |
try { |
4345 |
19 Apr 23 |
peter |
40 |
test1(suite); |
4345 |
19 Apr 23 |
peter |
41 |
} |
4345 |
19 Apr 23 |
peter |
42 |
catch (std::runtime_error& e) { |
4345 |
19 Apr 23 |
peter |
43 |
suite.add(false); |
4345 |
19 Apr 23 |
peter |
44 |
suite.err() << "error: what: " << e.what() << "\n"; |
4345 |
19 Apr 23 |
peter |
45 |
} |
4345 |
19 Apr 23 |
peter |
46 |
return suite.return_value(); |
4345 |
19 Apr 23 |
peter |
47 |
} |
4345 |
19 Apr 23 |
peter |
48 |
|
4345 |
19 Apr 23 |
peter |
49 |
#ifdef YAT_HAVE_HTSLIB |
4345 |
19 Apr 23 |
peter |
50 |
using namespace omic; |
4345 |
19 Apr 23 |
peter |
51 |
|
4345 |
19 Apr 23 |
peter |
52 |
void test1(test::Suite& suite) |
4345 |
19 Apr 23 |
peter |
53 |
{ |
4345 |
19 Apr 23 |
peter |
54 |
std::string fn = "../../data/foo.sorted.bam"; |
4345 |
19 Apr 23 |
peter |
55 |
|
4345 |
19 Apr 23 |
peter |
56 |
InBamFile bam_file(fn); |
4345 |
19 Apr 23 |
peter |
57 |
BamRead bam; |
4345 |
19 Apr 23 |
peter |
58 |
bam_file.read(bam); |
4345 |
19 Apr 23 |
peter |
59 |
size_t k=3; |
4345 |
19 Apr 23 |
peter |
60 |
BamReadSequenceIterator it(bam, k); |
4345 |
19 Apr 23 |
peter |
61 |
BamReadSequenceIterator end(bam, bam.sequence_length()); |
4345 |
19 Apr 23 |
peter |
62 |
if (bam.sequence_str(k) != it->base()) { |
4345 |
19 Apr 23 |
peter |
63 |
suite.add(false); |
4345 |
19 Apr 23 |
peter |
64 |
suite.err() << "error: ::sequence_str(k): " |
4345 |
19 Apr 23 |
peter |
65 |
<< bam.sequence_str(k) << " != it->base(): " |
4345 |
19 Apr 23 |
peter |
66 |
<< it->base() << "\n"; |
4345 |
19 Apr 23 |
peter |
67 |
} |
4345 |
19 Apr 23 |
peter |
68 |
if (bam.qual(k) != it->qual()) { |
4345 |
19 Apr 23 |
peter |
69 |
suite.add(false); |
4345 |
19 Apr 23 |
peter |
70 |
suite.err() << "error: ::qual(k): " |
4345 |
19 Apr 23 |
peter |
71 |
<< static_cast<int>(bam.qual(k)) << " != it->qual(): " |
4345 |
19 Apr 23 |
peter |
72 |
<< static_cast<int>(it->qual()) << "\n"; |
4345 |
19 Apr 23 |
peter |
73 |
} |
4345 |
19 Apr 23 |
peter |
74 |
it -= k; |
4345 |
19 Apr 23 |
peter |
75 |
int count = 0; |
4345 |
19 Apr 23 |
peter |
76 |
for ( ; it!=end; ++it) { |
4345 |
19 Apr 23 |
peter |
77 |
suite.out() << it->base() << "\t" << static_cast<int>(it->qual()) |
4345 |
19 Apr 23 |
peter |
78 |
<< "\t" << count << "\n"; |
4345 |
19 Apr 23 |
peter |
79 |
++count; |
4345 |
19 Apr 23 |
peter |
80 |
if (count > 1000) { |
4345 |
19 Apr 23 |
peter |
81 |
suite.err() << "error: count > 1000\n"; |
4345 |
19 Apr 23 |
peter |
82 |
suite.add(false); |
4345 |
19 Apr 23 |
peter |
83 |
break; |
4345 |
19 Apr 23 |
peter |
84 |
} |
4345 |
19 Apr 23 |
peter |
85 |
} |
4345 |
19 Apr 23 |
peter |
86 |
|
4345 |
19 Apr 23 |
peter |
87 |
BamReadSequenceIterator it2(bam); |
4345 |
19 Apr 23 |
peter |
88 |
test::test_const_iterator(it2); |
4345 |
19 Apr 23 |
peter |
89 |
suite.test_random_access_iterator(it2); |
4345 |
19 Apr 23 |
peter |
90 |
} |
4345 |
19 Apr 23 |
peter |
91 |
#else |
4345 |
19 Apr 23 |
peter |
92 |
void test1(test::Suite& suite) {} |
4345 |
19 Apr 23 |
peter |
93 |
#endif |