source: branches/0.11-stable/yat/omic/BamHeader.h @ 3116

Last change on this file since 3116 was 2999, checked in by Peter, 9 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#ifndef theplu_yat_omic_bam_header
2#define theplu_yat_omic_bam_header
3
4// $Id: BamHeader.h 2999 2013-03-14 13:30:14Z peter $
5
6/*
7  Copyright (C) 2012, 2013 Peter Johansson
8
9  This file is part of the yat library, http://dev.thep.lu.se/yat
10
11  The yat library is free software; you can redistribute it and/or
12  modify it under the terms of the GNU General Public License as
13  published by the Free Software Foundation; either version 3 of the
14  License, or (at your option) any later version.
15
16  The yat library is distributed in the hope that it will be useful,
17  but WITHOUT ANY WARRANTY; without even the implied warranty of
18  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19  General Public License for more details.
20
21  You should have received a copy of the GNU General Public License
22  along with this program. If not, see <http://www.gnu.org/licenses/>.
23*/
24
25#include "config_bam.h"
26
27#include YAT_BAM_HEADER
28
29#include <string>
30
31namespace theplu {
32namespace yat {
33namespace omic {
34
35  /**
36     Wrapper around bam_header_t struct.
37
38     Class is typically created within InBamFile
39
40     \since New in yat 0.10
41   */
42  class BamHeader
43  {
44  public:
45    /**
46       \brief Default constructor
47     */
48    BamHeader(void);
49
50    /**
51       Parse a region in the format: 'chr2:100,000-200,000 and return
52       values in variables \a tid, \a begin and \a end. \a reg is
53       1-based and \a begin and \a end are 0-based, i.e.,
54       "chr2:100,000-200,000" will set \a begin = 99000 and \a end =
55       200000.
56
57       \see bam_parse_region
58
59       \throw utility::runtime_error on failure
60
61       \since new in yat 0.11
62     */
63    void parse_region(const std::string& reg, int& tid, int& begin,
64                      int& end) const;
65
66    /**
67       Name of chromosome with ID \a tid
68     */
69    const char* target_name(size_t tid) const;
70
71    /**
72       Length of chromosome with ID \a tid
73     */
74    uint32_t target_length(size_t tid) const;
75
76    /**
77       \brief inverse of target_name(size_t)
78
79       \note If \a name does not exist, behaviour is unexpected.
80
81       \since new in yat 0.11
82     */
83    int32_t tid(const std::string& name) const;
84
85    /**
86       Number of chromosomes
87     */
88    int32_t n_targets(void) const;
89  private:
90    bam_header_t* header_;
91
92    friend class InBamFile;
93    friend class OutBamFile;
94    BamHeader(bam_header_t* h);
95
96    // using compiler generated copy and assignment
97    //BamHeader(const BamHeader&);
98    //BamHeader& operator=(const BamHeader& rhs);
99  };
100
101}}}
102#endif
Note: See TracBrowser for help on using the repository browser.