Skip to content
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

fix bug to avoid underflows in odgi viz #570

Merged
merged 1 commit into from
Apr 7, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions src/subcommand/viz_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -714,7 +714,7 @@ namespace odgi {
if (a >= pangenomic_start_pos && a <= pangenomic_end_pos || b >= pangenomic_start_pos && b <= pangenomic_end_pos) {
// In binned mode, the Links have to be tall to be visible; in standard mode, _bin_width is 1, so nothing changes here
const uint64_t dist = (b - a) * _bin_width;

double i = 0.0;

for (; i < dist; i += 1.0 / scale_y) {
Expand All @@ -741,21 +741,21 @@ namespace odgi {
// map into our bins
const uint64_t index_h = number_bool_packing::unpack_number(h) + !number_bool_packing::unpack_bit(h) - shift;
const uint64_t index_o = number_bool_packing::unpack_number(o) + number_bool_packing::unpack_bit(o) - shift;
const uint64_t _a = position_map[index_h] / _bin_width;
const uint64_t _b = position_map[index_o] / _bin_width;
const uint64_t h_pos = position_map[index_h] / _bin_width;
const uint64_t o_pos = position_map[index_o] / _bin_width;

// The last node has to be treated differently, as it has no following node, and its outgoing links would start outside the image
const double x_shift = (index_h == position_map.size() - 1) || (index_o == position_map.size() - 1) ? (1.0 / _bin_width) : 0.0;

const uint64_t a = std::min(_a, _b);
const uint64_t b = std::max(_a, _b) >= x_shift ? (std::max(_a, _b) - x_shift) : 0;
const uint64_t a = std::min(h_pos, o_pos);
const uint64_t b = std::max(h_pos, o_pos) >= x_shift ? (std::max(h_pos, o_pos) - x_shift) : 0;

#ifdef debug_odgi_viz
std::cerr << graph.get_id(h) << " (" << number_bool_packing::unpack_bit(h) << ") --> " << graph.get_id(o) << " (" << number_bool_packing::unpack_bit(o) << ") " << std::endl;
std::cerr << "edge " << a << " --> " << b << std::endl;
#endif

add_edge_from_positions(a, b, 0);
add_edge_from_positions(std::min(a, b), std::max(a, b), 0);
};

{
Expand Down