From 070e90dbc5326d58fcbb11f6d4f100eb8152b20a Mon Sep 17 00:00:00 2001 From: Anton Korobeynikov Date: Sat, 2 Nov 2024 20:41:07 +0300 Subject: [PATCH] Ensure we correctly handle edges on self-conjugate nodes --- graph/assemblygraphbuilder.cpp | 18 +++++++++++++++++- graph/debruijnedge.h | 3 +++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/graph/assemblygraphbuilder.cpp b/graph/assemblygraphbuilder.cpp index ca02b529..88ff757b 100644 --- a/graph/assemblygraphbuilder.cpp +++ b/graph/assemblygraphbuilder.cpp @@ -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); diff --git a/graph/debruijnedge.h b/graph/debruijnedge.h index d4c03cdb..918a7920 100644 --- a/graph/debruijnedge.h +++ b/graph/debruijnedge.h @@ -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;}