Example #1
0
        /// <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;
        }
Example #2
0
        private void ValidateNUCmerAlignGeneralTestCases(string nodeName, bool isFilePath, bool isAlignList, AdditionalParameters addParam,
                                                         PropertyParameters propParam, bool isAmbiguous)
        {
            IList<ISequence> refSeqList = new List<ISequence>();
            IList<ISequence> searchSeqList = new List<ISequence>();

            if (isFilePath)
            {
                // Gets the reference sequence from the FastA file
                string filePath = this.utilityObj.xmlUtil.GetTextValue(nodeName, Constants.FilePathNode);

                Assert.IsNotNull(filePath);
                ApplicationLog.WriteLine(string.Format(null, "NUCmer P1 : Successfully validated the File Path '{0}'.", filePath));

                var fastaparserobj = new FastAParser();
                IEnumerable<ISequence> referenceSeqList = fastaparserobj.Parse(filePath);

                foreach (ISequence seq in referenceSeqList)
                {
                    refSeqList.Add(seq);
                }

                // Gets the query sequence from the FastA file
                string queryFilePath = this.utilityObj.xmlUtil.GetTextValue(nodeName, Constants.SearchSequenceFilePathNode);

                Assert.IsNotNull(queryFilePath);
                ApplicationLog.WriteLine(string.Format(null, "NUCmer P1 : Successfully validated the File Path '{0}'.", queryFilePath));

                var queryParserobj = new FastAParser();
                IEnumerable<ISequence> serSeqList = queryParserobj.Parse(queryFilePath);

                foreach (ISequence seq in serSeqList)
                {
                    searchSeqList.Add(seq);
                }
            }
            else
            {
                // Gets the reference & search sequences from the configuration file
                string[] referenceSequences = this.utilityObj.xmlUtil.GetTextValues(nodeName, Constants.ReferenceSequencesNode);
                string[] searchSequences = this.utilityObj.xmlUtil.GetTextValues(nodeName, Constants.SearchSequencesNode);

                IAlphabet seqAlphabet = Utility.GetAlphabet(this.utilityObj.xmlUtil.GetTextValue(nodeName, Constants.AlphabetNameNode));
                IAlphabet ambAlphabet = null;
                if (isAmbiguous)
                {
                    switch (seqAlphabet.Name.ToLower(CultureInfo.CurrentCulture))
                    {
                        case "dna":
                        case "ambiguousdna":
                            ambAlphabet = AmbiguousDnaAlphabet.Instance;
                            break;
                        case "rna":
                        case "ambiguousrna":
                            ambAlphabet = AmbiguousRnaAlphabet.Instance;
                            break;
                        case "protein":
                        case "ambiguousprotein":
                            ambAlphabet = AmbiguousProteinAlphabet.Instance;
                            break;
                        default:
                            break;
                    }
                }
                else
                {
                    ambAlphabet = seqAlphabet;
                }

                for (int i = 0; i < referenceSequences.Length; i++)
                {
                    ISequence referSeq = new Sequence(ambAlphabet,
                                                      Encoding.ASCII.GetBytes(referenceSequences[i]));
                    referSeq.ID = "ref " + i;
                    refSeqList.Add(referSeq);
                }

                for (int i = 0; i < searchSequences.Length; i++)
                {
                    ISequence searchSeq = new Sequence(ambAlphabet,
                                                       Encoding.ASCII.GetBytes(searchSequences[i]));
                    searchSeq.ID = "qry " + i;
                    searchSeqList.Add(searchSeq);
                }
            }
            // Gets the mum length from the xml
            string mumLength = this.utilityObj.xmlUtil.GetTextValue(nodeName, Constants.MUMAlignLengthNode);

            var nucmerObj = new NucmerPairwiseAligner();
            // Check for additional parameters and update the object accordingly
            switch (addParam)
            {
                case AdditionalParameters.AlignSimilarityMatrix:
                    nucmerObj.SimilarityMatrix = new SimilarityMatrix(SimilarityMatrix.StandardSimilarityMatrix.Blosum50);
                    break;
                default:
                    break;
            }
            // Update other values for NUCmer object
            nucmerObj.MaximumSeparation = 0;
            nucmerObj.MinimumScore = 2;
            nucmerObj.SeparationFactor = 0.12f;
            nucmerObj.BreakLength = 2;
            nucmerObj.LengthOfMUM = long.Parse(mumLength, null);

            switch (propParam)
            {
                case PropertyParameters.MinimumScore:
                    nucmerObj.MinimumScore = int.Parse(
                        this.utilityObj.xmlUtil.GetTextValue(nodeName, Constants.MinimumScoreNode), null);
                    break;
                case PropertyParameters.MaximumSeparation:
                    nucmerObj.MaximumSeparation = int.Parse(
                        this.utilityObj.xmlUtil.GetTextValue(nodeName, Constants.MaximumSeparationNode), null);
                    break;
                case PropertyParameters.FixedSeparation:
                    nucmerObj.FixedSeparation = int.Parse(
                        this.utilityObj.xmlUtil.GetTextValue(nodeName, Constants.FixedSeparationNode), null);
                    break;
                case PropertyParameters.SeparationFactor:
                    nucmerObj.SeparationFactor = int.Parse(
                        this.utilityObj.xmlUtil.GetTextValue(nodeName, Constants.SeparationFactorNode), null);
                    break;
                case PropertyParameters.FixedSeparationAndSeparationFactor:
                    nucmerObj.SeparationFactor = int.Parse(
                        this.utilityObj.xmlUtil.GetTextValue(nodeName, Constants.SeparationFactorNode), null);
                    nucmerObj.FixedSeparation = int.Parse(
                        this.utilityObj.xmlUtil.GetTextValue(nodeName, Constants.FixedSeparationNode), null);
                    break;
                case PropertyParameters.MaximumFixedAndSeparationFactor:
                    nucmerObj.MaximumSeparation = int.Parse(
                        this.utilityObj.xmlUtil.GetTextValue(nodeName, Constants.MaximumSeparationNode), null);
                    nucmerObj.SeparationFactor = int.Parse(
                        this.utilityObj.xmlUtil.GetTextValue(nodeName, Constants.SeparationFactorNode), null);
                    nucmerObj.FixedSeparation = int.Parse(
                        this.utilityObj.xmlUtil.GetTextValue(nodeName, Constants.FixedSeparationNode), null);
                    break;
                default:
                    break;
            }

            IList<ISequenceAlignment> align = null;

            if (isAlignList)
            {
                var listOfSeq = new List<ISequence> {refSeqList.ElementAt(0), searchSeqList.ElementAt(0)};
                align = nucmerObj.Align(listOfSeq);
            }
            else
            {
                align = nucmerObj.Align(refSeqList, searchSeqList);
            }

            string expectedSequences = isFilePath
                    ? this.utilityObj.xmlUtil.GetFileTextValue(nodeName, Constants.ExpectedSequencesNode)
                    : this.utilityObj.xmlUtil.GetTextValue(nodeName, Constants.ExpectedSequencesNode);
            string[] expSeqArray = expectedSequences.Split(',');

            // Gets all the aligned sequences in comma separated format
            foreach (IPairwiseSequenceAlignment seqAlignment in align)
            {
                foreach (PairwiseAlignedSequence alignedSeq in seqAlignment)
                {
                    var actualStr = alignedSeq.FirstSequence.ConvertToString();
                    Assert.IsTrue(expSeqArray.Contains(actualStr));

                    actualStr = alignedSeq.SecondSequence.ConvertToString();
                    Assert.IsTrue(expSeqArray.Contains(actualStr));
                }
            }

            ApplicationLog.WriteLine("NUCmer P1 : Successfully validated all the aligned sequences.");
        }
