yat  0.21pre
BamReadIterator.h
1 #ifndef theplu_yat_omic_bam_read_iterator
2 #define theplu_yat_omic_bam_read_iterator
3 
4 // $Id: BamReadIterator.h 4274 2023-01-24 15:27:25Z peter $
5 
6 /*
7  Copyright (C) 2012, 2013, 2014, 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 
25 #include "BamFile.h"
26 #include "BamRead.h"
27 
28 #include <htslib/sam.h>
29 
30 #include <boost/iterator/iterator_facade.hpp>
31 
32 #include <iterator>
33 #include <memory>
34 #include <vector>
35 
36 namespace theplu {
37 namespace yat {
38 namespace omic {
39 
40  // forward declaration
41  class BamRegion;
42  class InBamFile;
43 
62  : public boost::iterator_facade<
63  BamReadIterator, const BamRead, std::input_iterator_tag
64  >
65  {
66  public:
70  BamReadIterator(void);
71 
78  explicit BamReadIterator(InBamFile& in);
79 
100  BamReadIterator(InBamFile& in, int32_t tid, int32_t start, int32_t end);
101 
121  BamReadIterator(InBamFile& in, int32_t tid, int32_t start=0);
122 
140  BamReadIterator(InBamFile& in, const BamRegion& region);
141 
150  BamReadIterator(InBamFile& in, const std::vector<BamRegion>& regions);
151  private:
152  friend class boost::iterator_core_access;
153  BamReadIterator::reference dereference(void) const;
154  bool equal(const BamReadIterator& other) const;
155  void increment(void);
156 
157 
158  /*
159  Interface class for the actor that handles difference between
160  an iterator that iterates the entire file and one that uses
161  index to iterate over a specific region.
162  */
163  class Actor
164  {
165  public:
166  explicit Actor(InBamFile*);
167  virtual ~Actor(void);
168  virtual void increment(void)=0;
169  InBamFile* in_;
170  BamRead read_;
171  };
172 
173  // class used when region is entire file
174  class AllActor : public Actor
175  {
176  public:
177  AllActor(void);
178  explicit AllActor(InBamFile&);
179  void increment(void);
180  };
181 
182  // functor calling bam_itr_destroy
183  struct IndexDestroyer
184  {
185  void operator()(hts_itr_t* i) const;
186  };
187 
188  class RegListDestroyer
189  {
190  public:
191  RegListDestroyer(size_t n);
192  void operator()(hts_reglist_t* r) const;
193  private:
194  size_t n_;
195  };
196 
197  // class used when iterating over a sub-region of the bam file
198  class IndexActor : public Actor
199  {
200  public:
201  IndexActor(InBamFile& in,
202  std::unique_ptr<hts_itr_t, IndexDestroyer>&& iter);
203  void increment(void);
204  private:
205  std::unique_ptr<hts_itr_t, IndexDestroyer> iter_;
206  };
207 
208  std::shared_ptr<Actor> actor_;
209 
210  };
211 }}}
212 #endif
The Department of Theoretical Physics namespace as we define it.
Class holding a bam query.
Definition: BamRead.h:51
BamReadIterator(void)
Contructs end of file iterator.
Definition: BamRegion.h:38
Definition: BamFile.h:134
class to iterate through a InBamFile
Definition: BamReadIterator.h:61

Generated on Wed Jan 25 2023 03:34:29 for yat by  doxygen 1.8.14