Beispiel #1
0
        public void SmithWatermanProteinSeqAffineGap()
        {
            IPairwiseSequenceAligner sw = new SmithWatermanAligner
            {
                SimilarityMatrix = new SimilarityMatrix(SimilarityMatrix.StandardSimilarityMatrix.Blosum62),
                GapOpenCost      = -8,
                GapExtensionCost = -1,
            };

            ISequence sequence1 = new Sequence(Alphabets.Protein, "HEAGAWGHEE");
            ISequence sequence2 = new Sequence(Alphabets.Protein, "PAWHEAE");
            IList <IPairwiseSequenceAlignment> result = sw.Align(sequence1, sequence2);

            AlignmentHelpers.LogResult(sw, result);

            IList <IPairwiseSequenceAlignment> expectedOutput = new List <IPairwiseSequenceAlignment>();
            IPairwiseSequenceAlignment         align          = new PairwiseSequenceAlignment();
            PairwiseAlignedSequence            alignedSeq     = new PairwiseAlignedSequence
            {
                FirstSequence  = new Sequence(Alphabets.Protein, "AWGHE"),
                SecondSequence = new Sequence(Alphabets.Protein, "AW-HE"),
                Consensus      = new Sequence(Alphabets.AmbiguousProtein, "AWGHE"),
                Score          = 20,
                FirstOffset    = 0,
                SecondOffset   = 3
            };

            align.PairwiseAlignedSequences.Add(alignedSeq);
            expectedOutput.Add(align);

            Assert.IsTrue(AlignmentHelpers.CompareAlignment(result, expectedOutput));
        }
Beispiel #2
0
        public void NeedlemanWunschDnaSeqSimpleGap()
        {
            IPairwiseSequenceAligner nw = new NeedlemanWunschAligner
            {
                SimilarityMatrix = new DiagonalSimilarityMatrix(2, -1),
                GapOpenCost      = -2
            };

            ISequence sequence1 = new Sequence(Alphabets.DNA, "GAATTCAGTTA");
            ISequence sequence2 = new Sequence(Alphabets.DNA, "GGATCGA");
            IList <IPairwiseSequenceAlignment> result = nw.AlignSimple(sequence1, sequence2);

            AlignmentHelpers.LogResult(nw, result);

            IList <IPairwiseSequenceAlignment> expectedOutput = new List <IPairwiseSequenceAlignment>();
            IPairwiseSequenceAlignment         align          = new PairwiseSequenceAlignment();

            align.PairwiseAlignedSequences.Add(new PairwiseAlignedSequence
            {
                FirstSequence  = new Sequence(Alphabets.DNA, "GAATTCAGTTA"),
                SecondSequence = new Sequence(Alphabets.DNA, "GGAT-C-G--A"),
                Consensus      = new Sequence(AmbiguousDnaAlphabet.Instance, "GRATTCAGTTA"),
                Score          = 3,
                FirstOffset    = 0,
                SecondOffset   = 0
            });
            expectedOutput.Add(align);

            Assert.IsTrue(AlignmentHelpers.CompareAlignment(result, expectedOutput));
        }
Beispiel #3
0
        public void NeedlemanWunschProteinSeqAffineGap()
        {
            IPairwiseSequenceAligner nw = new NeedlemanWunschAligner
            {
                SimilarityMatrix = new SimilarityMatrix(SimilarityMatrix.StandardSimilarityMatrix.Blosum62),
                GapOpenCost      = -8,
                GapExtensionCost = -1
            };

            ISequence sequence1 = new Sequence(Alphabets.Protein, "HEAGAWGHEE");
            ISequence sequence2 = new Sequence(Alphabets.Protein, "PAWHEAE");
            IList <IPairwiseSequenceAlignment> result = nw.Align(sequence1, sequence2);

            AlignmentHelpers.LogResult(nw, result);

            IList <IPairwiseSequenceAlignment> expectedOutput = new List <IPairwiseSequenceAlignment>();
            IPairwiseSequenceAlignment         align          = new PairwiseSequenceAlignment();

            align.PairwiseAlignedSequences.Add(new PairwiseAlignedSequence
            {
                FirstSequence  = new Sequence(Alphabets.Protein, "HEAGAWGHE-E"),
                SecondSequence = new Sequence(Alphabets.Protein, "P---AW-HEAE"),
                Consensus      = new Sequence(AmbiguousProteinAlphabet.Instance, "XEAGAWGHEAE"),
                Score          = 5,
                FirstOffset    = 0,
                SecondOffset   = 0
            });
            expectedOutput.Add(align);

            Assert.IsTrue(AlignmentHelpers.CompareAlignment(result, expectedOutput));
        }