Example #3
0
        public void TestNUCmer3CustomBreakLength()
        {
            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" },
            };

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

        }
Example #4
0
        public void TestNUCmer3MultipleReferencesAndQueries()
        {
            Sequence referenceSeq = null;
            Sequence searchSeq = null;
            List<ISequence> referenceSeqs = null;
            List<ISequence> searchSeqs = null;

            referenceSeqs = new List<ISequence>();

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

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

            searchSeqs = new List<ISequence>();

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

            search = "AGCT";
            searchSeq = new Sequence(Alphabets.DNA, search);
            searchSeq.ID = "Q11";
            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, "GCGCATCCCC");
            alignedSeq.SecondSequence = new Sequence(Alphabets.DNA, "GCGC--CCCC");
            alignedSeq.Consensus = new Sequence(Alphabets.DNA, "GCGCATCCCC");
            alignedSeq.Score = -5;
            alignedSeq.FirstOffset = 0;
            alignedSeq.SecondOffset = 0;
            align.PairwiseAlignedSequences.Add(alignedSeq);
            expectedOutput.Add(align);
            align = new PairwiseSequenceAlignment();
            alignedSeq = new PairwiseAlignedSequence();
            alignedSeq.FirstSequence = new Sequence(Alphabets.DNA, "AGCT");
            alignedSeq.SecondSequence = new Sequence(Alphabets.DNA, "AGCT");
            alignedSeq.Consensus = new Sequence(Alphabets.DNA, "AGCT");
            alignedSeq.Score = 12;
            alignedSeq.FirstOffset = 0;
            alignedSeq.SecondOffset = 1;
            align.PairwiseAlignedSequences.Add(alignedSeq);
            expectedOutput.Add(align);
            Assert.IsTrue(AlignmentHelpers.CompareAlignment(result, expectedOutput));
        }
