Example #1
0
        /// <summary>
        /// Adds the links between the nodes of the graph.
        /// </summary>
        private void GenerateLinks(KmerDictionary kmerManager)
        {
            // Prepare a mask to remove the bits representing the first nucleotide (or left most bits in the encoded kmer)
            // First calculate how many bits do you have to move down a character until you are at the start of the kmer encoded sequence
            int   distancetoShift = 2 * (KmerLength - 1);
            ulong rightMask       = ~(((ulong)3) << distancetoShift);

            Parallel.ForEach(_nodes, node =>
            {
                DeBruijnNode searchResult  = null;
                KmerData32 searchNodeValue = new KmerData32();

                // Right Extensions - Remove first position from the value
                // Remove the left most value by using an exclusive
                ulong nextKmer = node.NodeValue.KmerData & rightMask;

                // Move it over two to get make a position for the next pair of bits to represent a new nucleotide
                nextKmer = nextKmer << 2;
                for (ulong i = 0; i < 4; i++)
                {
                    ulong tmpNextKmer = nextKmer | i;    // Equivalent to "ACGTA"+"N" where N is the 0-3 encoding for A,C,G,T

                    // Now to set the kmer value to this, the orientationForward value is equal to false if the
                    // reverse compliment of the kmer is used instead of the kmer value itself.
                    bool matchIsRC = searchNodeValue.SetKmerData(tmpNextKmer, KmerLength);
                    searchResult   = kmerManager.TryGetOld(searchNodeValue);
                    if (searchResult != null)
                    {
                        node.SetExtensionNode(true, matchIsRC, searchResult);
                    }
                }

                // Left Extensions
                nextKmer = node.NodeValue.KmerData;

                //Chop off the right most basepair
                nextKmer >>= 2;
                for (ulong i = 0; i < 4; i++)     // Cycle through A,C,G,T
                {
                    // Add the character on to the left side of the kmer
                    // Equivalent to "N" + "ACGAT" where the basepair is added on as the 2 bits
                    ulong tmpNextKmer = (i << distancetoShift) | nextKmer;
                    bool matchIsRC    = searchNodeValue.SetKmerData(tmpNextKmer, KmerLength);
                    searchResult      = kmerManager.TryGetOld(searchNodeValue);
                    if (searchResult != null)
                    {
                        node.SetExtensionNode(false, matchIsRC, searchResult);
                    }
                }
            });

            LinkGenerationCompleted = true;
        }
Example #2
0
        /// <summary>
        /// Adds the links between the nodes of the graph.
        /// </summary>
        private void GenerateLinks(KmerDictionary kmerManager)
        {
            // Prepare a mask to remove the bits representing the first nucleotide (or left most bits in the encoded kmer)
            // First calculate how many bits do you have to move down a character until you are at the start of the kmer encoded sequence
            int distancetoShift=2*(KmerLength-1);
            ulong rightMask = ~( ((ulong)3) << distancetoShift);
            Parallel.ForEach(_nodes, node =>
                {
                    DeBruijnNode searchResult = null;
                    KmerData32 searchNodeValue = new KmerData32();
                    
                    // Right Extensions - Remove first position from the value
                    // Remove the left most value by using an exclusive 
                    ulong nextKmer = node.NodeValue.KmerData & rightMask;
                    
                    // Move it over two to get make a position for the next pair of bits to represent a new nucleotide
                    nextKmer= nextKmer << 2;
                    for (ulong i = 0; i < 4; i++)
                    {
                        ulong tmpNextKmer = nextKmer | i;// Equivalent to "ACGTA"+"N" where N is the 0-3 encoding for A,C,G,T
                        
                        // Now to set the kmer value to this, the orientationForward value is equal to false if the 
                        // reverse compliment of the kmer is used instead of the kmer value itself.
                        bool matchIsRC = searchNodeValue.SetKmerData(tmpNextKmer, KmerLength);
                        searchResult = kmerManager.TryGetOld(searchNodeValue);
                        if (searchResult != null)
                        {
                            node.SetExtensionNode(true, matchIsRC, searchResult);
                        }
                    }

                    // Left Extensions
                    nextKmer = node.NodeValue.KmerData;
                    
                    //Chop off the right most basepair
                    nextKmer >>= 2;
                    for (ulong i = 0; i < 4; i++) // Cycle through A,C,G,T
                    {
                        // Add the character on to the left side of the kmer
                        // Equivalent to "N" + "ACGAT" where the basepair is added on as the 2 bits
                        ulong tmpNextKmer = (i<<distancetoShift) | nextKmer; 
                        bool matchIsRC=searchNodeValue.SetKmerData(tmpNextKmer, KmerLength);
                        searchResult = kmerManager.TryGetOld(searchNodeValue);
                        if (searchResult != null)
                        {
                            node.SetExtensionNode(false, matchIsRC, searchResult);
                        }
                    }
                });

            LinkGenerationCompleted = true;
        }