Beispiel #4
0
        private void ValidateMUMmerAlignGeneralTestCases(string nodeName)
        {
            // Gets the reference sequence from the configuration file
            string filePath = utilityObj.xmlUtil.GetTextValue(nodeName, Constants.FilePathNode).TestDir();

            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).TestDir();

            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.");
        }
Beispiel #5
0
        public void TestNUCmer3SingleCluster()
        {
            string reference = "AGAAAAGTTTTCA";
            string search    = "TTTTGAGATAAAATC";

            Sequence         referenceSeq  = null;
            Sequence         searchSeq     = null;
            List <ISequence> referenceSeqs = null;
            List <ISequence> searchSeqs    = null;

            referenceSeq    = new Sequence(Alphabets.DNA, reference);
            referenceSeq.ID = "R1";

            searchSeq    = new Sequence(Alphabets.DNA, search);
            searchSeq.ID = "Q1";

            referenceSeqs = new List <ISequence>();
            referenceSeqs.Add(referenceSeq);

            searchSeqs = new List <ISequence>();
            searchSeqs.Add(searchSeq);

            NucmerPairwiseAligner nucmer = new NucmerPairwiseAligner();

            nucmer.FixedSeparation  = 0;
            nucmer.MinimumScore     = 2;
            nucmer.SeparationFactor = -1;
            nucmer.LengthOfMUM      = 3;
            nucmer.ForwardOnly      = true;
            IList <IPairwiseSequenceAlignment> result = nucmer.Align(referenceSeqs, searchSeqs).Select(a => a as IPairwiseSequenceAlignment).ToList();

            // 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, "AG--AAAA");
            alignedSeq.SecondSequence = new Sequence(Alphabets.DNA, "AGATAAAA");
            alignedSeq.Consensus      = new Sequence(Alphabets.DNA, "AGATAAAA");
            alignedSeq.Score          = -11;
            alignedSeq.FirstOffset    = 5;
            alignedSeq.SecondOffset   = 0;
            align.PairwiseAlignedSequences.Add(alignedSeq);
            alignedSeq = new PairwiseAlignedSequence();
            alignedSeq.FirstSequence  = new Sequence(Alphabets.DNA, "TTTT");
            alignedSeq.SecondSequence = new Sequence(Alphabets.DNA, "TTTT");
            alignedSeq.Consensus      = new Sequence(Alphabets.DNA, "TTTT");
            alignedSeq.Score          = 12;
            alignedSeq.FirstOffset    = 0;
            alignedSeq.SecondOffset   = 7;
            align.PairwiseAlignedSequences.Add(alignedSeq);
            expectedOutput.Add(align);
            Assert.IsTrue(AlignmentHelpers.CompareAlignment(result, expectedOutput));
        }
Beispiel #6
0
        public void SmithWatermanAlignerMultipleAlignments2()
        {
            IPairwiseSequenceAligner sw = new SmithWatermanAligner
            {
                SimilarityMatrix = new DiagonalSimilarityMatrix(5, -4),
                GapOpenCost      = -5
            };

            ISequence sequence1 = new Sequence(Alphabets.DNA, "AAAAGGGGGGCCCC");
            ISequence sequence2 = new Sequence(Alphabets.DNA, "AAAATTTTTTTCCCC");
            IList <IPairwiseSequenceAlignment> result = sw.AlignSimple(sequence1, sequence2);

            AlignmentHelpers.LogResult(sw, result);

            IList <IPairwiseSequenceAlignment> expectedOutput = new List <IPairwiseSequenceAlignment>();

            // First alignment
            IPairwiseSequenceAlignment align = new PairwiseSequenceAlignment(sequence1, sequence2);

            align.PairwiseAlignedSequences.Add(new PairwiseAlignedSequence
            {
                FirstSequence  = new Sequence(Alphabets.DNA, "AAAA"),
                SecondSequence = new Sequence(Alphabets.DNA, "AAAA"),
                Consensus      = new Sequence(Alphabets.DNA, "AAAA"),
                Score          = 20,
                FirstOffset    = 0,
                SecondOffset   = 0
            });

            // Second alignment
            align.PairwiseAlignedSequences.Add(new PairwiseAlignedSequence
            {
                FirstSequence  = new Sequence(Alphabets.DNA, "CCCC"),
                SecondSequence = new Sequence(Alphabets.DNA, "CCCC"),
                Consensus      = new Sequence(Alphabets.DNA, "CCCC"),
                Score          = 20,
                FirstOffset    = 1,
                SecondOffset   = 0
            });

            expectedOutput.Add(align);
            Assert.IsTrue(AlignmentHelpers.CompareAlignment(result, expectedOutput));
        }
