yat  0.10.4pre
BamRead.h
1 #ifndef theplu_yat_omic_bam_read
2 #define theplu_yat_omic_bam_read
3 
4 // $Id: BamRead.h 2969 2013-01-23 23:59:44Z peter $
5 //
6 // Copyright (C) 2012, 2013 Peter Johansson
7 //
8 // This program is free software; you can redistribute it and/or modify
9 // it under the terms of the GNU General Public License as published by
10 // the Free Software Foundation; either version 3 of the License, or
11 // (at your option) any later version.
12 //
13 // This program is distributed in the hope that it will be useful, but
14 // WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 // General Public License for more details.
17 //
18 // You should have received a copy of the GNU General Public License
19 // along with this program. If not, see <http://www.gnu.org/licenses/>.
20 
21 #include "config_bam.h"
22 
23 #include YAT_BAM_HEADER
24 #include YAT_SAM_HEADER
25 
26 #include <functional>
27 #include <string>
28 #include <vector>
29 
30 // backport #defines from samtools 0.1.19
31 #ifndef BAM_CIGAR_STR
32 #define BAM_CIGAR_STR "MIDNSHP=XB"
33 #define BAM_CIGAR_TYPE 0x3C1A7
34 
35 #define bam_cigar_op(c) ((c)&BAM_CIGAR_MASK)
36 #define bam_cigar_oplen(c) ((c)>>BAM_CIGAR_SHIFT)
37 #define bam_cigar_opchr(c) (BAM_CIGAR_STR[bam_cigar_op(c)])
38 #define bam_cigar_gen(l, o) ((l)<<BAM_CIGAR_SHIFT|(o))
39 #define bam_cigar_type(o) (BAM_CIGAR_TYPE>>((o)<<1)&3)
40 #endif
41 
42 /*
43  CIGAR
44 0 M 1 1 match
45 1 I 0 1 insert
46 2 D 1 0 deletion
47 3 N 1 0 spliced (rna)
48 4 S 0 1 soft clipped
49 5 H 0 0 hard clipped
50 6 P 0 0 padded
51 7 = 1 1 equal
52 8 X 1 1 mismatch
53 9 B 0 0
54 
55 3rd column: consumes reference sequence
56 4th column: consumes query sequence
57  */
58 
59 namespace theplu {
60 namespace yat {
61 namespace omic {
62 
74  class BamRead
75  {
76  public:
83  BamRead(void);
84 
88  BamRead(const BamRead& other);
89 
93  virtual ~BamRead(void);
94 
98  const BamRead& operator=(const BamRead& rhs);
99 
103  const uint8_t* aux(void) const;
104 
110  const bam1_core_t& core(void) const;
111 
117  bam1_core_t& core(void);
118 
125  const uint32_t* cigar(void) const;
126 
130  uint32_t cigar(size_t i) const;
131 
135  uint32_t cigar_op(size_t i) const;
136 
140  uint32_t cigar_oplen(size_t i) const;
141 
145  std::string cigar_str(void) const;
146 
152  void cigar(const std::vector<uint32_t>& c);
153 
157  uint8_t qual(size_t i) const;
158 
164  const char* name(void) const;
165 
169  int32_t tid(void) const;
170 
174  int32_t pos(void) const;
175 
184  int32_t end(void) const;
185 
189  int32_t mtid(void) const;
190 
194  int32_t mpos(void) const;
195 
201  std::string sequence(void) const;
202 
208  uint8_t sequence(size_t index) const;
209 
213  uint32_t sequence_length(void) const;
214 
220  uint16_t flag(void) const;
221 
225  void swap(BamRead& other);
226 
227  private:
228  bam1_t* bam_;
229 
230  friend class InBamFile;
231  friend class OutBamFile;
232  friend class BamReadIterator;
233  };
234 
243  void swap(BamRead& lhs, BamRead& rhs);
244 
253  bool soft_clipped(const BamRead& bam);
254 
263  uint32_t left_soft_clipped(const BamRead& bam);
264 
273  uint32_t right_soft_clipped(const BamRead& bam);
274 
284  bool same_query_name(const BamRead& lhs, const BamRead& rhs);
285 
294  struct BamLessPos
295  : public std::binary_function<const BamRead&, const BamRead&, bool>
296  {
303  bool operator()(const BamRead& lhs, const BamRead& rhs) const;
304  };
305 
306 
315  struct BamLessEnd
316  : public std::binary_function<const BamRead&, const BamRead&, bool>
317  {
324  bool operator()(const BamRead& lhs, const BamRead& rhs) const;
325  };
326 
327 }}}
328 #endif

Generated on Mon Nov 11 2013 09:41:44 for yat by  doxygen 1.8.1