source: trunk/test/bam_region_iterator.cc @ 2943

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

merge release 0.10 into trunk

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 2.2 KB
Line 
1// $Id: bam_region_iterator.cc 2943 2013-01-04 06:38:38Z 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#ifdef HAVE_LIBBAM
23#include "yat/omic/BamReadIterator.h"
24#include "yat/omic/BamWriteIterator.h"
25#include "yat/omic/config_bam.h"
26#endif
27
28#ifdef YAT_BAM_HEADER
29#include YAT_BAM_HEADER
30#endif
31
32#include <algorithm>
33#include <cassert>
34#include <fstream>
35#include <iostream>
36#include <string>
37
38using namespace theplu::yat;
39
40void test1(test::Suite& suite);
41int main(int argc, char* argv[])
42{
43  test::Suite suite(argc, argv);
44#ifndef HAVE_LIBBAM
45  suite.out() << "no libbam\n";
46  return EXIT_SKIP;
47#endif
48#ifndef HAVE_SAMTOOLS
49  suite.out() << "no samtools\n";
50  return EXIT_SKIP;
51#endif
52
53  try {
54    test1(suite);
55  }
56  catch (std::runtime_error& e) {
57    suite.err() << "what: " << e.what() << "\n";
58    suite.add(false);
59  }
60
61  return suite.return_value();
62}
63
64void test1(test::Suite& suite)
65{
66#ifdef HAVE_LIBBAM
67  using namespace omic;
68  std::string file = "../../data/foo.sorted.bam";
69
70  InBamFile bam_stream(file);
71  if (!bam_stream.is_open()) {
72    suite.err() << "cannot read " << file << "\n";
73    suite.add(false);
74    return;
75  }
76  int begin = 24500;
77  int endpos = 24600;
78  BamReadIterator first(bam_stream, 1, begin, endpos);
79  BamReadIterator end;
80
81  int count = 0;
82  while (first != end) {
83    if (!suite.add(first->pos() < endpos) || !suite.add(first->end() > begin))
84      suite.err() << "error: " << first->pos() << "-" << first->end() << "\n";
85    ++count;
86    ++first;
87  }
88  suite.out() << count << std::endl;
89
90  if (count==185)
91    return;
92
93  suite.err() << "count: " << count << "\nexpected: 185\n";
94  suite.add(false);
95#endif
96}
Note: See TracBrowser for help on using the repository browser.