source: branches/0.12-stable/test/bam_pair_iterator.cc @ 3234

Last change on this file since 3234 was 3234, checked in by Peter, 9 years ago

fixes #797

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