source: trunk/yat/omic/BamHeader.h @ 3363

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

improve docs. refs #794

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 2.7 KB
Line 
1#ifndef theplu_yat_omic_bam_header
2#define theplu_yat_omic_bam_header
3
4// $Id: BamHeader.h 3363 2014-11-25 10:42:54Z peter $
5
6/*
7  Copyright (C) 2012, 2013, 2014 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_SAM_HEADER
28
29#include <string>
30
31namespace theplu {
32namespace yat {
33namespace omic {
34
35  /**
36     \brief Wrapper around bam_hdr_t struct.
37
38     Class is typically created via InBamFile::header().
39
40     It is possible to copy and assign a BamHeader, but note that a
41     BamHeader does not own underlying data. The underlying data is
42     owned by the InBamFile and the BamHeader is thus invalid after
43     the corresponding InBamFile has been destroyed.
44
45     \since New in yat 0.10
46   */
47  class BamHeader
48  {
49  public:
50    /**
51       \brief Default constructor
52     */
53    BamHeader(void);
54
55    /**
56       Parse a region in the format: 'chr2:100,000-200,000 and return
57       values in variables \a tid, \a begin and \a end. \a reg is
58       1-based and \a begin and \a end are 0-based, i.e.,
59       "chr2:100,000-200,000" will set \a begin = 99999 and \a end =
60       200000.
61
62       \see bam_parse_region
63
64       \throw utility::runtime_error on failure
65
66       \since new in yat 0.11
67     */
68    void parse_region(const std::string& reg, int& tid, int& begin,
69                      int& end) const;
70
71    /**
72       Name of chromosome with ID \a tid
73     */
74    const char* target_name(size_t tid) const;
75
76    /**
77       Length of chromosome with ID \a tid
78     */
79    uint32_t target_length(size_t tid) const;
80
81    /**
82       \brief inverse of target_name(size_t)
83
84       If compiled against libbam and \a name does not exist,
85       behavious is undefined. If compiled against htslib, a
86       utility::runtime_error is thrown.
87
88       \since new in yat 0.11
89     */
90    int32_t tid(const std::string& name) const;
91
92    /**
93       \return Number of chromosomes
94     */
95    int32_t n_targets(void) const;
96  private:
97#ifndef YAT_HAVE_HTSLIB
98    typedef bam_header_t bam_hdr_t;
99#endif
100    bam_hdr_t* header_;
101
102    friend class InBamFile;
103    friend class OutBamFile;
104
105    // using compiler generated copy and assignment
106    //BamHeader(const BamHeader&);
107    //BamHeader& operator=(const BamHeader& rhs);
108  };
109
110}}}
111#endif
Note: See TracBrowser for help on using the repository browser.