Пример #1
0
        /// <summary>
        ///     Validate building Kmer using sequence and kmer length.
        /// </summary>
        /// <param name="nodeName">Name of the xml node for different test cases</param>
        /// <param name="IsKmerBuilder">True if validating kmerbuilder or else false.</param>
        private void ValidateKmer(string nodeName, bool IsKmerBuilder)
        {
            // Get the parameters from Xml
            string Sequence          = utilityObj.xmlUtil.GetTextValue(nodeName, Constants.SequenceNode1);
            string expectedKmerCount = utilityObj.xmlUtil.GetTextValue(nodeName, Constants.KmrSeqCountNode);
            string expectedKmerSeq   = utilityObj.xmlUtil.GetTextValue(nodeName, Constants.KmerSequenceNode);
            string expectedKmerPos   = utilityObj.xmlUtil.GetTextValue(nodeName, Constants.PositionsNode);

            // Create a Kmer Sequence.
            ISequence       seq = new Sequence(Alphabets.DNA, Sequence);
            KmersOfSequence kmerSeq;

            if (IsKmerBuilder)
            {
                // Build Kmer.
                var             kmerBuilder = new SequenceToKmerBuilder();
                KmersOfSequence kmerList    = kmerBuilder.Build(seq, 2);

                // Validate builder kmer.
                Assert.AreEqual(expectedKmerCount, kmerList.Kmers.Count.ToString((IFormatProvider)null));
                Assert.AreEqual(expectedKmerSeq, new String(kmerList.BaseSequence.Select(a => (char)a).ToArray()));
                Assert.AreEqual(expectedKmerPos, kmerList.Length.ToString((IFormatProvider)null));
            }
            else
            {
                kmerSeq = new KmersOfSequence(seq, 2);

                // Validate Kmer Seq.
                Assert.AreEqual(expectedKmerSeq, new String(kmerSeq.BaseSequence.Select(a => (char)a).ToArray()));
                Assert.AreEqual(expectedKmerPos, kmerSeq.Length.ToString((IFormatProvider)null));
            }
        }
Пример #2
0
        /// <summary>
        ///     Validates the Sequences for all the general test cases.
        /// </summary>
        /// <param name="node">Xml Node Name</param>
        /// <param name="additionalParameter">
        ///     Additional Parameter based
        ///     on which the validations are done.
        /// </param>
        private void ValidateComputeFeature(string node, AssemblyParameters additionalParameter)
        {
            // Get the parameters from Xml
            string firstSequence        = utilityObj.xmlUtil.GetTextValue(node, Constants.SequenceNode1);
            string secondSequence       = utilityObj.xmlUtil.GetTextValue(node, Constants.SequenceNode2);
            string kmerLength           = utilityObj.xmlUtil.GetTextValue(node, Constants.KmerLengthNode);
            string expectedFeatureCount = utilityObj.xmlUtil.GetTextValue(node, Constants.FeatureCount);
            string expectedFeature      = utilityObj.xmlUtil.GetTextValue(node, Constants.FeatureName);
            string expectedFeatureType  = utilityObj.xmlUtil.GetTextValue(node, Constants.FeatureType);
            string expectedStartIndex   = utilityObj.xmlUtil.GetTextValue(node, Constants.StartIndexNode);
            string expectedEndIndex     = utilityObj.xmlUtil.GetTextValue(node, Constants.EndIndexNode);

            ISequence seq1 = null;
            ISequence seq2 = null;

            // Create Sequences.
            switch (additionalParameter)
            {
            case AssemblyParameters.Assemble:
                var seqObj1 =
                    new Sequence(Alphabets.Protein, firstSequence);
                var seqObj2 =
                    new Sequence(Alphabets.Protein, secondSequence);
                seq1 = seqObj1;
                seq2 = seqObj2;
                break;

            case AssemblyParameters.Consensus:
                seq1 = new Sequence(Alphabets.DNA, firstSequence);
                seq2 = new Sequence(Alphabets.DNA, secondSequence);
                break;
            }

            var             kmerBuilder = new SequenceToKmerBuilder();
            KmersOfSequence kmerList    =
                kmerBuilder.Build(seq1, int.Parse(kmerLength, null));
            List <WordMatch> nodes =
                WordMatch.BuildMatchTable(
                    kmerList,
                    seq2,
                    int.Parse(kmerLength, null));
            List <WordMatch> matchList =
                WordMatch.GetMinimalList(nodes, int.Parse(kmerLength, null));
            List <DifferenceNode> diffNode =
                DifferenceNode.BuildDiffList(matchList, seq1, seq2);
            List <DifferenceNode.CompareFeature> features =
                DifferenceNode.OutputDiffList(diffNode, seq1, seq2);

            // Validate difference.

            Assert.AreEqual(expectedFeatureCount, features.Count.ToString((IFormatProvider)null));
            Assert.AreEqual(expectedFeature, features[0].Feature);
            Assert.AreEqual(expectedFeatureType, features[0].FeatureType);
            Assert.AreEqual(expectedStartIndex, features[0].Start.ToString((IFormatProvider)null));
            Assert.AreEqual(expectedEndIndex, features[0].End.ToString((IFormatProvider)null));
            ApplicationLog.WriteLine(string.Format(null, "Kmer P1 : Validated DifferenceNodes successfully."));
        }
