yat  0.18.2pre
BamHeader.h
1 #ifndef theplu_yat_omic_bam_header
2 #define theplu_yat_omic_bam_header
3 
4 // $Id: BamHeader.h 3999 2020-10-08 23:22:32Z peter $
5 
6 /*
7  Copyright (C) 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2020 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 
27 
28 #include <htslib/sam.h>
29 
30 #include <boost/iterator/transform_iterator.hpp>
31 
32 #include <map>
33 #include <string>
34 
35 namespace theplu {
36 namespace yat {
37 namespace omic {
38 
51  class BamHeader
52  {
53  typedef std::map<std::string, std::string> strMap;
54  typedef std::map<std::string, strMap> strMap2;
55  public:
59  BamHeader(void);
60 
64  ~BamHeader(void);
65 
69  BamHeader(const BamHeader&);
70 
74  BamHeader(BamHeader&&) noexcept;
75 
87  void parse_region(const std::string& reg, int& tid, int& begin,
88  int& end) const;
89 
104  const std::string& program_group(const std::string& id,
105  const std::string& key) const;
106 
123  const std::string& read_group(const std::string& id,
124  const std::string& key) const;
125 
137  const std::map<std::string, std::string>&
138  read_group(const std::string& id) const;
139 
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 
233  BamHeader& operator=(BamHeader&& rhs);
234 
235  private:
236  bam_hdr_t* header_;
237  mutable strMap2 read_group_;
238  mutable strMap2 program_group_;
239 
240  friend class InBamFile;
241  friend class OutBamFile;
242 
243  const std::string& group(strMap2& map, const std::string& type,
244  const std::string& id,
245  const std::string& key) const;
246 
247  void update_group(strMap2& map, const std::string& type) const;
248 
249  // using compiler generated copy and assignment
250  };
251 
259  void swap(BamHeader& lhs, BamHeader& rhs);
260 
261 }}}
262 #endif
BamHeader(void)
Default constructor.
const std::string & read_group(const std::string &id, const std::string &key) const
Access value in @RG lines.
const char * target_name(size_t tid) const
std::string text(void) const
int32_t n_targets(void) const
const std::string & program_group(const std::string &id, const std::string &key) const
Access value in @PG lines.
void parse_region(const std::string &reg, int &tid, int &begin, int &end) const
The Department of Theoretical Physics namespace as we define it.
int32_t tid(const std::string &name) const
inverse of target_name(size_t)
Wrapper around bam_hdr_t struct.
Definition: BamHeader.h:51
Functor that return std::pair.first.
Definition: stl_utility.h:764
read_group_iterator read_group_end(void) const
read_group_iterator read_group_begin(void) 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:245
boost::transform_iterator< utility::PairFirst< const strMap2::value_type >, strMap2::const_iterator > read_group_iterator
Definition: BamHeader.h:155
Definition: BamFile.h:134
uint32_t target_length(size_t tid) const

Generated on Tue Sep 7 2021 17:32:32 for yat by  doxygen 1.8.14