Example #5
0
        public void NUCmerAlignGreaterMumLength()
        {
            // Gets the reference & search sequences from the configuration file
            string[] referenceSequences = this.utilityObj.xmlUtil.GetTextValues(Constants.GreaterMumLengthSequence, Constants.ReferenceSequencesNode);
            string[] searchSequences = this.utilityObj.xmlUtil.GetTextValues(Constants.GreaterMumLengthSequence, Constants.SearchSequencesNode);
            IAlphabet seqAlphabet = Utility.GetAlphabet(this.utilityObj.xmlUtil.GetTextValue(Constants.GreaterMumLengthSequence, Constants.AlphabetNameNode));

            var refSeqList = referenceSequences.Select(t => new Sequence(seqAlphabet, Encoding.ASCII.GetBytes(t))).Cast<ISequence>().ToList();
            var searchSeqList = searchSequences.Select(t => new Sequence(seqAlphabet, Encoding.ASCII.GetBytes(t))).Cast<ISequence>().ToList();
            string mumLength = this.utilityObj.xmlUtil.GetTextValue(Constants.GreaterMumLengthSequence, Constants.MUMLengthNode);

            var nucmerObj = new NucmerPairwiseAligner
            {
                MaximumSeparation = 0,
                SeparationFactor = 0.12f,
                BreakLength = 2,
                LengthOfMUM = long.Parse(mumLength, null),
                MinimumScore = int.Parse(this.utilityObj.xmlUtil.GetTextValue(Constants.GreaterMumLengthSequence, Constants.MinimumScoreNode), null)
            };

            IList<ISequenceAlignment> seqAlign = nucmerObj.Align(refSeqList, searchSeqList);
            Assert.AreEqual(0, seqAlign.Count);
        }
Example #6
0
        /// <summary>
        ///     Validates the NUCmer align method for several test cases for the parameters passed.
        /// </summary>
        /// <param name="nodeName">Node name to be read from xml</param>
        private void ValidateNUCmerAlignSimpleGeneralTestCases(string nodeName)
        {
            // Gets the reference & search sequences from the configuration file
            string[] referenceSequences = this.utilityObj.xmlUtil.GetTextValues(nodeName, Constants.ReferenceSequencesNode);
            string[] searchSequences = this.utilityObj.xmlUtil.GetTextValues(nodeName, Constants.SearchSequencesNode);

            IAlphabet seqAlphabet = Utility.GetAlphabet(this.utilityObj.xmlUtil.GetTextValue(nodeName, Constants.AlphabetNameNode));
            var refSeqList = referenceSequences.Select(t => new Sequence(seqAlphabet, Encoding.ASCII.GetBytes(t))).Cast<ISequence>().ToList();
            var searchSeqList = searchSequences.Select(t => new Sequence(seqAlphabet, Encoding.ASCII.GetBytes(t))).Cast<ISequence>().ToList();

            // Gets the mum length from the xml
            string mumLength = this.utilityObj.xmlUtil.GetTextValue(nodeName, Constants.MUMAlignLengthNode);

            var nucmerObj = new NucmerPairwiseAligner
            {
                MaximumSeparation = int.Parse(this.utilityObj.xmlUtil.GetTextValue(nodeName, Constants.MUMAlignLengthNode), null),
                MinimumScore = int.Parse(this.utilityObj.xmlUtil.GetTextValue(nodeName, Constants.MUMAlignLengthNode), null),
                SeparationFactor = int.Parse(this.utilityObj.xmlUtil.GetTextValue(nodeName, Constants.MUMAlignLengthNode), null),
                BreakLength = int.Parse(this.utilityObj.xmlUtil.GetTextValue(nodeName, Constants.MUMAlignLengthNode), null),
                LengthOfMUM = long.Parse(mumLength, null)
            };

            IList<ISequence> seqList = refSeqList.ToList();

            foreach (ISequence seq in searchSeqList)
            {
                seqList.Add(seq);
            }

            IList<ISequenceAlignment> alignSimple = nucmerObj.AlignSimple(seqList);
            string expectedSequences = this.utilityObj.xmlUtil.GetTextValue(nodeName, Constants.ExpectedSequencesNode);
            string[] expSeqArray = expectedSequences.Split(',');

            int j = 0;

            // Gets all the aligned sequences in comma separated format
            foreach (PairwiseAlignedSequence alignedSeq in alignSimple.Cast<IPairwiseSequenceAlignment>().SelectMany(seqAlignment => seqAlignment))
            {
                Assert.AreEqual(expSeqArray[j], alignedSeq.FirstSequence.ConvertToString());
                ++j;
                Assert.AreEqual(expSeqArray[j], alignedSeq.SecondSequence.ConvertToString());
                j++;
            }

            ApplicationLog.WriteLine("NUCmer P2 : Successfully validated all the aligned sequences.");
        }
