@@ -340,11 +340,30 @@ using namespace std;
340340 }
341341#endif
342342
343- // we want to remove anchors that can be error-prone: short anchors in the tails and anchors in
344- // low complexity sequences
343+ // Read mapper-declared tail lengths. These coordinates are
344+ // relative to the stored read sequence and independent of path orientation.
345+ // Missing annotations remain zero, making tail-region pruning a no-op.
346+ size_t left_tail_length = 0 , right_tail_length = 0 ;
347+ if (source_aln) {
348+ if (has_annotation (*source_aln, " left_tail_length" )) {
349+ left_tail_length = static_cast <size_t >(get_annotation<double >(*source_aln, " left_tail_length" ));
350+ }
351+ if (has_annotation (*source_aln, " right_tail_length" )) {
352+ right_tail_length = static_cast <size_t >(get_annotation<double >(*source_aln, " right_tail_length" ));
353+ }
354+ }
355+ else {
356+ if (source_mp_aln->has_annotation (" left_tail_length" )) {
357+ left_tail_length = static_cast <size_t >(*((const double *) source_mp_aln->get_annotation (" left_tail_length" ).second ));
358+ }
359+ if (source_mp_aln->has_annotation (" right_tail_length" )) {
360+ right_tail_length = static_cast <size_t >(*((const double *) source_mp_aln->get_annotation (" right_tail_length" ).second ));
361+ }
362+ }
345363 for (auto it = path_overlapping_anchors.begin (); it != path_overlapping_anchors.end (); ++it) {
346364 prune_and_trim_anchors (source_aln ? source_aln->sequence () : source_mp_aln->sequence (),
347- it->second .first , it->second .second );
365+ it->second .first , it->second .second ,
366+ left_tail_length, right_tail_length);
348367 }
349368
350369 // the surjected alignment for each path we overlapped
@@ -4647,10 +4666,11 @@ using namespace std;
46474666 }
46484667
46494668 void Surjector::prune_and_trim_anchors (const string& sequence, vector<path_chunk_t >& path_chunks,
4650- vector<pair<step_handle_t , step_handle_t >>& step_ranges) const {
4651-
4652- if (!prune_suspicious_anchors && max_anchors > path_chunks.size ()) {
4653- // the setting don't require us to prune anything here
4669+ vector<pair<step_handle_t , step_handle_t >>& step_ranges,
4670+ size_t left_tail_length, size_t right_tail_length) const {
4671+
4672+ if (!prune_suspicious_anchors && !prune_tail_region_anchors && max_anchors > path_chunks.size ()) {
4673+ // the settings don't require us to prune anything here
46544674 return ;
46554675 }
46564676
@@ -4674,7 +4694,37 @@ using namespace std;
46744694 }
46754695
46764696 vector<bool > keep (path_chunks.size (), true );
4677-
4697+
4698+ // Clamp tail lengths to the read length
4699+ size_t read_length = sequence.size ();
4700+ left_tail_length = std::min (left_tail_length, read_length);
4701+ right_tail_length = std::min (right_tail_length, read_length);
4702+ size_t right_tail_begin = read_length - right_tail_length;
4703+
4704+ if (prune_tail_region_anchors) {
4705+ // Drop anchors whose entire read interval lies inside a mapper-declared tail region.
4706+ for (int i = 0 ; i < path_chunks.size (); ++i) {
4707+ auto & chunk = path_chunks[i];
4708+ size_t anchor_read_start = chunk.first .first - sequence.begin ();
4709+ size_t anchor_read_end = chunk.first .second - sequence.begin ();
4710+
4711+ bool fully_in_left_tail = (left_tail_length > 0 && anchor_read_end <= left_tail_length);
4712+ bool fully_in_right_tail = (right_tail_length > 0 && anchor_read_start >= right_tail_begin);
4713+
4714+ if (fully_in_left_tail || fully_in_right_tail) {
4715+ #ifdef debug_anchored_surject
4716+ cerr << " anchor " << i << " (read[" << anchor_read_start << " :" << anchor_read_end
4717+ << " ]) pruned for lying fully inside "
4718+ << (fully_in_left_tail ? " left" : " right" )
4719+ << " tail region"
4720+ << " (left_tail_length=" << left_tail_length
4721+ << " , right_tail_length=" << right_tail_length << " )" << endl;
4722+ #endif
4723+ keep[i] = false ;
4724+ }
4725+ }
4726+ }
4727+
46784728 if (prune_suspicious_anchors) {
46794729#ifdef debug_anchored_surject
46804730 cerr << " pruning suspicious anchors" ;
@@ -4686,7 +4736,12 @@ using namespace std;
46864736 for (int i = 0 ; i < path_chunks.size (); ++i) {
46874737 auto & chunk = path_chunks[i];
46884738 // Mark anchors that are themselves suspicious as not to be kept.
4689-
4739+
4740+ if (!keep[i]) {
4741+ // Already pruned by the tail-region check above; skip remaining checks.
4742+ continue ;
4743+ }
4744+
46904745 // Short tails
46914746 if ((chunk.first .first == path_chunks.front ().first .first || chunk.first .second == path_chunks.back ().first .second ) // Is at either tail
46924747 && (anchor_lengths[i] <= max_tail_anchor_prune || chunk.first .second - chunk.first .first <= max_tail_anchor_prune)) { // And is too short
0 commit comments