Repository navigation
surject changes: prune anchors in mapper-declared tail regions #5050
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
5075a01
f9c02e0
8a6e04c
13d7ed7
1e0ea34
4938d5b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -340,11 +340,30 @@ using namespace std; | |||||
| } | ||||||
| #endif | ||||||
|
|
||||||
| // we want to remove anchors that can be error-prone: short anchors in the tails and anchors in | ||||||
| // low complexity sequences | ||||||
| // Read mapper-declared tail lengths. These coordinates are | ||||||
| // relative to the stored read sequence and independent of path orientation. | ||||||
| // Missing annotations remain zero, making tail-region pruning a no-op. | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The annotation can't remain 0 if it's missing and so doesn't exist to begin with. I also don't know what the reader would think tail-region pruning would do for a zero-length tail other than nothing. This part isn't actually about the pruning (just the parsing) so we don't need to explain the edge case behavior of the pruning here.
Suggested change
|
||||||
| size_t left_tail_length = 0, right_tail_length = 0; | ||||||
| if (source_aln) { | ||||||
| if (has_annotation(*source_aln, "left_tail_length")) { | ||||||
| left_tail_length = static_cast<size_t>(get_annotation<double>(*source_aln, "left_tail_length")); | ||||||
| } | ||||||
| if (has_annotation(*source_aln, "right_tail_length")) { | ||||||
| right_tail_length = static_cast<size_t>(get_annotation<double>(*source_aln, "right_tail_length")); | ||||||
| } | ||||||
| } | ||||||
| else { | ||||||
| if (source_mp_aln->has_annotation("left_tail_length")) { | ||||||
| left_tail_length = static_cast<size_t>(*((const double*) source_mp_aln->get_annotation("left_tail_length").second)); | ||||||
| } | ||||||
| if (source_mp_aln->has_annotation("right_tail_length")) { | ||||||
| right_tail_length = static_cast<size_t>(*((const double*) source_mp_aln->get_annotation("right_tail_length").second)); | ||||||
| } | ||||||
| } | ||||||
| for (auto it = path_overlapping_anchors.begin(); it != path_overlapping_anchors.end(); ++it) { | ||||||
| prune_and_trim_anchors(source_aln ? source_aln->sequence() : source_mp_aln->sequence(), | ||||||
| it->second.first, it->second.second); | ||||||
| it->second.first, it->second.second, | ||||||
| left_tail_length, right_tail_length); | ||||||
| } | ||||||
|
|
||||||
| // the surjected alignment for each path we overlapped | ||||||
|
|
@@ -4647,10 +4666,11 @@ using namespace std; | |||||
| } | ||||||
|
|
||||||
| void Surjector::prune_and_trim_anchors(const string& sequence, vector<path_chunk_t>& path_chunks, | ||||||
| vector<pair<step_handle_t, step_handle_t>>& step_ranges) const { | ||||||
|
|
||||||
| if (!prune_suspicious_anchors && max_anchors > path_chunks.size()) { | ||||||
| // the setting don't require us to prune anything here | ||||||
| vector<pair<step_handle_t, step_handle_t>>& step_ranges, | ||||||
| size_t left_tail_length, size_t right_tail_length) const { | ||||||
|
|
||||||
| if (!prune_suspicious_anchors && !prune_tail_region_anchors && max_anchors > path_chunks.size()) { | ||||||
| // the settings don't require us to prune anything here | ||||||
| return; | ||||||
| } | ||||||
|
|
||||||
|
|
@@ -4674,7 +4694,37 @@ using namespace std; | |||||
| } | ||||||
|
|
||||||
| vector<bool> keep(path_chunks.size(), true); | ||||||
|
|
||||||
|
|
||||||
| // Clamp tail lengths to the read length | ||||||
| size_t read_length = sequence.size(); | ||||||
| left_tail_length = std::min(left_tail_length, read_length); | ||||||
| right_tail_length = std::min(right_tail_length, read_length); | ||||||
|
Comment on lines
+4697
to
+4700
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are we encountering tails longer than reads in real life? Do we have a good excuse for them? If not we might want to fail or warn, because if some of our tail annotations are garbage the rest might also be garbage.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We won't encounter a tail longer than the read right now, but surject can create this situation internally: when it splits a read with supplementary alignments into hard-clipped pieces, it currently copies the full read’s tail annotations unchanged. Eg. - A valid 500 bp tail on a 5 kb read can therefore exceed the length of a 300 bp piece. I’ve kept the existing clamping for now and added a TODO to translate the annotations into each piece’s coordinates. Clamping prevents out-of-range lengths but does not correct the coordinates. Once this is taken care of, I agree that oversized tails should be reported rather than silently accepted. But since that might need to address the whole supplementary surjection structure, I'm not introducing that in this PR.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OK, then I think it makes sense to keep this here. |
||||||
| size_t right_tail_begin = read_length - right_tail_length; | ||||||
|
|
||||||
| if (prune_tail_region_anchors) { | ||||||
| // Drop anchors whose entire read interval lies inside a mapper-declared tail region. | ||||||
| for (int i = 0; i < path_chunks.size(); ++i) { | ||||||
| auto& chunk = path_chunks[i]; | ||||||
| size_t anchor_read_start = chunk.first.first - sequence.begin(); | ||||||
| size_t anchor_read_end = chunk.first.second - sequence.begin(); | ||||||
|
|
||||||
| bool fully_in_left_tail = (left_tail_length > 0 && anchor_read_end <= left_tail_length); | ||||||
| bool fully_in_right_tail = (right_tail_length > 0 && anchor_read_start >= right_tail_begin); | ||||||
|
|
||||||
| if (fully_in_left_tail || fully_in_right_tail) { | ||||||
| #ifdef debug_anchored_surject | ||||||
| cerr << "anchor " << i << " (read[" << anchor_read_start << ":" << anchor_read_end | ||||||
| << "]) pruned for lying fully inside " | ||||||
| << (fully_in_left_tail ? "left" : "right") | ||||||
| << " tail region" | ||||||
| << " (left_tail_length=" << left_tail_length | ||||||
| << ", right_tail_length=" << right_tail_length << ")" << endl; | ||||||
| #endif | ||||||
| keep[i] = false; | ||||||
| } | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| if (prune_suspicious_anchors) { | ||||||
| #ifdef debug_anchored_surject | ||||||
| cerr << "pruning suspicious anchors"; | ||||||
|
|
@@ -4686,7 +4736,12 @@ using namespace std; | |||||
| for (int i = 0; i < path_chunks.size(); ++i) { | ||||||
| auto& chunk = path_chunks[i]; | ||||||
| // Mark anchors that are themselves suspicious as not to be kept. | ||||||
|
|
||||||
|
|
||||||
| if (!keep[i]) { | ||||||
| // Already pruned by the tail-region check above; skip remaining checks. | ||||||
| continue; | ||||||
| } | ||||||
|
|
||||||
| // Short tails | ||||||
| if ((chunk.first.first == path_chunks.front().first.first || chunk.first.second == path_chunks.back().first.second) // Is at either tail | ||||||
| && (anchor_lengths[i] <= max_tail_anchor_prune || chunk.first.second - chunk.first.first <= max_tail_anchor_prune)) { // And is too short | ||||||
|
|
||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be so weird for the annotations stored in the read to be relative to some path in the graph and not the read that they are actually on, to the point where I think it is going to confuse the reader to tell them that it isn't the case.