Example #7
0
        /// <summary>
        ///     Validates the NUCmer align method for several test cases for the parameters passed.
        /// </summary>
        /// <param name="nodeName">Node name to be read from xml</param>
        private void ValidateNUCmerAlignGeneralTestCases(string nodeName)
        {
            // Gets the reference & search sequences from the configuration file
            string[] referenceSequences = this.utilityObj.xmlUtil.GetTextValues(nodeName, Constants.ReferenceSequencesNode);
            string[] searchSequences = this.utilityObj.xmlUtil.GetTextValues(nodeName, Constants.SearchSequencesNode);
            IAlphabet seqAlphabet = Utility.GetAlphabet(this.utilityObj.xmlUtil.GetTextValue(nodeName, Constants.AlphabetNameNode));

            var refSeqList = referenceSequences.Select(t => new Sequence(seqAlphabet, Encoding.ASCII.GetBytes(t))).Cast<ISequence>().ToList();
            var searchSeqList = searchSequences.Select(t => new Sequence(seqAlphabet, Encoding.ASCII.GetBytes(t))).Cast<ISequence>().ToList();

            var nucmerObj = new NucmerPairwiseAligner();
            string mumLength = this.utilityObj.xmlUtil.GetTextValue(nodeName, Constants.MUMLengthNode);

            // Update other values for NUCmer object
            nucmerObj.MaximumSeparation = 0;
            nucmerObj.MinimumScore = 2;
            nucmerObj.SeparationFactor = 0.12f;
            nucmerObj.BreakLength = 2;
            nucmerObj.LengthOfMUM = long.Parse(mumLength, null);
            nucmerObj.MinimumScore = int.Parse(this.utilityObj.xmlUtil.GetTextValue(nodeName,
                                                                               Constants.MinimumScoreNode), null);

            try
            {
                nucmerObj.Align(refSeqList, searchSeqList);
                Assert.Fail("Expected Exception: ArgumentException");
            }
            catch (ArgumentException)
            {
            }
        }
        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.");
        }
Example #9
0
        public void ValidateAlignedSequenceToString()
        {
            IList<ISequence> seqList = new List<ISequence>();
            string actualAlignedSeqString = this.utilityObj.xmlUtil.GetTextValue(Constants.ToStringNodeName,
                                                                            Constants.AlignedSeqActualNode);
            seqList.Add(new Sequence(Alphabets.DNA,
                                     actualAlignedSeqString));
            seqList.Add(new Sequence(Alphabets.DNA, "CAAAAGGGATTGC---"));
            seqList.Add(new Sequence(Alphabets.DNA, "TAGTAGTTCTGCTATATACATTTG"));
            seqList.Add(new Sequence(Alphabets.DNA, "GTTATCATGCGAACAATTCAACAGACACTGTAGA"));
            var num = new NucmerPairwiseAligner();
            num.BreakLength = 8;
            num.FixedSeparation = 0;
            num.MinimumScore = 0;
            num.MaximumSeparation = 0;
            num.SeparationFactor = 0;
            num.LengthOfMUM = 8;
            IList<ISequence> sequenceList = seqList;
            IList<ISequenceAlignment> alignmentObj = num.Align(sequenceList);
            var alignedSeqs = (AlignedSequence) alignmentObj[0].AlignedSequences[0];

            string actualString = alignedSeqs.ToString();
            string expectedString = this.utilityObj.xmlUtil.GetTextValue(Constants.ToStringNodeName,
                                                                    Constants.AlignedSeqExpectedNode);
            Assert.AreEqual(actualString, expectedString.Replace("\\r\\n", System.Environment.NewLine));
        }
