1 | // $Id: bam_read_filter.cc 2994 2013-03-10 13:04:07Z peter $ |
---|
2 | // |
---|
3 | // Copyright (C) 2013 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 | #ifdef HAVE_LIBBAM |
---|
23 | #include "yat/omic/BamFile.h" |
---|
24 | #include "yat/omic/BamRead.h" |
---|
25 | #include "yat/omic/BamReadFilter.h" |
---|
26 | #include "yat/omic/BamReadIterator.h" |
---|
27 | #endif |
---|
28 | |
---|
29 | #include <boost/iterator/filter_iterator.hpp> |
---|
30 | |
---|
31 | #include <algorithm> |
---|
32 | #include <cassert> |
---|
33 | #include <string> |
---|
34 | #include <vector> |
---|
35 | |
---|
36 | using namespace theplu::yat; |
---|
37 | |
---|
38 | void test1(test::Suite& suite); |
---|
39 | |
---|
40 | int main(int argc, char* argv[]) |
---|
41 | { |
---|
42 | test::Suite suite(argc, argv); |
---|
43 | #ifndef HAVE_LIBBAM |
---|
44 | suite.out() << "no libbam\n"; |
---|
45 | return EXIT_SKIP; |
---|
46 | #endif |
---|
47 | #ifndef HAVE_SAMTOOLS |
---|
48 | suite.out() << "no samtools\n"; |
---|
49 | return EXIT_SKIP; |
---|
50 | #endif |
---|
51 | #ifdef HAVE_LIBBAM |
---|
52 | test1(suite); |
---|
53 | #endif |
---|
54 | return suite.return_value(); |
---|
55 | } |
---|
56 | |
---|
57 | #ifdef HAVE_LIBBAM |
---|
58 | using namespace omic; |
---|
59 | |
---|
60 | void test1(test::Suite& suite) |
---|
61 | { |
---|
62 | std::string file = "../../data/foo.sorted.bam"; |
---|
63 | |
---|
64 | InBamFile in; |
---|
65 | in.open(file); |
---|
66 | BamReadIterator begin(in); |
---|
67 | BamReadIterator end; |
---|
68 | |
---|
69 | BamReadFilter filter(20, BAM_DEF_MASK | BAM_FMUNMAP, BAM_FPROPER_PAIR); |
---|
70 | std::vector<BamRead> result; |
---|
71 | std::copy(boost::make_filter_iterator(filter, begin, end), |
---|
72 | boost::make_filter_iterator(filter, end), |
---|
73 | back_inserter(result)); |
---|
74 | suite.out() << result.size() << "\n"; |
---|
75 | suite.add(result.size()==710); |
---|
76 | } |
---|
77 | #endif |
---|