Beispiel #7
0
        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-UUUU-------GG"),
                Consensus      = new Sequence(AmbiguousRnaAlphabet.Instance, "UAURCUUUUCCCCCCCGG"),
                Score          = -2,
                FirstOffset    = 1,
                SecondOffset   = 0
            });
            expectedOutput.Add(align);
            AlignmentHelpers.CompareAlignment(result, expectedOutput);
        }
Beispiel #8
0
        public void ValidatePairwiseAlignedSequenceCustomBreakLength()
        {
            var referenceSeqs = new List <ISequence>()
            {
                new Sequence(Alphabets.DNA, "CAAAAGGGATTGCAAATGTTGGAGTGAATGCCATTACCTACCGGCTAGGAGGAGT")
                {
                    ID = "R1"
                },
                new Sequence(Alphabets.DNA, "CCCCCCCCC")
                {
                    ID = "R2"
                },
                new Sequence(Alphabets.DNA, "TTTTT")
                {
                    ID = "R3"
                }
            };

            var searchSeqs = new List <ISequence>()
            {
                new Sequence(Alphabets.DNA, "CATTAATGATAAAGGGAAAGAAGTCCTCGTGCTATGGGGCATTCACCATCCATCTACTAGTGCTGACCAA")
                {
                    ID = "Q1"
                },
                new Sequence(Alphabets.DNA, "CAAAGTCTCTATCAGAATGCAGATGCAGATGTTTTTGTGGGGTCATCAAGATATAGCAAGAAGTTCAAGC")
                {
                    ID = "Q2"
                },
                new Sequence(Alphabets.DNA, "AAGCAAAATTAAACAGAGAAGAAATAGATGGGGTAAAGCTGGAATCAACAAGGATTTACCAGATTTTGGC")
                {
                    ID = "Q3"
                },
            };

            var nucmer = new NucmerPairwiseAligner
            {
                MaximumSeparation = 0,
                MinimumScore      = 2,
                SeparationFactor  = 0.12F,
                LengthOfMUM       = 5,
                BreakLength       = 2,
                ForwardOnly       = true,
            };

            var result = nucmer.Align(referenceSeqs, searchSeqs).Select(a => a as IPairwiseSequenceAlignment).ToList();

            // Check if output is not null
            Assert.AreNotEqual(null, result);

            var expectedOutput = new List <IPairwiseSequenceAlignment>();

            IPairwiseSequenceAlignment align = new PairwiseSequenceAlignment();

            align.PairwiseAlignedSequences.Add(new PairwiseAlignedSequence
            {
                FirstSequence  = new Sequence(Alphabets.DNA, "AAAGGGA"),
                SecondSequence = new Sequence(Alphabets.DNA, "AAAGGGA"),
                Consensus      = new Sequence(Alphabets.DNA, "AAAGGGA"),
                Score          = 21,
                FirstOffset    = 8,
                SecondOffset   = 0
            });
            align.PairwiseAlignedSequences.Add(new PairwiseAlignedSequence
            {
                FirstSequence  = new Sequence(Alphabets.DNA, "CATTA"),
                SecondSequence = new Sequence(Alphabets.DNA, "CATTA"),
                Consensus      = new Sequence(Alphabets.DNA, "CATTA"),
                Score          = 15,
                FirstOffset    = 0,
                SecondOffset   = 31
            });
            expectedOutput.Add(align);

            align = new PairwiseSequenceAlignment();
            align.PairwiseAlignedSequences.Add(new PairwiseAlignedSequence
            {
                FirstSequence  = new Sequence(Alphabets.DNA, "ATGTT"),
                SecondSequence = new Sequence(Alphabets.DNA, "ATGTT"),
                Consensus      = new Sequence(Alphabets.DNA, "ATGTT"),
                Score          = 15,
                FirstOffset    = 13,
                SecondOffset   = 0
            });
            align.PairwiseAlignedSequences.Add(new PairwiseAlignedSequence
            {
                FirstSequence  = new Sequence(Alphabets.DNA, "GAATGC"),
                SecondSequence = new Sequence(Alphabets.DNA, "GAATGC"),
                Consensus      = new Sequence(Alphabets.DNA, "GAATGC"),
                Score          = 18,
                FirstOffset    = 0,
                SecondOffset   = 11
            });
            align.PairwiseAlignedSequences.Add(new PairwiseAlignedSequence
            {
                FirstSequence  = new Sequence(Alphabets.DNA, "TTTTT"),
                SecondSequence = new Sequence(Alphabets.DNA, "TTTTT"),
                Consensus      = new Sequence(Alphabets.DNA, "TTTTT"),
                Score          = 15,
                FirstOffset    = 31,
                SecondOffset   = 0
            });
            expectedOutput.Add(align);

            align = new PairwiseSequenceAlignment();
            align.PairwiseAlignedSequences.Add(new PairwiseAlignedSequence
            {
                FirstSequence  = new Sequence(Alphabets.DNA, "CAAAA"),
                SecondSequence = new Sequence(Alphabets.DNA, "CAAAA"),
                Consensus      = new Sequence(Alphabets.DNA, "CAAAA"),
                Score          = 15,
                FirstOffset    = 3,
                SecondOffset   = 0
            });
            align.PairwiseAlignedSequences.Add(new PairwiseAlignedSequence
            {
                FirstSequence  = new Sequence(Alphabets.DNA, "GGATT"),
                SecondSequence = new Sequence(Alphabets.DNA, "GGATT"),
                Consensus      = new Sequence(Alphabets.DNA, "GGATT"),
                Score          = 15,
                FirstOffset    = 45,
                SecondOffset   = 0
            });
            align.PairwiseAlignedSequences.Add(new PairwiseAlignedSequence
            {
                FirstSequence  = new Sequence(Alphabets.DNA, "GCAAA"),
                SecondSequence = new Sequence(Alphabets.DNA, "GCAAA"),
                Consensus      = new Sequence(Alphabets.DNA, "GCAAA"),
                Score          = 15,
                FirstOffset    = 0,
                SecondOffset   = 9
            });
            align.PairwiseAlignedSequences.Add(new PairwiseAlignedSequence
            {
                FirstSequence  = new Sequence(Alphabets.DNA, "TTACC"),
                SecondSequence = new Sequence(Alphabets.DNA, "TTACC"),
                Consensus      = new Sequence(Alphabets.DNA, "TTACC"),
                Score          = 15,
                FirstOffset    = 22,
                SecondOffset   = 0
            });
            expectedOutput.Add(align);

            Assert.IsTrue(AlignmentHelpers.CompareAlignment(result, expectedOutput));

            ApplicationLog.WriteLine("PairwiseAlignedSequence P1: Successfully validated Sequence with Custom Break Length.");
        }