Example #10
0
        /// <summary>
        /// Validates the NUCmer align method for several test cases for the parameters passed.
        /// </summary>
        /// <param name="nodeName">Node name to be read from xml</param>
        /// <param name="isAlignList">Is align method to take list?</param>
        void ValidateNUCmerAlignSimpleGeneralTestCases(string nodeName,
            bool isAlignList)
        {
            string[] referenceSequences = null;
            string[] searchSequences = null;
            List<ISequence> refSeqList = new List<ISequence>();
            List<ISequence> searchSeqList = new List<ISequence>();

            // Gets the reference & search sequences from the configurtion file
            referenceSequences = this.utilityObj.xmlUtil.GetTextValues(nodeName,
                Constants.ReferenceSequencesNode);
            searchSequences = this.utilityObj.xmlUtil.GetTextValues(nodeName,
              Constants.SearchSequencesNode);

            IAlphabet seqAlphabet = Utility.GetAlphabet(
                this.utilityObj.xmlUtil.GetTextValue(nodeName,
                Constants.AlphabetNameNode));

            for (int i = 0; i < referenceSequences.Length; i++)
            {
                ISequence referSeq = new Sequence(seqAlphabet,
                    this.encodingObj.GetBytes(referenceSequences[i]));
                refSeqList.Add(referSeq);
            }

            for (int i = 0; i < searchSequences.Length; i++)
            {
                ISequence searchSeq = new Sequence(seqAlphabet,
                    this.encodingObj.GetBytes(searchSequences[i]));
                searchSeqList.Add(searchSeq);
            }

            // Gets the mum length from the xml
            string mumLength = this.utilityObj.xmlUtil.GetTextValue(nodeName,
                Constants.MUMAlignLengthNode);

            NucmerPairwiseAligner nucmerObj = new NucmerPairwiseAligner();

            // Update other values for NUCmer object
            nucmerObj.MaximumSeparation = int.Parse
                (this.utilityObj.xmlUtil.GetTextValue(nodeName, Constants.MUMAlignLengthNode), (IFormatProvider)null);
            nucmerObj.MinimumScore = int.Parse(
                this.utilityObj.xmlUtil.GetTextValue(nodeName, Constants.MUMAlignLengthNode), (IFormatProvider)null);
            nucmerObj.SeparationFactor = int.Parse(
                this.utilityObj.xmlUtil.GetTextValue(nodeName, Constants.MUMAlignLengthNode), (IFormatProvider)null);
            nucmerObj.BreakLength = int.Parse(
                this.utilityObj.xmlUtil.GetTextValue(nodeName, Constants.MUMAlignLengthNode), (IFormatProvider)null);
            nucmerObj.LengthOfMUM = long.Parse(mumLength, null);

            IList<ISequenceAlignment> alignSimple = null;

            if (isAlignList)
            {
                List<ISequence> listOfSeq = new List<ISequence>();
                listOfSeq.Add(refSeqList[0]);
                listOfSeq.Add(searchSeqList[0]);
                alignSimple = nucmerObj.AlignSimple(listOfSeq);
            }

            string expectedSequences = string.Empty;
            expectedSequences = this.utilityObj.xmlUtil.GetTextValue(nodeName,
                Constants.ExpectedSequencesNode);

            string[] expSeqArray = expectedSequences.Split(',');

            int j = 0;

            // Gets all the aligned sequences in comma seperated format
            foreach (IPairwiseSequenceAlignment seqAlignment in alignSimple)
            {
                foreach (PairwiseAlignedSequence alignedSeq in seqAlignment)
                {
                    Assert.AreEqual(expSeqArray[j], new string(alignedSeq.FirstSequence.Select(a => (char)a).ToArray()));
                    ++j;
                    Assert.AreEqual(expSeqArray[j], new string(alignedSeq.SecondSequence.Select(a => (char)a).ToArray()));
                    j++;
                }
            }

            ApplicationLog.WriteLine("NUCmer BVT : Successfully validated all the aligned sequences.");
        }
