1 | // $Id: bam_region_iterator.cc 2895 2012-12-10 21:38:12Z peter $ |
---|
2 | // |
---|
3 | // Copyright (C) 2012 Peter Johansson |
---|
4 | // |
---|
5 | // This program is free software; you can redistribute it and/or modify |
---|
6 | // it under the terms of the GNU General Public License as published by |
---|
7 | // the Free Software Foundation; either version 3 of the License, or |
---|
8 | // (at your option) any later version. |
---|
9 | // |
---|
10 | // This program is distributed in the hope that it will be useful, but |
---|
11 | // WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
---|
13 | // General Public License for more details. |
---|
14 | // |
---|
15 | // You should have received a copy of the GNU General Public License |
---|
16 | // along with this program. If not, see <http://www.gnu.org/licenses/>. |
---|
17 | |
---|
18 | #include <config.h> |
---|
19 | |
---|
20 | #include "Suite.h" |
---|
21 | |
---|
22 | #include "yat/omic/BamReadIterator.h" |
---|
23 | #include "yat/omic/BamWriteIterator.h" |
---|
24 | |
---|
25 | #include <bam.h> |
---|
26 | |
---|
27 | #include <algorithm> |
---|
28 | #include <cassert> |
---|
29 | #include <fstream> |
---|
30 | #include <iostream> |
---|
31 | #include <string> |
---|
32 | |
---|
33 | using namespace theplu::yat; |
---|
34 | using namespace theplu::yat::omic; |
---|
35 | |
---|
36 | void test1(test::Suite& suite) |
---|
37 | { |
---|
38 | std::string file = "../../data/foo.sorted.bam"; |
---|
39 | |
---|
40 | InBamFile bam_stream(file); |
---|
41 | if (!bam_stream.is_open()) { |
---|
42 | suite.err() << "cannot read " << file << "\n"; |
---|
43 | suite.add(false); |
---|
44 | return; |
---|
45 | } |
---|
46 | int begin = 24500; |
---|
47 | int endpos = 24600; |
---|
48 | BamReadIterator first(bam_stream, 1, begin, endpos); |
---|
49 | BamReadIterator end; |
---|
50 | |
---|
51 | int count = 0; |
---|
52 | while (first != end) { |
---|
53 | if (!suite.add(first->pos() < endpos) || !suite.add(first->end() > begin)) |
---|
54 | suite.err() << "error: " << first->pos() << "-" << first->end() << "\n"; |
---|
55 | ++count; |
---|
56 | ++first; |
---|
57 | } |
---|
58 | suite.out() << count << std::endl; |
---|
59 | |
---|
60 | if (count==185) |
---|
61 | return; |
---|
62 | |
---|
63 | suite.err() << "count: " << count << "\nexpected: 185\n"; |
---|
64 | suite.add(false); |
---|
65 | } |
---|
66 | |
---|
67 | |
---|
68 | int main(int argc, char* argv[]) |
---|
69 | { |
---|
70 | #ifndef HAVE_SAMTOOLS |
---|
71 | return EXIT_SKIP; |
---|
72 | #endif |
---|
73 | test::Suite suite(argc, argv); |
---|
74 | |
---|
75 | try { |
---|
76 | test1(suite); |
---|
77 | } |
---|
78 | catch (std::runtime_error& e) { |
---|
79 | suite.err() << "what: " << e.what() << "\n"; |
---|
80 | suite.add(false); |
---|
81 | } |
---|
82 | |
---|
83 | return suite.return_value(); |
---|
84 | } |
---|