bool is_indel_conflict(const indel_key& ik1, const indel_key& ik2) { // add one to the end_pos of all indels to prevent immediately // adjacent indels in the final alignments: pos_range pr1(ik1.open_pos_range()); pr1.end_pos++; pos_range pr2(ik2.open_pos_range()); pr2.end_pos++; return pr1.is_range_intersect(pr2); }
// 99% of this task is taking care of indel normalization static bool convert_indel_to_htype(const indel_key& ik, const indel_data& /*id*/, const read_segment& rseg, const reference_contig_segment& ref, htype_element& he) { he.clear(); // get best alignment: const alignment* alptr(rseg.get_best_alignment()); assert(alptr); const alignment& al(*alptr); // Check that alignment is compatible with indel. Many // cases where this fails will be for 'private' // indels. The posterior above is over all candidate // indels, so one candidate may be the best for this read, // *but* the best alignment contains a private indel // instead. // pos_range read_indel_pr; if (! is_indel_in_alignment(al,ik,read_indel_pr)) return false; const bam_seq read_seq(rseg.get_bam_read()); const rc_segment_bam_seq ref_bseq(ref); pos_range ref_indel_pr(ik.open_pos_range()); assert(! read_indel_pr.is_empty()); assert(! ref_indel_pr.is_empty()); // normalization function adjusts ranges: // normalize_indel(read_indel_pr,ref_indel_pr,read_seq,ref_bseq,read_indel_pr,ref_indel_pr); assert(! read_indel_pr.is_empty()); assert(! ref_indel_pr.is_empty()); // build he: if (ref_indel_pr.is_complete()) { he.delete_length=ref_indel_pr.end_pos-ref_indel_pr.begin_pos; } if (! read_indel_pr.is_begin_pos) { he.pos=read_indel_pr.end_pos; } else { he.pos=read_indel_pr.begin_pos; } if (! read_indel_pr.is_end_pos) { he.open_end=OPEN::RIGHT; } else if (! read_indel_pr.is_begin_pos) { he.open_end=OPEN::LEFT; } { // copy into htype element seq (don't worry about efficiency for now) pos_range pr(read_indel_pr); if (! pr.is_complete()) { const pos_range nonclip_pr(get_nonclip_range(al.path)); assert(nonclip_pr.is_complete()); if (! pr.is_begin_pos) { pr.set_begin_pos(nonclip_pr.begin_pos); } else { pr.set_end_pos(nonclip_pr.end_pos); } } assert(pr.begin_pos<=pr.end_pos && pr.begin_pos>=0); for (pos_t i(pr.begin_pos); i<pr.end_pos; ++i) { he.seq.push_back(read_seq.get_char(i)); } } if ((he.delete_length==0) && (he.insert_length()==0)) { he.clear(); return false; } return true; }