public void TestNeedlemanWunschProfileAligner() { ISequence templateSequence = new Sequence(Alphabets.DNA, "ATGCSWRYKMBVHDN-"); Dictionary <ISequenceItem, int> itemSet = new Dictionary <ISequenceItem, int>(); for (int i = 0; i < templateSequence.Count; ++i) { itemSet.Add(templateSequence[i], i); } Profiles.ItemSet = itemSet; IProfileAligner profileAligner = new NeedlemanWunschProfileAligner(); SimilarityMatrix similarityMatrix = new SimilarityMatrix(SimilarityMatrix.StandardSimilarityMatrices.AmbiguousDna); int gapOpenPenalty = -8; int gapExtendPenalty = -1; profileAligner.SimilarityMatrix = similarityMatrix; profileAligner.GapOpenCost = gapOpenPenalty; profileAligner.GapExtensionCost = gapExtendPenalty; ISequence seqA = new Sequence(Alphabets.DNA, "GGGAAAAATCAGATT"); ISequence seqB = new Sequence(Alphabets.DNA, "GGGAATCAAAATCAG"); List <ISequence> sequences = new List <ISequence>(); sequences.Add(seqA); sequences.Add(seqB); IProfileAlignment profileAlignmentA = ProfileAlignment.GenerateProfileAlignment(sequences[0]); IProfileAlignment profileAlignmentB = ProfileAlignment.GenerateProfileAlignment(sequences[1]); profileAligner.Align(profileAlignmentA, profileAlignmentB); List <int> eStringSubtree = profileAligner.GenerateEString(profileAligner.AlignedA); List <int> eStringSubtreeB = profileAligner.GenerateEString(profileAligner.AlignedB); List <ISequence> alignedSequences = new List <ISequence>(); ISequence seq = profileAligner.GenerateSequenceFromEString(eStringSubtree, sequences[0]); alignedSequences.Add(seq); seq = profileAligner.GenerateSequenceFromEString(eStringSubtreeB, sequences[1]); alignedSequences.Add(seq); float profileScore = MsaUtils.MultipleAlignmentScoreFunction(alignedSequences, similarityMatrix, gapOpenPenalty, gapExtendPenalty); ISequence expectedSeqA = new Sequence(Alphabets.DNA, "GGGAA---AAATCAGATT"); ISequence expectedSeqB = new Sequence(Alphabets.DNA, "GGGAATCAAAATCAG---"); Assert.AreEqual(expectedSeqA.ToString(), alignedSequences[0].ToString()); Assert.AreEqual(expectedSeqB.ToString(), alignedSequences[1].ToString()); Assert.AreEqual(40, profileScore); }
public void TestProfile() { ISequence templateSequence = new Sequence(Alphabets.AmbiguousDNA, "ATGCSWRYKMBVHDN-"); Dictionary <byte, int> itemSet = new Dictionary <byte, int>(); for (int i = 0; i < templateSequence.Count; ++i) { itemSet.Add(templateSequence[i], i); if (char.IsLetter((char)templateSequence[i])) { itemSet.Add((byte)char.ToLower((char)templateSequence[i]), i); } } Profiles.ItemSet = itemSet; ISequence seqA = new Sequence(Alphabets.DNA, "GGGAAAAATCAGATT"); ISequence seqB = new Sequence(Alphabets.DNA, "GGGAATCAAAATCAG"); List <ISequence> sequences = new List <ISequence>(); sequences.Add(seqA); sequences.Add(seqB); // Test GenerateProfiles IProfiles profileA = Profiles.GenerateProfiles(sequences[0]); Assert.AreEqual(16, profileA.ColumnSize); Assert.AreEqual(sequences[0].Count, profileA.RowSize); // Test ProfileMatrix Assert.AreEqual(1, profileA.ProfilesMatrix[0][2]); Assert.AreEqual(0, profileA.ProfilesMatrix[0][3]); // Test ProfileAlignment IProfileAlignment profileAlignmentA = ProfileAlignment.GenerateProfileAlignment(sequences[0]); Assert.AreEqual(1, profileAlignmentA.ProfilesMatrix[0][2]); Assert.AreEqual(0, profileAlignmentA.ProfilesMatrix[0][3]); Assert.AreEqual(1, profileAlignmentA.NumberOfSequences); IProfileAlignment profileAlignmentB = ProfileAlignment.GenerateProfileAlignment(sequences); Assert.AreEqual(1, profileAlignmentB.ProfilesMatrix[0][2]); Assert.AreEqual(0, profileAlignmentB.ProfilesMatrix[0][3]); Assert.AreEqual(2, profileAlignmentB.NumberOfSequences); Assert.AreEqual(0.5, profileAlignmentB.ProfilesMatrix[5][0]); Assert.AreEqual(0.5, profileAlignmentB.ProfilesMatrix[5][1]); Assert.AreEqual(0, profileAlignmentB.ProfilesMatrix[5][2]); }
public void TestNeedlemanWunschProfileAligner() { Console.WriteLine("Number of logical processors: {0}", Environment.ProcessorCount); ISequence templateSequence = new Sequence(Alphabets.AmbiguousDNA, "ATGCSWRYKMBVHDN-"); Dictionary <byte, int> itemSet = new Dictionary <byte, int>(); for (int i = 0; i < templateSequence.Count; ++i) { itemSet.Add(templateSequence[i], i); if (char.IsLetter((char)templateSequence[i])) { itemSet.Add((byte)char.ToLower((char)templateSequence[i]), i); } } Profiles.ItemSet = itemSet; SimilarityMatrix similarityMatrix = new SimilarityMatrix(SimilarityMatrix.StandardSimilarityMatrix.AmbiguousDna); int gapOpenPenalty = -3; int gapExtendPenalty = -1; IProfileAligner profileAligner = new NeedlemanWunschProfileAlignerSerial(similarityMatrix, ProfileScoreFunctionNames.WeightedInnerProduct, gapOpenPenalty, gapExtendPenalty, Environment.ProcessorCount); ISequence seqA = new Sequence(Alphabets.DNA, "GGGAAAAATCAGATT"); ISequence seqB = new Sequence(Alphabets.DNA, "GGGAATCAAAATCAG"); List <ISequence> sequences = new List <ISequence>(); sequences.Add(seqA); sequences.Add(seqB); IProfileAlignment profileAlignmentA = ProfileAlignment.GenerateProfileAlignment(sequences[0]); IProfileAlignment profileAlignmentB = ProfileAlignment.GenerateProfileAlignment(sequences[1]); profileAligner.Align(profileAlignmentA, profileAlignmentB); List <int> eStringSubtree = profileAligner.GenerateEString(profileAligner.AlignedA); List <int> eStringSubtreeB = profileAligner.GenerateEString(profileAligner.AlignedB); List <ISequence> alignedSequences = new List <ISequence>(); ISequence seq = profileAligner.GenerateSequenceFromEString(eStringSubtree, sequences[0]); alignedSequences.Add(seq); seq = profileAligner.GenerateSequenceFromEString(eStringSubtreeB, sequences[1]); alignedSequences.Add(seq); float profileScore = MsaUtils.MultipleAlignmentScoreFunction(alignedSequences, similarityMatrix, gapOpenPenalty, gapExtendPenalty); Console.WriteLine("alignment score is: {0}", profileScore); Console.WriteLine("the aligned sequences are:"); for (int i = 0; i < alignedSequences.Count; ++i) { Console.WriteLine(new string(alignedSequences[i].Select(a => (char)a).ToArray())); } // Test on case 3: 36 sequences string filepath = @"\TestUtils\RV11_BBS_allSmall.afa"; string filePathObj = Directory.GetCurrentDirectory() + filepath; FastAParser parser = new FastAParser(filePathObj); IList <ISequence> orgSequences = parser.Parse().ToList(); sequences = MsaUtils.UnAlign(orgSequences); int numberOfSequences = orgSequences.Count; Console.WriteLine("Original unaligned sequences are:"); for (int i = 0; i < numberOfSequences; ++i) { Console.WriteLine(">"); Console.WriteLine(new string(sequences[i].Select(a => (char)a).ToArray())); } for (int i = 1; i < numberOfSequences - 1; ++i) { for (int j = i + 1; j < numberOfSequences; ++j) { profileAlignmentA = ProfileAlignment.GenerateProfileAlignment(sequences[i]); profileAlignmentB = ProfileAlignment.GenerateProfileAlignment(sequences[j]); profileAligner = new NeedlemanWunschProfileAlignerSerial(similarityMatrix, ProfileScoreFunctionNames.WeightedInnerProduct, gapOpenPenalty, gapExtendPenalty, Environment.ProcessorCount); profileAligner.Align(profileAlignmentA, profileAlignmentB); eStringSubtree = profileAligner.GenerateEString(profileAligner.AlignedA); eStringSubtreeB = profileAligner.GenerateEString(profileAligner.AlignedB); Console.WriteLine("Sequences lengths are: {0}-{1}", sequences[i].Count, sequences[j].Count); Console.WriteLine("estring 1:"); for (int k = 0; k < eStringSubtree.Count; ++k) { Console.Write("{0}\t", eStringSubtree[k]); } Console.WriteLine("\nestring 2:"); for (int k = 0; k < eStringSubtreeB.Count; ++k) { Console.Write("{0}\t", eStringSubtreeB[k]); } alignedSequences = new List <ISequence>(); seq = profileAligner.GenerateSequenceFromEString(eStringSubtree, sequences[i]); alignedSequences.Add(seq); seq = profileAligner.GenerateSequenceFromEString(eStringSubtreeB, sequences[j]); alignedSequences.Add(seq); profileScore = MsaUtils.MultipleAlignmentScoreFunction(alignedSequences, similarityMatrix, gapOpenPenalty, gapExtendPenalty); Console.WriteLine("\nalignment score is: {0}", profileScore); Console.WriteLine("the aligned sequences are:"); for (int k = 0; k < alignedSequences.Count; ++k) { Console.WriteLine(new string(alignedSequences[k].Select(a => (char)a).ToArray())); } } ((FastAParser)parser).Dispose(); } }
public void TestNeedlemanWunschProfileAligner() { Console.WriteLine("Number of logical processors: {0}", Environment.ProcessorCount); ISequence templateSequence = new Sequence(Alphabets.DNA, "ATGCSWRYKMBVHDN-"); Dictionary <ISequenceItem, int> itemSet = new Dictionary <ISequenceItem, int>(); for (int i = 0; i < templateSequence.Count; ++i) { itemSet.Add(templateSequence[i], i); } Profiles.ItemSet = itemSet; SimilarityMatrix similarityMatrix = new SimilarityMatrix(SimilarityMatrix.StandardSimilarityMatrix.AmbiguousDna); int gapOpenPenalty = -3; int gapExtendPenalty = -1; IProfileAligner profileAligner = new NeedlemanWunschProfileAlignerSerial(similarityMatrix, ProfileScoreFunctionNames.WeightedInnerProduct, gapOpenPenalty, gapExtendPenalty, Environment.ProcessorCount); ISequence seqA = new Sequence(Alphabets.DNA, "GGGAAAAATCAGATT"); ISequence seqB = new Sequence(Alphabets.DNA, "GGGAATCAAAATCAG"); List <ISequence> sequences = new List <ISequence>(); sequences.Add(seqA); sequences.Add(seqB); IProfileAlignment profileAlignmentA = ProfileAlignment.GenerateProfileAlignment(sequences[0]); IProfileAlignment profileAlignmentB = ProfileAlignment.GenerateProfileAlignment(sequences[1]); profileAligner.Align(profileAlignmentA, profileAlignmentB); List <int> eStringSubtree = profileAligner.GenerateEString(profileAligner.AlignedA); List <int> eStringSubtreeB = profileAligner.GenerateEString(profileAligner.AlignedB); List <ISequence> alignedSequences = new List <ISequence>(); ISequence seq = profileAligner.GenerateSequenceFromEString(eStringSubtree, sequences[0]); alignedSequences.Add(seq); seq = profileAligner.GenerateSequenceFromEString(eStringSubtreeB, sequences[1]); alignedSequences.Add(seq); float profileScore = MsaUtils.MultipleAlignmentScoreFunction(alignedSequences, similarityMatrix, gapOpenPenalty, gapExtendPenalty); Console.WriteLine("alignment score is: {0}", profileScore); Console.WriteLine("the aligned sequences are:"); for (int i = 0; i < alignedSequences.Count; ++i) { Console.WriteLine(alignedSequences[i].ToString()); } ISequence expectedSeqA = new Sequence(Alphabets.DNA, "GGGAA---AAATCAGATT"); ISequence expectedSeqB = new Sequence(Alphabets.DNA, "GGGAATCAAAATCAG---"); // Test on case 3: 36 sequences ISequenceParser parser = new FastaParser(); string filepath = @"testdata\FASTA\RV11_BBS_all.afa"; IList <ISequence> orgSequences = parser.Parse(filepath); sequences = MsaUtils.UnAlign(orgSequences); int numberOfSequences = orgSequences.Count; Console.WriteLine("Original unaligned sequences are:"); for (int i = 0; i < numberOfSequences; ++i) { Console.WriteLine(">"); Console.WriteLine(sequences[i].ToString()); } for (int i = 1; i < numberOfSequences - 1; ++i) { for (int j = i + 1; j < numberOfSequences; ++j) { profileAlignmentA = ProfileAlignment.GenerateProfileAlignment(sequences[i]); profileAlignmentB = ProfileAlignment.GenerateProfileAlignment(sequences[j]); profileAligner = new NeedlemanWunschProfileAlignerSerial(similarityMatrix, ProfileScoreFunctionNames.WeightedInnerProduct, gapOpenPenalty, gapExtendPenalty, Environment.ProcessorCount); profileAligner.Align(profileAlignmentA, profileAlignmentB); eStringSubtree = profileAligner.GenerateEString(profileAligner.AlignedA); eStringSubtreeB = profileAligner.GenerateEString(profileAligner.AlignedB); Console.WriteLine("Sequences lengths are: {0}-{1}", sequences[i].Count, sequences[j].Count); Console.WriteLine("estring 1:"); for (int k = 0; k < eStringSubtree.Count; ++k) { Console.Write("{0}\t", eStringSubtree[k]); } Console.WriteLine("\nestring 2:"); for (int k = 0; k < eStringSubtreeB.Count; ++k) { Console.Write("{0}\t", eStringSubtreeB[k]); } alignedSequences = new List <ISequence>(); seq = profileAligner.GenerateSequenceFromEString(eStringSubtree, sequences[i]); alignedSequences.Add(seq); seq = profileAligner.GenerateSequenceFromEString(eStringSubtreeB, sequences[j]); alignedSequences.Add(seq); profileScore = MsaUtils.MultipleAlignmentScoreFunction(alignedSequences, similarityMatrix, gapOpenPenalty, gapExtendPenalty); Console.WriteLine("\nalignment score is: {0}", profileScore); Console.WriteLine("the aligned sequences are:"); for (int k = 0; k < alignedSequences.Count; ++k) { Console.WriteLine(alignedSequences[k].ToString()); } } } }