Exemplo n.º 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, CodonChange.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);
        }
Exemplo n.º 2
0
        /// <summary>
        /// This method is called when the Transcribe button is clicked.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button1_Click(object sender, EventArgs e)
        {
            // If we have an active sequence
            if (cbSequences.SelectedIndex >= 0)
            {
                ISequence seq = _sequences[cbSequences.SelectedIndex];

                // Determine the sequence type (DNA vs. RNA)
                ISequence result = null, proteinResult = null;
                if (seq.Alphabet == Alphabets.DNA)
                {
                    result        = Transcription.Transcribe(seq);
                    proteinResult = ProteinTranslation.Translate(result);
                }
                else if (seq.Alphabet == Alphabets.RNA)
                {
                    result = Transcription.ReverseTranscribe(seq);
                }

                // Set the result.
                targetSequenceText.Text = (result != null)
                    ? GetString(result)
                    : string.Empty;

                // Translate the protein result
                proteinTextBox.Text = (proteinResult != null)
                    ? GetString(proteinResult)
                    : string.Empty;
            }
            else
            {
                // Reset the fields.
                targetSequenceText.Text = string.Empty;
            }
        }
Exemplo n.º 3
0
        public void ValidateDnaProteinTranslationWithOffset()
        {
            // Get Node values from XML.
            string alphabetName = this.utilityObj.xmlUtil.GetTextValue(Constants.SimpleDnaAlphabetNode,
                                                                       Constants.AlphabetNameNode);
            string expectedSeq = this.utilityObj.xmlUtil.GetTextValue(Constants.TranscribeNode,
                                                                      Constants.DnaSequence);
            string expectedProtein = this.utilityObj.xmlUtil.GetTextValue(Constants.TranslationNode,
                                                                          Constants.AminoAcidForOffsetTwelveDna);
            string expectedOffset = this.utilityObj.xmlUtil.GetTextValue(Constants.CodonsNode,
                                                                         Constants.OffsetVaule1);
            ISequence transcribe = null;

            var seq = new Sequence(Utility.GetAlphabet(alphabetName), expectedSeq);

            // Transcription of DNA Sequence.
            transcribe = Transcription.Transcribe(seq);

            // Protein Translation by passing offset value.
            ISequence proteinTranslation = new Sequence(Alphabets.RNA,
                                                        new string(transcribe.Select(a => (char)a).ToArray()));
            ISequence protein = ProteinTranslation.Translate(proteinTranslation,
                                                             Convert.ToInt32(expectedOffset, null));

            // Validate Protein Translation.
            Assert.AreEqual(expectedProtein, new string(protein.Select(a => (char)a).ToArray()));
            ApplicationLog.WriteLine(
                "Translation P1: Protein translation validation is completed successfully.");
        }
    public static string[] Proteins(string strand)
    {
        List <string> PolypeptideChain = new List <string>();
        Dictionary <string, string[]> CodonDictionary = ProteinTranslation.InitializeDictionary();

        for (int i = 0; i < strand.Length; i += 3)
        {
            string codon = strand[i..(i + 3)];
Exemplo n.º 5
0
        private void JaredTest_Click(object sender, RoutedEventArgs e)
        {
            Sequence      rna     = new Sequence(Alphabets.RNA, "AUGGCGCCGAUAAUGACGGUCCUUCCUUGA");
            ISequence     protein = ProteinTranslation.Translate(rna);
            string        rnaStr  = rna.ToString();
            StringBuilder buff    = new StringBuilder();

            foreach (byte aa in protein)
            {
                buff.Append((char)aa);
                buff.Append(' ');
            }
            string aaStr = buff.ToString();
        }
Exemplo n.º 6
0
        public void ValidateSingleSymbolTranslation()
        {
            // Get Node values from XML.
            string expectedSeq = _utilityObj._xmlUtil.GetTextValue(
                Constants.TranscribeNode, Constants.DnaSymbol);

            // Translate Single char RNA to protein.
            ISequence proteinTranslation = new Sequence(Alphabets.RNA, expectedSeq);
            ISequence protein            = ProteinTranslation.Translate(proteinTranslation);

            // Validate Protein Translation.
            Assert.AreEqual(protein.ToString(), string.Empty);

            ApplicationLog.WriteLine(
                "Translation P1: Amino Acid validation for a given sequence was completed successfully.");
        }
Exemplo n.º 7
0
        /// <summary>
        /// Not used or tested right now...
        /// </summary>
        /// <param name="exons"></param>
        /// <param name="proteinID"></param>
        /// <returns></returns>
        public static Protein ThreeFrameTranslation(List <Exon> exons, string proteinID)
        {
            string seq = String.Join("", exons.Select(x => SequenceExtensions.ConvertToString(x.Sequence)));

            if (seq.Contains('N'))
            {
                return(null);
            }
            ISequence dna_seq = new Sequence(Alphabets.DNA, seq);
            ISequence rna_seq = Transcription.Transcribe(exons[0].IsStrandPlus() ? dna_seq : dna_seq.GetReverseComplementedSequence());

            ISequence[] prot_seq = Enumerable.Range(0, 3).Select(i => ProteinTranslation.Translate(rna_seq, i)).ToArray();

            //return the protein sequence corresponding to the longest ORF
            return(new Protein(prot_seq.SelectMany(s => SequenceExtensions.ConvertToString(s).Split('*')).OrderByDescending(s => s.Length).FirstOrDefault(), proteinID));
        }
Exemplo n.º 8
0
        public void ValidateMoreThanTwelveCharsProteinTranslation()
        {
            // Get Node values from XML.
            string expectedSeq = _utilityObj._xmlUtil.GetTextValue(
                Constants.TranslationNode, Constants.RnaSequenceWithMoreThanTwelveChars);
            string expectedProtein = _utilityObj._xmlUtil.GetTextValue(
                Constants.TranslationNode, Constants.AminoAcidForMoreThanTwelveChars);

            // Translate more than twelve characters RNA to protein.
            ISequence proteinTranslation = new Sequence(Alphabets.RNA, expectedSeq);
            ISequence protein            = ProteinTranslation.Translate(proteinTranslation);

            // Validate Protein Translation.
            Assert.AreEqual(protein.ToString(), expectedProtein);
            ApplicationLog.WriteLine(
                "Translation P1: Protein translation validation is completed successfully.");
        }
Exemplo n.º 9
0
        public void TestProteinTranslation()
        {
            Sequence  rnaSeq = new Sequence(Alphabets.RNA, "AUGCGCCCG");
            ISequence phase1 = ProteinTranslation.Translate(rnaSeq);

            Assert.IsTrue(CompareSequenceToString("MRP", phase1));
            Assert.AreEqual(Alphabets.Protein, phase1.Alphabet);

            rnaSeq = new Sequence(Alphabets.RNA, "AUGCGCCCG");
            phase1 = ProteinTranslation.Translate(rnaSeq, 0);
            Assert.IsTrue(CompareSequenceToString("MRP", phase1));
            Assert.AreEqual(Alphabets.Protein, phase1.Alphabet);

            rnaSeq = new Sequence(Alphabets.RNA, "AUGCGCCCG");
            phase1 = ProteinTranslation.Translate(rnaSeq, 1);
            Assert.IsTrue(CompareSequenceToString("CA", phase1));
            Assert.AreEqual(Alphabets.Protein, phase1.Alphabet);
        }
        public string Translate(string seq)
        {
            try {
                var          parser    = new FastAParser();
                var          byteArray = Encoding.UTF8.GetBytes(seq);
                Bio.Sequence result;
                using (var stream = new MemoryStream(byteArray)) {
                    result = parser.Parse(stream).First() as Bio.Sequence;
                }

                var transcribed = Transcription.Transcribe(result);

                return(ProteinTranslation.Translate(transcribed) is Bio.Sequence translated ? translated.ConvertToString() : "Couldn't translate to protein.");
            }
            catch {
                return("Invalid operation. Check your sequence. Check your format (must be FASTA).");
            }
        }
Exemplo n.º 11
0
        public void ValidateTwelveCharsProteinTranslationWithOffsetTwelve()
        {
            // Get Node values from XML.
            string expectedSeq = _utilityObj._xmlUtil.GetTextValue(
                Constants.TranslationNode, Constants.RnaSequenceWithTwelveChars);
            string expectedOffset = _utilityObj._xmlUtil.GetTextValue(
                Constants.CodonsNode, Constants.OffsetVaule3);

            // Translate twelve characters RNA to protein with  offset value "12".
            ISequence proteinTranslation = new Sequence(Alphabets.RNA, expectedSeq);
            ISequence protein            = ProteinTranslation.Translate(proteinTranslation,
                                                                        Convert.ToInt32(expectedOffset, null));

            // Validate Protein Translation.
            Assert.AreEqual(protein.ToString(), string.Empty);
            ApplicationLog.WriteLine(
                "Translation P1: Protein translation validation is completed successfully.");
        }
Exemplo n.º 12
0
        public void ValidateTranslationForNull()
        {
            bool Exthrown = false;

            // Translation by passing null Sequence.
            try
            {
                ProteinTranslation.Translate(null);
            }
            catch (NullReferenceException)
            {
                Exthrown = true;
            }
            // Validate if Translate method is throwing an exception.
            Assert.IsTrue(Exthrown);
            ApplicationLog.WriteLine(
                "Translation P2: Translate method was throwing an expection for null value.");
        }
Exemplo n.º 13
0
        public void ValidateProteinTranslationForAmbiguousRna()
        {
            // Get Node values from XML.
            string expectedSeq = utilityObj.xmlUtil.GetTextValue(
                Constants.TranslationNode, Constants.AmbiguousRnaSequence);
            string expectedProtein = utilityObj.xmlUtil.GetTextValue(
                Constants.TranslationNode, Constants.AmbiguousProteinSequence);
            ISequence protein = null;

            // Translate 15 characters ambiguous RNA to protein.
            var proteinTranslation = new Sequence(Alphabets.AmbiguousRNA, expectedSeq);

            protein = ProteinTranslation.Translate(proteinTranslation);

            // Validate Protein Translation.
            Assert.AreEqual(expectedProtein, new string(protein.Select(a => (char)a).ToArray()));
            ApplicationLog.WriteLine(
                "Translation P1: Protein translation validation is completed successfully.");
        }
Exemplo n.º 14
0
        public void ValidateTwelveCharsProteinTranslation()
        {
            // Get Node values from XML.
            string expectedSeq = utilityObj.xmlUtil.GetTextValue(
                Constants.TranslationNode, Constants.RnaSequenceWithTwelveChars);
            string expectedProtein = utilityObj.xmlUtil.GetTextValue(
                Constants.TranslationNode, Constants.AminoAcidForTwelveChars);
            ISequence protein = null;

            // Translate twelve characters RNA to protein.
            var proteinTranslation = new Sequence(Alphabets.RNA, expectedSeq);

            protein = ProteinTranslation.Translate(proteinTranslation);

            // Validate Protein Translation.
            Assert.AreEqual(new string(protein.Select(a => (char)a).ToArray()), expectedProtein);
            ApplicationLog.WriteLine(
                "Translation P1: Protein translation validation is completed successfully.");
        }
Exemplo n.º 15
0
        public void ValidateTranslationForInvalidOffset()
        {
            // Get Node values from XML.
            bool Exthrown = false;

            // Translation by passing null Sequence.
            try
            {
                ProteinTranslation.Translate(null, 10);
            }
            catch (ArgumentNullException)
            {
                Exthrown = true;
            }
            // Validate if Translate method is throwing an exception.
            Assert.IsTrue(Exthrown);
            ApplicationLog.WriteLine(
                "Translation P2: Translate method was throwing an expection for null value.");
        }
Exemplo n.º 16
0
        public void ValidateSixCharsProteinTranslation()
        {
            // Get Node values from XML.
            string expectedSeq = _utilityObj._xmlUtil.GetTextValue(
                Constants.TranslationNode, Constants.RnaSequence);
            string expectedProtein = _utilityObj._xmlUtil.GetTextValue(
                Constants.TranslationNode, Constants.AminoAcidForSixChars);
            string expectedOffset = _utilityObj._xmlUtil.GetTextValue(
                Constants.CodonsNode, Constants.OffsetVaule);

            // Translate Six characters RNA to protein.
            ISequence proteinTranslation = new Sequence(Alphabets.RNA, expectedSeq);
            ISequence protein            = ProteinTranslation.Translate(proteinTranslation,
                                                                        Convert.ToInt32(expectedOffset, null));

            // Validate Protein Translation.
            Assert.AreEqual(protein.ToString(), expectedProtein);
            ApplicationLog.WriteLine(
                "Translation P1: Protein translation validation is completed successfully.");
        }
Exemplo n.º 17
0
        public void ValidateProteinTranslationWithOffset()
        {
            // Get Node values from XML.
            string expectedSeq = Utility._xmlUtil.GetTextValue(
                Constants.TranslationNode, Constants.ExpectedSequence);
            string expectedAminoAcid = Utility._xmlUtil.GetTextValue(
                Constants.TranslationNode, Constants.AminoAcid);

            ISequence proteinTranslation = new Sequence(Alphabets.RNA, expectedSeq);
            ISequence protein            = ProteinTranslation.Translate(proteinTranslation, 0);

            // Validate Protein Translation.
            Assert.AreEqual(protein.Alphabet, Alphabets.Protein);
            Assert.AreEqual(protein.ToString(), expectedAminoAcid);

            ApplicationLog.WriteLine(string.Format(null,
                                                   "Translation BVT: Amino Acid {0} is expected.", protein));
            ApplicationLog.WriteLine(
                "Translation BVT: Amino Acid validation for a given sequence was completed successfully.");
        }
Exemplo n.º 18
0
        public void ValidateMoreThanTwelveCharsProteinTranslationWithOffsetTwelve()
        {
            // Get Node values from XML.
            string expectedSeq = utilityObj.xmlUtil.GetTextValue(
                Constants.TranslationNode, Constants.RnaSequenceWithMoreThanTwelveChars);
            string expectedProtein = utilityObj.xmlUtil.GetTextValue(
                Constants.TranslationNode, Constants.AminoAcidForOffsetTwelve);
            string expectedOffset = utilityObj.xmlUtil.GetTextValue(
                Constants.CodonsNode, Constants.OffsetVaule3);
            ISequence protein = null;

            // Translate twelve characters RNA to protein with  offset value "12".
            var proteinTranslation = new Sequence(Alphabets.RNA, expectedSeq);

            protein = ProteinTranslation.Translate(proteinTranslation,
                                                   Convert.ToInt32(expectedOffset, null));

            // Validate Protein Translation.
            Assert.AreEqual(new string(protein.Select(a => (char)a).ToArray()), expectedProtein);
            ApplicationLog.WriteLine(
                "Translation P1: Protein translation validation is completed successfully.");
        }
Exemplo n.º 19
0
        public void TestProteinTranslationInvalid()
        {
            try
            {
                Sequence  rnaSeq = new Sequence(Alphabets.RNA, "AUGCGCCCG");
                ISequence phase1 = ProteinTranslation.Translate(rnaSeq, 100);
                Assert.Fail();
            }
            catch (ArgumentException)
            {
            }

            try
            {
                Sequence  dnaSeq = new Sequence(Alphabets.DNA, "ATGC");
                ISequence phase1 = ProteinTranslation.Translate(dnaSeq);
                Assert.Fail();
            }
            catch (InvalidOperationException)
            {
            }
        }
Exemplo n.º 20
0
        public void ValidateProteinTranslation()
        {
            // Get Node values from XML.
            string expectedSeq = utilityObj.xmlUtil.GetTextValue(
                Constants.TranslationNode, Constants.ExpectedSequence);
            string expectedAminoAcid = utilityObj.xmlUtil.GetTextValue(
                Constants.TranslationNode, Constants.AminoAcid);
            ISequence protein = null;

            Sequence proteinTranslation = new Sequence(Alphabets.RNA, expectedSeq);

            protein = ProteinTranslation.Translate(proteinTranslation);

            // Validate Protein Translation.
            Assert.AreEqual(protein.Alphabet, Alphabets.Protein);
            Assert.AreEqual(new string(protein.Select(a => (char)a).ToArray()), expectedAminoAcid);

            ApplicationLog.WriteLine(string.Format((IFormatProvider)null,
                                                   "Translation BVT: Amino Acid {0} is expected.", protein));
            ApplicationLog.WriteLine(
                "Translation BVT: Amino Acid validation for a given sequence was completed successfully.");
        }
Exemplo n.º 21
0
        public void TestProteinTranslation()
        {
            Sequence  rnaSeq = new Sequence(Alphabets.RNA, "AUGCGCCCG");
            ISequence phase1 = ProteinTranslation.Translate(rnaSeq);

            Assert.IsTrue(CompareSequenceToString("MRP", phase1));
            Assert.AreEqual(Alphabets.Protein, phase1.Alphabet);

            rnaSeq = new Sequence(Alphabets.RNA, "AUGCGCCCG");
            phase1 = ProteinTranslation.Translate(rnaSeq, 0);
            Assert.IsTrue(CompareSequenceToString("MRP", phase1));
            Assert.AreEqual(Alphabets.Protein, phase1.Alphabet);

            rnaSeq = new Sequence(Alphabets.RNA, "AUGCGCCCG");
            phase1 = ProteinTranslation.Translate(rnaSeq, 1);
            Assert.IsTrue(CompareSequenceToString("CA", phase1));
            Assert.AreEqual(Alphabets.Protein, phase1.Alphabet);

            rnaSeq = new Sequence(Alphabets.AmbiguousRNA, "NCUCCAUCUUNUUGGAACAAA");
            phase1 = ProteinTranslation.Translate(rnaSeq, 0);
            Assert.IsTrue(CompareSequenceToString("XPSXWNK", phase1));
            Assert.AreEqual(Alphabets.AmbiguousProtein, phase1.Alphabet);
        }
Exemplo n.º 22
0
        public void ValidateTranslationOfAmbiguousRnaUsingRnaAlphabet()
        {
            // Get Node values from XML.
            string rnaSequenceStr = utilityObj.xmlUtil.GetTextValue(Constants.TranslationNode,
                                                                    Constants.AmbiguousRnaSequence);
            bool Exthrown = false;

            // Build ambiguous RNA sequence using an RNA alphabet.
            ISequence rnaSequence = new Sequence(Alphabets.RNA, rnaSequenceStr, false);

            // Call a translate method by passing negative offset value.
            try
            {
                ProteinTranslation.Translate(rnaSequence);
            }
            catch (InvalidOperationException)
            {
                Exthrown = true;
            }
            // Validate if Translate method is throwing an exception.
            Assert.IsTrue(Exthrown);
            ApplicationLog.WriteLine(
                "Translation P2: Translate method was throwing an expection for ambiguous RNA.");
        }
Exemplo n.º 23
0
        public void ValidateTranslationForNegativeOffset()
        {
            // Get Node values from XML.
            string expectedSeq = _utilityObj._xmlUtil.GetTextValue(Constants.TranslationNode,
                                                                   Constants.RnaSequence);
            bool Exthrown = false;

            // Translate Six characters RNA to protein.
            ISequence proteinTranslation = new Sequence(Alphabets.RNA, expectedSeq);

            // Call a translate method by passing negative offset value.
            try
            {
                ProteinTranslation.Translate(proteinTranslation, -10);
            }
            catch (ArgumentOutOfRangeException)
            {
                Exthrown = true;
            }
            // Validate if Translate method is throwing an exception.
            Assert.IsTrue(Exthrown);
            ApplicationLog.WriteLine(
                "Translation P2: Translate method was throwing an expection for null value.");
        }
        /// <summary>
        /// This is called to transform sequences
        /// </summary>
        private void OnTransformSequences()
        {
            TranslatedSequences.Clear();

            foreach (var sequence in SelectedSequences)
            {
                ISequence result = null;

                try
                {
                    if (sequence.Alphabet == Alphabets.DNA)
                    {
                        result = Transcription.Transcribe(sequence);
                        result.Metadata["Documentation"] = "Transcribed RNA from DNA sequence " + sequence.ID;
                    }
                    else if (sequence.Alphabet == Alphabets.RNA)
                    {
                        var alphabet      = sequence.Alphabet;
                        var noGapSequence = new Sequence(alphabet, sequence.Where(b => !alphabet.CheckIsGap(b)).ToArray());

                        result = ProteinTranslation.Translate(noGapSequence);
                        result.Metadata["Documentation"] = "Translated Protein from RNA sequence " + sequence.ID;
                    }
                }
                catch (Exception ex)
                {
                    ShowError("Translation Failed",
                              "Unable to transcribe/translate sequence", ex);
                }

                if (result != null)
                {
                    TranslatedSequences.Add(result);
                }
            }
        }
 public void Stop_codon_rna_sequence_2()
 {
     Assert.Empty(ProteinTranslation.Proteins("UAG"));
 }
 public void Tryptophan_rna_sequence()
 {
     Assert.Equal(new[] { "Tryptophan" }, ProteinTranslation.Proteins("UGG"));
 }
 public void Cysteine_rna_sequence_2()
 {
     Assert.Equal(new[] { "Cysteine" }, ProteinTranslation.Proteins("UGC"));
 }
 public void Methionine_rna_sequence()
 {
     Assert.Equal(new[] { "Methionine" }, ProteinTranslation.Proteins("AUG"));
 }
 public void Tyrosine_rna_sequence_2()
 {
     Assert.Equal(new[] { "Tyrosine" }, ProteinTranslation.Proteins("UAC"));
 }
 public void Serine_rna_sequence_4()
 {
     Assert.Equal(new[] { "Serine" }, ProteinTranslation.Proteins("UCG"));
 }