1 #ifndef theplu_yat_omic_bam_pair_iterator2 2 #define theplu_yat_omic_bam_pair_iterator2 29 #include "yat/utility/yat_assert.h" 31 #include <boost/concept/assert.hpp> 32 #include <boost/iterator/iterator_concepts.hpp> 33 #include <boost/iterator/iterator_facade.hpp> 67 template<
typename Base>
69 :
public boost::iterator_facade<
70 BamPairIterator2<Base>, const BamPair, std::input_iterator_tag,
88 #ifndef YAT_HAVE_BOOST_ITERATOR_FACADE_PROXY_PTR 95 typename BamPairIterator2::pointer
operator->(
void)
const 108 dummie_.
first() = first_->first;
109 dummie_.
second() = second_->second;
119 typedef std::pair<int32_t, int32_t> Position;
121 typedef std::multimap<Position, BamRead> MultiMap;
122 std::shared_ptr<MultiMap> reads_;
123 MultiMap::iterator first_;
124 MultiMap::iterator second_;
125 friend class boost::iterator_core_access;
127 void assign_pair(
void);
131 std::multimap<Position, BamRead>::iterator
133 void increment(
void);
144 template<
typename Base>
155 template<
typename Base>
163 template<
typename Base>
165 : iter_(base), end_(end),
167 first_(reads_->end()), second_(reads_->end())
169 BOOST_CONCEPT_ASSERT((boost_concepts::ReadableIterator<Base>));
170 BOOST_CONCEPT_ASSERT((boost_concepts::SinglePassIterator<Base>));
171 using boost::Convertible;
172 typedef typename std::iterator_traits<Base>::value_type value_type;
173 BOOST_CONCEPT_ASSERT((Convertible<value_type, BamRead>));
178 template<
typename Base>
181 BOOST_CONCEPT_ASSERT((boost::InputIterator<Base>));
182 using boost::Convertible;
183 typedef typename std::iterator_traits<Base>::value_type value_type;
184 BOOST_CONCEPT_ASSERT((Convertible<value_type, BamRead>));
188 template<
typename Base>
195 YAT_ASSERT(reads_->size());
196 first_ = reads_->begin();
197 second_ = find_mate(first_->second);
198 if (second_ == reads_->end())
206 template<
typename Base>
208 BamPairIterator2<Base>::dereference(
void)
const 210 return BamPairProxy(&first_->second, &second_->second);
214 template<
typename Base>
215 bool BamPairIterator2<Base>::equal(
const BamPairIterator2& other)
const 217 return iter_ == other.iter_ && reads_->size() == other.reads_->size();
221 template<
typename Base>
222 void BamPairIterator2<Base>::increment(
void)
229 template<
typename Base>
230 BamPairIterator2<Base>::MultiMap::iterator
231 BamPairIterator2<Base>::find_mate(
const yat::omic::BamRead& bam)
233 Position mate_pos(bam.mtid(), bam.mpos());
234 YAT_ASSERT(reads_->size());
237 while (reads_->rbegin()->first <= mate_pos && iter_!=end_)
240 typedef MultiMap::iterator iterator;
241 std::pair<iterator, iterator> range = reads_->equal_range(mate_pos);
242 for (; range.first != range.second; ++range.first) {
243 if (!same_query_name(bam, range.first->second))
246 if (bam.pos()==bam.mpos() && bam.tid()==bam.mtid() &&
247 bam.flag() == range.first->second.flag())
251 return reads_->end();
255 template<
typename Base>
256 void BamPairIterator2<Base>::pop(
void)
258 YAT_ASSERT(reads_->size());
259 reads_->erase(first_);
263 template<
typename Base>
264 bool BamPairIterator2<Base>::push(
void)
268 Position position(iter_->tid(), iter_->pos());
269 reads_->insert(reads_->end(), std::make_pair(position, *iter_));
BamPairIterator2(void)
default constructor
Definition: BamPairIterator2.h:179
BamRead & first(void)
access first BamRead
BamPairIterator2::pointer operator->(void) const
Definition: BamPairIterator2.h:95
The Department of Theoretical Physics namespace as we define it.
Definition: stl_utility.h:64
Class holding a bam query.
Definition: BamRead.h:51
BamPairIterator2< Base > bam_pair_iterator2(Base end)
Definition: BamPairIterator2.h:156
Definition: BamPairIterator2.h:68
BamPairIterator2< Base > bam_pair_iterator2(Base base, Base end)
Definition: BamPairIterator2.h:145
BamRead & second(void)
access second BamRead