Ejemplo n.º 1
0
        /// <summary>
        /// For input sequence, constructs k-mers by sliding
        /// a frame of size kmerLength along the input sequence.
        /// Track positions of occurance for each kmer in sequence.
        /// Constructs KmersOfSequence for sequence and associated k-mers.
        /// </summary>
        /// <param name="sequence">Input sequence.</param>
        /// <param name="kmerLength">K-mer length.</param>
        /// <returns>KmersOfSequence constructed from sequence and associated k-mers.</returns>
        public static KmerPositionDictionary BuildKmerDictionary(ISequence sequence, int kmerLength)
        {
            if (sequence == null)
            {
                throw new ArgumentNullException("sequence");
            }

            if (kmerLength > sequence.Count)
            {
                throw new ArgumentException(Properties.Resource.KmerLengthIsTooLong);
            }

            // kmers maintains the map between k-mer strings to list of positions in sequence.
            KmerPositionDictionary kmers = new KmerPositionDictionary();

            // Sequence 'kmer' stores the k-mer in each window.
            // Construct each k-mer using range from sequence.
            for (long i = 0; i <= sequence.Count - kmerLength; ++i)
            {
                ISequence kmerString = sequence.GetSubSequence(i, kmerLength);
                if (kmers.ContainsKey(kmerString))
                {
                    kmers[kmerString].Add(i);
                }
                else
                {
                    kmers[kmerString] = new List <long>()
                    {
                        i
                    };
                }
            }

            return(kmers);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// For input sequence, constructs k-mers by sliding 
        /// a frame of size kmerLength along the input sequence.
        /// Track positions of occurance for each kmer in sequence.
        /// Constructs KmersOfSequence for sequence and associated k-mers.
        /// </summary>
        /// <param name="sequence">Input sequence.</param>
        /// <param name="kmerLength">K-mer length.</param>
        /// <returns>KmersOfSequence constructed from sequence and associated k-mers.</returns>
        public static KmerPositionDictionary BuildKmerDictionary(ISequence sequence, int kmerLength)
        {
            if (sequence == null)
            {
                throw new ArgumentNullException("sequence");
            }

            if (kmerLength > sequence.Count)
            {
                throw new ArgumentException(Properties.Resource.KmerLengthIsTooLong);
            }

            // kmers maintains the map between k-mer strings to list of positions in sequence.
            KmerPositionDictionary kmers = new KmerPositionDictionary();

            // Sequence 'kmer' stores the k-mer in each window.
            // Construct each k-mer using range from sequence.
            for (long i = 0; i <= sequence.Count - kmerLength; ++i)
            {
                ISequence kmerString = sequence.GetSubSequence(i, kmerLength);
                if (kmers.ContainsKey(kmerString))
                {
                    kmers[kmerString].Add(i);
                }
                else
                {
                    kmers[kmerString] = new List<long>() { i };
                }
            }

            return kmers;
        }