Example #11
0
        /// <summary>
        /// Validates the NUCmer 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>
        void ValidateNUCmerAlignGeneralTestCases(string nodeName, bool isFilePath)
        {
            IList<ISequence> refSeqList, searchSeqList;

            if (isFilePath)
            {
                // Gets the reference sequence from the FastA file
                string filePath = this.utilityObj.xmlUtil.GetTextValue(nodeName, Constants.FilePathNode);
                Assert.IsNotNull(filePath);
                Assert.IsTrue(File.Exists(filePath));
                ApplicationLog.WriteLine(string.Format(null, "NUCmer BVT : Successfully validated the File Path '{0}'.", filePath));

                FastAParser parser = new FastAParser();
                refSeqList = parser.Parse(filePath).ToList();

                // Gets the query sequence from the FastA file
                string queryFilePath = this.utilityObj.xmlUtil.GetTextValue(nodeName, Constants.SearchSequenceFilePathNode);
                Assert.IsNotNull(queryFilePath);
                Assert.IsTrue(File.Exists(queryFilePath));
                ApplicationLog.WriteLine(string.Format(null, "NUCmer BVT : Successfully validated the File Path '{0}'.", queryFilePath));

                searchSeqList = parser.Parse(queryFilePath).ToList();
            }
            else
            {
                // Gets the reference & search sequences from the configuration file
                IAlphabet seqAlphabet = Utility.GetAlphabet(this.utilityObj.xmlUtil.GetTextValue(nodeName, Constants.AlphabetNameNode));

                string[] sequences = this.utilityObj.xmlUtil.GetTextValues(nodeName, Constants.ReferenceSequencesNode);
                refSeqList = sequences.Select((t, i) => new Sequence(seqAlphabet, this.encodingObj.GetBytes(t)) {ID = "ref " + i}).Cast<ISequence>().ToList();

                sequences = this.utilityObj.xmlUtil.GetTextValues(nodeName, Constants.SearchSequencesNode);
                searchSeqList = sequences.Select((t, i) => new Sequence(seqAlphabet, this.encodingObj.GetBytes(t)) { ID = "qry " + i }).Cast<ISequence>().ToList();
            }

            var aligner = new NucmerPairwiseAligner
            {
                MaximumSeparation = 0,
                MinimumScore = 2,
                SeparationFactor = 0.12f,
                BreakLength = 2,
                LengthOfMUM = long.Parse(this.utilityObj.xmlUtil.GetTextValue(nodeName, Constants.MUMAlignLengthNode), null)
            };

            IList<ISequenceAlignment> align = aligner.Align(refSeqList, searchSeqList);

            string expectedSequences = isFilePath
                    ? this.utilityObj.xmlUtil.GetFileTextValue(nodeName, Constants.ExpectedSequencesNode)
                    : this.utilityObj.xmlUtil.GetTextValue(nodeName, Constants.ExpectedSequencesNode);

            string[] expSeqArray = expectedSequences.Split(',');

            // Gets all the aligned sequences in comma separated format
            foreach (IPairwiseSequenceAlignment seqAlignment in align)
            {
                foreach (PairwiseAlignedSequence alignedSeq in seqAlignment)
                {
                    string actualStr = alignedSeq.FirstSequence.ConvertToString();
                    Assert.IsTrue(expSeqArray.Contains(actualStr));

                    actualStr = alignedSeq.SecondSequence.ConvertToString();
                    Assert.IsTrue(expSeqArray.Contains(actualStr));
                }
            }
        }
Example #12
0
 public void NUCmerAlignerProperties()
 {
     NucmerPairwiseAligner nucmerObj = new NucmerPairwiseAligner();
     Assert.AreEqual(Constants.NUCLength, nucmerObj.LengthOfMUM.ToString((IFormatProvider)null));
     Assert.AreEqual(200, nucmerObj.BreakLength);
     Assert.AreEqual(-8, nucmerObj.GapExtensionCost);
     Assert.AreEqual(-13, nucmerObj.GapOpenCost);
     Assert.AreEqual(Constants.NUCFixedSeperation, nucmerObj.FixedSeparation.ToString(CultureInfo.InvariantCulture));
     Assert.AreEqual(Constants.NUCMaximumSeparation, nucmerObj.MaximumSeparation.ToString(CultureInfo.InvariantCulture));
     Assert.AreEqual(Constants.NUCMinimumScore, nucmerObj.MinimumScore.ToString(CultureInfo.InvariantCulture));
     Assert.AreEqual(Constants.NUCSeparationFactor, nucmerObj.SeparationFactor.ToString(CultureInfo.InvariantCulture));
 }
Example #13
0
        public void NUCmerAlignSmallSizeAlignSequence()
        {
            // Gets the reference sequence from the FastA file
            string filePath = this.utilityObj.xmlUtil.GetTextValue(Constants.SmallSizeSequenceNodeName,
                Constants.FilePathNode);

            Assert.IsNotNull(filePath);

            FastAParser parser = new FastAParser();
            IEnumerable<ISequence> refSeqList = parser.Parse(filePath);

            // Gets the query sequence from the FastA file
            string queryFilePath = this.utilityObj.xmlUtil.GetTextValue(Constants.SmallSizeSequenceNodeName,
                Constants.SearchSequenceFilePathNode);

            Assert.IsNotNull(queryFilePath);

            FastAParser queryParser = new FastAParser();
            IEnumerable<ISequence> searchSeqList = queryParser.Parse(queryFilePath);

            string mumLength = this.utilityObj.xmlUtil.GetTextValue(Constants.SmallSizeSequenceNodeName, Constants.MUMAlignLengthNode);

            NucmerPairwiseAligner nucmerObj = new NucmerPairwiseAligner
                {
                    MaximumSeparation = 0,
                    MinimumScore = 2,
                    SeparationFactor = 0.12f,
                    BreakLength = 2,
                    LengthOfMUM = long.Parse(mumLength, null)
                };

            IList<ISequenceAlignment> align = nucmerObj.Align(refSeqList.ElementAt(0), searchSeqList);

            string expectedSequences = this.utilityObj.xmlUtil.GetFileTextValue(Constants.SmallSizeSequenceNodeName,
                Constants.ExpectedSequencesNode);

            string[] expSeqArray = expectedSequences.Split(',');

            int j = 0;

            // Gets all the aligned sequences in comma separated format
            foreach (IPairwiseSequenceAlignment seqAlignment in align)
            {
                foreach (PairwiseAlignedSequence alignedSeq in seqAlignment)
                {
                    Assert.AreEqual(expSeqArray[j], alignedSeq.FirstSequence.ConvertToString());
                    ++j;
                    Assert.AreEqual(expSeqArray[j], alignedSeq.SecondSequence.ConvertToString());
                    j++;
                }
            }
        }
