yat  0.11.3pre
BamRead.h
1 #ifndef theplu_yat_omic_bam_read
2 #define theplu_yat_omic_bam_read
3 
4 // $Id: BamRead.h 3055 2013-06-16 00:21:30Z peter $
5 
6 /*
7  Copyright (C) 2012, 2013 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_BAM_HEADER
28 #include YAT_SAM_HEADER
29 
30 #include <functional>
31 #include <string>
32 #include <vector>
33 
34 // backport #defines from samtools 0.1.19
35 #ifndef BAM_CIGAR_STR
36 #define BAM_CIGAR_STR "MIDNSHP=XB"
37 // lookup table used in bam_cigar_type
38 #define BAM_CIGAR_TYPE 0x3C1A7
39 
41 #define bam_cigar_op(c) ((c)&BAM_CIGAR_MASK)
42 // length of the operation
43 #define bam_cigar_oplen(c) ((c)>>BAM_CIGAR_SHIFT)
44 // char describing the operation, see column 2 in table below
45 #define bam_cigar_opchr(c) (BAM_CIGAR_STR[bam_cigar_op(c)])
46 // Create a cigar element with length l and operation o
47 #define bam_cigar_gen(l, o) ((l)<<BAM_CIGAR_SHIFT|(o))
48 // Returns a two-bits number describing the type of operation. The
49 // first bit, bam_cigar_type & 1, (4th column in table below) is 1 iff
50 // operation consumes query sequence. The second bit, bam_cigar_type &
51 // 2, (3rd column below) is 1 iff operation consumes reference
52 // sequence.
53 #define bam_cigar_type(o) (BAM_CIGAR_TYPE>>((o)<<1)&3)
54 #endif
55 
56 /*
57  CIGAR
58 0 M 1 1 match
59 1 I 0 1 insert
60 2 D 1 0 deletion
61 3 N 1 0 spliced (rna)
62 4 S 0 1 soft clipped
63 5 H 0 0 hard clipped
64 6 P 0 0 padded
65 7 = 1 1 equal
66 8 X 1 1 mismatch
67 9 B 0 0
68 
69 3rd column: consumes reference sequence
70 4th column: consumes query sequence
71  */
72 
73 namespace theplu {
74 namespace yat {
75 namespace omic {
76 
88  class BamRead
89  {
90  public:
97  BamRead(void);
98 
102  BamRead(const BamRead& other);
103 
107  virtual ~BamRead(void);
108 
112  const BamRead& operator=(const BamRead& rhs);
113 
119  const uint8_t* aux(void) const;
120 
132  const uint8_t* aux(const char tag[2]) const;
133 
146  void aux_append(const char tag[2], char type, int len, uint8_t* data);
147 
155  void aux_del(const char tag[2]);
156 
162  int aux_size(void) const;
163 
169  const bam1_core_t& core(void) const;
170 
176  bam1_core_t& core(void);
177 
184  const uint32_t* cigar(void) const;
185 
189  uint32_t cigar(size_t i) const;
190 
194  uint32_t cigar_op(size_t i) const;
195 
199  uint32_t cigar_oplen(size_t i) const;
200 
204  std::string cigar_str(void) const;
205 
211  void cigar(const std::vector<uint32_t>& c);
212 
216  uint8_t qual(size_t i) const;
217 
226  void qual(size_t i, uint8_t q);
227 
233  const char* name(void) const;
234 
240  void name(const std::string& n);
241 
245  int32_t tid(void) const;
246 
250  int32_t pos(void) const;
251 
260  int32_t end(void) const;
261 
265  int32_t mtid(void) const;
266 
270  int32_t mpos(void) const;
271 
277  std::string sequence(void) const;
278 
284  uint8_t sequence(size_t index) const;
285 
295  void sequence(size_t i, uint8_t x);
296 
302  void sequence(const std::string& seq, const std::vector<uint8_t>& qual);
303 
307  uint32_t sequence_length(void) const;
308 
314  uint16_t flag(void) const;
315 
319  void swap(BamRead& other);
320 
321  private:
322  // ensure capacity of data pointer is (at least) n
323  void reserve(int n);
324 
325  bam1_t* bam_;
326 
327  friend class InBamFile;
328  friend class OutBamFile;
329  friend class BamReadIterator;
330  };
331 
340  void swap(BamRead& lhs, BamRead& rhs);
341 
350  bool soft_clipped(const BamRead& bam);
351 
360  uint32_t left_soft_clipped(const BamRead& bam);
361 
370  uint32_t right_soft_clipped(const BamRead& bam);
371 
381  bool same_query_name(const BamRead& lhs, const BamRead& rhs);
382 
391  struct BamLessPos
392  : public std::binary_function<const BamRead&, const BamRead&, bool>
393  {
400  bool operator()(const BamRead& lhs, const BamRead& rhs) const;
401  };
402 
403 
412  struct BamLessEnd
413  : public std::binary_function<const BamRead&, const BamRead&, bool>
414  {
421  bool operator()(const BamRead& lhs, const BamRead& rhs) const;
422  };
423 
424 }}}
425 #endif

Generated on Sat May 24 2014 03:33:05 for yat by  doxygen 1.8.2