source: trunk/test/bam_header.cc @ 2999

Last change on this file since 2999 was 2999, checked in by Peter, 10 years ago

closes #739. Two new functions in BamHeader?: tid(string) and parse_region.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 2.3 KB
Line 
1// $Id: bam_header.cc 2999 2013-03-14 13:30:14Z 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/BamHeader.h"
25#endif
26
27using namespace theplu::yat;
28
29void test1(test::Suite& suite);
30
31int main(int argc, char* argv[])
32{
33#ifdef SKIP_BAM_TEST
34  return EXIT_SKIP;
35#endif
36  test::Suite suite(argc, argv);
37  try {
38    test1(suite);
39  }
40  catch (std::runtime_error& e) {
41    suite.err() << "what: " << e.what() << "\n";
42    suite.add(false);
43  }
44
45  return suite.return_value();
46}
47
48void test1(test::Suite& suite)
49{
50#ifdef HAVE_LIBBAM
51  using namespace omic;
52  std::string file = "../../data/foo.sorted.bam";
53
54  InBamFile bam_stream(file);
55  BamHeader hdr = bam_stream.header();
56  suite.out() << hdr.n_targets() << "\n";
57  suite.add(hdr.n_targets()==84);
58  suite.out() << hdr.target_name(0) << "\n";
59  if (!suite.add(std::string("1")==hdr.target_name(0)))
60    suite.err() << "error\n";
61  int32_t tid = hdr.tid("1");
62  suite.out() << "tid: " << tid << "\n";
63  if (!suite.add(tid==0))
64    suite.err() << "error\n";
65
66  int begin, end;
67  hdr.parse_region("GL000197.1", tid, begin, end);
68  suite.out() << tid << " " << begin << " " << end << "\n";
69  suite.add(tid==35);
70  hdr.parse_region("GL000197.1:1000-2000", tid, begin, end);
71  suite.out() << tid << " " << begin << " " << end << "\n";
72  if (!suite.add(tid==35))
73    suite.err() << "incorrect tid\n";
74  if (!suite.add(begin==999))
75    suite.err() << "incorrect begin\n";
76  if (!suite.add(end==2000))
77    suite.err() << "incorrect end\n";
78
79  suite.out() << hdr.target_name(35) << "\n";
80  if (!suite.add(std::string("GL000197.1")==hdr.target_name(35)))
81    suite.err() << "error\n";
82  suite.out() << hdr.target_length(0) << "\n";
83  suite.add(hdr.target_length(0)==249250621);
84#endif
85}
Note: See TracBrowser for help on using the repository browser.