yat  0.14.5pre
BamHeader.h
1 #ifndef theplu_yat_omic_bam_header
2 #define theplu_yat_omic_bam_header
3 
4 // $Id: BamHeader.h 3550 2017-01-03 05:41:02Z peter $
5 
6 /*
7  Copyright (C) 2012, 2013, 2014, 2015, 2016 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 
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 
91  void parse_region(const std::string& reg, int& tid, int& begin,
92  int& end) const;
93 
108  const std::string& program_group(const std::string& id,
109  const std::string& key) const;
110 
127  const std::string& read_group(const std::string& id,
128  const std::string& key) const;
129 
141  const std::map<std::string, std::string>&
142  read_group(const std::string& id) const;
143 
152  typedef boost::transform_iterator<
154  strMap2::const_iterator>
156 
163 
172 
178  void swap(BamHeader& other);
179 
183  const char* target_name(size_t tid) const;
184 
188  uint32_t target_length(size_t tid) const;
189 
195  std::string text(void) const;
196 
207  void text(const std::string& txt);
208 
218  int32_t tid(const std::string& name) const;
219 
223  int32_t n_targets(void) const;
224 
228  BamHeader& operator=(const BamHeader& rhs);
229 
230  private:
231 #ifndef YAT_HAVE_HTSLIB
232  typedef bam_header_t bam_hdr_t;
233 #endif
234  bam_hdr_t* header_;
235  mutable strMap2 read_group_;
236  mutable strMap2 program_group_;
237 
238  friend class InBamFile;
239  friend class OutBamFile;
240 
241  const std::string& group(strMap2& map, const std::string& type,
242  const std::string& id,
243  const std::string& key) const;
244 
245  void update_group(strMap2& map, const std::string& type) const;
246 
247  // using compiler generated copy and assignment
248  };
249 
257  void swap(BamHeader& lhs, BamHeader& rhs);
258 
259 }}}
260 #endif
BamHeader(void)
Default constructor.
int32_t tid(const std::string &name) const
inverse of target_name(size_t)
const std::string & program_group(const std::string &id, const std::string &key) const
Access value in @PG lines.
read_group_iterator read_group_begin(void) const
std::string text(void) const
int32_t n_targets(void) const
Wrapper around bam_hdr_t struct.
Definition: BamHeader.h:60
const std::string & read_group(const std::string &id, const std::string &key) const
Access value in @RG lines.
Functor that return std::pair.first.
Definition: stl_utility.h:762
uint32_t target_length(size_t tid) const
const char * target_name(size_t tid) const
void parse_region(const std::string &reg, int &tid, int &begin, int &end) const
void swap(BamHeader &other)
Exchanges the content in *this and other.
BamHeader & operator=(const BamHeader &rhs)
assignment operator
~BamHeader(void)
Destructor.
Definition: BamFile.h:233
boost::transform_iterator< utility::PairFirst< const strMap2::value_type >, strMap2::const_iterator > read_group_iterator
Definition: BamHeader.h:155
Definition: BamFile.h:118
read_group_iterator read_group_end(void) const

Generated on Tue Sep 26 2017 02:33:29 for yat by  doxygen 1.8.5