public void TestMUMmerAlignerMultipleMum() { string reference = "ATGCGCATCCCCTT"; string search = "GCGCCCCCTA"; Sequence referenceSeq = null; Sequence searchSeq = null; referenceSeq = new Sequence(Alphabets.DNA, reference); searchSeq = new Sequence(Alphabets.DNA, search); List<ISequence> searchSeqs = new List<ISequence>(); searchSeqs.Add(searchSeq); MUMmerAligner mummer = new MUMmerAligner(); mummer.LengthOfMUM = 4; mummer.PairWiseAlgorithm = new NeedlemanWunschAligner(); IList<IPairwiseSequenceAlignment> result = mummer.AlignSimple(referenceSeq, searchSeqs); // Check if output is not null Assert.AreNotEqual(null, result); IList<IPairwiseSequenceAlignment> expectedOutput = new List<IPairwiseSequenceAlignment>(); IPairwiseSequenceAlignment align = new PairwiseSequenceAlignment(); PairwiseAlignedSequence alignedSeq = new PairwiseAlignedSequence(); alignedSeq.FirstSequence = new Sequence(Alphabets.DNA, "ATGCGCATCCCCTT"); alignedSeq.SecondSequence = new Sequence(Alphabets.DNA, "--GCGC--CCCCTA"); alignedSeq.Consensus = new Sequence(AmbiguousDnaAlphabet.Instance, "ATGCGCATCCCCTW"); alignedSeq.Score = -11; alignedSeq.FirstOffset = 0; alignedSeq.SecondOffset = 2; align.PairwiseAlignedSequences.Add(alignedSeq); expectedOutput.Add(align); Assert.IsTrue(CompareAlignment(result, expectedOutput)); }
private void ValidateMUMmerAlignGeneralTestCases(string nodeName) { // Gets the reference sequence from the configuration file string filePath = utilityObj.xmlUtil.GetTextValue(nodeName, Constants.FilePathNode); Assert.IsNotNull(filePath); ApplicationLog.WriteLine(string.Format(null, "MUMmer P2 : Successfully validated the File Path '{0}'.", filePath)); var fastaParserObj = new FastAParser(); IEnumerable<ISequence> referenceSeqs = fastaParserObj.Parse(filePath); ISequence referenceSeq = referenceSeqs.ElementAt(0); // Gets the reference sequence from the configuration file string queryFilePath = utilityObj.xmlUtil.GetTextValue(nodeName, Constants.SearchSequenceFilePathNode); Assert.IsNotNull(queryFilePath); ApplicationLog.WriteLine(string.Format(null, "MUMmer P2 : Successfully validated the Search File Path '{0}'.", queryFilePath)); var fastaParserObj1 = new FastAParser(); IEnumerable<ISequence> querySeqs = fastaParserObj1.Parse(queryFilePath); string mumLength = utilityObj.xmlUtil.GetTextValue(nodeName, Constants.MUMAlignLengthNode); var mum = new MUMmerAligner { LengthOfMUM = long.Parse(mumLength, null), StoreMUMs = true, PairWiseAlgorithm = new NeedlemanWunschAligner(), GapOpenCost = int.Parse(utilityObj.xmlUtil.GetTextValue(nodeName, Constants.GapOpenCostNode), null) }; IList<IPairwiseSequenceAlignment> align = mum.Align(referenceSeq, querySeqs); // Validate FinalMUMs and MUMs Properties. Assert.IsNotNull(mum.MUMs); string expectedScore = utilityObj.xmlUtil.GetTextValue(nodeName, Constants.ScoreNodeName); string[] expectedSequences = utilityObj.xmlUtil.GetTextValues(nodeName, Constants.ExpectedSequencesNode); IList<IPairwiseSequenceAlignment> expectedOutput = new List<IPairwiseSequenceAlignment>(); IPairwiseSequenceAlignment seqAlign = new PairwiseSequenceAlignment(); var alignedSeq = new PairwiseAlignedSequence { FirstSequence = new Sequence(referenceSeq.Alphabet, expectedSequences[0]), SecondSequence = new Sequence(referenceSeq.Alphabet, expectedSequences[1]), Score = Convert.ToInt32(expectedScore, null), FirstOffset = Int32.MinValue, SecondOffset = Int32.MinValue, }; seqAlign.PairwiseAlignedSequences.Add(alignedSeq); expectedOutput.Add(seqAlign); Assert.IsTrue(AlignmentHelpers.CompareAlignment(align, expectedOutput)); ApplicationLog.WriteLine("MUMmer P2 : Successfully validated the aligned sequences."); }
/// <summary> /// Initializes static members of the SequenceAligners class. /// Static constructor /// </summary> static SequenceAligners() { NUCmer = new NucmerPairwiseAligner(); MUMmer = new MUMmerAligner(); NeedlemanWunsch = new NeedlemanWunschAligner(); SmithWaterman = new SmithWatermanAligner(); var knownAligners = new List<ISequenceAligner> { SmithWaterman, NeedlemanWunsch, MUMmer, NUCmer }; // Get the registered aligners IEnumerable<ISequenceAligner> registeredAligners = GetAligners(); if (null != registeredAligners) { knownAligners.AddRange(registeredAligners .Where(aligner => aligner != null && knownAligners.All(sa => string.Compare(sa.Name, aligner.Name, StringComparison.OrdinalIgnoreCase) != 0))); } All = knownAligners; }
public void TestMUMmerAlignerSingleMum() { const string reference = "TTAATTTTAG"; const string search = "AGTTTAGAG"; ISequence referenceSeq = new Sequence(Alphabets.DNA, reference); ISequence searchSeq = new Sequence(Alphabets.DNA, search); var searchSeqs = new List<ISequence> {searchSeq}; MUMmerAligner mummer = new MUMmerAligner { LengthOfMUM = 3, PairWiseAlgorithm = new NeedlemanWunschAligner(), GapExtensionCost = -2 }; IList<IPairwiseSequenceAlignment> result = mummer.Align(referenceSeq, searchSeqs); // Check if output is not null Assert.AreNotEqual(null, result); IList<IPairwiseSequenceAlignment> expectedOutput = new List<IPairwiseSequenceAlignment>(); IPairwiseSequenceAlignment align = new PairwiseSequenceAlignment(); PairwiseAlignedSequence alignedSeq = new PairwiseAlignedSequence { FirstSequence = new Sequence(Alphabets.DNA, "TTAATTTTAG--"), SecondSequence = new Sequence(Alphabets.DNA, "---AGTTTAGAG"), Consensus = new Sequence(AmbiguousDnaAlphabet.Instance, "TTAAKTTTAGAG"), Score = -6, FirstOffset = 0, SecondOffset = 3 }; align.PairwiseAlignedSequences.Add(alignedSeq); expectedOutput.Add(align); Assert.IsTrue(CompareAlignment(result, expectedOutput)); }
public void TestMUMmerAlignerSingleMumRNA() { const string reference = "AUGCUUUUCCCCCCC"; const string search = "UAUAUUUUGG"; MUMmerAligner mummer = new MUMmerAligner { LengthOfMUM = 3, PairWiseAlgorithm = new NeedlemanWunschAligner(), SimilarityMatrix = new SimilarityMatrix(SimilarityMatrix.StandardSimilarityMatrix.AmbiguousRna), GapOpenCost = -8, GapExtensionCost = -2 }; ISequence referenceSeq = new Sequence(Alphabets.RNA, reference); List<ISequence> searchSeqs = new List<ISequence> { new Sequence(Alphabets.RNA, search) }; IList<IPairwiseSequenceAlignment> result = mummer.Align(referenceSeq, searchSeqs); // Check if output is not null Assert.AreNotEqual(0, result.Count); IList<IPairwiseSequenceAlignment> expectedOutput = new List<IPairwiseSequenceAlignment>(); IPairwiseSequenceAlignment align = new PairwiseSequenceAlignment(); align.PairwiseAlignedSequences.Add(new PairwiseAlignedSequence { FirstSequence = new Sequence(Alphabets.RNA, "-AUGCUUUUCCCCCCC"), SecondSequence = new Sequence(Alphabets.RNA, "UAUA-UUUUGG-----"), Consensus = new Sequence(AmbiguousRnaAlphabet.Instance, "UAURCUUUUSSCCCCC"), Score = -14, FirstOffset = 1, SecondOffset = 0 }); expectedOutput.Add(align); AlignmentHelpers.CompareAlignment(result, expectedOutput); }
public void TestMUMmer3MultipleMumWithCustomMatrix() { string reference = "ATGCGCATCCCCTT"; string search = "GCGCCCCCTA"; Sequence referenceSeq = null; Sequence searchSeq = null; referenceSeq = new Sequence(Alphabets.DNA, reference); searchSeq = new Sequence(Alphabets.DNA, search); List<ISequence> searchSeqs = new List<ISequence>(); searchSeqs.Add(searchSeq); int[,] customMatrix = new int[256, 256]; customMatrix[(byte)'A', (byte)'A'] = 3; customMatrix[(byte)'A', (byte)'T'] = -2; customMatrix[(byte)'A', (byte)'G'] = -2; customMatrix[(byte)'A', (byte)'c'] = -2; customMatrix[(byte)'G', (byte)'G'] = 3; customMatrix[(byte)'G', (byte)'A'] = -2; customMatrix[(byte)'G', (byte)'T'] = -2; customMatrix[(byte)'G', (byte)'C'] = -2; customMatrix[(byte)'T', (byte)'T'] = 3; customMatrix[(byte)'T', (byte)'A'] = -2; customMatrix[(byte)'T', (byte)'G'] = -2; customMatrix[(byte)'T', (byte)'C'] = -2; customMatrix[(byte)'C', (byte)'C'] = 3; customMatrix[(byte)'C', (byte)'T'] = -2; customMatrix[(byte)'C', (byte)'A'] = -2; customMatrix[(byte)'C', (byte)'G'] = -2; DiagonalSimilarityMatrix matrix = new DiagonalSimilarityMatrix(3, -2); int gapOpenCost = -6; MUMmerAligner mummer = new MUMmerAligner(); mummer.LengthOfMUM = 4; mummer.PairWiseAlgorithm = new NeedlemanWunschAligner(); mummer.SimilarityMatrix = matrix; mummer.GapOpenCost = gapOpenCost; mummer.GapExtensionCost = -2; IList<IPairwiseSequenceAlignment> result = mummer.AlignSimple(referenceSeq, searchSeqs); // Check if output is not null Assert.AreNotEqual(null, result); IList<IPairwiseSequenceAlignment> expectedOutput = new List<IPairwiseSequenceAlignment>(); IPairwiseSequenceAlignment align = new PairwiseSequenceAlignment(); PairwiseAlignedSequence alignedSeq = new PairwiseAlignedSequence(); alignedSeq.FirstSequence = new Sequence(Alphabets.DNA, "ATGCGCATCCCCTT"); alignedSeq.SecondSequence = new Sequence(Alphabets.DNA, "--GCGC--CCCCTA"); alignedSeq.Consensus = new Sequence(AmbiguousDnaAlphabet.Instance, "ATGCGCATCCCCTW"); alignedSeq.Score = 1; alignedSeq.FirstOffset = 0; alignedSeq.SecondOffset = 2; align.PairwiseAlignedSequences.Add(alignedSeq); expectedOutput.Add(align); Assert.IsTrue(CompareAlignment(result, expectedOutput)); }
/// <summary> /// Validates the Mummer align method for several test cases for the parameters passed. /// </summary> /// <param name="nodeName">Node name to be read from xml</param> /// <param name="isFilePath">Is Sequence saved in File</param> /// <param name="isAlignList">Is align method to take list?</param> /// <param name="addParam">Additional parameter</param> /// Suppress the ParserParam variable CA1801 as this would be reused later. void ValidateMUMmerAlignGeneralTestCases(string nodeName, bool isFilePath, bool isAlignList, AdditionalParameters addParam) { ISequence referenceSeq; IList<ISequence> querySeqs; List<ISequence> alignList = null; if (isFilePath) { // Gets the reference sequence from the configuration file string filePath = this.utilityObj.xmlUtil.GetTextValue(nodeName, Constants.FilePathNode); Assert.IsNotNull(filePath); Assert.IsTrue(File.Exists(filePath)); IEnumerable<ISequence> referenceSeqs; FastAParser fastaParserObj = new FastAParser(); referenceSeqs = fastaParserObj.Parse(filePath); referenceSeq = referenceSeqs.FirstOrDefault(); Assert.IsNotNull(referenceSeq); // Gets the query sequence from the configuration file string queryFilePath = this.utilityObj.xmlUtil.GetTextValue(nodeName, Constants.SearchSequenceFilePathNode); Assert.IsNotNull(queryFilePath); Assert.IsTrue(File.Exists(queryFilePath)); querySeqs = fastaParserObj.Parse(queryFilePath).ToList(); ISequence querySeq = querySeqs.First(); if (isAlignList) { alignList = new List<ISequence> {referenceSeq, querySeq}; } } else { // Gets the reference sequence from the configuration file string referenceSequence = this.utilityObj.xmlUtil.GetTextValue(nodeName, Constants.SequenceNode); string referenceSeqAlphabet = this.utilityObj.xmlUtil.GetTextValue(nodeName, Constants.AlphabetNameNode); referenceSeq = new Sequence(Utility.GetAlphabet(referenceSeqAlphabet), referenceSequence); string querySequence = this.utilityObj.xmlUtil.GetTextValue(nodeName, Constants.SearchSequenceNode); referenceSeqAlphabet = this.utilityObj.xmlUtil.GetTextValue(nodeName, Constants.SearchSequenceAlphabetNode); ISequence querySeq = new Sequence(Utility.GetAlphabet(referenceSeqAlphabet), querySequence); querySeqs = new List<ISequence>(); if (isAlignList) { alignList = new List<ISequence> {referenceSeq, querySeq}; } else querySeqs.Add(querySeq); } // Setup the algorithm string mumLength = this.utilityObj.xmlUtil.GetTextValue(nodeName, Constants.MUMAlignLengthNode); MUMmerAligner mumAlignObj = new MUMmerAligner {LengthOfMUM = long.Parse(mumLength, null), StoreMUMs = true}; switch (addParam) { case AdditionalParameters.PerformSimilarityMatrixChange: mumAlignObj.SimilarityMatrix = new SimilarityMatrix(SimilarityMatrix.StandardSimilarityMatrix.Blosum50); mumAlignObj.GapOpenCost = int.Parse(this.utilityObj.xmlUtil.GetTextValue(nodeName, Constants.GapOpenCostNode), null); break; default: mumAlignObj.GapOpenCost = int.Parse(this.utilityObj.xmlUtil.GetTextValue(nodeName, Constants.GapOpenCostNode), null); break; } IEnumerable<ISequence> alignEnumSeqs = alignList; IList<IPairwiseSequenceAlignment> align = isAlignList ? mumAlignObj.AlignSimple(alignEnumSeqs) : mumAlignObj.AlignSimple(referenceSeq, querySeqs); // Validate MUMs Properties Assert.IsNotNull(mumAlignObj.MUMs); string expectedScore = this.utilityObj.xmlUtil.GetTextValue(nodeName, Constants.ScoreNodeName); string[] expectedSequences = this.utilityObj.xmlUtil.GetTextValues(nodeName, Constants.ExpectedSequencesNode); IList<IPairwiseSequenceAlignment> expectedOutput = new List<IPairwiseSequenceAlignment>(); // Validate for two aligned sequences and single aligned sequences appropriately if (querySeqs.Count <= 1) { IPairwiseSequenceAlignment seqAlign = new PairwiseSequenceAlignment(); PairwiseAlignedSequence alignedSeq = new PairwiseAlignedSequence { FirstSequence = new Sequence(referenceSeq.Alphabet, expectedSequences[0]), SecondSequence = new Sequence(referenceSeq.Alphabet, expectedSequences[1]), Score = Convert.ToInt32(expectedScore,null), FirstOffset = Int32.MinValue, SecondOffset = Int32.MinValue, }; seqAlign.PairwiseAlignedSequences.Add(alignedSeq); expectedOutput.Add(seqAlign); Assert.IsTrue(CompareAlignment(align, expectedOutput)); } else { string[] expectedScores = expectedScore.Split(','); IPairwiseSequenceAlignment seq1Align = new PairwiseSequenceAlignment(); IPairwiseSequenceAlignment seq2Align = new PairwiseSequenceAlignment(); // Get the first sequence for validation PairwiseAlignedSequence alignedSeq1 = new PairwiseAlignedSequence { FirstSequence = new Sequence(referenceSeq.Alphabet, expectedSequences[0]), SecondSequence = new Sequence(referenceSeq.Alphabet, expectedSequences[1]), Score = int.Parse(expectedScores[0], null), FirstOffset = Int32.MinValue, SecondOffset = Int32.MinValue, }; seq1Align.PairwiseAlignedSequences.Add(alignedSeq1); expectedOutput.Add(seq1Align); // Get the second sequence for validation PairwiseAlignedSequence alignedSeq2 = new PairwiseAlignedSequence { FirstSequence = new Sequence(referenceSeq.Alphabet, expectedSequences[2]), SecondSequence = new Sequence(referenceSeq.Alphabet, expectedSequences[3]), Score = int.Parse(expectedScores[1], null), FirstOffset = Int32.MinValue, SecondOffset = Int32.MinValue, }; seq2Align.PairwiseAlignedSequences.Add(alignedSeq2); expectedOutput.Add(seq2Align); Assert.IsTrue(CompareAlignment(align, expectedOutput)); } }