Beispiel #9
0
        public void ValidatePairwiseAlignedSequenceMultipleRefQuery()
        {
            var referenceSeqs = new List <ISequence>()
            {
                new Sequence(Alphabets.DNA, "ATGCGCATCCCC")
                {
                    ID = "R1"
                },
                new Sequence(Alphabets.DNA, "TAGCT")
                {
                    ID = "R2"
                }
            };

            var searchSeqs = new List <ISequence>()
            {
                new Sequence(Alphabets.DNA, "CCGCGCCCCCTC")
                {
                    ID = "Q1"
                },
                new Sequence(Alphabets.DNA, "AGCT")
                {
                    ID = "Q2"
                }
            };

            var nucmer = new NucmerPairwiseAligner
            {
                FixedSeparation  = 0,
                MinimumScore     = 2,
                SeparationFactor = -1,
                LengthOfMUM      = 3,
                ForwardOnly      = true,
            };

            IList <IPairwiseSequenceAlignment> result = nucmer.Align(referenceSeqs, searchSeqs).Select(a => a as IPairwiseSequenceAlignment).ToList();

            // Check if output is not null
            Assert.AreNotEqual(null, result);

            IList <IPairwiseSequenceAlignment> expectedOutput = new List <IPairwiseSequenceAlignment>();
            IPairwiseSequenceAlignment         align          = new PairwiseSequenceAlignment();
            var alignedSeq = new PairwiseAlignedSequence
            {
                FirstSequence  = new Sequence(Alphabets.DNA, "GCGCATCCCC"),
                SecondSequence = new Sequence(Alphabets.DNA, "GCGC--CCCC"),
                Consensus      = new Sequence(Alphabets.DNA, "GCGCATCCCC"),
                Score          = -5,
                FirstOffset    = 0,
                SecondOffset   = 0
            };

            align.PairwiseAlignedSequences.Add(alignedSeq);
            expectedOutput.Add(align);

            align      = new PairwiseSequenceAlignment();
            alignedSeq = new PairwiseAlignedSequence
            {
                FirstSequence  = new Sequence(Alphabets.DNA, "AGCT"),
                SecondSequence = new Sequence(Alphabets.DNA, "AGCT"),
                Consensus      = new Sequence(Alphabets.DNA, "AGCT"),
                Score          = 12,
                FirstOffset    = 0,
                SecondOffset   = 1
            };
            align.PairwiseAlignedSequences.Add(alignedSeq);
            expectedOutput.Add(align);

            Assert.IsTrue(AlignmentHelpers.CompareAlignment(result, expectedOutput));
            ApplicationLog.WriteLine("PairwiseAlignedSequence P1: Successfully validated Sequence with Multiple Reference.");
        }
        /// <summary>
        ///     Validates PairwiseOverlapAlignment algorithm for the parameters passed.
        /// </summary>
        /// <param name="isTextFile">Is text file an input.</param>
        /// <param name="alignParam">parameter based on which certain validations are done.</param>
        /// <param name="alignType">Is the Align type Simple or Align with Gap Extension cost?</param>
        private void ValidatePairwiseOverlapAlignment(bool isTextFile, AlignmentParamType alignParam, AlignmentType alignType)
        {
            ISequence aInput;
            ISequence bInput;

            IAlphabet alphabet = Utility.GetAlphabet(this.utilityObj.xmlUtil.GetTextValue(Constants.PairwiseOverlapAlignAlgorithmNodeName, Constants.AlphabetNameNode));

            if (isTextFile)
            {
                // Read the xml file for getting both the files for aligning.
                string filePath1 = this.utilityObj.xmlUtil.GetTextValue(Constants.PairwiseOverlapAlignAlgorithmNodeName, Constants.FilePathNode1).TestDir();
                string filePath2 = this.utilityObj.xmlUtil.GetTextValue(Constants.PairwiseOverlapAlignAlgorithmNodeName, Constants.FilePathNode2).TestDir();

                //Parse the files and get the sequence.
                var parser = new FastAParser {
                    Alphabet = alphabet
                };
                aInput = parser.Parse(filePath1).ElementAt(0);
                bInput = parser.Parse(filePath2).ElementAt(0);
            }
            else
            {
                // Read the xml file for getting both the files for aligning.
                string origSequence1 = this.utilityObj.xmlUtil.GetTextValue(Constants.PairwiseOverlapAlignAlgorithmNodeName, Constants.SequenceNode1);
                string origSequence2 = this.utilityObj.xmlUtil.GetTextValue(Constants.PairwiseOverlapAlignAlgorithmNodeName, Constants.SequenceNode2);
                aInput = new Sequence(alphabet, origSequence1);
                bInput = new Sequence(alphabet, origSequence2);
            }

            var aInputString = aInput.ConvertToString();
            var bInputString = bInput.ConvertToString();

            ApplicationLog.WriteLine($"PairwiseOverlapAligner BVT : First sequence used is '{aInputString}'.");
            ApplicationLog.WriteLine($"PairwiseOverlapAligner BVT : Second sequence used is '{bInputString}'.");

            string blosumFilePath = this.utilityObj.xmlUtil.GetTextValue(Constants.PairwiseOverlapAlignAlgorithmNodeName, Constants.BlosumFilePathNode).TestDir();

            var sm               = new SimilarityMatrix(new StreamReader(blosumFilePath));
            int gapOpenCost      = int.Parse(this.utilityObj.xmlUtil.GetTextValue(Constants.PairwiseOverlapAlignAlgorithmNodeName, Constants.GapOpenCostNode), null);
            int gapExtensionCost = int.Parse(this.utilityObj.xmlUtil.GetTextValue(Constants.PairwiseOverlapAlignAlgorithmNodeName, Constants.GapExtensionCostNode), null);

            var pairwiseOverlapObj = new PairwiseOverlapAligner();

            if (AlignmentParamType.AllParam != alignParam)
            {
                pairwiseOverlapObj.SimilarityMatrix = sm;
                pairwiseOverlapObj.GapOpenCost      = gapOpenCost;
            }

            IList <IPairwiseSequenceAlignment> result = null;

            switch (alignParam)
            {
            case AlignmentParamType.AlignList:
                var sequences = new List <ISequence> {
                    aInput, bInput
                };
                switch (alignType)
                {
                case AlignmentType.Align:
                    result = pairwiseOverlapObj.Align(sequences);
                    break;

                default:
                    result = pairwiseOverlapObj.AlignSimple(sequences);
                    break;
                }
                break;

            case AlignmentParamType.AlignTwo:
                switch (alignType)
                {
                case AlignmentType.Align:
                    result = pairwiseOverlapObj.Align(aInput, bInput);
                    break;

                default:
                    result = pairwiseOverlapObj.AlignSimple(aInput, bInput);
                    break;
                }
                break;

            case AlignmentParamType.AllParam:
                switch (alignType)
                {
                case AlignmentType.Align:
                    result = pairwiseOverlapObj.Align(sm, gapOpenCost,
                                                      gapExtensionCost, aInput, bInput);
                    break;

                default:
                    result = pairwiseOverlapObj.AlignSimple(sm, gapOpenCost, aInput, bInput);
                    break;
                }
                break;

            default:
                break;
            }

            // Read the xml file for getting both the files for aligning.
            string expectedSequence1;
            string expectedSequence2;
            string expectedScore;

            switch (alignType)
            {
            case AlignmentType.Align:
                expectedScore     = this.utilityObj.xmlUtil.GetTextValue(Constants.PairwiseOverlapAlignAlgorithmNodeName, Constants.ExpectedGapExtensionScoreNode);
                expectedSequence1 = this.utilityObj.xmlUtil.GetTextValue(Constants.PairwiseOverlapAlignAlgorithmNodeName, Constants.ExpectedGapExtensionSequence1Node);
                expectedSequence2 = this.utilityObj.xmlUtil.GetTextValue(Constants.PairwiseOverlapAlignAlgorithmNodeName, Constants.ExpectedGapExtensionSequence2Node);
                break;

            default:
                expectedScore     = this.utilityObj.xmlUtil.GetTextValue(Constants.PairwiseOverlapAlignAlgorithmNodeName, Constants.ExpectedScoreNode);
                expectedSequence1 = this.utilityObj.xmlUtil.GetTextValue(Constants.PairwiseOverlapAlignAlgorithmNodeName, Constants.ExpectedSequenceNode1);
                expectedSequence2 = this.utilityObj.xmlUtil.GetTextValue(Constants.PairwiseOverlapAlignAlgorithmNodeName, Constants.ExpectedSequenceNode2);
                break;
            }

            IList <IPairwiseSequenceAlignment> expectedOutput = new List <IPairwiseSequenceAlignment>();
            var seperators = new[] { ';' };

            string[] expectedSequences1 = expectedSequence1.Split(seperators);
            string[] expectedSequences2 = expectedSequence2.Split(seperators);

            IPairwiseSequenceAlignment align = new PairwiseSequenceAlignment();

            for (int i = 0; i < expectedSequences1.Length; i++)
            {
                PairwiseAlignedSequence alignedSeq = new PairwiseAlignedSequence
                {
                    FirstSequence  = new Sequence(alphabet, expectedSequences1[i]),
                    SecondSequence = new Sequence(alphabet, expectedSequences2[i]),
                    Score          = Convert.ToInt32(expectedScore, null)
                };
                align.PairwiseAlignedSequences.Add(alignedSeq);
            }

            expectedOutput.Add(align);
            Assert.IsTrue(AlignmentHelpers.CompareAlignment(result, expectedOutput));

            ApplicationLog.WriteLine(string.Format(null, "PairwiseOverlapAligner BVT : Final Score '{0}'.", expectedScore));
            ApplicationLog.WriteLine(string.Format(null, "PairwiseOverlapAligner BVT : Aligned First Sequence is '{0}'.", expectedSequence1));
            ApplicationLog.WriteLine(string.Format(null, "PairwiseOverlapAligner BVT : Aligned Second Sequence is '{0}'.", expectedSequence2));
        }
