yat  0.16.4pre
BamHeader.h
1 #ifndef theplu_yat_omic_bam_header
2 #define theplu_yat_omic_bam_header
3 
4 // $Id: BamHeader.h 3792 2019-04-12 07:15:09Z peter $
5 
6 /*
7  Copyright (C) 2012, 2013, 2014, 2015, 2016, 2017, 2018 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 yat. If not, see <http://www.gnu.org/licenses/>.
23 */
24 
25 #include "config_bam.h"
26 
28 
30 
31 #include YAT_SAM_HEADER
32 
33 #include <boost/iterator/transform_iterator.hpp>
34 
35 #include <map>
36 #include <string>
37 
38 namespace theplu {
39 namespace yat {
40 namespace omic {
41 
42 #ifndef YAT_HAVE_HTSLIB
43  namespace detail {
44  bam_header_t * bam_hdr_dup(const bam_header_t* other);
45  }
46 #endif
47 
60  class BamHeader
61  {
62  typedef std::map<std::string, std::string> strMap;
63  typedef std::map<std::string, strMap> strMap2;
64  public:
68  BamHeader(void);
69 
73  ~BamHeader(void);
74 
78  BamHeader(const BamHeader&);
79 
80 #ifdef YAT_HAVE_RVALUE
81 
84  BamHeader(BamHeader&&) noexcept;
85 #endif
86 
98  void parse_region(const std::string& reg, int& tid, int& begin,
99  int& end) const;
100 
115  const std::string& program_group(const std::string& id,
116  const std::string& key) const;
117 
134  const std::string& read_group(const std::string& id,
135  const std::string& key) const;
136 
148  const std::map<std::string, std::string>&
149  read_group(const std::string& id) const;
150 
163  typedef boost::transform_iterator<
165  strMap2::const_iterator>
167 
173  read_group_iterator read_group_begin(void) const;
174 
182  read_group_iterator read_group_end(void) const;
183 
189  void swap(BamHeader& other);
190 
194  const char* target_name(size_t tid) const;
195 
199  uint32_t target_length(size_t tid) const;
200 
206  std::string text(void) const;
207 
218  void text(const std::string& txt);
219 
229  int32_t tid(const std::string& name) const;
230 
234  int32_t n_targets(void) const;
235 
239  BamHeader& operator=(const BamHeader& rhs);
240 
241 #ifdef YAT_HAVE_RVALUE
242 
245  BamHeader& operator=(BamHeader&& rhs);
246 #endif
247 
248  private:
249 #ifndef YAT_HAVE_HTSLIB
250  typedef bam_header_t bam_hdr_t;
251 #endif
252  bam_hdr_t* header_;
253  mutable strMap2 read_group_;
254  mutable strMap2 program_group_;
255 
256  friend class InBamFile;
257  friend class OutBamFile;
258 
259  const std::string& group(strMap2& map, const std::string& type,
260  const std::string& id,
261  const std::string& key) const;
262 
263  void update_group(strMap2& map, const std::string& type) const;
264 
265  // using compiler generated copy and assignment
266  };
267 
275  void swap(BamHeader& lhs, BamHeader& rhs);
276 
277 }}}
278 #endif
The Department of Theoretical Physics namespace as we define it.
Wrapper around bam_hdr_t struct.
Definition: BamHeader.h:60
Functor that return std::pair.first.
Definition: stl_utility.h:764
Definition: BamFile.h:252
boost::transform_iterator< utility::PairFirst< const strMap2::value_type >, strMap2::const_iterator > read_group_iterator
Definition: BamHeader.h:166
Definition: BamFile.h:132

Generated on Thu Dec 12 2019 03:12:08 for yat by  doxygen 1.8.11