Changeset 3174
- Timestamp:
- Mar 8, 2014, 3:51:20 PM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/yat/omic/BamPairIterator.h
r3173 r3174 29 29 #include <boost/concept/assert.hpp> 30 30 #include <boost/iterator/iterator_facade.hpp> 31 #include <boost/shared_ptr.hpp> 31 32 32 33 #include <iterator> … … 51 52 stepping until it finds a read whose mate it has already seen, and 52 53 operator* return the pair of BamReads. 54 55 Note that BamPairIterator is a single-pass iterator, i.e., once it 56 is incremented the behaviour of its copies is undefined. 53 57 */ 54 58 template<typename Base> … … 78 82 Base end_; 79 83 std::pair<BamRead, BamRead> x_; 80 std::map<std::string, BamRead> siam_reads_;84 boost::shared_ptr<std::map<std::string, BamRead> > siam_reads_; 81 85 typedef std::pair<int32_t, int32_t> Position; 82 std::multimap<Position, BamRead> reads_;86 boost::shared_ptr<std::multimap<Position, BamRead> > reads_; 83 87 friend class boost::iterator_core_access; 84 88 … … 116 120 template<typename Base> 117 121 BamPairIterator<Base>::BamPairIterator(Base base, Base end) 118 : iter_(base), end_(end) 122 : iter_(base), end_(end), 123 siam_reads_(new std::map<std::string, BamRead>), 124 reads_(new std::multimap<Position, BamRead>) 119 125 { 120 126 BOOST_CONCEPT_ASSERT((boost::InputIterator<Base>)); … … 167 173 Position mate_position(iter_->mtid(), iter_->mpos()); 168 174 // clear siam reads if iter is more advanced than siam reads 169 if (siam_reads_ .size() && less(siam_reads_.begin()->second, *iter_))170 siam_reads_ .clear();175 if (siam_reads_->size() && less(siam_reads_->begin()->second, *iter_)) 176 siam_reads_->clear(); 171 177 172 178 // have not seen mate yet 173 179 if (mate_position > position) 174 reads_ .insert(std::make_pair(mate_position, *iter_));180 reads_->insert(std::make_pair(mate_position, *iter_)); 175 181 else if (position > mate_position) { 176 182 std::multimap<Position, BamRead>::iterator 177 lower = reads_ .lower_bound(position);183 lower = reads_->lower_bound(position); 178 184 // erase all reads with mate position less than current 179 185 // position (assuming input range is sorted) 180 reads_ .erase(reads_.begin(), lower);186 reads_->erase(reads_->begin(), lower); 181 187 182 188 // find mate and assign pair 183 for (; lower!=reads_ .end() && lower->first == position; ++lower)189 for (; lower!=reads_->end() && lower->first == position; ++lower) 184 190 if (same_query_name(lower->second, *iter_)) { 185 191 x_.first = lower->second; … … 191 197 // check if we have already seen mate and stored it in map 192 198 std::map<std::string, BamRead>::iterator 193 mate = siam_reads_ .lower_bound(iter_->name());194 if (mate!=siam_reads_ .end() && same_query_name(mate->second, *iter_)) {199 mate = siam_reads_->lower_bound(iter_->name()); 200 if (mate!=siam_reads_->end() && same_query_name(mate->second, *iter_)) { 195 201 x_.first = mate->second; 196 202 x_.second = *iter_; … … 199 205 else 200 206 // insert with hint 201 siam_reads_ .insert(mate, std::make_pair(iter_->name(), *iter_));207 siam_reads_->insert(mate, std::make_pair(iter_->name(), *iter_)); 202 208 } 203 209 }
Note: See TracChangeset
for help on using the changeset viewer.