Esempio n. 1
0
        /// <summary>
        /// Creates triplet groups of nucleobases along the specified range. the
        /// range must be of appropriate length, i.e. a multiple of the codon length.
        /// </summary>
        /// <param name="seq">RNA sequence to group</param>
        /// <param name="startIndex">index of the first nucleobase in the first codon</param>
        /// <param name="stopIndex">index of the first nucleobase in the last codon</param>
        /// <returns>Returns list of AACodons</returns>
        private List <AACodon> CreateReadingFrame(Nucleobase[] seq, int startIndex, int stopIndex)
        {
            if (stopIndex < startIndex + this.codonLength)
            {
                throw new ArgumentException("stop index must be at least " + this.codonLength +
                                            "greater than start index.");
            }
            int rangeLength = stopIndex - startIndex;

            if (rangeLength % 3 != 0)
            {
                throw new ArgumentException("the length of the reading frame must"
                                            + "be a multiple of " + this.codonLength + " -- in other words, " +
                                            "the reading frame must contain a whole number of codons.");
            }

            List <AACodon> triplets   = new List <AACodon>();
            int            lengthDiff = seq.Length - this.codonLength; //readability

            for (int i = startIndex; i < stopIndex + this.codonLength; i += this.codonLength)
            {
                triplets.Add(AACodonExtension.BuildAACodon(seq, i, i + this.codonLength));
            }

            return(triplets);
        }
Esempio n. 2
0
        /// <summary>
        /// Scans the given sequence for a codon in the provided list, returning the
        /// index of the first base in the found codon
        /// </summary>
        /// <param name="seq">sequence to scan</param>
        /// <param name="cod">set of codons to scan for</param>
        /// <param name="beginScan">index at which to begin scanning for the specified codon</param>
        /// <returns>Returns the index of the first nucleobase in a matching sequence</returns>
        private int Scan(Nucleobase[] seq, List <AACodon> cod, int beginScan, int granularity)
        {
            if (this.codonLength >= seq.Length - beginScan)
            {
                throw new ArgumentException("given codon is longer than the provided sequence");
            }
            else if (beginScan < 0 || beginScan > seq.Length)
            {
                throw new ArgumentOutOfRangeException("scan must begin at a valid index. Attempted scan start: " +
                                                      beginScan + ". Sequence length: " + seq.Length + ".");
            }

            for (int i = beginScan; i < seq.Length - this.codonLength + 1; i += granularity)
            {
                var tempCodon = AACodonExtension.BuildAACodon(seq, i, i + this.codonLength);
                if (cod.Contains(tempCodon))
                {
                    return(i);
                }
            }
            throw new CodonNotFoundException();
        }