source: trunk/test/bam_pair_iterator.cc @ 3194

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

add missing file. see r3173

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 2.3 KB
Line 
1// $Id: bam_pair_iterator.cc 3194 2014-04-22 09:24:56Z 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 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;
35using namespace omic;
36
37void test1(test::Suite& suite);
38
39int main(int argc, char* argv[])
40{
41  test::Suite suite(argc, argv);
42#ifndef HAVE_LIBBAM
43  suite.out() << "no libbam\n";
44  return EXIT_SKIP;
45#endif
46#ifndef HAVE_SAMTOOLS
47  suite.out() << "no samtools\n";
48  return EXIT_SKIP;
49#endif
50  try {
51    test1(suite);
52  }
53  catch (std::runtime_error& e) {
54    suite.add(false);
55    suite.err() << "error: what: " << e.what() << "\n";
56  }
57  return suite.return_value();
58}
59
60#ifdef HAVE_LIBBAM
61using namespace omic;
62
63void test1(test::Suite& suite)
64{
65  std::string file = "../../data/foo.sorted.bam";
66
67  InBamFile in(file);
68  BamReadIterator iter(in);
69  BamReadIterator end;
70
71  std::vector<BamPair> result;
72  BamPairIterator<BamReadIterator> piter(iter, end);
73  BamPairIterator<BamReadIterator> pend(end, end);
74  for (; piter!=pend; ++piter) {
75    result.push_back(*piter);
76    result.back().first() = piter->first();
77    result.back().second() = piter->second();
78  }
79  // not really doing anything since we've already iterated through
80  // the range, but checking that bam_pair_iterator functions compile
81  std::copy(bam_pair_iterator(iter, end), bam_pair_iterator(end),
82            result.begin());
83
84  in.close();
85  if (!suite.add(result.size()))
86    suite.err() << "error: empty result\n";
87
88  // suite.test_input_iterator(piter);
89}
90#endif
Note: See TracBrowser for help on using the repository browser.