Example #1
0
 /// <summary>
 /// Apply Distance constrains on given two nodes.
 /// The distances between contigs are calculated using paired read information.
 /// </summary>
 /// <param name="childPath">Destination node.</param>
 /// <param name="contigPairedReadMaps">Map of contigs and paired reads.</param>
 /// <returns>Whether Distance between contig nodes lie in constraint or not.</returns>
 private bool DistanceConstraint(
     Paths childPath,
     Dictionary<ISequence, IList<ValidMatePair>> contigPairedReadMaps)
 {
     IList<ValidMatePair> map;
     if (contigPairedReadMaps.TryGetValue(this.graph.GetNodeSequence(childPath.CurrentNode.Key), out map))
     {
         float pathlength = this.GetPathLength(childPath);
         if (childPath.CurrentNode.Value.IsSameOrientation)
         {
             if ((map[0].DistanceBetweenContigs[0] -
                 (3 * map[0].StandardDeviation[0]) <= pathlength) &&
                 (pathlength <= map[0].DistanceBetweenContigs[0] +
                 (3 * map[0].StandardDeviation[0])))
             {
                 return true;
             }
             return false;
         }
         
         if ((map[0].DistanceBetweenContigs[1] -
              (3 * map[0].StandardDeviation[1]) <= pathlength) &&
             (pathlength <= map[0].DistanceBetweenContigs[1] +
              (3 * map[0].StandardDeviation[1])))
         {
             return true;
         }
     
         return false;
     }
     
     return true;
 }
Example #2
0
        /// <summary>
        /// Get length of path traversed using BFS.
        /// </summary>
        /// <param name="childPath">Path travelled to reach destination node.</param>
        /// <returns>Distance between first and last contig node.</returns>
        private float GetPathLength(Paths childPath)
        {
            float distance = 0;
            for (int index = 1; index < childPath.FamilyTree.Count; index++)
            {
                distance += this.graph.GetNodeSequence(childPath.FamilyTree[index].Key).Count - this.kmerLength;
            }

            distance -= this.kmerLength;
            return distance;
        }
Example #3
0
        /// <summary>
        /// Add right extension of the nodes to queue.
        /// </summary>
        /// <param name="node">Current node.</param>
        /// <param name="search">Queue for BFS.</param>
        /// <param name="paths">List of paths.</param>
        /// <param name="familyTree">Nodes visited for construction of paths.</param>
        /// <param name="contigPairedReadMap">Contig and valid mate pair map.</param>
        private void RightExtension(
            KeyValuePair<Node, Edge> node,
            Queue<Paths> search,
            List<Paths> paths,
            ScaffoldPath familyTree,
            Dictionary<ISequence, IList<ValidMatePair>> contigPairedReadMap)
        {
            Paths childPath;
            if (node.Key.RightExtensionNodes.Count > 0)
            {
                foreach (KeyValuePair<Node, Edge> child in node.Key.RightExtensionNodes)
                {
                    childPath = new Paths();
                    childPath.CurrentNode = child;
                    if (familyTree == null)
                    {
                        childPath.FamilyTree.Add(node);
                    }
                    else
                    {
                        childPath.FamilyTree.AddRange(familyTree);
                        childPath.FamilyTree.Add(node);
                    }

                    childPath.NodeOrientation = true;
                    if (this.DistanceConstraint(childPath, contigPairedReadMap) &&
                        childPath.FamilyTree.Count < this.depth && 
                        !contigPairedReadMap.All(
                        t => childPath.FamilyTree.Any(k => t.Key == this.graph.GetNodeSequence(k.Key))))
                    {
                        search.Enqueue(childPath);
                    }
                    else
                    {
                       if (contigPairedReadMap.All(
                            t => childPath.FamilyTree.Any(k => t.Key == this.graph.GetNodeSequence(k.Key))))
                        {
                            paths.Add(childPath);
                        }
                    }
                }
            }
            else
            {
                childPath = new Paths();
                if (familyTree == null)
                {
                    childPath.FamilyTree.Add(node);
                }
                else
                {
                    childPath.FamilyTree.AddRange(familyTree);
                    childPath.FamilyTree.Add(node);
                }

               if (contigPairedReadMap.All(
                    t => childPath.FamilyTree.Any(k => t.Key == this.graph.GetNodeSequence(k.Key))))
                {
                    paths.Add(childPath);
                }
            }
        }