Пример #3
0
        public static void FindDifferencesInSequences(string firstFile, string secondFile)
        {
            // parsowanie pierwszej listy
            if (!SequenceParsers.IsFasta(firstFile))
            {
                Console.WriteLine("Nieprawidlowy format pierwszego pliku!");
                return;
            }

            if (!SequenceParsers.IsFasta(secondFile))
            {
                Console.WriteLine("Nieprawidlowy format drugiego pliku!");
                return;
            }

            var firstParser = SequenceParsers.FindParserByFileName(firstFile);

            firstParser.Alphabet = AmbiguousProteinAlphabet.Instance;
            var firstSequenceList  = firstParser.Parse();
            var firstFileSequences = Helper.ConvertIenumerableToList(firstSequenceList);

            // parsowanie drugiej listy
            var secondParser = SequenceParsers.FindParserByFileName(firstFile);

            secondParser.Alphabet = AmbiguousProteinAlphabet.Instance;
            var secondSequenceList  = secondParser.Parse();
            var secondFileSequences = Helper.ConvertIenumerableToList(secondSequenceList);

            // pobranie listy KMER'ów
            var kmerBuilder = new SequenceToKmerBuilder();
            var kmerList    = kmerBuilder.Build(firstFileSequences.First(), 2);
            var nodes       = WordMatch.BuildMatchTable(kmerList, secondFileSequences.First(), 2);

            var list2 = new List <WordMatch>(nodes);

            var matchList = WordMatch.GetMinimalList(list2, 2);

            var list3 = new List <WordMatch>(matchList);

            // znajdŸ ró¿nice miêdzy wêz³ami
            var diffNode = DifferenceNode.BuildDiffList(list3, firstFileSequences.First(), secondFileSequences.First());

            var list4 = new List <DifferenceNode>(diffNode);

            var features = DifferenceNode.OutputDiffList(list4, firstFileSequences.First(), secondFileSequences.First());

            foreach (var compareFeature in features)
            {
                Console.WriteLine(compareFeature.Feature);
            }
        }
Пример #4
0
        public void SequenceCompare()
        {
            ISequence seq1 = new Sequence(Alphabets.DNA, "AAAAAA");
            ISequence seq2 = new Sequence(Alphabets.DNA, "AAATAA");

            SequenceToKmerBuilder kmerBuilder             = new SequenceToKmerBuilder();
            KmersOfSequence       kmers                   = kmerBuilder.Build(seq1, 2);
            List <WordMatch>      nodes                   = WordMatch.BuildMatchTable(kmers, seq1, seq2, 2);
            List <WordMatch>      matchList               = WordMatch.GetMinimalList(nodes, 2);
            List <DifferenceNode> diffNode                = DifferenceNode.BuildDiffList(matchList, seq1, seq2);
            List <DifferenceNode.CompareFeature> features = DifferenceNode.OutputDiffList(diffNode, seq1, seq2);

            Assert.AreEqual(features.Count, 4);
            Assert.AreEqual(features[0].Feature, "Insertion of 1 bases in 2 ");
            Assert.AreEqual(features[1].FeatureType, "REPLACE");
            Assert.AreEqual(features[2].Feature, "Insertion of 1 bases in 1 ");
            Assert.AreEqual(features[3].FeatureType, "REPLACE");
        }
