1 #ifndef theplu_yat_omic_bam_pair_iterator
2 #define theplu_yat_omic_bam_pair_iterator
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>
34 #include <boost/shared_ptr.hpp>
62 template<
typename Base>
64 :
public boost::iterator_facade<
65 BamPairIterator<Base>, const BamPair, std::input_iterator_tag,
85 #ifndef YAT_HAVE_BOOST_ITERATOR_FACADE_PROXY_PTR
104 YAT_ASSERT(iter_ != end_);
105 dummie_.
first() = *mate_;
106 dummie_.
second() = *iter_;
117 boost::shared_ptr<std::map<std::string, BamRead> > siam_reads_;
118 typedef std::pair<int32_t, int32_t> Position;
119 boost::shared_ptr<std::multimap<Position, BamRead> > reads_;
120 friend class boost::iterator_core_access;
124 void increment(
void);
125 void find_next(
void);
134 template<
typename Base>
145 template<
typename Base>
153 template<
typename Base>
155 : iter_(base), end_(end),
156 siam_reads_(new std::map<std::string,
BamRead>),
157 reads_(new std::multimap<Position,
BamRead>)
159 BOOST_CONCEPT_ASSERT((boost_concepts::ReadableIterator<Base>));
160 BOOST_CONCEPT_ASSERT((boost_concepts::SinglePassIterator<Base>));
161 using boost::Convertible;
162 typedef typename std::iterator_traits<Base>::value_type value_type;
163 BOOST_CONCEPT_ASSERT((Convertible<value_type, BamRead>));
168 template<
typename Base>
171 BOOST_CONCEPT_ASSERT((boost::InputIterator<Base>));
172 using boost::Convertible;
173 typedef typename std::iterator_traits<Base>::value_type value_type;
174 BOOST_CONCEPT_ASSERT((Convertible<value_type, BamRead>));
178 template<
typename Base>
186 template<
typename Base>
187 bool BamPairIterator<Base>::equal(
const BamPairIterator& other)
const
189 return iter_ == other.iter_;
193 template<
typename Base>
194 void BamPairIterator<Base>::increment(
void)
201 template<
typename Base>
202 void BamPairIterator<Base>::find_next(
void)
205 for (; iter_!=end_; ++iter_) {
206 Position position(iter_->tid(), iter_->pos());
207 Position mate_position(iter_->mtid(), iter_->mpos());
209 if (siam_reads_->size() && less(siam_reads_->begin()->second, *iter_))
210 siam_reads_->clear();
213 if (mate_position > position)
214 reads_->insert(std::make_pair(mate_position, *iter_));
215 else if (position > mate_position) {
216 std::multimap<Position, BamRead>::iterator
217 lower = reads_->lower_bound(position);
220 reads_->erase(reads_->begin(), lower);
223 for (; lower!=reads_->end() && lower->first == position; ++lower)
224 if (same_query_name(lower->second, *iter_)) {
225 mate_ = &lower->second;
231 std::map<std::string, BamRead>::iterator
232 mate = siam_reads_->lower_bound(iter_->name());
233 if (mate!=siam_reads_->end() && same_query_name(mate->second, *iter_)) {
234 mate_ = &mate->second;
239 siam_reads_->insert(mate, std::make_pair(iter_->name(), *iter_));
BamPairIterator(void)
default constructor
Definition: BamPairIterator.h:169
BamRead & first(void)
access first BamRead
BamPairIterator::pointer operator->(void) const
Definition: BamPairIterator.h:92
Class holding a bam query.
Definition: BamRead.h:53
BamPairIterator< Base > bam_pair_iterator(Base end)
Definition: BamPairIterator.h:146
Definition: BamPairIterator.h:63
BamPairIterator< Base > bam_pair_iterator(Base base, Base end)
Definition: BamPairIterator.h:135
BamRead & second(void)
access second BamRead