Example #14
0
        private void ValidateNUCmerAlignSimpleGeneralTestCases(string nodeName, bool isFilePath, bool isAlignList)
        {
            IList<ISequence> refSeqList = new List<ISequence>();
            IList<ISequence> searchSeqList = new List<ISequence>();

            if (isFilePath)
            {
                // Gets the reference sequence from the FastA file
                string filePath = this.utilityObj.xmlUtil.GetTextValue(nodeName, Constants.FilePathNode);

                Assert.IsNotNull(filePath);
                ApplicationLog.WriteLine(string.Format(null, "NUCmer P1 : Successfully validated the File Path '{0}'.", filePath));

                var fastaparserobj = new FastAParser();
                IEnumerable<ISequence> referenceSeqList = fastaparserobj.Parse(filePath);

                foreach (ISequence seq in referenceSeqList)
                {
                    refSeqList.Add(seq);
                }

                // Gets the query sequence from the FastA file
                string queryFilePath = this.utilityObj.xmlUtil.GetTextValue(nodeName, Constants.SearchSequenceFilePathNode);

                Assert.IsNotNull(queryFilePath);
                ApplicationLog.WriteLine(string.Format(null,"NUCmer P1 : Successfully validated the File Path '{0}'.", queryFilePath));

                var fastaParserobj = new FastAParser();
                IEnumerable<ISequence> querySeqList = fastaParserobj.Parse(queryFilePath);
                foreach (ISequence seq in querySeqList)
                {
                    searchSeqList.Add(seq);
                }
            }
            else
            {
                // Gets the reference & search sequences from the configuration file
                string[] referenceSequences = this.utilityObj.xmlUtil.GetTextValues(nodeName, Constants.ReferenceSequencesNode);
                string[] searchSequences = this.utilityObj.xmlUtil.GetTextValues(nodeName, Constants.SearchSequencesNode);

                IAlphabet seqAlphabet = Utility.GetAlphabet(this.utilityObj.xmlUtil.GetTextValue(nodeName, Constants.AlphabetNameNode));

                foreach (Sequence referSeq in referenceSequences.Select(t => new Sequence(seqAlphabet, Encoding.ASCII.GetBytes(t))))
                {
                    refSeqList.Add(referSeq);
                }

                foreach (Sequence searchSeq in searchSequences.Select(t => new Sequence(seqAlphabet, Encoding.ASCII.GetBytes(t))))
                {
                    searchSeqList.Add(searchSeq);
                }
            }

            // Gets the mum length from the xml
            string mumLength = this.utilityObj.xmlUtil.GetTextValue(nodeName, Constants.MUMAlignLengthNode);

            var nucmerObj = new NucmerPairwiseAligner
            {
                MaximumSeparation = int.Parse(this.utilityObj.xmlUtil.GetTextValue(nodeName, Constants.MUMAlignLengthNode), null),
                MinimumScore = int.Parse(this.utilityObj.xmlUtil.GetTextValue(nodeName, Constants.MUMAlignLengthNode), null), 
                SeparationFactor = int.Parse(this.utilityObj.xmlUtil.GetTextValue(nodeName, Constants.MUMAlignLengthNode), null),
                BreakLength = int.Parse(this.utilityObj.xmlUtil.GetTextValue(nodeName, Constants.MUMAlignLengthNode), null),
                LengthOfMUM = long.Parse(mumLength, null)
            };

            IList<ISequenceAlignment> alignSimple = null;
            if (isAlignList)
            {
                var listOfSeq = new List<ISequence> {refSeqList[0], searchSeqList[0]};
                alignSimple = nucmerObj.AlignSimple(listOfSeq);
            }

            string expectedSequences = isFilePath
                ? this.utilityObj.xmlUtil.GetFileTextValue(nodeName, Constants.ExpectedSequencesNode)
                : this.utilityObj.xmlUtil.GetTextValue(nodeName, Constants.ExpectedSequencesNode);

            string[] expSeqArray = expectedSequences.Split(',');

            int j = 0;

            // Gets all the aligned sequences in comma separated format
            foreach (PairwiseAlignedSequence alignedSeq in alignSimple.Cast<IPairwiseSequenceAlignment>().SelectMany(seqAlignment => seqAlignment))
            {
                Assert.AreEqual(expSeqArray[j], alignedSeq.FirstSequence.ConvertToString());
                ++j;
                Assert.AreEqual(expSeqArray[j], alignedSeq.SecondSequence.ConvertToString());
                j++;
            }

            ApplicationLog.WriteLine("NUCmer P1 : Successfully validated all the aligned sequences.");
        }