Пример #5
0
        public void ValidateSequenceCompare()
        {
            string firstSequence = utilityObj.xmlUtil.GetTextValue(Constants.SequenceCompareNode,
                                                                   Constants.SequenceNode1);
            string secondSequence = utilityObj.xmlUtil.GetTextValue(Constants.SequenceCompareNode,
                                                                    Constants.SequenceNode2);
            string replace = utilityObj.xmlUtil.GetTextValue(Constants.SequenceCompareNode,
                                                             Constants.ReplaceNode);
            ISequence             seq1                    = new Sequence(Alphabets.DNA, firstSequence);
            ISequence             seq2                    = new Sequence(Alphabets.DNA, secondSequence);
            var                   kmerBuilder             = new SequenceToKmerBuilder();
            KmersOfSequence       kmers                   = kmerBuilder.Build(seq1, 2);
            List <WordMatch>      nodes                   = WordMatch.BuildMatchTable(kmers, seq2, 2);
            List <WordMatch>      matchList               = WordMatch.GetMinimalList(nodes, 2);
            List <DifferenceNode> diffNode                = DifferenceNode.BuildDiffList(matchList, seq1, seq2);
            List <DifferenceNode.CompareFeature> features = DifferenceNode.OutputDiffList(diffNode, seq1, seq2);

            //Validating the bahavior.
            Assert.AreEqual(features.Count, 4);
            Assert.AreEqual(features[0].Feature, Constants.InsertionOfOneBaseIn2);
            Assert.AreEqual(features[1].FeatureType, replace);
            Assert.AreEqual(features[2].Feature, Constants.InsertionOfOneBaseIn1);
            Assert.AreEqual(features[3].FeatureType, replace);
        }
Пример #6
0
        /// <summary>
        /// Validate building Kmer using sequence and kmer length.
        /// </summary>
        /// <param name="nodeName">Name of the xml node for different test cases</param>
        /// <param name="IsKmerBuilder">True if validating kmerbuilder or else false.</param>
        static void ValidateKmer(string nodeName, bool IsKmerBuilder)
        {
            // Get the parameters from Xml
            string Sequence = Utility._xmlUtil.GetTextValue(nodeName,
                                                            Constants.SequenceNode1);
            string expectedKmerCount = Utility._xmlUtil.GetTextValue(nodeName,
                                                                     Constants.KmrSeqCountNode);
            string expectedKmerSeq = Utility._xmlUtil.GetTextValue(nodeName,
                                                                   Constants.KmerSequenceNode);
            string expectedKmerPos = Utility._xmlUtil.GetTextValue(nodeName,
                                                                   Constants.PositionsNode);

            // Create a Kmer Sequence.
            ISequence       seq = new Sequence(Alphabets.DNA, Sequence);
            KmersOfSequence kmerSeq;

            if (IsKmerBuilder)
            {
                // Build Kmer.
                SequenceToKmerBuilder kmerBuilder = new SequenceToKmerBuilder();
                KmersOfSequence       kmerList    = kmerBuilder.Build(seq, 2);

                // Validate builder kmer.
                Assert.AreEqual(expectedKmerCount, kmerList.Kmers.Count.ToString());
                Assert.AreEqual(expectedKmerSeq, kmerList.BaseSequence.ToString());
                Assert.AreEqual(expectedKmerPos, kmerList.Length.ToString());
            }
            else
            {
                kmerSeq = new KmersOfSequence(seq, 2);

                // Validate Kmer Seq.
                Assert.AreEqual(expectedKmerSeq, kmerSeq.BaseSequence.ToString());
                Assert.AreEqual(expectedKmerPos, kmerSeq.Length.ToString());
            }
        }