Example #1
0
        /// <summary>
        /// Search for containing and overlapping paths.
        /// </summary>
        /// <param name="scaffoldPath">Current Path</param>
        /// <param name="isConsumed">Path status</param>
        /// <returns>Update list or not</returns>
        private bool SearchContainingAndOverlappingPaths(
            ScaffoldPath scaffoldPath,
            bool[] isConsumed)
        {
            bool isUpdated = false;

            for (int index = 0; index < _scaffoldPaths.Count; index++)
            {
                if (!isConsumed[index] && scaffoldPath != _scaffoldPaths[index])
                {
                    if (RemoveContainingPaths(scaffoldPath, _scaffoldPaths[index]))
                    {
                        isConsumed[index] = true;
                        isUpdated         = true;
                    }
                    else
                    {
                        if (RemoveOverlappingPaths(scaffoldPath, _scaffoldPaths[index]))
                        {
                            isConsumed[index] = true;
                            isUpdated         = true;
                        }
                    }
                }
            }

            return(isUpdated);
        }
Example #2
0
 /// <summary>
 /// Remove containing paths.
 /// </summary>
 /// <param name="scaffoldPath">Current path</param>
 /// <param name="path">Path to be compared with</param>
 /// <returns>containing paths or not</returns>
 private static bool RemoveContainingPaths(
     ScaffoldPath scaffoldPath,
     ScaffoldPath path)
 {
     if (scaffoldPath.Count >= path.Count)
     {
         if (path.All(t => scaffoldPath.Where(k => k.Key == t.Key).ToList().Count > 0))
         {
             return(true);
         }
         else
         {
             return(false);
         }
     }
     else
     {
         if (scaffoldPath.All(t => path.Where(k => k.Key == t.Key).ToList().Count > 0))
         {
             scaffoldPath.Clear();
             ((List <KeyValuePair <DeBruijnNode, DeBruijnEdge> >)scaffoldPath).AddRange(path);
             return(true);
         }
         else
         {
             return(false);
         }
     }
 }
Example #3
0
        /// <summary>
        /// Removes Overlapping paths by generating pairwise overlaps between paths.
        /// </summary>
        /// <param name="scaffoldPath">Current path</param>
        /// <param name="path">Path to be compared with</param>
        /// <returns>Overlapping paths or not</returns>
        private static bool RemoveOverlappingPaths(
            ScaffoldPath scaffoldPath,
            ScaffoldPath path)
        {
            // Generate Overlap Matrix [Similar To Pairwise Overlap aligner]
            bool[,] matrix = new bool[scaffoldPath.Count, path.Count];
            for (int index = 0; index < scaffoldPath.Count; index++)
            {
                for (int index1 = 0; index1 < path.Count; index1++)
                {
                    if (scaffoldPath[index].Key == path[index1].Key)
                    {
                        matrix.SetValue(true, index, index1);
                    }
                    else
                    {
                        matrix.SetValue(false, index, index1);
                    }
                }
            }

            //Search in last row for a match.
            int startPosOfRow = -1;

            for (int index = scaffoldPath.Count - 1; index >= 0; index--)
            {
                if ((bool)matrix.GetValue(index, path.Count - 1))
                {
                    int index1 = 1;
                    while (path.Count - 1 - index1 >= 0 && index - index1 >= 0)
                    {
                        if ((bool)matrix.GetValue(index - index1, path.Count - 1 - index1))
                        {
                            index1++;
                        }
                        else
                        {
                            break;
                        }
                    }

                    if (path.Count - 1 - index1 <= 0 || index - index1 <= 0)
                    {
                        startPosOfRow = index;
                        break;
                    }
                }
            }

            //Search in last column for match.
            int startPosOfCol = -1;

            for (int index = path.Count - 2; index >= 0; index--)
            {
                if ((bool)matrix.GetValue(scaffoldPath.Count - 1, index))
                {
                    int index1 = 1;
                    while (scaffoldPath.Count - 1 - index1 > 0 && index - index1 > 0)
                    {
                        if ((bool)matrix.GetValue(scaffoldPath.Count - 1 - index1, index - index1))
                        {
                            index1++;
                        }
                        else
                        {
                            break;
                        }
                    }

                    if (scaffoldPath.Count - 1 - index1 <= 0 || index - index1 <= 0)
                    {
                        startPosOfCol = index;
                        break;
                    }
                }
            }

            if (startPosOfCol != -1 || startPosOfRow != -1)
            {
                if (startPosOfRow >= startPosOfCol)
                {
                    StitchPath(scaffoldPath, path, startPosOfRow, path.Count - 1);
                    return(true);
                }
                else
                {
                    StitchPath(scaffoldPath, path, scaffoldPath.Count - 1, startPosOfCol);
                    return(true);
                }
            }

            return(false);
        }
Example #4
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 <DeBruijnNode, DeBruijnEdge> node,
            Queue <Paths> search,
            List <Paths> paths,
            ScaffoldPath familyTree,
            Dictionary <ISequence, IList <ValidMatePair> > contigPairedReadMap)
        {
            Paths childPath;

            if (node.Key.RightExtensionNodes.Count > 0)
            {
                foreach (KeyValuePair <DeBruijnNode, DeBruijnEdge> 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 (DistanceConstraint(childPath, contigPairedReadMap) &&
                        childPath.FamilyTree.Count < _depth &&
                        !contigPairedReadMap.All(
                            t => childPath.FamilyTree.Any(k => t.Key == _graph.GetNodeSequence(k.Key))))
                    {
                        search.Enqueue(childPath);
                    }
                    else
                    {
                        if (contigPairedReadMap.All(
                                t => childPath.FamilyTree.Any(k => t.Key == _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 == _graph.GetNodeSequence(k.Key))))
                {
                    paths.Add(childPath);
                }
            }
        }