Beispiel #11
0
 /// <summary>
 ///     Compare the alignment of mummer and defined alignment
 /// </summary>
 /// <param name="actualAlignment"></param>
 /// <param name="expectedAlignment">expected output</param>
 /// <returns>Compare result of alignments</returns>
 private static bool CompareAlignment(IList <IPairwiseSequenceAlignment> actualAlignment,
                                      IList <IPairwiseSequenceAlignment> expectedAlignment)
 {
     return(AlignmentHelpers.CompareAlignment(actualAlignment, expectedAlignment));
 }
Beispiel #12
0
        public void TestNUCmer3CustomBreakLength()
        {
            Sequence         referenceSeq  = null;
            Sequence         searchSeq     = null;
            List <ISequence> referenceSeqs = null;
            List <ISequence> searchSeqs    = null;

            referenceSeqs = new List <ISequence>();

            string reference = "CAAAAGGGATTGCAAATGTTGGAGTGAATGCCATTACCTACCGGCTAGGAGGAGT";

            referenceSeq    = new Sequence(Alphabets.DNA, reference);
            referenceSeq.ID = "R1";
            referenceSeqs.Add(referenceSeq);

            reference       = "CCCCCCCCC";
            referenceSeq    = new Sequence(Alphabets.DNA, reference);
            referenceSeq.ID = "R2";
            referenceSeqs.Add(referenceSeq);

            reference       = "TTTTT";
            referenceSeq    = new Sequence(Alphabets.DNA, reference);
            referenceSeq.ID = "R3";
            referenceSeqs.Add(referenceSeq);

            searchSeqs = new List <ISequence>();

            string search = "CATTAATGATAAAGGGAAAGAAGTCCTCGTGCTATGGGGCATTCACCATCCATCTACTAGTGCTGACCAA";

            searchSeq    = new Sequence(Alphabets.DNA, search);
            searchSeq.ID = "Q1";
            searchSeqs.Add(searchSeq);

            search       = "CAAAGTCTCTATCAGAATGCAGATGCAGATGTTTTTGTGGGGTCATCAAGATATAGCAAGAAGTTCAAGC";
            searchSeq    = new Sequence(Alphabets.DNA, search);
            searchSeq.ID = "Q2";
            searchSeqs.Add(searchSeq);

            search       = "AAGCAAAATTAAACAGAGAAGAAATAGATGGGGTAAAGCTGGAATCAACAAGGATTTACCAGATTTTGGC";
            searchSeq    = new Sequence(Alphabets.DNA, search);
            searchSeq.ID = "Q3";
            searchSeqs.Add(searchSeq);

            NucmerPairwiseAligner nucmer = new NucmerPairwiseAligner();

            nucmer.MaximumSeparation = 0;
            nucmer.MinimumScore      = 2;
            nucmer.SeparationFactor  = 0.12F;
            nucmer.LengthOfMUM       = 5;
            nucmer.BreakLength       = 2;
            nucmer.ForwardOnly       = true;
            IList <IPairwiseSequenceAlignment> result = nucmer.Align(referenceSeqs, searchSeqs).Select(a => a as IPairwiseSequenceAlignment).ToList();

            // Check if output is not null
            Assert.AreNotEqual(null, result);

            List <IPairwiseSequenceAlignment> expectedOutput = new List <IPairwiseSequenceAlignment>();
            IPairwiseSequenceAlignment        align          = new PairwiseSequenceAlignment();
            PairwiseAlignedSequence           alignedSeq     = new PairwiseAlignedSequence();

            alignedSeq.FirstSequence  = new Sequence(Alphabets.DNA, "AAAGGGA");
            alignedSeq.SecondSequence = new Sequence(Alphabets.DNA, "AAAGGGA");
            alignedSeq.Consensus      = new Sequence(Alphabets.DNA, "AAAGGGA");
            alignedSeq.Score          = 21;
            alignedSeq.FirstOffset    = 8;
            alignedSeq.SecondOffset   = 0;
            align.PairwiseAlignedSequences.Add(alignedSeq);
            alignedSeq = new PairwiseAlignedSequence();
            alignedSeq.FirstSequence  = new Sequence(Alphabets.DNA, "CATTA");
            alignedSeq.SecondSequence = new Sequence(Alphabets.DNA, "CATTA");
            alignedSeq.Consensus      = new Sequence(Alphabets.DNA, "CATTA");
            alignedSeq.Score          = 15;
            alignedSeq.FirstOffset    = 0;
            alignedSeq.SecondOffset   = 31;
            align.PairwiseAlignedSequences.Add(alignedSeq);
            expectedOutput.Add(align);

            align      = new PairwiseSequenceAlignment();
            alignedSeq = new PairwiseAlignedSequence();
            alignedSeq.FirstSequence  = new Sequence(Alphabets.DNA, "ATGTT");
            alignedSeq.SecondSequence = new Sequence(Alphabets.DNA, "ATGTT");
            alignedSeq.Consensus      = new Sequence(Alphabets.DNA, "ATGTT");
            alignedSeq.Score          = 15;
            alignedSeq.FirstOffset    = 13;
            alignedSeq.SecondOffset   = 0;
            align.PairwiseAlignedSequences.Add(alignedSeq);
            alignedSeq = new PairwiseAlignedSequence();
            alignedSeq.FirstSequence  = new Sequence(Alphabets.DNA, "GAATGC");
            alignedSeq.SecondSequence = new Sequence(Alphabets.DNA, "GAATGC");
            alignedSeq.Consensus      = new Sequence(Alphabets.DNA, "GAATGC");
            alignedSeq.Score          = 18;
            alignedSeq.FirstOffset    = 0;
            alignedSeq.SecondOffset   = 11;
            align.PairwiseAlignedSequences.Add(alignedSeq);
            alignedSeq = new PairwiseAlignedSequence();
            alignedSeq.FirstSequence  = new Sequence(Alphabets.DNA, "TTTTT");
            alignedSeq.SecondSequence = new Sequence(Alphabets.DNA, "TTTTT");
            alignedSeq.Consensus      = new Sequence(Alphabets.DNA, "TTTTT");
            alignedSeq.Score          = 15;
            alignedSeq.FirstOffset    = 31;
            alignedSeq.SecondOffset   = 0;
            align.PairwiseAlignedSequences.Add(alignedSeq);
            expectedOutput.Add(align);

            align      = new PairwiseSequenceAlignment();
            alignedSeq = new PairwiseAlignedSequence();
            alignedSeq.FirstSequence  = new Sequence(Alphabets.DNA, "CAAAA");
            alignedSeq.SecondSequence = new Sequence(Alphabets.DNA, "CAAAA");
            alignedSeq.Consensus      = new Sequence(Alphabets.DNA, "CAAAA");
            alignedSeq.Score          = 15;
            alignedSeq.FirstOffset    = 3;
            alignedSeq.SecondOffset   = 0;
            align.PairwiseAlignedSequences.Add(alignedSeq);
            alignedSeq = new PairwiseAlignedSequence();
            alignedSeq.FirstSequence  = new Sequence(Alphabets.DNA, "GGATT");
            alignedSeq.SecondSequence = new Sequence(Alphabets.DNA, "GGATT");
            alignedSeq.Consensus      = new Sequence(Alphabets.DNA, "GGATT");
            alignedSeq.Score          = 15;
            alignedSeq.FirstOffset    = 45;
            alignedSeq.SecondOffset   = 0;
            align.PairwiseAlignedSequences.Add(alignedSeq);
            alignedSeq = new PairwiseAlignedSequence();
            alignedSeq.FirstSequence  = new Sequence(Alphabets.DNA, "GCAAA");
            alignedSeq.SecondSequence = new Sequence(Alphabets.DNA, "GCAAA");
            alignedSeq.Consensus      = new Sequence(Alphabets.DNA, "GCAAA");
            alignedSeq.Score          = 15;
            alignedSeq.FirstOffset    = 0;
            alignedSeq.SecondOffset   = 9;
            align.PairwiseAlignedSequences.Add(alignedSeq);
            alignedSeq = new PairwiseAlignedSequence();
            alignedSeq.FirstSequence  = new Sequence(Alphabets.DNA, "TTACC");
            alignedSeq.SecondSequence = new Sequence(Alphabets.DNA, "TTACC");
            alignedSeq.Consensus      = new Sequence(Alphabets.DNA, "TTACC");
            alignedSeq.Score          = 15;
            alignedSeq.FirstOffset    = 22;
            alignedSeq.SecondOffset   = 0;
            align.PairwiseAlignedSequences.Add(alignedSeq);
            expectedOutput.Add(align);
            Assert.IsTrue(AlignmentHelpers.CompareAlignment(result, expectedOutput));
        }