yat  0.16.4pre
BamReadIterator.h
1 #ifndef theplu_yat_omic_bam_read_iterator
2 #define theplu_yat_omic_bam_read_iterator
3 
4 // $Id: BamReadIterator.h 3792 2019-04-12 07:15:09Z peter $
5 
6 /*
7  Copyright (C) 2012, 2013, 2014, 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 "BamFile.h"
26 #include "BamRead.h"
27 #include "config_bam.h"
28 
29 #include YAT_SAM_HEADER
30 
31 #include <boost/iterator/iterator_facade.hpp>
32 #include <boost/shared_ptr.hpp>
33 
34 #include <iterator>
35 
36 namespace theplu {
37 namespace yat {
38 namespace omic {
39 
40  // forward declaration
41  class InBamFile;
42 
61  : public boost::iterator_facade<
62  BamReadIterator, const BamRead, std::input_iterator_tag
63  >
64  {
65  public:
69  BamReadIterator(void);
70 
77  explicit BamReadIterator(InBamFile& in);
78 
96  BamReadIterator(InBamFile& in, int32_t tid, int32_t start, int32_t end);
97 
114  BamReadIterator(InBamFile& in, int32_t tid, int32_t start=0);
115  private:
116  friend class boost::iterator_core_access;
117  BamReadIterator::reference dereference(void) const;
118  bool equal(const BamReadIterator& other) const;
119  void increment(void);
120 
121  /*
122  Interface class for the actor that handles difference between
123  an iterator that iterates the entire file and one that uses
124  index to iterate over a specific region.
125  */
126  class Actor
127  {
128  public:
129  explicit Actor(InBamFile*);
130  virtual ~Actor(void);
131  virtual void increment(void)=0;
132  InBamFile* in_;
133  BamRead read_;
134  };
135 
136  // class used when region is entire file
137  class AllActor : public Actor
138  {
139  public:
140  AllActor(void);
141  explicit AllActor(InBamFile&);
142  void increment(void);
143  };
144 
145  // class used when iterating over a sub-region of the bam file
146  class IndexActor : public Actor
147  {
148  public:
149  IndexActor(InBamFile& bf, int32_t tid, int32_t begin, int32_t end);
150  void increment(void);
151  private:
152 #if YAT_HAVE_HTSLIB
153  boost::shared_ptr<hts_itr_t> iter_;
154 #else
155  boost::shared_ptr<__bam_iter_t> iter_;
156 #endif
157  };
158 
159  boost::shared_ptr<Actor> actor_;
160 
161  struct IndexDestroyer
162  {
163 #if YAT_HAVE_HTSLIB
164  void operator()(hts_itr_t* i) const
165  {
166  bam_itr_destroy(i);
167  }
168 #else
169  void operator()(bam_iter_t i) const
170  {
171  bam_iter_destroy(i);
172  }
173 #endif
174  };
175  };
176 }}}
177 #endif
The Department of Theoretical Physics namespace as we define it.
Class holding a bam query.
Definition: BamRead.h:53
BamReadIterator(void)
Contructs end of file iterator.
Definition: BamFile.h:132
class to iterate through a InBamFile
Definition: BamReadIterator.h:60

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