Skip to content

Commit

Permalink
further isolate snarl code
Browse files Browse the repository at this point in the history
  • Loading branch information
glennhickey committed May 17, 2024
1 parent 7b6ae3a commit f0c7874
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 41 deletions.
81 changes: 43 additions & 38 deletions src/deconstructor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1027,6 +1027,48 @@ string Deconstructor::get_vcf_header() {
return stream.str();
}

void Deconstructor::deconstruct_graph(SnarlManager* snarl_manager) {

vector<const Snarl*> snarls_todo;
// Do the top-level snarls in parallel
snarl_manager->for_each_top_level_snarl([&](const Snarl* snarl) {
vector<const Snarl*> todo(1, snarl);
vector<const Snarl*> next;
while (!todo.empty()) {
for (auto next_snarl : todo) {
// if we can't make a variant from the snarl due to not finding
// paths through it, we try again on the children
// note: we may want to push the parallelism down a bit
#pragma omp critical (snarls_todo)
snarls_todo.push_back(next_snarl);
if (include_nested) {
// n.b. we no longer attempt to deconstruct the site to determine if we nest
const vector<const Snarl*>& children = snarl_manager->children_of(next_snarl);
next.insert(next.end(), children.begin(), children.end());
}
}
swap(todo, next);
next.clear();
}
});

//#pragma omp parallel
//#pragma omp single
{
#pragma omp parallel for schedule(dynamic,1)
for (size_t i = 0; i < snarls_todo.size(); i++) {
//#pragma omp task firstprivate(i)
{
auto& snarl = snarls_todo[i];
deconstruct_site(graph->get_handle(snarl->start().node_id(), snarl->start().backward()),
graph->get_handle(snarl->end().node_id(), snarl->end().backward()));
}
}
}
//#pragma omp taskwait

}

/**
* Convenience wrapper function for deconstruction of multiple paths.
*/
Expand All @@ -1040,7 +1082,6 @@ void Deconstructor::deconstruct(vector<string> ref_paths, const PathPositionHand
gbwt::GBWT* gbwt) {

this->graph = graph;
this->snarl_manager = snarl_manager;
this->ref_paths = set<string>(ref_paths.begin(), ref_paths.end());
this->include_nested = include_nested;
this->path_jaccard_window = context_jaccard_window;
Expand Down Expand Up @@ -1069,43 +1110,7 @@ void Deconstructor::deconstruct(vector<string> ref_paths, const PathPositionHand
gbwt_trav_finder = unique_ptr<GBWTTraversalFinder>(new GBWTTraversalFinder(*graph, *gbwt));
}

vector<const Snarl*> snarls_todo;
// Do the top-level snarls in parallel
snarl_manager->for_each_top_level_snarl([&](const Snarl* snarl) {
vector<const Snarl*> todo(1, snarl);
vector<const Snarl*> next;
while (!todo.empty()) {
for (auto next_snarl : todo) {
// if we can't make a variant from the snarl due to not finding
// paths through it, we try again on the children
// note: we may want to push the parallelism down a bit
#pragma omp critical (snarls_todo)
snarls_todo.push_back(next_snarl);
if (include_nested) {
// n.b. we no longer attempt to deconstruct the site to determine if we nest
const vector<const Snarl*>& children = snarl_manager->children_of(next_snarl);
next.insert(next.end(), children.begin(), children.end());
}
}
swap(todo, next);
next.clear();
}
});

//#pragma omp parallel
//#pragma omp single
{
#pragma omp parallel for schedule(dynamic,1)
for (size_t i = 0; i < snarls_todo.size(); i++) {
//#pragma omp task firstprivate(i)
{
auto& snarl = snarls_todo[i];
deconstruct_site(graph->get_handle(snarl->start().node_id(), snarl->start().backward()),
graph->get_handle(snarl->end().node_id(), snarl->end().backward()));
}
}
}
//#pragma omp taskwait
deconstruct_graph(snarl_manager);

// write variants in sorted order
write_variants(cout, snarl_manager);
Expand Down
5 changes: 2 additions & 3 deletions src/deconstructor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ class Deconstructor : public VCFOutputCaller {

// initialize the vcf and get the header
string get_vcf_header();

void deconstruct_graph(SnarlManager* snarl_manager);

// write a vcf record for the given site. returns true if a record was written
// (need to have a path going through the site)
Expand Down Expand Up @@ -101,9 +103,6 @@ class Deconstructor : public VCFOutputCaller {
// the graph
const PathPositionHandleGraph* graph;

// the snarl manager
SnarlManager* snarl_manager;

// the gbwt
gbwt::GBWT* gbwt;

Expand Down

0 comments on commit f0c7874

Please sign in to comment.