source: trunk/test/bam_pair_iterator.cc @ 3209

Last change on this file since 3209 was 3209, checked in by Peter, 8 years ago

add missing source file and fix compilation error --without-samtools

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 2.5 KB
Line 
1// $Id: bam_pair_iterator.cc 3209 2014-05-04 13:52:34Z peter $
2//
3// Copyright (C) 2014 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 YAT_HAVE_LIBBAM
23#include "yat/omic/BamFile.h"
24#include "yat/omic/BamPairIterator.h"
25#include "yat/omic/BamRead.h"
26#include "yat/omic/BamReadIterator.h"
27#include "yat/omic/BamWriteIterator.h"
28#endif
29
30#include <algorithm>
31#include <cassert>
32#include <string>
33
34using namespace theplu::yat;
35#ifdef YAT_HAVE_LIBBAM
36using namespace omic;
37#endif
38
39void test1(test::Suite& suite);
40
41int main(int argc, char* argv[])
42{
43  test::Suite suite(argc, argv, true);
44  try {
45    test1(suite);
46  }
47  catch (std::runtime_error& e) {
48    suite.add(false);
49    suite.err() << "error: what: " << e.what() << "\n";
50  }
51  return suite.return_value();
52}
53
54
55void test1(test::Suite& suite)
56{
57#ifdef YAT_HAVE_LIBBAM
58  std::string file = "../../data/foo.sorted.bam";
59
60  InBamFile in(file);
61  BamReadIterator iter(in);
62  BamReadIterator end;
63
64  std::vector<BamPair> result;
65  BamPairIterator<BamReadIterator> piter(iter, end);
66  BamPairIterator<BamReadIterator> pend(end, end);
67  for (; piter!=pend; ++piter) {
68    result.push_back(*piter);
69    result.back() = *piter;
70    // This code doesn't work with boost 1.48 (or older). See
71    // https://svn.boost.org/trac/boost/ticket/5697 for details. It's
72    // not obvious the fix was included in v1.49, but let's test here
73    // and if it wasn't modify this test accordingly and update the
74    // docs in 'yat/omic/BamPairIterator.h'.
75    result.back().first() = piter->first();
76    result.back().second() = piter->second();
77  }
78  // not really doing anything since we've already iterated through
79  // the range, but checking that bam_pair_iterator functions compile
80  std::copy(bam_pair_iterator(iter, end), bam_pair_iterator(end),
81            result.begin());
82
83  in.close();
84  if (!suite.add(result.size()))
85    suite.err() << "error: empty result\n";
86
87  // suite.test_input_iterator(piter);
88#endif
89}
Note: See TracBrowser for help on using the repository browser.