// -*- mode: c++; indent-tabs-mode: nil; -*- // // Copyright 2009 Illumina, Inc. // // This software is covered by the "Illumina Genome Analyzer Software // License Agreement" and the "Illumina Source Code License Agreement", // and certain third party copyright/licenses, and any user of this // source file is bound by the terms therein (see accompanying files // Illumina_Genome_Analyzer_Software_License_Agreement.pdf and // Illumina_Source_Code_License_Agreement.pdf and third party // copyright/license notices). // // /// \file /// /// \author Chris Saunders /// #include "indel_buffer.hh" #include #include //#define IB_DEBUG std::pair indel_buffer:: pos_range_iter(const pos_t begin_pos, const pos_t end_pos) { const indel_key end_range_key(end_pos); const iterator end(_idata.lower_bound(end_range_key)); const indel_key begin_range_key(begin_pos); iterator begin(_idata.lower_bound(begin_range_key)); indel_key left_begin_key(end_range_key); if((begin!=_idata.end()) and (begin->firstfirst; const indel_key begin_key(leftmost_rightkey(begin_range_key,end_range_key)); if(begin_key < left_begin_key) begin=_idata.find(begin_key); return std::make_pair(begin,end); } std::pair indel_buffer:: pos_range_iter(const pos_t begin_pos, const pos_t end_pos) const { const indel_key end_range_key(end_pos); const const_iterator end(_idata.lower_bound(end_range_key)); const indel_key begin_range_key(begin_pos); const_iterator begin(_idata.lower_bound(begin_range_key)); indel_key left_begin_key(end_range_key); if((begin!=_idata.end()) and (begin->firstfirst; const indel_key begin_key(leftmost_rightkey(begin_range_key,end_range_key)); #ifdef IB_DEBUG const bool b1found(begin != _idata.end()); #endif if(begin_key < left_begin_key) begin=_idata.find(begin_key); #ifdef IB_DEBUG const bool b2found(begin != _idata.end()); const bool efound(end != _idata.end()); std::cerr << "b1found: " << b1found << " b2found: " << b2found << " efound: " << efound << " left_begin_key: " << left_begin_key; #endif return std::make_pair(begin,end); } // search for a key in the right-sorted list with value less // than begin_key: indel_key indel_buffer:: leftmost_rightkey(const indel_key& begin_range_key, const indel_key& end_range_key) const { indel_key begin_key(end_range_key); riter ri(_rightkey.lower_bound(begin_range_key)); const riter ri_end(_rightkey.lower_bound(end_range_key)); for(;ri!=ri_end;++ri) begin_key=std::min(begin_key,*ri); #ifdef IB_DEBUG std::cerr << "leftmost_right_key: begin_range: " << begin_range_key; std::cerr << "leftmost_right_key: end_range: " << end_range_key; std::cerr << "leftmost_right_key: begin: " << begin_key; #endif return begin_key; } static void add_evidence(indel_data::evidence_t& sum, const indel_data::evidence_t& x) { sum.insert(x.begin(),x.end()); } bool indel_buffer:: insert_indel(const indel& in) { assert(in.key.type != INDEL::NONE); idata_t::iterator i(_idata.find(in.key)); if(i == _idata.end()){ _idata[in.key] = in.data; _rightkey.insert(in.key); return true; } indel_data& id(i->second); if(in.key.is_breakpoint() and (id.seq.size() < in.data.seq.size())) { id.seq = in.data.seq; } add_evidence(id.contig_ids,in.data.contig_ids); add_evidence(id.all_read_ids,in.data.all_read_ids); add_evidence(id.map_read_ids,in.data.map_read_ids); add_evidence(id.submap_read_ids,in.data.submap_read_ids); return false; } void indel_buffer:: clear_pos(const pos_t pos) { const iterator i_begin(pos_iter(pos)); const iterator i_end(pos_iter(pos+1)); for(iterator i(i_begin);i!=i_end;++i){ assert(_rightkey.find(i->first) != _rightkey.end()); _rightkey.erase(i->first); } _idata.erase(i_begin,i_end); } void indel_buffer:: dump_pos(const pos_t pos, std::ostream& os) const { const_iterator i(pos_iter(pos)); const const_iterator i_end(pos_iter(pos+1)); for(;i!=i_end;++i){ os << i->first << i->second; } } void indel_buffer:: dump(std::ostream& os) const { os << "INDEL_BUFFER DUMP ON\n"; const_iterator i(_idata.begin()); const const_iterator i_end(_idata.end()); for(;i!=i_end;++i){ os << i->first << i->second; } os << "INDEL_BUFFER DUMP OFF\n"; }