public static uint CalculateConnectionWeight(DeBruijnNode FirstNode, DeBruijnNode SecondNode) { //First verify that they share if (!FirstNode.GetExtensionNodes().Contains(SecondNode)) { throw new Exception("Can't calculate non-overlapping extensions"); } return(SecondNode.KmerCount); }
/// <summary> /// Removes nodes in link from the graph. /// Parallelization Note: Locks required here. We are modifying graph structure here. /// </summary> /// <param name="nodes">List of nodes to remove.</param> /// <param name="lastNodes">Set of all nodes occurring at end of dangling links.</param> private static void RemoveLinkNodes(DeBruijnPath nodes, HashSet <DeBruijnNode> lastNodes) { // Nodes in the list are part of a single dangling link. // Only the last element of link can have left or right extensions that are valid parts of graph. DeBruijnNode linkStartNode = nodes.PathNodes.Last(); // Update adjacency of nodes connected to the last node. // Read lock not required as linkStartNode's dictionary will not get updated // Locks used during removal of extensions. foreach (DeBruijnNode graphNode in linkStartNode.GetExtensionNodes()) { // Condition to avoid updating other linkStartNode's dictionary. Reduces conflicts. if (!lastNodes.Contains(graphNode)) { graphNode.RemoveExtensionThreadSafe(linkStartNode); } } }
/// <summary> /// Visits all connected nodes, not caring about orientation here. Hope the graph /// is not so big this leads to an OOM exception. /// </summary> /// <param name="startNode">Start node.</param> private void visitAllConnectedNodes(DeBruijnNode startNode) { Stack <DeBruijnNode> toProcess = new Stack <DeBruijnNode> (16000); toProcess.Push(startNode); //Visit all nodes, avoid function all recursion with stack. do { DeBruijnNode next = toProcess.Pop(); next.IsVisited = true; foreach (DeBruijnNode neighbor in next.GetExtensionNodes()) { if (neighbor.IsVisited) { continue; } else { toProcess.Push(neighbor); } } }while(toProcess.Count > 0); }