Example #1
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 = this.utilityObj.xmlUtil.GetTextValue(node, Constants.SequenceNode1);
            string secondSequence = this.utilityObj.xmlUtil.GetTextValue(node, Constants.SequenceNode2);
            string kmerLength = this.utilityObj.xmlUtil.GetTextValue(node, Constants.KmerLengthNode);
            string expectedFeatureCount = this.utilityObj.xmlUtil.GetTextValue(node, Constants.FeatureCount);
            string expectedFeature = this.utilityObj.xmlUtil.GetTextValue(node, Constants.FeatureName);
            string expectedFeatureType = this.utilityObj.xmlUtil.GetTextValue(node, Constants.FeatureType);
            string expectedStartIndex = this.utilityObj.xmlUtil.GetTextValue(node, Constants.StartIndexNode);
            string expectedEndIndex = this.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."));
        }
Example #2
0
        public void ValidateSequenceCompare()
        {
            string firstSequence = this.utilityObj.xmlUtil.GetTextValue(Constants.SequenceCompareNode,
                                                                   Constants.SequenceNode1);
            string secondSequence = this.utilityObj.xmlUtil.GetTextValue(Constants.SequenceCompareNode,
                                                                    Constants.SequenceNode2);
            string replace = this.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 behavior. 
            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);
        }
Example #3
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 = this.utilityObj.xmlUtil.GetTextValue(nodeName, Constants.SequenceNode1);
            string expectedKmerCount = this.utilityObj.xmlUtil.GetTextValue(nodeName, Constants.KmrSeqCountNode);
            string expectedKmerSeq = this.utilityObj.xmlUtil.GetTextValue(nodeName, Constants.KmerSequenceNode);
            string expectedKmerPos = this.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));
            }
        }
Example #4
0
        /// <summary>
        /// Validate KmersOfSequence ctor by passing base sequence reads, kmer length and
        /// built kmers and validate its properties.
        /// </summary>
        /// <param name="nodeName">xml node name.</param>
        internal void ValidateKmersOfSequenceCtorProperties(string nodeName)
        {
            string filePath = utilityObj.xmlUtil.GetTextValue(nodeName,
              Constants.FilePathNode);
            string kmerLength = utilityObj.xmlUtil.GetTextValue(nodeName,
              Constants.KmerLengthNode);
            string expectedSeq = utilityObj.xmlUtil.GetTextValue(nodeName,
              Constants.BaseSequenceNode);
            string expectedKmers = utilityObj.xmlUtil.GetTextValue(nodeName,
              Constants.KmersCountNode);

            // Get the input reads
            IEnumerable<ISequence> sequenceReads = null;
            using (FastAParser parser = new FastAParser(filePath))
            {
                sequenceReads = parser.Parse();

                SequenceToKmerBuilder builder = new SequenceToKmerBuilder();

                KmersOfSequence kmer = builder.Build(sequenceReads.ToList()[0],
                  int.Parse(kmerLength, (IFormatProvider)null));
                KmersOfSequence kmerSequence = new KmersOfSequence(sequenceReads.ToList()[0],
                  int.Parse(kmerLength, (IFormatProvider)null), kmer.Kmers);

                // Validate KmerOfSequence properties.
                Assert.AreEqual(expectedSeq, new string(kmerSequence.BaseSequence.Select(a => (char)a).ToArray()));
                Assert.AreEqual(expectedKmers, kmerSequence.Kmers.Count.ToString((IFormatProvider)null));
            }

            ApplicationLog.WriteLine(@"Padena P1 : KmersOfSequence ctor with build kmers method validation completed successfully");
        }
