Skip to content

Commit

Permalink
make node length hack optional
Browse files Browse the repository at this point in the history
  • Loading branch information
AndreaGuarracino committed Feb 13, 2024
1 parent 22a4c43 commit 2cd6e57
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 10 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,7 @@ docs/sphinx_build
docs/sphinx_build_man
docs/_build
Testing/
.idea/
.idea/
.vscode/
.cmake/
cmake-build-debug/
11 changes: 6 additions & 5 deletions src/algorithms/draw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ Coordinates adjustNodeLength(double x1, double y1, double x2, double y2, double
// Return the new coordinates
return Coordinates{new_x1, new_y1, new_x2, new_y2};
}
Coordinates adjustNodeEndpoints(const handle_t& handle, const std::vector<double>& X, const std::vector<double>& Y, double scale, double x_off, double y_off, double sparsification_factor) {
Coordinates adjustNodeEndpoints(const handle_t& handle, const std::vector<double>& X, const std::vector<double>& Y, double scale, double x_off, double y_off, double sparsification_factor, bool lengthen_left_nodes) {
// Original coordinates
uint64_t a = 2 * number_bool_packing::unpack_number(handle);
double x1 = (X[a] * scale) - x_off;
Expand All @@ -178,7 +178,7 @@ Coordinates adjustNodeEndpoints(const handle_t& handle, const std::vector<double
double length = std::sqrt(std::pow(x2 - x1, 2) + std::pow(y2 - y1, 2));

// Adjust length based on 1.0 / sparsification_factor
double new_length = sparsification_factor == 0 ? length : length * (1.0 / sparsification_factor);
double new_length = !lengthen_left_nodes || sparsification_factor == 0 ? length : length * (1.0 / sparsification_factor);

// Calculate the midpoint
double mid_x = (x1 + x2) / 2.0;
Expand Down Expand Up @@ -207,7 +207,8 @@ void draw_svg(std::ostream &out,
const double& line_width,
std::vector<algorithms::color_t>& node_id_to_color,
ska::flat_hash_map<handlegraph::nid_t, std::set<std::string>>& node_id_to_label_map,
const float& sparsification_factor) {
const float& sparsification_factor,
const bool& lengthen_left_nodes) {

std::vector<std::vector<handle_t>> weak_components;
coord_range_2d_t rendered_range;
Expand Down Expand Up @@ -251,7 +252,7 @@ void draw_svg(std::ostream &out,
continue; // Skip this node to output a lighter SVG (do not nodes with labels, if any)
}

Coordinates newEndpoints = adjustNodeEndpoints(handle, X, Y, scale, x_off, y_off, sparsification_factor);
Coordinates newEndpoints = adjustNodeEndpoints(handle, X, Y, scale, x_off, y_off, sparsification_factor, lengthen_left_nodes);

if (color == COLOR_BLACK || color == COLOR_LIGHTGRAY) {
out << "<line x1=\""
Expand Down Expand Up @@ -294,7 +295,7 @@ void draw_svg(std::ostream &out,

// color highlights
for (auto& handle : highlights) {
Coordinates newEndpoints = adjustNodeEndpoints(handle, X, Y, scale, x_off, y_off, sparsification_factor);
Coordinates newEndpoints = adjustNodeEndpoints(handle, X, Y, scale, x_off, y_off, sparsification_factor, lengthen_left_nodes);
algorithms::color_t color = node_id_to_color.empty() ? COLOR_BLACK : node_id_to_color[graph.get_id(handle)];
out << "<line x1=\""
<< newEndpoints.x1
Expand Down
3 changes: 2 additions & 1 deletion src/algorithms/draw.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ void draw_svg(std::ostream &out,
const double& line_width,
std::vector<algorithms::color_t>& node_id_to_color,
ska::flat_hash_map<handlegraph::nid_t, std::set<std::string>>& node_id_to_label_map,
const float& sparsification_factor);
const float& sparsification_factor,
const bool& lengthen_left_nodes);

std::vector<uint8_t> rasterize(const std::vector<double> &X,
const std::vector<double> &Y,
Expand Down
7 changes: 4 additions & 3 deletions src/subcommand/draw_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ int main_draw(int argc, char **argv) {
"Colors are derived from the 4th column, if present, else from the path name."
"If the 4th column value is in the format 'string#RRGGBB', the RRGGBB color (in hex notation) will be used.",
{'b', "bed-file"});
args::ValueFlag<float> node_sparsification(parser, "N", "Remove this fraction of nodes from the SVG output (to output smaller files) (default: 0.0, keep all nodes).", {'f', "svg-sparse-factor"});
args::ValueFlag<float> node_sparsification(visualizations_opts, "N", "Remove this fraction of nodes from the SVG output (to output smaller files) (default: 0.0, keep all nodes).", {'f', "svg-sparse-factor"});
args::Flag lengthen_left_nodes(visualizations_opts, "lengthen", "When node sparsitication is active, lengthen the remaining nodes proportionally with the sparsification factor", {'l', "svg-lengthen-nodes"});
args::Group threading(parser, "[ Threading ]");
args::ValueFlag<uint64_t> nthreads(threading, "N", "Number of threads to use for parallel operations.", {'t', "threads"});
args::Group processing_info_opts(parser, "[ Processing Information ]");
Expand Down Expand Up @@ -111,7 +112,7 @@ int main_draw(int argc, char **argv) {
if (infile == "-") {
graph.deserialize(std::cin);
} else {
utils::handle_gfa_odgi_input(infile, "draw", args::get(progress), num_threads, graph);
utils::handle_gfa_odgi_input(infile, "draw", lengthen_left_nodes, num_threads, graph);
}
}
}
Expand Down Expand Up @@ -231,7 +232,7 @@ int main_draw(int argc, char **argv) {
// todo could be done with callbacks
std::vector<double> X = layout.get_X();
std::vector<double> Y = layout.get_Y();
algorithms::draw_svg(f, X, Y, graph, svg_scale, border_bp, _png_line_width, node_id_to_color, node_id_to_label_map, sparse_nodes);
algorithms::draw_svg(f, X, Y, graph, svg_scale, border_bp, _png_line_width, node_id_to_color, node_id_to_label_map, sparse_nodes, args::get(lengthen_left_nodes));
f.close();
}

Expand Down

0 comments on commit 2cd6e57

Please sign in to comment.