/// <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)); } }
/// <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.")); }
/// <summary> /// Finds the sequence in the list of IKmer and returns the list of position /// of the Kmers. /// </summary> /// <param name="sequence">Sequence which has to be matched in the list of IKmer.</param> /// <param name="kmerList">List of IKmer.</param> /// <returns>Returns the list of position of IKmer.</returns> private static IList <int> FindCorrespondingMatch(ISequence sequence, KmersOfSequence kmerList) { IList <int> positions = null; string sequenceString = sequence.ToString(); foreach (KmersOfSequence.KmerPositions kmer in kmerList.Kmers) { if (sequenceString.Equals(kmerList.KmerToSequence(kmer).ToString())) { positions = kmer.Positions; break; } } return(positions); }
/// <summary> /// Finds the sequence in the list of IKmer and returns the list of position /// of the Kmers. /// </summary> /// <param name="sequence">Sequence which has to be matched in the list of IKmer.</param> /// <param name="kmerList">List of IKmer.</param> /// <returns>Returns the list of position of IKmer.</returns> private static IList <long> FindCorrespondingMatch(string sequence, KmersOfSequence kmerList) { IList <long> positions = null; foreach (KmersOfSequence.KmerPositions kmer in kmerList.Kmers) { string kmerString = new string(kmerList.KmerToSequence(kmer).Select(a => (char)a).ToArray()); if (sequence.Equals(kmerString)) { positions = kmer.Positions; break; } } return(positions); }
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"); }
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); }
/// <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()); } }
/// <summary> /// Create a list of all the matches and order them by the /// second sequence. /// </summary> /// <param name="kmerList">List of kmer's.</param> /// <param name="seq2">Second sequence.</param> /// <param name="wordLength">Wordlength entered by the user</param> /// <returns>List of all the matches.</returns> public static List <WordMatch> BuildMatchTable(KmersOfSequence kmerList, ISequence seq2, int wordLength) { if (seq2 == null) { throw new ArgumentNullException("seq2"); } int i = 0; int ilast = (int)seq2.Count - wordLength; List <WordMatch> wordCurList = new List <WordMatch>(); List <WordMatch> hitList = new List <WordMatch>(); bool matched = false; while (i < (ilast + 1)) { IList <long> positions = FindCorrespondingMatch(new string(seq2.Skip(i).Take(wordLength).Select(a => (char)a).ToArray()), kmerList); if (positions != null) { int kcur = 0; int kcur2 = 0; int knew = 0; if (wordCurList.Count > 0) { WordMatch curmatch = wordCurList[0]; kcur = curmatch.sequence1Start + curmatch.length - wordLength + 1; kcur2 = curmatch.sequence2Start + curmatch.length - wordLength + 1; } foreach (int position in positions) { knew = position; matched = false; foreach (WordMatch curmatch in wordCurList) { if (!curmatch.Deleted) { kcur = curmatch.sequence1Start + curmatch.length - wordLength + 1; kcur2 = curmatch.sequence2Start + curmatch.length - wordLength + 1; // When we test, we may have already incremented // one of the matches - so test old and new kcur2 if (kcur2 != i && kcur2 != i + 1) { curmatch.Deleted = true; continue; } if (kcur == knew && kcur2 == i) { curmatch.length++; matched = true; continue; } } } if (!matched) { // New current match WordMatch match2 = new WordMatch(wordLength, knew, i); hitList.Add(match2); wordCurList.Add(match2); } } } i++; } wordCurList.Sort(); foreach (WordMatch curmatch in wordCurList) { curmatch.Deleted = false; } return(wordCurList); }