Skip to content

Commit 3fd24eb

Browse files
committed
we need to check which nodes have been explored!
1 parent cc97955 commit 3fd24eb

File tree

1 file changed

+39
-32
lines changed

1 file changed

+39
-32
lines changed

src/subgraph.cpp

+39-32
Original file line numberDiff line numberDiff line change
@@ -139,9 +139,9 @@ void DBG::subgraph() {
139139

140140
std::vector<std::function<bool()>> jobs;
141141
std::array<uint16_t, 2> mapRange = {0,0};
142-
142+
143143
while (mapRange[1] < mapCount) {
144-
144+
145145
mapRange = computeMapRange(mapRange);
146146
loadMapRange(mapRange);
147147

@@ -154,30 +154,10 @@ void DBG::subgraph() {
154154
jobs.clear();
155155

156156
deleteMapRange(mapRange);
157-
157+
158158
}
159159
lg.verbose("Merging subgraphs");
160160
mergeSubgraphs();
161-
lg.verbose("Searching graph");
162-
if (userInput.travAlgorithm == "best-first") {
163-
if (userInput.kmerDepth == -1)
164-
userInput.kmerDepth = userInput.kmerLen; // unidirectional search
165-
bestFirst();
166-
}else if (userInput.travAlgorithm == "traversal") {
167-
if (userInput.kmerDepth == -1)
168-
userInput.kmerDepth = std::ceil((float)userInput.kmerLen/2); // kmer search is in both directions
169-
traversal();
170-
}else{
171-
fprintf(stderr, "Cannot find input algorithm (%s). Terminating.\n", userInput.travAlgorithm.c_str());
172-
exit(EXIT_FAILURE);
173-
}
174-
lg.verbose("Remove missing edges");
175-
removeMissingEdges();
176-
lg.verbose("Computing summary graph");
177-
summary(*DBGsubgraph);
178-
lg.verbose("Generating GFA");
179-
DBGgraphToGFA();
180-
181161
}
182162

183163
void DBG::summary(ParallelMap32color& DBGsubgraph) {
@@ -307,6 +287,21 @@ bool DBG::DBGsubgraphFromSegment(InSegment *inSegment, std::array<uint16_t, 2> m
307287
return true;
308288
}
309289

290+
void DBG::searchGraph() {
291+
if (userInput.travAlgorithm == "best-first") {
292+
if (this->userInput.kmerDepth == -1)
293+
userInput.kmerDepth = userInput.kmerLen; // unidirectional search
294+
bestFirst();
295+
}else if (userInput.travAlgorithm == "traversal") {
296+
if (userInput.kmerDepth == -1)
297+
userInput.kmerDepth = std::ceil((float)userInput.kmerLen/2); // kmer search is in both directions
298+
traversal();
299+
}else{
300+
fprintf(stderr, "Cannot find input algorithm (%s). Terminating.\n", userInput.travAlgorithm.c_str());
301+
exit(EXIT_FAILURE);
302+
}
303+
}
304+
310305
void DBG::traversal() {
311306

312307
ParallelMap32color candidates, newCandidates;
@@ -426,25 +421,34 @@ ParallelMap32color DBG::traversalPass(ParallelMap32color* subgraph, std::array<u
426421
void DBG::bestFirst() {
427422

428423
ParallelMap32color* candidates = new ParallelMap32color;
429-
uint32_t explored = 0, total = DBGsubgraph->size();
424+
uint64_t explored = 0, total = DBGsubgraph->size();
430425
std::array<uint16_t, 2> mapRange;
431426
ParallelMap32color* DBGsubgraphCpy = new ParallelMap32color;
427+
bool* visited = new bool[DBGsubgraph->size()]{false};
428+
432429
while(explored < total) {
433430

434431
mapRange = {0,0};
432+
uint64_t i = 0;
435433

436434
while (mapRange[1] < mapCount) {
437435

438436
mapRange = computeMapRange(mapRange);
439437
loadMapRange(mapRange);
440438
for (auto pair : *DBGsubgraph) {
441-
auto results = dijkstra(pair, mapRange);;
442-
explored += results.first;
443-
if (results.first) {
444-
candidates->insert(results.second.begin(), results.second.end());
445-
DBGsubgraphCpy->insert(pair);
446-
// DBGsubgraph->erase(pair.first);
439+
440+
if(!visited[i]) {
441+
442+
auto results = dijkstra(pair, mapRange);;
443+
explored += results.first;
444+
if (results.first) {
445+
candidates->insert(results.second.begin(), results.second.end());
446+
DBGsubgraphCpy->insert(pair);
447+
// DBGsubgraph->erase(pair.first);
448+
visited[i] = true;
449+
}
447450
}
451+
++i;
448452
// std::cout<<DBGsubgraphCpy.size()<<std::endl;
449453
}
450454
deleteMapRange(mapRange);
@@ -454,6 +458,7 @@ void DBG::bestFirst() {
454458
delete DBGsubgraph;
455459
DBGsubgraph = DBGsubgraphCpy;
456460
delete candidates;
461+
delete[] visited;
457462
}
458463

459464
std::pair<bool,ParallelMap32color> DBG::dijkstra(std::pair<uint64_t,DBGkmer32color> source, std::array<uint16_t, 2> mapRange) {
@@ -473,12 +478,12 @@ std::pair<bool,ParallelMap32color> DBG::dijkstra(std::pair<uint64_t,DBGkmer32col
473478
int16_t depth = 0;
474479
bool direction = true, isFw;
475480

476-
while (Q.size() > 0 && depth < userInput.kmerDepth + 1) { // The main loop
481+
while (Q.size() > 0 && depth < userInput.kmerDepth + 1) { // the main loop
477482
explored = false; // if there are still node in the queue we cannot be done
478483
ParallelMap *map;
479484
// ParallelMap32 *map32;
480485

481-
std::pair<const uint64_t, DBGkmer32>* u = Q.extractMin(); // Remove and return best vertex
486+
std::pair<const uint64_t, DBGkmer32>* u = Q.extractMin(); // remove and return best vertex
482487
auto got = prev.find(u->first); // check direction
483488
if (got != prev.end()) {
484489
direction = got->second.second;
@@ -622,6 +627,8 @@ void DBG::removeMissingEdges() {
622627
}
623628
}
624629
}
630+
lg.verbose("Computing summary graph");
631+
summary(*DBGsubgraph);
625632
}
626633

627634

0 commit comments

Comments
 (0)