Example #5
0
        /// <summary>
        /// Validate KmersOfSequence ctor by passing base sequence reads, kmer length and
        /// built kmers
        /// </summary>
        /// <param name="nodeName">xml node name.</param>
        internal void ValidateKmersOfSequenceCtorWithBuildKmers(string nodeName)
        {
            string filePath = utilityObj.xmlUtil.GetTextValue(nodeName, Constants.FilePathNode);
            string kmerLength = utilityObj.xmlUtil.GetTextValue(nodeName, Constants.KmerLengthNode);

            // Get the input reads
            IEnumerable<ISequence> sequenceReads = null;
            using (FastAParser parser = new FastAParser(filePath))
            {
                sequenceReads = parser.Parse();

                SequenceToKmerBuilder builder = new SequenceToKmerBuilder();
                IList<KmersOfSequence> lstKmers = new List<KmersOfSequence>();

                // Validate KmersOfSequence ctor using build kmers
                foreach (ISequence sequence in sequenceReads)
                {
                    KmersOfSequence kmer = builder.Build(sequence, int.Parse(kmerLength, (IFormatProvider)null));
                    KmersOfSequence kmerSequence = new KmersOfSequence(sequence,
                      int.Parse(kmerLength, (IFormatProvider)null), kmer.Kmers);
                    lstKmers.Add(kmerSequence);
                }

                ValidateKmersList(lstKmers, sequenceReads.ToList(), nodeName);
            }
            ApplicationLog.WriteLine(@"Padena P1 : KmersOfSequence ctor with build kmers method validation completed successfully");
        }
Example #6
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);
            }
        }
Example #7
0
        /// <summary>
        /// Validate SequenceRangeToKmerBuilder Build() which build kmers 
        /// using one base sequence 
        /// </summary>
        /// <param name="nodeName">xml node name used for different testcases</param>
        internal void ValidateKmerBuilderBuildWithSequence(string nodeName)
        {
            string filePath = utilityObj.xmlUtil.GetTextValue(
              nodeName, Constants.FilePathNode);
            string kmerLength = utilityObj.xmlUtil.GetTextValue(
              nodeName, Constants.KmerLengthNode);

            // Get the input reads
            IEnumerable<ISequence> sequenceReads = null;
            using (FastAParser parser = new FastAParser(filePath))
            {
                sequenceReads = parser.Parse();

                // Pass each input read and kmerLength
                // Add all the generated kmers to kmer list
                SequenceToKmerBuilder builder = new SequenceToKmerBuilder();
                IList<KmersOfSequence> lstKmers = new List<KmersOfSequence>();
                foreach (ISequence sequence in sequenceReads)
                {
                    lstKmers.Add(builder.Build(sequence, int.Parse(kmerLength, (IFormatProvider)null)));
                }

                // Validate all the kmers
                ValidateKmersList(lstKmers, sequenceReads.ToList(), nodeName);
            }

            ApplicationLog.WriteLine(
                @"Padena BVT : Validation of Build with each input read sequence 
                    completed successfully");
        }
Example #8
0
        /// <summary>
        /// Validate SequenceRangeToKmerBuilder Build() method which build kmers
        /// </summary>
        /// <param name="nodeName">xml node name for test data</param>
        internal void ValidateKmerBuilderBuild(string nodeName)
        {
            string filePath = utilityObj.xmlUtil.GetTextValue(
              nodeName, Constants.FilePathNode);
            string kmerLength = utilityObj.xmlUtil.GetTextValue(
              nodeName, Constants.KmerLengthNode);

            // Get the input reads
            IEnumerable<ISequence> sequenceReads = null;
            using (FastAParser parser = new FastAParser(filePath))
            {
                sequenceReads = parser.Parse();

                // Pass all the input reads and kmerLength to generate kmers
                SequenceToKmerBuilder builder = new SequenceToKmerBuilder();
                IEnumerable<KmersOfSequence> lstKmers = builder.Build(sequenceReads,
                  int.Parse(kmerLength, (IFormatProvider)null));

                // Validate kmers list
                ValidateKmersList(new List<KmersOfSequence>(lstKmers),
                    new List<ISequence>(sequenceReads), nodeName);
            }

            ApplicationLog.WriteLine(
                @"Padena BVT : Validation of Build with all input reads 
                    sequence completed successfully");
        }