@@ -462,7 +462,7 @@ std::pair<bool,ParallelMap32color> DBG::dijkstra(std::pair<uint64_t,DBGkmer32col
462
462
std::vector<uint64_t > destinations;
463
463
FibonacciHeap<std::pair<const uint64_t , DBGkmer32>*> Q; // node priority queue Q
464
464
phmap::parallel_flat_hash_map<uint64_t ,uint8_t > dist;
465
- phmap::parallel_flat_hash_map<uint64_t ,uint64_t > prev; // distance table
465
+ phmap::parallel_flat_hash_map<uint64_t ,std::pair< uint64_t , bool > > prev; // distance table
466
466
ParallelMap32color discoveredNodes;
467
467
468
468
dist[source.first ] = 1 ;
@@ -471,16 +471,20 @@ std::pair<bool,ParallelMap32color> DBG::dijkstra(std::pair<uint64_t,DBGkmer32col
471
471
472
472
uint64_t key;
473
473
int16_t depth = 0 ;
474
+ bool direction = true , isFw;
474
475
475
476
while (Q.size () > 0 && depth < userInput.kmerDepth + 1 ) { // The main loop
476
477
explored = false ; // if there are still node in the queue we cannot be done
477
478
ParallelMap *map;
478
479
// ParallelMap32 *map32;
479
480
480
- bool isFw = false ;
481
481
std::pair<const uint64_t , DBGkmer32>* u = Q.extractMin (); // Remove and return best vertex
482
-
483
- auto checkNext = [&,this ] (uint64_t key) {
482
+ auto got = prev.find (u->first ); // check direction
483
+ if (got != prev.end ()) {
484
+ direction = got->second .second ;
485
+ }
486
+
487
+ auto checkNext = [&,this ] (uint64_t key, bool direction) {
484
488
auto startNode = DBGsubgraph->find (key);
485
489
if (startNode == DBGsubgraph->end ()) { // if we connect to the original graph we are done
486
490
auto nextKmer = graphCache->find (key); // check if the node is in the cache (already visited)
@@ -504,38 +508,51 @@ std::pair<bool,ParallelMap32color> DBG::dijkstra(std::pair<uint64_t,DBGkmer32col
504
508
Q.insert (&*nextKmer, 0 );
505
509
}
506
510
if (alt < dist[nextKmer->first ]) {
507
- prev[nextKmer->first ] = u->first ;
511
+ prev[nextKmer->first ] = std::make_pair ( u->first ,direction) ;
508
512
dist[nextKmer->first ] = alt;
509
513
Q.decreaseKey (&*nextKmer, alt);
510
514
}
511
515
}
512
516
return true ;
513
517
};
514
518
uint8_t edgeCount = 0 , exploredCount = 0 ;
515
- for (uint8_t i = 0 ; i<4 ; ++i) { // forward edges
516
- if (u->second .fw [i] > userInput.covCutOff ) {
517
- uint8_t nextKmer[k];
518
- buildNextKmer (nextKmer, u->first , i, true ); // compute next node
519
- key = hash (nextKmer, &isFw);
520
- bool found = checkNext (key);
521
- if (found) {
522
- ++exploredCount;
523
- if (key != source.first && DBGsubgraph->find (key) != DBGsubgraph->end ())
524
- destinations.push_back (u->first );
519
+ for (uint8_t i = 0 ; i<4 ; ++i) {
520
+
521
+ if (direction || depth == 0 ) { // forward edges
522
+
523
+ if (depth == 0 )
524
+ direction = true ;
525
+
526
+ if (u->second .fw [i] > userInput.covCutOff ) {
527
+ uint8_t nextKmer[k];
528
+ buildNextKmer (nextKmer, u->first , i, true ); // compute next node
529
+ key = hash (nextKmer, &isFw);
530
+ bool found = checkNext (key, isFw ? direction : !direction);
531
+ if (found) {
532
+ ++exploredCount;
533
+ if (key != source.first && DBGsubgraph->find (key) != DBGsubgraph->end ())
534
+ destinations.push_back (u->first );
535
+ }
536
+ ++edgeCount;
525
537
}
526
- ++edgeCount;
527
538
}
528
- if (u->second .bw [i] > userInput.covCutOff ) { // backward edges
529
- uint8_t nextKmer[k];
530
- buildNextKmer (nextKmer, u->first , i, false ); // compute next node
531
- key = hash (nextKmer, &isFw);
532
- bool found = checkNext (key);
533
- if (found) {
534
- ++exploredCount;
535
- if (key != source.first && DBGsubgraph->find (key) != DBGsubgraph->end ())
536
- destinations.push_back (u->first );
539
+ if (!direction || depth == 0 ) {
540
+
541
+ if (depth == 0 )
542
+ direction = false ;
543
+
544
+ if (u->second .bw [i] > userInput.covCutOff ) { // backward edges
545
+ uint8_t nextKmer[k];
546
+ buildNextKmer (nextKmer, u->first , i, false ); // compute next node
547
+ key = hash (nextKmer, &isFw);
548
+ bool found = checkNext (key, isFw ? direction : !direction);
549
+ if (found) {
550
+ ++exploredCount;
551
+ if (key != source.first && DBGsubgraph->find (key) != DBGsubgraph->end ())
552
+ destinations.push_back (u->first );
553
+ }
554
+ ++edgeCount;
537
555
}
538
- ++edgeCount;
539
556
}
540
557
}
541
558
depth += 1 ;
@@ -547,7 +564,7 @@ std::pair<bool,ParallelMap32color> DBG::dijkstra(std::pair<uint64_t,DBGkmer32col
547
564
while (destination != source.first ) { // construct the shortest path with a stack S
548
565
discoveredNodes.insert (*graphCache->find (destination)); // push the vertex onto the stack
549
566
dist.erase (destination);
550
- destination = prev[destination];
567
+ destination = prev[destination]. first ;
551
568
}
552
569
}
553
570
}else {
0 commit comments