Skip to content

Commit

Permalink
Merge pull request #2474 from vgteam/packed-call
Browse files Browse the repository at this point in the history
[wip] Clean up vg augment
  • Loading branch information
glennhickey authored Sep 20, 2019
2 parents 7fa3ee8 + 8d7b747 commit ed86372
Show file tree
Hide file tree
Showing 21 changed files with 189 additions and 6,455 deletions.
36 changes: 29 additions & 7 deletions src/augment.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ void augment(MutablePathMutableHandleGraph* graph,
istream& gam_stream,
vector<Translation>* out_translations,
ostream* gam_out_stream,
function<void(Path&)> save_path_fn,
bool embed_paths,
bool break_at_ends,
bool remove_softclips) {

Expand All @@ -32,7 +32,7 @@ void augment(MutablePathMutableHandleGraph* graph,
iterate_gam,
out_translations,
gam_out_stream,
save_path_fn,
embed_paths,
break_at_ends,
remove_softclips);
}
Expand All @@ -41,7 +41,7 @@ void augment(MutablePathMutableHandleGraph* graph,
vector<Path>& path_vector,
vector<Translation>* out_translations,
ostream* gam_out_stream,
function<void(Path&)> save_path_fn,
bool embed_paths,
bool break_at_ends,
bool remove_softclips) {

Expand All @@ -59,7 +59,7 @@ void augment(MutablePathMutableHandleGraph* graph,
iterate_gam,
out_translations,
gam_out_stream,
save_path_fn,
embed_paths,
break_at_ends,
remove_softclips);
}
Expand All @@ -68,7 +68,7 @@ void augment_impl(MutablePathMutableHandleGraph* graph,
function<void(function<void(Alignment&)>, bool)> iterate_gam,
vector<Translation>* out_translations,
ostream* gam_out_stream,
function<void(Path&)> save_path_fn,
bool embed_paths,
bool break_at_ends,
bool remove_softclips) {
// Collect the breakpoints
Expand Down Expand Up @@ -138,8 +138,8 @@ void augment_impl(MutablePathMutableHandleGraph* graph,
// Copy over the name
*added.mutable_name() = aln.name();

if (save_path_fn) {
save_path_fn(added);
if (embed_paths) {
add_path_to_graph(graph, added);
}

// something is off about this check.
Expand Down Expand Up @@ -198,6 +198,19 @@ void augment_impl(MutablePathMutableHandleGraph* graph,
if (out_translations != nullptr) {
*out_translations = make_translation(graph, node_translation, added_nodes, orig_node_sizes);
}

VG* vg_graph = dynamic_cast<VG*>(graph);

// This code got run after augment in VG::edit, so we make sure it happens here too
if (vg_graph != nullptr) {
// Rebuild path ranks, aux mapping, etc. by compacting the path ranks
// Todo: can we just do this once?
vg_graph->paths.compact_ranks();

// execute a semi partial order sort on the nodes
vg_graph->sort();
}

}


Expand Down Expand Up @@ -297,6 +310,15 @@ void find_breakpoints(const Path& path, unordered_map<id_t, set<pos_t>>& breakpo

}

path_handle_t add_path_to_graph(MutablePathHandleGraph* graph, const Path& path) {
path_handle_t path_handle = graph->create_path_handle(path.name(), path.is_circular());
for (int i = 0; i < path.mapping_size(); ++i) {
graph->append_step(path_handle, graph->get_handle(path.mapping(i).position().node_id(),
path.mapping(i).position().is_reverse()));
}
return path_handle;
}

unordered_map<id_t, set<pos_t>> forwardize_breakpoints(const HandleGraph* graph,
const unordered_map<id_t, set<pos_t>>& breakpoints) {
unordered_map<id_t, set<pos_t>> fwd;
Expand Down
12 changes: 8 additions & 4 deletions src/augment.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ using namespace std;
/// If out_translation is not null, a list of translations, one per node existing
/// after the edit, describing
/// how each new or conserved node is embedded in the old graph.
/// if save_path_fn is not null, this function will be run on each modified path
/// if embed_paths is true, then the augmented alignemnents will be saved as embededed paths in the graph
/// in order to add it back to the graph.
/// If break_at_ends is true, nodes will be broken at
/// the ends of paths that start/end woth perfect matches, so the paths can
Expand All @@ -35,7 +35,7 @@ void augment(MutablePathMutableHandleGraph* graph,
istream& gam_stream,
vector<Translation>* out_translation = nullptr,
ostream* gam_out_stream = nullptr,
function<void(Path&)> save_path_fn = nullptr,
bool embed_paths = false,
bool break_at_ends = false,
bool remove_soft_clips = false);

Expand All @@ -45,7 +45,7 @@ void augment(MutablePathMutableHandleGraph* graph,
vector<Path>& path_vector,
vector<Translation>* out_translation = nullptr,
ostream* gam_out_stream = nullptr,
function<void(Path&)> save_path_fn = nullptr,
bool embed_paths = false,
bool break_at_ends = false,
bool remove_soft_clips = false);

Expand All @@ -54,10 +54,14 @@ void augment_impl(MutablePathMutableHandleGraph* graph,
function<void(function<void(Alignment&)>, bool)> iterate_gam,
vector<Translation>* out_translation,
ostream* gam_out_stream,
function<void(Path&)> save_path_fn,
bool embed_paths,
bool break_at_ends,
bool remove_soft_clips);

/// Add a path to the graph. This is like VG::extend, and expects
/// a path with no edits, and for all the nodes and edges in the path
/// to exist exactly in the graph
path_handle_t add_path_to_graph(MutablePathHandleGraph* graph, const Path& path);

/// Find all the points at which a Path enters or leaves nodes in the graph. Adds
/// them to the given map by node ID of sets of bases in the node that will need
Expand Down
2 changes: 1 addition & 1 deletion src/io/register_loader_saver_hash_graph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ using namespace std;
using namespace vg::io;

void register_loader_saver_hash_graph() {
Registry::register_bare_loader_saver<bdsg::HashGraph, PathHandleGraph, HandleGraph>("HashGraph", [](istream& input) -> void* {
Registry::register_bare_loader_saver<bdsg::HashGraph, MutablePathMutableHandleGraph, MutableHandleGraph, PathHandleGraph, HandleGraph>("HashGraph", [](istream& input) -> void* {
// Allocate a HashGraph
bdsg::HashGraph* hash_graph = new bdsg::HashGraph();

Expand Down
4 changes: 2 additions & 2 deletions src/io/register_loader_saver_odgi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ using namespace std;
using namespace vg::io;

void register_loader_saver_odgi() {
Registry::register_bare_loader_saver<bdsg::ODGI, PathHandleGraph, HandleGraph>("PackedGraph", [](istream& input) -> void* {
Registry::register_bare_loader_saver<bdsg::ODGI, MutablePathMutableHandleGraph, MutableHandleGraph, PathHandleGraph, HandleGraph>("PackedGraph", [](istream& input) -> void* {
// Allocate a PackedGraph
bdsg::ODGI* odgi = new bdsg::ODGI();
bdsg::ODGI* odgi = new bdsg::ODGI();

// Load it
odgi->load(input);
Expand Down
2 changes: 1 addition & 1 deletion src/io/register_loader_saver_packed_graph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ using namespace std;
using namespace vg::io;

void register_loader_saver_packed_graph() {
Registry::register_bare_loader_saver<bdsg::PackedGraph, PathHandleGraph, HandleGraph>("PackedGraph", [](istream& input) -> void* {
Registry::register_bare_loader_saver<bdsg::PackedGraph, MutablePathMutableHandleGraph, MutableHandleGraph, PathHandleGraph, HandleGraph>("PackedGraph", [](istream& input) -> void* {
// Allocate a PackedGraph
bdsg::PackedGraph* packed_graph = new bdsg::PackedGraph();

Expand Down
2 changes: 1 addition & 1 deletion src/io/register_loader_saver_vg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ using namespace vg::io;

void register_loader_saver_vg() {
// We register for "" so we can handle untagged old-style vg files and make them into HandleGraphs
Registry::register_loader_saver<VG, PathHandleGraph, HandleGraph>(vector<string>{"VG", ""},
Registry::register_loader_saver<VG, MutablePathMutableHandleGraph, MutableHandleGraph, PathHandleGraph, HandleGraph>(vector<string>{"VG", ""},
[](const message_sender_function_t& for_each_message) -> void* {
// We have a bit of a control problem.
// The source function wants to drive; we give it a function of strings, and it calls it with all the strings in turn.
Expand Down
Loading

1 comment on commit ed86372

@adamnovak
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

vg CI tests complete for merge to master. View the full report here.

19 tests passed, 0 tests failed and 0 tests skipped in 13274 seconds

Tests produced 361 warnings. 361 were for lower-than-expected alignment scores

Please sign in to comment.