Ejemplo n.º 1
0
        //select() method returns the index of n-th occurence of given character in input nucleotide string.
        //It doesn't use RRR data structure, it uses regular bitmap.
        public int select(int nthOccurrence, char character)
        {
            Interval    alphabeticInterval           = new Interval(0, alphabet.Count - 1);
            WaveletNode currentNode                  = rootNode;
            int         indexOfCharInAlph            = getIndex(character, alphabet);
            bool        characterRepresentedWithZero = true;

            while (alphabeticInterval.isGreaterThanTwo())
            {
                if (alphabeticInterval.getSize() == 3)
                {
                    if (alphabeticInterval.getRightIndex() == indexOfCharInAlph)
                    {
                        characterRepresentedWithZero = false;
                        break;
                    }
                }

                if (indexOfCharInAlph <= alphabeticInterval.getMiddleIndex())
                {
                    currentNode = currentNode.getLeftChild();
                    alphabeticInterval.setRightIndex();
                }
                else
                {
                    currentNode = currentNode.getRightChild();
                    alphabeticInterval.setLeftIndex();
                }
            }

            if (characterRepresentedWithZero)
            {
                if (alphabeticInterval.getLeftIndex() == indexOfCharInAlph)
                {
                    characterRepresentedWithZero = true;
                }
                else
                {
                    characterRepresentedWithZero = false;
                }
            }

            int position = getPositionOfNthOccurrence(currentNode.getBitmap(), nthOccurrence, characterRepresentedWithZero);

            if (position == 0)
            {
                return(-1);
            }

            WaveletNode child = currentNode;

            currentNode = currentNode.getParent();

            while (currentNode != null)
            {
                if (currentNode.getLeftChild().Equals(child))
                {
                    position = getPositionOfNthOccurrence(currentNode.getBitmap(), position, true);
                }
                else
                {
                    position = getPositionOfNthOccurrence(currentNode.getBitmap(), position, false);
                }

                currentNode = currentNode.getParent();
                child       = child.getParent();
            }

            return(position - 1);
        }
Ejemplo n.º 2
0
        //selectRRR() method returns index of n-th occurence of given character in input nucleotide string
        public int selectRRR(int nthOccurrence, char character)
        {
            Interval    alphabeticInterval           = new Interval(0, alphabet.Count - 1);
            WaveletNode currentNode                  = rootNode;
            int         indexOfCharInAlph            = getIndex(character, alphabet);
            bool        characterRepresentedWithZero = true;

            while (alphabeticInterval.isGreaterThanTwo())
            {
                if (alphabeticInterval.getSize() == 3)
                {
                    if (alphabeticInterval.getRightIndex() == indexOfCharInAlph)
                    {
                        characterRepresentedWithZero = false;
                        break;
                    }
                }

                if (indexOfCharInAlph <= alphabeticInterval.getMiddleIndex())
                {
                    currentNode = currentNode.getLeftChild();
                    alphabeticInterval.setRightIndex();
                }
                else
                {
                    currentNode = currentNode.getRightChild();
                    alphabeticInterval.setLeftIndex();
                }
            }

            if (characterRepresentedWithZero)
            {
                if (alphabeticInterval.getLeftIndex() == indexOfCharInAlph)
                {
                    characterRepresentedWithZero = true;
                }
                else
                {
                    characterRepresentedWithZero = false;
                }
            }

            //  bottom-up tree traversal once we have node representing given character
            int position = selectOnBitmap(currentNode, nthOccurrence, characterRepresentedWithZero);

            if (position == 0)
            {
                return(-1); // no n occurrences of character
            }

            WaveletNode child = currentNode;

            currentNode = currentNode.getParent();

            while (currentNode != null)
            {
                if (currentNode.getLeftChild().Equals(child))
                {
                    position = selectOnBitmap(currentNode, position, true);
                }
                else
                {
                    position = selectOnBitmap(currentNode, position, false);
                }

                currentNode = currentNode.getParent();
                child       = child.getParent();
            }

            return(position - 1);
        }