Skip to content

Commit

Permalink
Ensure we correctly handle edges on self-conjugate nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
asl committed Nov 2, 2024
1 parent ec14f6d commit a793415
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
18 changes: 17 additions & 1 deletion graph/assemblygraphbuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -343,8 +343,24 @@ namespace io {
DeBruijnNode *oppositeNodePtr = nullptr;
auto rcSeq = sequence.GetReverseComplement();
if (!sequence.empty() && !sequence.missing() && sequence == rcSeq) {
// We might already have opposite node recorded (e.g. a placeholder).
// If yes, we'd need to transfer the edges
auto [oppositeNodeStorage, inserted] = graph.m_deBruijnGraphNodes.insert(oppositeNodeName, nodePtr);
if (!inserted) {
oppositeNodePtr = *oppositeNodeStorage;

for (auto *edge : oppositeNodePtr->edges()) {
if (edge->getEndingNode() == oppositeNodePtr)
edge->setEndingNode(nodePtr);
if (edge->getStartingNode() == oppositeNodePtr)
edge->setStartingNode(nodePtr);
nodePtr->addEdge(edge);
}

*oppositeNodeStorage = nodePtr;
}

oppositeNodePtr = nodePtr;
graph.m_deBruijnGraphNodes[oppositeNodeName] = oppositeNodePtr;
} else {
oppositeNodePtr =
maybeAddSegment(getOppositeNodeName(nodeName), nodeDepth, rcSeq, graph);
Expand Down
3 changes: 3 additions & 0 deletions graph/debruijnedge.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ class DeBruijnEdge

DeBruijnNode * getStartingNode() const {return m_startingNode;}
DeBruijnNode * getEndingNode() const {return m_endingNode;}
void setStartingNode(DeBruijnNode *node) { m_startingNode = node;}
void setEndingNode(DeBruijnNode *node) { m_endingNode = node;}

GraphicsItemEdge * getGraphicsItemEdge() const {return m_graphicsItemEdge;}
DeBruijnEdge * getReverseComplement() const {return m_reverseComplement;}
bool isDrawn() const {return m_drawn;}
Expand Down

0 comments on commit a793415

Please sign in to comment.