Esempio n. 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 = 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));
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Validate KmersOfSequence ToSequences() method which returns kmers sequence
        /// using its positions
        /// </summary>
        /// <param name="nodeName">xml node name used for different testcases</param>
        internal void ValidateKmersOfSequenceToSequences(string nodeName)
        {
            string filePath = utilityObj.xmlUtil.GetTextValue(nodeName, Constants.FilePathNode);
            string kmerLength = utilityObj.xmlUtil.GetTextValue(nodeName, Constants.KmerLengthNode);
            string kmerOutputFile = utilityObj.xmlUtil.GetTextValue(nodeName,
                  Constants.KmersOutputFileNode);

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

                this.KmerLength = int.Parse(kmerLength, (IFormatProvider)null);
                this.SequenceReads.Clear();

                this.SetSequenceReads(sequenceReads.ToList());
                IList<KmersOfSequence> lstKmers = new List<KmersOfSequence>(
                    (new SequenceToKmerBuilder()).Build(this.SequenceReads, this.KmerLength));

                // Get the array of kmer sequence using ToSequence()
                int index = 0;

                // Validate the generated kmer sequence with the expected output
                using (StreamReader kmerFile = new StreamReader(kmerOutputFile))
                {
                    string line = string.Empty;
                    List<string[]> fileContent = new List<string[]>();
                    while (null != (line = kmerFile.ReadLine()))
                    {
                        fileContent.Add(line.Split(','));
                    }

                    foreach (ISequence sequenceRead in sequenceReads)
                    {
                        int count = 0;
                        KmersOfSequence kmerSequence = new KmersOfSequence(sequenceRead,
                          int.Parse(kmerLength, (IFormatProvider)null), lstKmers[index].Kmers);
                        IEnumerable<ISequence> sequences = kmerSequence.KmersToSequences();
                        foreach (ISequence sequence in sequences)
                        {
                            string aab = new string(sequence.Select(a => (char)a).ToArray());
                            Assert.AreEqual(fileContent[index][count], aab);
                            count++;
                        }
                        index++;
                    }
                }
            }

            ApplicationLog.WriteLine(@"Padena P1 : KmersOfSequence ToSequences() method validation completed successfully");
        }
Esempio n. 3
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");
        }
Esempio n. 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");
        }
Esempio n. 5
0
        /// <summary>
        /// Validate kmersofsequence ctor() by passing kmers, kmer length and input reads
        /// </summary>
        /// <param name="nodeName">xml node name used for different testcases</param>
        internal void ValidateKmersOfSequenceCtor(string nodeName)
        {
            string filePath = utilityObj.xmlUtil.GetTextValue(nodeName, Constants.FilePathNode);
            string kmerLength = utilityObj.xmlUtil.GetTextValue(nodeName, Constants.KmerLengthNode);

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

                // Validate the KmersOfSequence ctor by passing build kmers
                // Validate the kmersof sequence instance using GetKmerSequence()
                this.KmerLength = int.Parse(kmerLength, (IFormatProvider)null);
                this.SequenceReads.Clear();

                this.SetSequenceReads(sequenceReads.ToList());
                IEnumerable<KmersOfSequence> lstKmers =
                    (new SequenceToKmerBuilder()).Build(this.SequenceReads, this.KmerLength);
                IList<KmersOfSequence> newKmersList = new List<KmersOfSequence>();
                int index = 0;
                foreach (KmersOfSequence kmer in lstKmers)
                {
                    KmersOfSequence newkmer = new KmersOfSequence(sequenceReads.ElementAt(index),
                      int.Parse(kmerLength, (IFormatProvider)null), kmer.Kmers);
                    newKmersList.Add(newkmer);
                    index++;
                }

                ValidateKmersList(newKmersList, new List<ISequence>(sequenceReads), nodeName);
            }

            ApplicationLog.WriteLine(
                @"Padena BVT : KmersOfSequence ctor validation for 
                    Padena step1 completed successfully");
        }