Example #1
0
        /// <summary>
        /// Translate the coding sequence of a transcript
        /// </summary>
        /// <param name="transcript"></param>
        /// <returns></returns>
        public static ISequence OneFrameTranslation(ISequence dnaSequence, bool mitochondrial)
        {
            ISequence rnaSequence = Transcription.Transcribe(dnaSequence);
            ISequence proteinSequence;

            if (!mitochondrial)
            {
                proteinSequence = ProteinTranslation.Translate(rnaSequence);
            }
            else
            {
                List <byte> aminoAcidSequence = new List <byte>();
                for (int codonNum = 0; codonNum < (int)(rnaSequence.Count / 3); codonNum++)
                {
                    // Check for start codon, and add 'M' if so
                    if (aminoAcidSequence.Count == 0 &&
                        CodonsVertebrateMitochondrial.START_CODONS.Contains(
                            new string(dnaSequence.GetSubSequence(codonNum * 3, GeneModel.CODON_SIZE).Select(bp => (char)bp).ToArray())))
                    {
                        aminoAcidSequence.Add((byte)CodonsVertebrateMitochondrial.DEFAULT_START_AA);
                        continue;
                    }
                    aminoAcidSequence.Add(CodonsVertebrateMitochondrial.TryLookup(rnaSequence, codonNum * 3, out byte aa) ? aa : (byte)'X');
                }
                proteinSequence = new Sequence(Alphabets.AmbiguousProtein, aminoAcidSequence.ToArray());
            }
            return(proteinSequence);
        }
 /// <summary>
 /// Translate 3 byte representations of DNA bases to an amino acid
 /// </summary>
 /// <param name="mitochondrial"></param>
 /// <param name="base1"></param>ec
 /// <param name="base2"></param>
 /// <param name="base3"></param>
 /// <param name="aminoAcid"></param>
 /// <returns></returns>
 public static bool TryTranslateBytes(bool mitochondrial, byte base1, byte base2, byte base3, out byte aminoAcid)
 {
     if (mitochondrial)
     {
         return(CodonsVertebrateMitochondrial.TryLookup(
                    Transcription.GetRnaComplement(base1),
                    Transcription.GetRnaComplement(base2),
                    Transcription.GetRnaComplement(base3),
                    out aminoAcid));
     }
     else
     {
         return(Codons.TryLookup(
                    Transcription.GetRnaComplement(base1),
                    Transcription.GetRnaComplement(base2),
                    Transcription.GetRnaComplement(base3),
                    out aminoAcid));
     }
 }