Example #15
0
        /// <summary>
        ///     Validates the NUCmer align method for several test cases for the parameters passed.
        /// </summary>
        /// <param name="sequenceList">List of Input Sequences</param>
        private static void ValidateNUCmerEmptyAlignGeneralTestCases(IEnumerable<ISequence> sequenceList)
        {
            var nucmerObj = new NucmerPairwiseAligner();

            try
            {
                IList<ISequenceAlignment> result = nucmerObj.Align(sequenceList);
                ApplicationLog.WriteLine("NUCmer P2 : Exception not thrown");
                Assert.Fail("ArgumentNullException not thrown.");
            }
            catch (ArgumentNullException)
            {
                ApplicationLog.WriteLine("NUCmer P2: Successfully validated empty SequenceList");
            }
        }
Example #16
0
        public void NUCmerAlignWithIsAlignAndGaps()
        {
            IList<ISequence> seqList = new List<ISequence>();
            seqList.Add(new Sequence(Alphabets.DNA, Encoding.ASCII.GetBytes("CAAAAGGGATTGC---TGTTGGAGTGAATGCCATTACCTACCGGCTAGGAGGAGTAGTACAAAGGAGC")));
            seqList.Add(new Sequence(Alphabets.DNA, Encoding.ASCII.GetBytes("CAAAAGGGATTGC---")));
            seqList.Add(new Sequence(Alphabets.DNA, Encoding.ASCII.GetBytes("TAGTAGTTCTGCTATATACATTTG")));
            seqList.Add(new Sequence(Alphabets.DNA, Encoding.ASCII.GetBytes("GTTATCATGCGAACAATTCAACAGACACTGTAGA")));
            var num = new NucmerPairwiseAligner
                          {
                              BreakLength = 8,
                              FixedSeparation = 0,
                              MinimumScore = 0,
                              MaximumSeparation = 0,
                              SeparationFactor = 0,
                              LengthOfMUM = 8
                          };
            IList<ISequence> sequenceList = seqList;
            IList<ISequenceAlignment> alignmentObj = num.Align(sequenceList);

            var alignedSeqs = (AlignedSequence) alignmentObj[0].AlignedSequences[0];
            Assert.AreEqual("CAAAAGGGATTGC---", new string(alignedSeqs.Sequences[0].Select(a => (char) a).ToArray()));
            Assert.AreEqual("CAAAAGGGATTGC---", new string(alignedSeqs.Sequences[1].Select(a => (char) a).ToArray()));

            ApplicationLog.WriteLine("Successfully validated Align method with IsAlign and Gaps");
        }
Example #17
0
        public void TestAlignedSequenceToString()
        {
            var seqList = new List<ISequence>
            {
                new Sequence(Alphabets.DNA,"CAAAAGGGATTGC---TGTTGGAGTGAATGCCATTACCTACCGGCTAGGAGGAGTAGTACAAAGGAGC"),
                new Sequence(Alphabets.DNA, "CAAAAGGGATTGC---"),
                new Sequence(Alphabets.DNA, "TAGTAGTTCTGCTATATACATTTG"),
                new Sequence(Alphabets.DNA, "GTTATCATGCGAACAATTCAACAGACACTGTAGA")
            };

            NucmerPairwiseAligner num = new NucmerPairwiseAligner
            {
                BreakLength = 8,
                FixedSeparation = 0,
                MinimumScore = 0,
                MaximumSeparation = 0,
                SeparationFactor = 0,
                LengthOfMUM = 8
            };

            IList<ISequence> sequenceList = seqList;
            IList<ISequenceAlignment> alignmentObj = num.Align(sequenceList);
            Assert.AreNotEqual(0, alignmentObj.Count);

            var alignedSeqs = (AlignedSequence) alignmentObj[0].AlignedSequences[0];

            string actualString = alignedSeqs.ToString();
            string ExpectedString = "CAAAAGGGATTGC---\r\nCAAAAGGGATTGC---\r\nCAAAAGGGATTGC---\r\n".Replace("\r\n", Environment.NewLine);
            Assert.AreEqual(ExpectedString, actualString);
        }