예제 #1
0
        public void ValidateDnaProteinTranslation()
        {
            // Get Node values from XML.
            string alphabetName = utilityObj.xmlUtil.GetTextValue(
                Constants.SimpleDnaAlphabetNode, Constants.AlphabetNameNode);
            string expectedSeq = utilityObj.xmlUtil.GetTextValue(
                Constants.TranscribeNode, Constants.DnaSequence);
            string expectedProtein = utilityObj.xmlUtil.GetTextValue(
                Constants.TranslationNode, Constants.AminoAcidForSixCharsV2);
            ISequence transcribe = null;

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

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

            // Protein Translation.
            ISequence proteinTranslation = new Sequence(Alphabets.RNA,
                                                        new string(transcribe.Select(a => (char)a).ToArray()));
            ISequence 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.");
        }
예제 #2
0
        public void ValidateDnaProteinTranslationWithOffset()
        {
            // Get Node values from XML.
            string alphabetName = _utilityObj._xmlUtil.GetTextValue(Constants.SimpleDnaAlphabetNode,
                                                                    Constants.AlphabetNameNode);
            string expectedSeq = _utilityObj._xmlUtil.GetTextValue(Constants.TranscribeNode,
                                                                   Constants.DnaSequence);
            string expectedProtein = _utilityObj._xmlUtil.GetTextValue(Constants.TranslationNode,
                                                                       Constants.AminoAcidForOffsetTwelve);
            string expectedOffset = _utilityObj._xmlUtil.GetTextValue(Constants.CodonsNode,
                                                                      Constants.OffsetVaule1);
            ISequence seq = new Sequence(Utility.GetAlphabet(alphabetName), expectedSeq);

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

            // Protein Translation by passing offset value.
            ISequence proteinTranslation = new Sequence(Alphabets.RNA, transcribe.ToString());
            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.");
        }
예제 #3
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);
        }
예제 #4
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;
            }
        }
예제 #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();
        }
예제 #6
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));
        }
예제 #7
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.");
        }
예제 #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.");
        }
예제 #9
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.");
        }
예제 #10
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.");
        }
예제 #11
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).");
            }
        }
예제 #13
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.");
        }
예제 #14
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.");
        }
예제 #15
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.");
        }
예제 #16
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.");
        }
예제 #17
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.");
        }
예제 #18
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.");
        }
예제 #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)
            {
            }
        }
예제 #20
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.");
        }
예제 #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);
        }
        /// <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);
                }
            }
        }
예제 #23
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.");
        }
예제 #24
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.");
        }
예제 #25
0
 /// <summary>
 /// The execution method for the activity.
 /// </summary>
 /// <param name="executionContext">The execution context.</param>
 /// <returns>The execution status.</returns>
 protected override ActivityExecutionStatus Execute(ActivityExecutionContext executionContext)
 {
     Protein = ProteinTranslation.Translate(RnaSequence, initialSequenceOffset);
     return(ActivityExecutionStatus.Closed);
 }
예제 #26
0
 public void Stops_translation_if_stop_codon_present()
 {
     Assert.Equal(new[] { "Methionine", "Phenylalanine" }, ProteinTranslation.Translate("AUGUUUUAA"));
 }
예제 #27
0
 public void Identifies_methionine_codons(string codon)
 {
     Assert.Equal(new[] { "Methionine" }, ProteinTranslation.Translate(codon));
 }
예제 #28
0
 public void Stops_translation_of_longer_strand()
 {
     Assert.Equal(new[] { "Tryptophan", "Cysteine", "Tyrosine" }, ProteinTranslation.Translate("UGGUGUUAUUAAUGGUUU"));
 }
예제 #29
0
 public void Throws_for_invalid_codons()
 {
     Assert.Throws <Exception>(() => ProteinTranslation.Translate("CARROT"));
 }
예제 #30
0
        public ISequence Translate(SequenceModel sequenceData)
        {
            var sequence = _provider.Provide(sequenceData?.FileName, sequenceData?.Content)?.First();

            return(ProteinTranslation.Translate(sequence));
        }