1 | #ifndef theplu_yat_omic_bam_header |
---|
2 | #define theplu_yat_omic_bam_header |
---|
3 | |
---|
4 | // $Id: BamHeader.h 3408 2015-04-16 00:22:24Z 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/utility/config_public.h" |
---|
28 | |
---|
29 | #include YAT_SAM_HEADER |
---|
30 | |
---|
31 | #include <string> |
---|
32 | |
---|
33 | namespace theplu { |
---|
34 | namespace yat { |
---|
35 | namespace omic { |
---|
36 | |
---|
37 | #ifndef YAT_HAVE_HTSLIB |
---|
38 | namespace detail { |
---|
39 | bam_header_t * bam_hdr_dup(const bam_header_t* other); |
---|
40 | } |
---|
41 | #endif |
---|
42 | |
---|
43 | /** |
---|
44 | \brief Wrapper around bam_hdr_t struct. |
---|
45 | |
---|
46 | Class is typically created via InBamFile::header(). |
---|
47 | |
---|
48 | It is possible to copy and assign a BamHeader, but note that a |
---|
49 | BamHeader does not own underlying data. The underlying data is |
---|
50 | owned by the InBamFile and the BamHeader is thus invalid after |
---|
51 | the corresponding InBamFile has been destroyed. |
---|
52 | |
---|
53 | \since New in yat 0.10 |
---|
54 | */ |
---|
55 | class BamHeader |
---|
56 | { |
---|
57 | public: |
---|
58 | /** |
---|
59 | \brief Default constructor |
---|
60 | */ |
---|
61 | BamHeader(void); |
---|
62 | |
---|
63 | /** |
---|
64 | \brief Destructor |
---|
65 | */ |
---|
66 | ~BamHeader(void); |
---|
67 | |
---|
68 | /** |
---|
69 | \brief Copy constructor |
---|
70 | */ |
---|
71 | BamHeader(const BamHeader&); |
---|
72 | |
---|
73 | /** |
---|
74 | Parse a region in the format: 'chr2:100,000-200,000 and return |
---|
75 | values in variables \a tid, \a begin and \a end. \a reg is |
---|
76 | 1-based and \a begin and \a end are 0-based, i.e., |
---|
77 | "chr2:100,000-200,000" will set \a begin = 99999 and \a end = |
---|
78 | 200000. |
---|
79 | |
---|
80 | \see bam_parse_region |
---|
81 | |
---|
82 | \throw utility::runtime_error on failure |
---|
83 | |
---|
84 | \since new in yat 0.11 |
---|
85 | */ |
---|
86 | void parse_region(const std::string& reg, int& tid, int& begin, |
---|
87 | int& end) const; |
---|
88 | |
---|
89 | /** |
---|
90 | \brief Exchanges the content in \c *this and \a other |
---|
91 | |
---|
92 | \since New in yat 0.13 |
---|
93 | */ |
---|
94 | void swap(BamHeader& other); |
---|
95 | |
---|
96 | /** |
---|
97 | Name of chromosome with ID \a tid |
---|
98 | */ |
---|
99 | const char* target_name(size_t tid) const; |
---|
100 | |
---|
101 | /** |
---|
102 | Length of chromosome with ID \a tid |
---|
103 | */ |
---|
104 | uint32_t target_length(size_t tid) const; |
---|
105 | |
---|
106 | /** |
---|
107 | \return text in header |
---|
108 | |
---|
109 | \since New in yat 0.13 |
---|
110 | */ |
---|
111 | std::string text(void) const; |
---|
112 | |
---|
113 | /** |
---|
114 | \brief set text in header |
---|
115 | |
---|
116 | This function parses \a txt and updates fields. |
---|
117 | |
---|
118 | \since New in yat 0.13 |
---|
119 | */ |
---|
120 | void text(const std::string& txt); |
---|
121 | |
---|
122 | /** |
---|
123 | \brief inverse of target_name(size_t) |
---|
124 | |
---|
125 | If compiled against libbam and \a name does not exist, |
---|
126 | behavious is undefined. If compiled against htslib, a |
---|
127 | utility::runtime_error is thrown. |
---|
128 | |
---|
129 | \since new in yat 0.11 |
---|
130 | */ |
---|
131 | int32_t tid(const std::string& name) const; |
---|
132 | |
---|
133 | /** |
---|
134 | \return Number of chromosomes |
---|
135 | */ |
---|
136 | int32_t n_targets(void) const; |
---|
137 | |
---|
138 | /** |
---|
139 | \brief assignment operator |
---|
140 | */ |
---|
141 | BamHeader& operator=(const BamHeader& rhs); |
---|
142 | |
---|
143 | private: |
---|
144 | #ifndef YAT_HAVE_HTSLIB |
---|
145 | typedef bam_header_t bam_hdr_t; |
---|
146 | #endif |
---|
147 | bam_hdr_t* header_; |
---|
148 | |
---|
149 | friend class InBamFile; |
---|
150 | friend class OutBamFile; |
---|
151 | |
---|
152 | // using compiler generated copy and assignment |
---|
153 | }; |
---|
154 | |
---|
155 | /** |
---|
156 | Exchanges the content in the headers. |
---|
157 | |
---|
158 | \since New in yat 0.13 |
---|
159 | |
---|
160 | \relates BamHeader |
---|
161 | */ |
---|
162 | void swap(BamHeader& lhs, BamHeader& rhs); |
---|
163 | |
---|
164 | }}} |
---|
165 | #endif |
---|