-
Notifications
You must be signed in to change notification settings - Fork 212
Add functionality to compute discontiguous supplementary alignments in short-read Giraffe #4767
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
Merged
eizengaj-roche
merged 6 commits into
vgteam:master
from
eizengaj-roche:giraffe-supplementary
Jan 5, 2026
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
a1e0c01
add functionality to compute supplementary alignments in short read g…
jeizenga b8d7f67
add 2 files missing from the previous commit
jeizenga 6ae26ac
refactor hard clipping out of Surjector::surject()
jeizenga 7001b5b
update libvgio to add supplementaries to gaf output
jeizenga c56b52b
fix stray character in test file
jeizenga 085b255
move GAM supplementaries into a main field
jeizenga File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3898,4 +3898,6 @@ Alignment target_alignment(const PathPositionHandleGraph* graph, const path_hand | |
| } | ||
| return aln; | ||
| } | ||
|
|
||
|
|
||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,113 @@ | ||
| /** | ||
| * \file interval_union.cpp: contains the implementation of IntervalUnion | ||
| */ | ||
|
|
||
|
|
||
| #include "interval_union.hpp" | ||
|
|
||
| #include <cassert> | ||
| #include <iostream> | ||
|
|
||
| namespace vg { | ||
|
|
||
| using namespace std; | ||
|
|
||
| void IntervalUnion::add(size_t begin, size_t end) { | ||
|
|
||
| assert(begin <= end); | ||
| if (begin == end) { | ||
| // empty interval, can be ignore | ||
| return; | ||
| } | ||
|
|
||
| auto after = irvl_union.upper_bound(begin); | ||
| auto merge_from = irvl_union.end(); | ||
| if (after != irvl_union.begin()) { | ||
| // get the nearest interval to the left, possibly at the same index | ||
| auto before = after; | ||
| --before; | ||
| if (before->second >= begin) { | ||
| // merge this interval into the earlier interval | ||
| if (end > before->second) { | ||
| union_size += end - before->second; | ||
| before->second = end; | ||
| merge_from = before; | ||
| } | ||
| } | ||
| else { | ||
| // the start of this interval is outside the one to the left | ||
| union_size += (end - begin); | ||
| merge_from = irvl_union.emplace_hint(after, begin, end); | ||
| } | ||
| } | ||
| else { | ||
| // there is no interval to the left | ||
| union_size += (end - begin); | ||
| merge_from = irvl_union.emplace_hint(after, begin, end); | ||
| } | ||
|
|
||
| // TODO: it might also be possible to do a lazy-update version of this data structure | ||
| // to get amortized O(log n) add | ||
|
|
||
| if (merge_from != irvl_union.end()) { | ||
| // try to merge this interval with the ones to the right | ||
| auto next = merge_from; | ||
| ++next; | ||
| while (next != irvl_union.end() && next->first <= merge_from->second) { | ||
| union_size -= (min(merge_from->second, next->second) - next->first); | ||
| merge_from->second = max(merge_from->second, next->second); | ||
| irvl_union.erase(next); | ||
| next = merge_from; | ||
| ++next; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| void IntervalUnion::clear() { | ||
| union_size = 0; | ||
| irvl_union.clear(); | ||
| } | ||
|
|
||
| size_t IntervalUnion::overlap(size_t begin, size_t end) const { | ||
|
|
||
| // start to the left of the query interval | ||
| auto iter = irvl_union.upper_bound(begin); | ||
| if (iter != irvl_union.begin()) { | ||
| --iter; | ||
| } | ||
|
|
||
| // TODO: there's a worst-case O(log n) solution using a sum-augmented range tree | ||
| // to get the contribution from strictly contained intervals, but rebalancing it | ||
| // would be a pain | ||
|
|
||
| // add up the length of the intervals that this overlaps | ||
| size_t total_overlap = 0; | ||
| while (iter != irvl_union.end() && iter->first < end) { | ||
| if (iter->second > begin && end > iter->first) { | ||
| total_overlap += (min(end, iter->second) - max(begin, iter->first)); | ||
| } | ||
| ++iter; | ||
| } | ||
|
|
||
| return total_overlap; | ||
| } | ||
|
|
||
| size_t IntervalUnion::total_size() const { | ||
| return union_size; | ||
| } | ||
|
|
||
| size_t IntervalUnion::component_size() const { | ||
| return irvl_union.size(); | ||
| } | ||
|
|
||
| vector<pair<size_t, size_t>> IntervalUnion::get_union() const { | ||
| vector<pair<size_t, size_t>> intervals; | ||
| intervals.reserve(irvl_union.size()); | ||
| for (const auto& interval : irvl_union) { | ||
| intervals.push_back(interval); | ||
| } | ||
| return intervals; | ||
| } | ||
|
|
||
| } | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| /** \file | ||
| * interval_union.hpp: defines the union of a collection of intervals that can | ||
| * be constructed incrementally | ||
| */ | ||
| #ifndef VG_INTERVAL_UNION_HPP_INCLUDED | ||
| #define VG_INTERVAL_UNION_HPP_INCLUDED | ||
|
|
||
| #include <map> | ||
| #include <vector> | ||
| #include <utility> | ||
|
|
||
| namespace vg { | ||
|
|
||
| using namespace std; | ||
|
|
||
| /** | ||
| * The union of a collection of intervals | ||
| */ | ||
| class IntervalUnion | ||
| { | ||
| public: | ||
| IntervalUnion() = default; | ||
| ~IntervalUnion() = default; | ||
|
|
||
| // add a new interval to the union | ||
| void add(size_t begin, size_t end); | ||
| inline void add(const pair<size_t, size_t>& interval); | ||
|
|
||
| // return the union to an empy starting state | ||
| void clear(); | ||
|
|
||
| // query an interval's length of overlap with the union | ||
| size_t overlap(size_t begin, size_t end) const; | ||
| inline size_t overlap(const pair<size_t, size_t>& interval) const; | ||
|
|
||
| // get the total size of the intervals in the union | ||
| size_t total_size() const; | ||
|
|
||
| // return the number of disjoint intervals that comprise the union | ||
| size_t component_size() const; | ||
|
|
||
| // get the intervals that comprise the union | ||
| vector<pair<size_t, size_t>> get_union() const; | ||
|
|
||
| private: | ||
|
|
||
| map<size_t, size_t> irvl_union; | ||
|
|
||
| size_t union_size = 0; | ||
|
|
||
| }; | ||
|
|
||
| /* | ||
| * Inline implementations | ||
| */ | ||
|
|
||
| void IntervalUnion::add(const pair<size_t, size_t>& interval) { | ||
| add(interval.first, interval.second); | ||
| } | ||
|
|
||
| size_t IntervalUnion::overlap(const pair<size_t, size_t>& interval) const { | ||
| return overlap(interval.first, interval.second); | ||
| } | ||
|
|
||
| } | ||
|
|
||
| #endif // VG_INTERVAL_UNION_HPP_INCLUDED | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
This is a candidate for living in
structures.