yat  0.18.2pre
BamReadIterator.h
1 #ifndef theplu_yat_omic_bam_read_iterator
2 #define theplu_yat_omic_bam_read_iterator
3 
4 // $Id: BamReadIterator.h 3999 2020-10-08 23:22:32Z 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 #include <boost/shared_ptr.hpp>
32 
33 #include <iterator>
34 
35 namespace theplu {
36 namespace yat {
37 namespace omic {
38 
39  // forward declaration
40  class InBamFile;
41 
60  : public boost::iterator_facade<
61  BamReadIterator, const BamRead, std::input_iterator_tag
62  >
63  {
64  public:
68  BamReadIterator(void);
69 
76  explicit BamReadIterator(InBamFile& in);
77 
95  BamReadIterator(InBamFile& in, int32_t tid, int32_t start, int32_t end);
96 
113  BamReadIterator(InBamFile& in, int32_t tid, int32_t start=0);
114  private:
115  friend class boost::iterator_core_access;
116  BamReadIterator::reference dereference(void) const;
117  bool equal(const BamReadIterator& other) const;
118  void increment(void);
119 
120  /*
121  Interface class for the actor that handles difference between
122  an iterator that iterates the entire file and one that uses
123  index to iterate over a specific region.
124  */
125  class Actor
126  {
127  public:
128  explicit Actor(InBamFile*);
129  virtual ~Actor(void);
130  virtual void increment(void)=0;
131  InBamFile* in_;
132  BamRead read_;
133  };
134 
135  // class used when region is entire file
136  class AllActor : public Actor
137  {
138  public:
139  AllActor(void);
140  explicit AllActor(InBamFile&);
141  void increment(void);
142  };
143 
144  // class used when iterating over a sub-region of the bam file
145  class IndexActor : public Actor
146  {
147  public:
148  IndexActor(InBamFile& bf, int32_t tid, int32_t begin, int32_t end);
149  void increment(void);
150  private:
151  boost::shared_ptr<hts_itr_t> iter_;
152  };
153 
154  boost::shared_ptr<Actor> actor_;
155 
156  struct IndexDestroyer
157  {
158  void operator()(hts_itr_t* i) const
159  {
160  bam_itr_destroy(i);
161  }
162  };
163  };
164 }}}
165 #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: BamFile.h:134
class to iterate through a InBamFile
Definition: BamReadIterator.h:59

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