Ejemplo n.º 1
0
 public void Add(SortedElement s)
 {
     if (SortedElementsList.Count == 0)
     {
         SortedElementsList.Add(s);
     }
     else
     {
         var start = 0;
         var end   = SortedElementsList.Count;
         while (end > start)
         {
             var n = start + ((end - start) / 2);
             if (BwtComparer.Compare(s.Chars, SortedElementsList[n].Chars) == 1)
             {
                 end = n;
             }
             else
             {
                 start = n + 1;
             }
         }
         SortedElementsList.Insert(start, s);
     }
 }
Ejemplo n.º 2
0
        private static void FindAllPairs(SortedElement src, int sufStart, int sufLength, int v, int localPosition, Edge currentNode, int missmatch, int misslimit,
                                         int[,] overlapMatrix, int indexOverlap, ref int kmer, bool[] addedPatterns)
        {
            while (true)
            {
                if (sufLength == v)
                {
                    for (int i = currentNode.StartIndex; i < currentNode.EndIndex + 1; i++)
                    {
                        if (overlapMatrix[indexOverlap, i] < v)
                        {
                            if (i != indexOverlap && !addedPatterns[i])
                            {
                                overlapMatrix[indexOverlap, i] = v;
                                kmer++;
                            }
                        }
                    }
                    return;
                }

                if (localPosition <= currentNode.LengthString - 1)
                {
                    if (src.Chars[v + sufStart] != currentNode.Src.Chars[currentNode.StartString + localPosition])
                    {
                        missmatch++;
                    }

                    if (missmatch > misslimit)
                    {
                        return;
                    }

                    localPosition++;
                    v++;
                }
                else
                {
                    for (int j = 0; j < 4; j++)
                    {
                        var mistemp = missmatch;
                        if (src.CodeChars[sufStart + v] != j)
                        {
                            mistemp++;
                        }
                        if (currentNode.Childs[j] != null && mistemp <= misslimit)
                        {
                            var v1 = v + 1;
                            FindAllPairs(src, sufStart, sufLength, v1, 1, currentNode.Childs[j], mistemp, misslimit, overlapMatrix,
                                         indexOverlap, ref kmer, addedPatterns);
                        }
                    }
                    return;
                }
            }
        }
Ejemplo n.º 3
0
        private static void EditErrorsInSortedElement(int[] overlapVector, SortedElement[] sortedElements,
                                                      SortedElement currentElement)
        {
            var length      = currentElement.Chars.Length;
            var sortderList = Sort(overlapVector);

            var minIndex = sortderList[0];
            var minValue = overlapVector[minIndex];

            for (int j = 0; j < minValue; j++)
            {
                if (currentElement.Chars[length - 1 - j] != sortedElements[minIndex].Chars[minValue - 1 - j])
                {
                    currentElement.Chars[length - 1 - j]     = sortedElements[minIndex].Chars[minValue - 1 - j];
                    currentElement.CodeChars[length - 1 - j] = sortedElements[minIndex].CodeChars[minValue - 1 - j];
                    break;
                }
            }
        }
Ejemplo n.º 4
0
 public void Update(SortedElement s)
 {
     SortedElementsList.RemoveAt(s.PositionInList);
     Add(s);
     UpdateIndexes();
 }
Ejemplo n.º 5
0
        private static void CreatePrefix(Edge root, SortedElement sortedElement)
        {
            var inputArr = sortedElement.Chars;
            var codes    = sortedElement.CodeChars;
            var length   = inputArr.Length;

            var curentEdge = root;

            for (int j = 0; j < length; j++)
            {
                Edge searchElement = null;
                var  cCode         = codes[j];
                if (curentEdge.Childs[cCode] != null)
                {
                    searchElement = curentEdge.Childs[cCode];
                }
                if (searchElement == null)
                {
                    var newEdge = new Edge();
                    newEdge.LengthString = length - j;
                    newEdge.StartString  = j;
                    newEdge.StartIndex   = sortedElement.PositionInList;
                    newEdge.EndIndex     = sortedElement.PositionInList;

                    newEdge.Src = sortedElement;

                    curentEdge.Childs[codes[j]] = newEdge;
                    break;
                }
                else
                {
                    var minL  = Math.Min(searchElement.LengthString, length - j);
                    var copyL = 1;

                    var charsInEdge      = searchElement.Src.Chars;
                    var codesCharsInEdge = searchElement.Src.CodeChars;

                    for (int k = 1; k < minL; k++)
                    {
                        if (charsInEdge[searchElement.StartString + k] == inputArr[j + k])
                        {
                            copyL++;
                        }
                        else
                        {
                            break;
                        }
                    }

                    if (copyL < searchElement.LengthString)
                    {
                        var newEdge = new Edge();
                        newEdge.StartString  = searchElement.StartString + copyL;
                        newEdge.LengthString = searchElement.LengthString - copyL;
                        newEdge.CopyChilds(searchElement.Childs);
                        newEdge.EndIndex   = searchElement.EndIndex;
                        newEdge.StartIndex = searchElement.StartIndex;

                        newEdge.Src = searchElement.Src;


                        searchElement.CleanChild();
                        searchElement.Childs[codesCharsInEdge[newEdge.StartString]] = newEdge;
                        searchElement.LengthString = copyL;
                    }
                    searchElement.EndIndex = sortedElement.PositionInList;
                    j          = j + copyL - 1;
                    curentEdge = searchElement;
                }
            }
        }