示例#1
0
        /// <summary>
        /// Try Parse Sequence File.
        /// </summary>
        /// <param name="fileName">The fileName.</param>
        /// <param name="alphabet">The Alphabet.</param>
        /// <param name="sequences">List of sequences.</param>
        /// <returns>True if Parsed sequence properly.</returns>
        private static bool TryParseSequenceFile(string fileName, IAlphabet alphabet, out IList <ISequence> sequences)
        {
            // Read the first line.
            string firstLine;

            using (var reader = new StreamReader(fileName))
            {
                firstLine = reader.ReadLine();
            }

            // Attempt to discover the format.
            if (ValidateFastaFormat(firstLine))
            {
                var parse = new FastAParser {
                    Alphabet = alphabet
                };
                using (parse.Open(fileName))
                {
                    sequences = parse.Parse().ToList();
                }

                return(true);
            }

            if (ValidatePhylipFormat(firstLine))
            {
                var parse = new PhylipParser {
                    Alphabet = alphabet
                };
                using (parse.Open(fileName))
                {
                    sequences = ConvertAlignedSequenceToSequence(parse.Parse());
                }

                return(true);
            }

            if (ValidateTabFormat(firstLine))
            {
                var parse = new FieldTextFileParser {
                    Alphabet = alphabet
                };
                using (parse.Open(fileName))
                {
                    sequences = parse.Parse().ToList();
                    return(true);
                }
            }

            sequences = null;
            return(false);
        }
示例#2
0
        /// <summary>
        /// General method to invalidate Phylip parser
        /// </summary>
        /// <param name="nodeName">xml node name.</param>
        /// <param name="method">Phylip Parser method parameters</param>
        void InvalidatePhylipParserTestCases(
            string nodeName,
            ParserTestAttributes method)
        {
            try
            {
                string filePath = utilityObj.xmlUtil.GetTextValue(
                    nodeName,
                    Constants.FilePathNode);
                PhylipParser parser = new PhylipParser();

                switch (method)
                {
                case ParserTestAttributes.Parse:
                    parser.Parse(filePath);
                    break;

                case ParserTestAttributes.ParseOne:
                    parser.ParseOne(filePath);
                    break;

                default:
                    break;
                }

                Assert.Fail();
            }
            catch (InvalidDataException)
            {
                ApplicationLog.WriteLine(
                    "Phylip Parser P2 : All the features validated successfully.");
                Console.WriteLine(
                    "Phylip Parser P2 : All the features validated successfully.");
            }
            catch (FormatException)
            {
                ApplicationLog.WriteLine(
                    "Phylip Parser P2 : All the features validated successfully.");
                Console.WriteLine(
                    "Phylip Parser P2 : All the features validated successfully.");
            }
        }
示例#3
0
        /// <summary>
        /// Try Parse Sequence File.
        /// </summary>
        /// <param name="fileName">The fileName.</param>
        /// <param name="alphabet">The Alphabet.</param>
        /// <param name="sequences">List of sequences.</param>
        /// <returns>True if Parsed sequence properly.</returns>
        private static bool TryParseSequenceFile(string fileName, IAlphabet alphabet, out IList <ISequence> sequences)
        {
            using (TextReader reader = new StreamReader(fileName))
            {
                string firstLine = reader.ReadLine();
                if (ValidateFastaFormat(firstLine))
                {
                    using (FastAParser parse = new FastAParser())
                    {
                        parse.Alphabet = alphabet;
                        sequences      = parse.Parse().ToList();
                    }

                    return(true);
                }
                else if (ValidatePhylipFormat(firstLine))
                {
                    PhylipParser parse = new PhylipParser();
                    parse.Alphabet = alphabet;
                    sequences      = ConvertAlignedSequenceToSequence(parse.Parse(fileName));
                    return(true);
                }
                else if (ValidateTabFormat(firstLine))
                {
                    using (FieldTextFileParser parse = new FieldTextFileParser(fileName))
                    {
                        parse.Alphabet = alphabet;
                        sequences      = parse.Parse().ToList();
                        return(true);
                    }
                }
                else
                {
                    sequences = null;
                    return(false);
                }
            }
        }
示例#4
0
        /// <summary>
        /// Parsers the Phylip file for different test cases based
        /// on Additional parameter
        /// </summary>
        /// <param name="nodeName">Xml Node name</param>
        /// <param name="addParam">Additional parameter</param>
        static void ParserGeneralTestCases(string nodeName,
                                           ParserTestAttributes addParam)
        {
            // Gets the Filename
            string filePath = Utility._xmlUtil.GetTextValue(
                nodeName, Constants.FilePathNode);

            Assert.IsNotEmpty(filePath);
            ApplicationLog.WriteLine(string.Format(
                                         "Phylip Parser BVT: Reading the File from location '{0}'", filePath));
            Console.WriteLine(string.Format(
                                  "Phylip Parser BVT: Reading the File from location '{0}'", filePath));

            // Get the rangelist after parsing.
            PhylipParser parserObj = new PhylipParser();

            IList <ISequenceAlignment> sequenceAlignmentList = null;
            ISequenceAlignment         sequenceAlignment     = null;

            // Gets the SequenceAlignment list based on the parameters.
            switch (addParam)
            {
            case ParserTestAttributes.Parse:
                sequenceAlignmentList = parserObj.Parse(filePath);
                break;

            case ParserTestAttributes.ParseOne:
                sequenceAlignment = parserObj.ParseOne(filePath);
                break;

            case ParserTestAttributes.ParseTextReader:
                sequenceAlignmentList = parserObj.Parse(
                    new StreamReader(filePath));
                break;

            case ParserTestAttributes.ParseOneTextReader:
                sequenceAlignment = parserObj.ParseOne(
                    new StreamReader(filePath));
                break;

            case ParserTestAttributes.ParseOneTextReaderReadOnly:
                sequenceAlignment = parserObj.ParseOne(
                    new StreamReader(filePath), false);
                break;

            case ParserTestAttributes.ParseTextReaderReadOnly:
                sequenceAlignmentList = parserObj.Parse(
                    new StreamReader(filePath), false);
                break;

            case ParserTestAttributes.ParseReadOnly:
                sequenceAlignmentList = parserObj.Parse(filePath,
                                                        false);
                break;

            case ParserTestAttributes.ParseOneReadOnly:
                sequenceAlignment = parserObj.ParseOne(filePath,
                                                       false);
                break;

            case ParserTestAttributes.ParseEncoding:
                PhylipParser parser =
                    new PhylipParser(Encodings.Ncbi4NA);
                sequenceAlignmentList = parser.Parse(
                    new StreamReader(filePath), false);
                break;

            default:
                break;
            }

            // Gets all the expected values from xml.
            IList <Dictionary <string, string> > expectedAlignmentList =
                new List <Dictionary <string, string> >();
            Dictionary <string, string> expectedAlignmentObj =
                new Dictionary <string, string>();

            XmlNode expectedAlignmentNodes = Utility._xmlUtil.GetNode(
                nodeName, Constants.ExpectedAlignmentNode);
            XmlNodeList alignNodes = expectedAlignmentNodes.ChildNodes;

            // Create a ISequenceAlignment List
            switch (addParam)
            {
            case ParserTestAttributes.ParseOne:
            case ParserTestAttributes.ParseOneTextReader:
            case ParserTestAttributes.ParseOneTextReaderReadOnly:
            case ParserTestAttributes.ParseOneReadOnly:
                sequenceAlignmentList = new List <ISequenceAlignment>();
                sequenceAlignmentList.Add(sequenceAlignment);
                break;

            default:
                break;
            }

            foreach (XmlNode expectedAlignment in alignNodes)
            {
                expectedAlignmentObj[expectedAlignment.Name] =
                    expectedAlignment.InnerText;
            }

            expectedAlignmentList.Add(expectedAlignmentObj);

            Assert.IsTrue(CompareOutput(sequenceAlignmentList,
                                        expectedAlignmentList));
            ApplicationLog.WriteLine(
                "Phylip Parser BVT: Successfully validated all the Alignment Sequences");
            Console.WriteLine(
                "Phylip Parser BVT: Successfully validated all the Alignment Sequences");
        }
示例#5
0
        public void PhylipParse()
        {
            string filepath = @"TestUtils\Phylip\dna.phy";

            Assert.IsTrue(File.Exists(filepath));

            IList <Dictionary <string, string> > expectedOutput = new List <Dictionary <string, string> >();

            Dictionary <string, string> expectedAlignment = new Dictionary <string, string>();

            expectedAlignment["Cow"] = "ATGGCATATCCCATACAACTAGGATTCCAAGATGCAACATCACCAATCATAGAAGAACTA"
                                       + "CTTCACTTTCATGACCACACGCTAATAATTGTCTTCTTAATTAGCTCATTAGTACTTTAC"
                                       + "ATTATTTCACTAATACTAACGACAAAGCTGACCCATACAAGCACGATAGATGCACAAGAA"
                                       + "GTAGAGACAATCTGAACCATTCTGCCCGCCATCATCTTAATTCTAATTGCTCTTCCTTCT"
                                       + "TTACGAATTCTATACATAATAGATGAAATCAATAACCCATCTCTTACAGTAAAAACCATA"
                                       + "GGACATCAGTGATACTGAAGCTATGAGTATACAGATTATGAGGACTTAAGCTTCGACTCC"
                                       + "TACATAATTCCAACATCAGAATTAAAGCCAGGGGAGCTACGACTATTAGAAGTCGATAAT"
                                       + "CGAGTTGTACTACCAATAGAAATAACAATCCGAATGTTAGTCTCCTCTGAAGACGTATTA"
                                       + "CACTCATGAGCTGTGCCCTCTCTAGGACTAAAAACAGACGCAATCCCAGGCCGTCTAAAC"
                                       + "CAAACAACCCTTATATCGTCCCGTCCAGGCTTATATTACGGTCAATGCTCAGAAATTTGC"
                                       + "GGGTCAAACCACAGTTTCATACCCATTGTCCTTGAGTTAGTCCCACTAAAGTACTTTGAA"
                                       + "AAATGATCTGCGTCAATATTA---------------------TAA";

            expectedAlignment["Carp"] = "ATGGCACACCCAACGCAACTAGGTTTCAAGGACGCGGCCATACCCGTTATAGAGGAACTT"
                                        + "CTTCACTTCCACGACCACGCATTAATAATTGTGCTCCTAATTAGCACTTTAGTTTTATAT"
                                        + "ATTATTACTGCAATGGTATCAACTAAACTTACTAATAAATATATTCTAGACTCCCAAGAA"
                                        + "ATCGAAATCGTATGAACCATTCTACCAGCCGTCATTTTAGTACTAATCGCCCTGCCCTCC"
                                        + "CTACGCATCCTGTACCTTATAGACGAAATTAACGACCCTCACCTGACAATTAAAGCAATA"
                                        + "GGACACCAATGATACTGAAGTTACGAGTATACAGACTATGAAAATCTAGGATTCGACTCC"
                                        + "TATATAGTACCAACCCAAGACCTTGCCCCCGGACAATTCCGACTTCTGGAAACAGACCAC"
                                        + "CGAATAGTTGTTCCAATAGAATCCCCAGTCCGTGTCCTAGTATCTGCTGAAGACGTGCTA"
                                        + "CATTCTTGAGCTGTTCCATCCCTTGGCGTAAAAATGGACGCAGTCCCAGGACGACTAAAT"
                                        + "CAAGCCGCCTTTATTGCCTCACGCCCAGGGGTCTTTTACGGACAATGCTCTGAAATTTGT"
                                        + "GGAGCTAATCACAGCTTTATACCAATTGTAGTTGAAGCAGTACCTCTCGAACACTTCGAA"
                                        + "AACTGATCCTCATTAATACTAGAAGACGCCTCGCTAGGAAGCTAA";

            expectedAlignment["Chicken"] = "ATGGCCAACCACTCCCAACTAGGCTTTCAAGACGCCTCATCCCCCATCATAGAAGAGCTC"
                                           + "GTTGAATTCCACGACCACGCCCTGATAGTCGCACTAGCAATTTGCAGCTTAGTACTCTAC"
                                           + "CTTCTAACTCTTATACTTATAGAAAAACTATCA---TCAAACACCGTAGATGCCCAAGAA"
                                           + "GTTGAACTAATCTGAACCATCCTACCCGCTATTGTCCTAGTCCTGCTTGCCCTCCCCTCC"
                                           + "CTCCAAATCCTCTACATAATAGACGAAATCGACGAACCTGATCTCACCCTAAAAGCCATC"
                                           + "GGACACCAATGATACTGAACCTATGAATACACAGACTTCAAGGACCTCTCATTTGACTCC"
                                           + "TACATAACCCCAACAACAGACCTCCCCCTAGGCCACTTCCGCCTACTAGAAGTCGACCAT"
                                           + "CGCATTGTAATCCCCATAGAATCCCCCATTCGAGTAATCATCACCGCTGATGACGTCCTC"
                                           + "CACTCATGAGCCGTACCCGCCCTCGGGGTAAAAACAGACGCAATCCCTGGACGACTAAAT"
                                           + "CAAACCTCCTTCATCACCACTCGACCAGGAGTGTTTTACGGACAATGCTCAGAAATCTGC"
                                           + "GGAGCTAACCACAGCTACATACCCATTGTAGTAGAGTCTACCCCCCTAAAACACTTTGAA"
                                           + "GCCTGATCCTCACTA------------------CTGTCATCTTAA";

            expectedAlignment["Human"] = "ATGGCACATGCAGCGCAAGTAGGTCTACAAGACGCTACTTCCCCTATCATAGAAGAGCTT"
                                         + "ATCACCTTTCATGATCACGCCCTCATAATCATTTTCCTTATCTGCTTCCTAGTCCTGTAT"
                                         + "GCCCTTTTCCTAACACTCACAACAAAACTAACTAATACTAACATCTCAGACGCTCAGGAA"
                                         + "ATAGAAACCGTCTGAACTATCCTGCCCGCCATCATCCTAGTCCTCATCGCCCTCCCATCC"
                                         + "CTACGCATCCTTTACATAACAGACGAGGTCAACGATCCCTCCCTTACCATCAAATCAATT"
                                         + "GGCCACCAATGGTACTGAACCTACGAGTACACCGACTACGGCGGACTAATCTTCAACTCC"
                                         + "TACATACTTCCCCCATTATTCCTAGAACCAGGCGACCTGCGACTCCTTGACGTTGACAAT"
                                         + "CGAGTAGTACTCCCGATTGAAGCCCCCATTCGTATAATAATTACATCACAAGACGTCTTG"
                                         + "CACTCATGAGCTGTCCCCACATTAGGCTTAAAAACAGATGCAATTCCCGGACGTCTAAAC"
                                         + "CAAACCACTTTCACCGCTACACGACCGGGGGTATACTACGGTCAATGCTCTGAAATCTGT"
                                         + "GGAGCAAACCACAGTTTCATGCCCATCGTCCTAGAATTAATTCCCCTAAAAATCTTTGAA"
                                         + "ATA---------------------GGGCCCGTATTTACCCTATAG";

            expectedAlignment["Loach"] = "ATGGCACATCCCACACAATTAGGATTCCAAGACGCGGCCTCACCCGTAATAGAAGAACTT"
                                         + "CTTCACTTCCATGACCATGCCCTAATAATTGTATTTTTGATTAGCGCCCTAGTACTTTAT"
                                         + "GTTATTATTACAACCGTCTCAACAAAACTCACTAACATATATATTTTGGACTCACAAGAA"
                                         + "ATTGAAATCGTATGAACTGTGCTCCCTGCCCTAATCCTCATTTTAATCGCCCTCCCCTCA"
                                         + "CTACGAATTCTATATCTTATAGACGAGATTAATGACCCCCACCTAACAATTAAGGCCATG"
                                         + "GGGCACCAATGATACTGAAGCTACGAGTATACTGATTATGAAAACTTAAGTTTTGACTCC"
                                         + "TACATAATCCCCACCCAGGACCTAACCCCTGGACAATTCCGGCTACTAGAGACAGACCAC"
                                         + "CGAATGGTTGTTCCCATAGAATCCCCTATTCGCATTCTTGTTTCCGCCGAAGATGTACTA"
                                         + "CACTCCTGGGCCCTTCCAGCCATGGGGGTAAAGATAGACGCGGTCCCAGGACGCCTTAAC"
                                         + "CAAACCGCCTTTATTGCCTCCCGCCCCGGGGTATTCTATGGGCAATGCTCAGAAATCTGT"
                                         + "GGAGCAAACCACAGCTTTATACCCATCGTAGTAGAAGCGGTCCCACTATCTCACTTCGAA"
                                         + "AACTGGTCCACCCTTATACTAAAAGACGCCTCACTAGGAAGCTAA";

            expectedAlignment["Mouse"] = "ATGGCCTACCCATTCCAACTTGGTCTACAAGACGCCACATCCCCTATTATAGAAGAGCTA"
                                         + "ATAAATTTCCATGATCACACACTAATAATTGTTTTCCTAATTAGCTCCTTAGTCCTCTAT"
                                         + "ATCATCTCGCTAATATTAACAACAAAACTAACACATACAAGCACAATAGATGCACAAGAA"
                                         + "GTTGAAACCATTTGAACTATTCTACCAGCTGTAATCCTTATCATAATTGCTCTCCCCTCT"
                                         + "CTACGCATTCTATATATAATAGACGAAATCAACAACCCCGTATTAACCGTTAAAACCATA"
                                         + "GGGCACCAATGATACTGAAGCTACGAATATACTGACTATGAAGACCTATGCTTTGATTCA"
                                         + "TATATAATCCCAACAAACGACCTAAAACCTGGTGAACTACGACTGCTAGAAGTTGATAAC"
                                         + "CGAGTCGTTCTGCCAATAGAACTTCCAATCCGTATATTAATTTCATCTGAAGACGTCCTC"
                                         + "CACTCATGAGCAGTCCCCTCCCTAGGACTTAAAACTGATGCCATCCCAGGCCGACTAAAT"
                                         + "CAAGCAACAGTAACATCAAACCGACCAGGGTTATTCTATGGCCAATGCTCTGAAATTTGT"
                                         + "GGATCTAACCATAGCTTTATGCCCATTGTCCTAGAAATGGTTCCACTAAAATATTTCGAA"
                                         + "AACTGATCTGCTTCAATAATT---------------------TAA";

            expectedAlignment["Rat"] = "ATGGCTTACCCATTTCAACTTGGCTTACAAGACGCTACATCACCTATCATAGAAGAACTT"
                                       + "ACAAACTTTCATGACCACACCCTAATAATTGTATTCCTCATCAGCTCCCTAGTACTTTAT"
                                       + "ATTATTTCACTAATACTAACAACAAAACTAACACACACAAGCACAATAGACGCCCAAGAA"
                                       + "GTAGAAACAATTTGAACAATTCTCCCAGCTGTCATTCTTATTCTAATTGCCCTTCCCTCC"
                                       + "CTACGAATTCTATACATAATAGACGAGATTAATAACCCAGTTCTAACAGTAAAAACTATA"
                                       + "GGACACCAATGATACTGAAGCTATGAATATACTGACTATGAAGACCTATGCTTTGACTCC"
                                       + "TACATAATCCCAACCAATGACCTAAAACCAGGTGAACTTCGTCTATTAGAAGTTGATAAT"
                                       + "CGGGTAGTCTTACCAATAGAACTTCCAATTCGTATACTAATCTCATCCGAAGACGTCCTG"
                                       + "CACTCATGAGCCATCCCTTCACTAGGGTTAAAAACCGACGCAATCCCCGGCCGCCTAAAC"
                                       + "CAAGCTACAGTCACATCAAACCGACCAGGTCTATTCTATGGCCAATGCTCTGAAATTTGC"
                                       + "GGCTCAAATCACAGCTTCATACCCATTGTACTAGAAATAGTGCCTCTAAAATATTTCGAA"
                                       + "AACTGATCAGCTTCTATAATT---------------------TAA";

            expectedAlignment["Seal"] = "ATGGCATACCCCCTACAAATAGGCCTACAAGATGCAACCTCTCCCATTATAGAGGAGTTA"
                                        + "CTACACTTCCATGACCACACATTAATAATTGTGTTCCTAATTAGCTCATTAGTACTCTAC"
                                        + "ATTATCTCACTTATACTAACCACGAAACTCACCCACACAAGTACAATAGACGCACAAGAA"
                                        + "GTGGAAACGGTGTGAACGATCCTACCCGCTATCATTTTAATTCTCATTGCCCTACCATCA"
                                        + "TTACGAATCCTCTACATAATGGACGAGATCAATAACCCTTCCTTGACCGTAAAAACTATA"
                                        + "GGACATCAGTGATACTGAAGCTATGAGTACACAGACTACGAAGACCTGAACTTTGACTCA"
                                        + "TATATGATCCCCACACAAGAACTAAAGCCCGGAGAACTACGACTGCTAGAAGTAGACAAT"
                                        + "CGAGTAGTCCTCCCAATAGAAATAACAATCCGCATACTAATCTCATCAGAAGATGTACTC"
                                        + "CACTCATGAGCCGTACCGTCCCTAGGACTAAAAACTGATGCTATCCCAGGACGACTAAAC"
                                        + "CAAACAACCCTAATAACCATACGACCAGGACTGTACTACGGTCAATGCTCAGAAATCTGT"
                                        + "GGTTCAAACCACAGCTTCATACCTATTGTCCTCGAATTGGTCCCACTATCCCACTTCGAG"
                                        + "AAATGATCTACCTCAATGCTT---------------------TAA";

            expectedAlignment["Whale"] = "ATGGCATATCCATTCCAACTAGGTTTCCAAGATGCAGCATCACCCATCATAGAAGAGCTC"
                                         + "CTACACTTTCACGATCATACACTAATAATCGTTTTTCTAATTAGCTCTTTAGTTCTCTAC"
                                         + "ATTATTACCCTAATGCTTACAACCAAATTAACACATACTAGTACAATAGACGCCCAAGAA"
                                         + "GTAGAAACTGTCTGAACTATCCTCCCAGCCATTATCTTAATTTTAATTGCCTTGCCTTCA"
                                         + "TTACGGATCCTTTACATAATAGACGAAGTCAATAACCCCTCCCTCACTGTAAAAACAATA"
                                         + "GGTCACCAATGATATTGAAGCTATGAGTATACCGACTACGAAGACCTAAGCTTCGACTCC"
                                         + "TATATAATCCCAACATCAGACCTAAAGCCAGGAGAACTACGATTATTAGAAGTAGATAAC"
                                         + "CGAGTTGTCTTACCTATAGAAATAACAATCCGAATATTAGTCTCATCAGAAGACGTACTC"
                                         + "CACTCATGGGCCGTACCCTCCTTGGGCCTAAAAACAGATGCAATCCCAGGACGCCTAAAC"
                                         + "CAAACAACCTTAATATCAACACGACCAGGCCTATTTTATGGACAATGCTCAGAGATCTGC"
                                         + "GGCTCAAACCACAGTTTCATACCAATTGTCCTAGAACTAGTACCCCTAGAAGTCTTTGAA"
                                         + "AAATGATCTGTATCAATACTA---------------------TAA";

            expectedAlignment["Frog"] = "ATGGCACACCCATCACAATTAGGTTTTCAAGACGCAGCCTCTCCAATTATAGAAGAATTA"
                                        + "CTTCACTTCCACGACCATACCCTCATAGCCGTTTTTCTTATTAGTACGCTAGTTCTTTAC"
                                        + "ATTATTACTATTATAATAACTACTAAACTAACTAATACAAACCTAATGGACGCACAAGAG"
                                        + "ATCGAAATAGTGTGAACTATTATACCAGCTATTAGCCTCATCATAATTGCCCTTCCATCC"
                                        + "CTTCGTATCCTATATTTAATAGATGAAGTTAATGATCCACACTTAACAATTAAAGCAATC"
                                        + "GGCCACCAATGATACTGAAGCTACGAATATACTAACTATGAGGATCTCTCATTTGACTCT"
                                        + "TATATAATTCCAACTAATGACCTTACCCCTGGACAATTCCGGCTGCTAGAAGTTGATAAT"
                                        + "CGAATAGTAGTCCCAATAGAATCTCCAACCCGACTTTTAGTTACAGCCGAAGACGTCCTC"
                                        + "CACTCGTGAGCTGTACCCTCCTTGGGTGTCAAAACAGATGCAATCCCAGGACGACTTCAT"
                                        + "CAAACATCATTTATTGCTACTCGTCCGGGAGTATTTTACGGACAATGTTCAGAAATTTGC"
                                        + "GGAGCAAACCACAGCTTTATACCAATTGTAGTTGAAGCAGTACCGCTAACCGACTTTGAA"
                                        + "AACTGATCTTCATCAATACTA---GAAGCATCACTA------AGA";

            expectedOutput.Add(expectedAlignment);

            IList <ISequenceAlignment> actualOutput = null;
            ISequenceAlignmentParser   parser       = new PhylipParser();

            using (StreamReader reader = File.OpenText(filepath))
            {
                actualOutput = parser.Parse(reader);
            }

            CompareOutput(actualOutput, expectedOutput);
        }
示例#6
0
        public void PhylipParsePrimates()
        {
            string filepath = @"TestUtils\Phylip\primates.phy";

            Assert.IsTrue(File.Exists(filepath));

            IList <Dictionary <string, string> > expectedOutput = new List <Dictionary <string, string> >();

            Dictionary <string, string> expectedAlignment = new Dictionary <string, string>();

            expectedAlignment["Mouse"] = "ACCAAAAAAACATCCAAACACCAACCCCAGCCCTTACGCAATAGCCATACAAAGAATATT"
                                         + "ATACTACTAAAAACTCAAATTAACTCTTTAATCTTTATACAACATTCCACCAACCTATCC"
                                         + "ACACAAAAAAACTCATATTTATCTAAATACGAACTTCACACAACCTTAACACATAAACAT"
                                         + "ACCCCAGCCCAACACCCTTCCACAAATCCTTAATATACGCACCATAAATAAC";

            expectedAlignment["Bovine"] = "ACCAAACCTGTCCCCACCATCTAACACCAACCCACATATACAAGCTAAACCAAAAATACC"
                                          + "ATACAACCATAAATAAGACTAATCTATTAAAATAACCCATTACGATACAAAATCCCTTTC"
                                          + "GTCTAGATACAAACCACAACACACAATTAATACACACCACAATTACAATACTAAACTCCC"
                                          + "ATCCCACCAAATCACCCTCCATCAAATCCACAAATTACACAACCATTAACCC";

            expectedAlignment["Lemur"] = "ACCAAACTAACATCTAACAACTACCTCCAACTCTAAAAAAGCACTCTTACCAAACCCATC"
                                         + "ACAACTCTATCAACCTAACCAAACTATCAACATGCCCTCTCCTAATTAAAAACATTGCCA"
                                         + "CACTAAACCTACACACCTCATCACCATTAACGCATAACTCCTCAGTCATATCTACTACAC"
                                         + "ACCCTAACAATTTATCCCTCCCATAATCCAAAAACTCCATAAACACAAATTC";

            expectedAlignment["Tarsier"] = "ATCTACCTTATCTCCCCCAATCAATACCAACCTAAAAACTCTACAATTAAAAACCCCACC"
                                           + "GCTCAATTACTAGCAAAAATAGACATTCAACTCCTCCCATCATAACATAAAACATTCCTC"
                                           + "GCTCCAATAAACACATCACAATCCCAATAACGCATATACCTAAATACATCATTTAATAAT"
                                           + "AATACTCCAACTCCCATAACACAGCATACATAAACTCCATAAGTTTGAACAC";

            expectedAlignment["Squir Monk"] = "ACCCCAGCAACTCGTTGTGACCAACATCAATCCAAAATTAGCAAACGTACCAACAATCTC"
                                              + "CCAAATTTAAAAACACATCCTACCTTTACAATTAATAACCATTGTCTAGATATACCCCTA"
                                              + "AAATAAATGAATATAAACCCTCGCCGATAACATA-ACCCCTAAAATCAAGACATCCTCTC"
                                              + "ACAACGCCAAACCCCCCTCTCATAACTCTACAAAATACACAATCACCAACAC";

            expectedAlignment["Jpn Macaq"] = "ACTCCACCTGCTCACCTCATCCACTACTACTCCTCAAGCAATACATAAACTAAAAACTTC"
                                             + "TCACCTCTAATACTACACACCACTCCTGAAATCAATGCCCTCCACTAAAAAACATCACCA"
                                             + "GCCCAAACAAACACCTATCTACCCCCCCGGTCCACGCCCCTAACTCCATCATTCCCCCTC"
                                             + "AATACATCAAACAATTCCCCCCAATACCCACAAACTGCATAAGCAAACAGAC";

            expectedAlignment["Rhesus Mac"] = "ACTTCACCCGTTCACCTCATCCACTACTACTCCTCAAGCGATACATAAATCAAAAACTTC"
                                              + "TCACCTCCAATACTACGCACCGCTCCTAAAATCAATGCCCCCCACCAAAAAACATCACCA"
                                              + "ACCCAAACAAACACCTACCCATCCCCCCGGTTCACGCCTCAAACTCCATCATTCCCCCTC"
                                              + "AATACATCAAACAATTCCCCCCAATACCCACAAACTACATAAACAAACAAAC";

            expectedAlignment["Crab-E.Mac"] = "ACCCCACCTACCCGCCTCGTCCGCTACTGCTTCTCAAACAATATATAGACCAACAACTTC"
                                              + "TCACCTTTAACACTACATATCACTCCTGAGCTTAACACCCTCCGCTAAAAAACACCACTA"
                                              + "ACCCAAACAAACACCTATCTATCCCCCCGGTCCACGCCCCAAACCCCGCTATTCCCCCCT"
                                              + "AATACACCAAACAATTTTCTCCAACACCCACAAACTGTATAAACAAACAAAC";

            expectedAlignment["BarbMacaq"] = "ACCCTATCTATCTACCTCACCCGCCACCACCCCCCAAACAACACACAAACCAACAACTTT"
                                             + "TTATCTTTAGCACCACACATCACCCCCAAAAGCAATACCCTTCACCAAAAAGCACCATCA"
                                             + "AATCAAACAAACACCTATTTATTCCCCTAATTCACGTCCCAAATCCCATTATCTCTCCCC"
                                             + "AACATACCAAACAATTCTCCCTAATATACACAAACCACGCAAACAAACAAAC";

            expectedAlignment["Gibbon"] = "ACTATACCCACCCAACTCGACCTACACCAATCCCCACATAGCACACAGACCAACAACCTC"
                                          + "CCACCTTCCATACCAAGCCCCGACTTTACCGCCAACGCACCTCATCAAAACATACCTACA"
                                          + "ACACAAACAAATGCCCCCCCACCCTCCTTCTTCAAGCCCACTAGACCATCCTACCTTCCT"
                                          + "AGCACGCCAAGCTCTCTACCATCAAACGCACAACTTACACATACAGAACCAC";

            expectedAlignment["Orang"] = "ACCCCACCCGTCTACACCAGCCAACACCAACCCCCACCTACTATACCAACCAATAACCTC"
                                         + "TCAACCCCTAAACCAAACACTATCCCCAAAACCAACACACTCTACCAAAATACACCCCCA"
                                         + "ATTCACATCCGCACACCCCCACCCCCCCTGCCCACGTCCATCCCATCACCCTCTCCTCCC"
                                         + "AACACCCTAAGCCACCTTCCTCAAAATCCAAAACCCACACAACCGAAACAAC";

            expectedAlignment["Gorilla"] = "ACCCCATTTATCCATAAAAACCAACACCAACCCCCATCTAACACACAAACTAATGACCCC"
                                           + "CCACCCTCAAAGCCAAACACCAACCCTATAATCAATACGCCTTATCAAAACACACCCCCA"
                                           + "ACATAAACCCACGCACCCCCACCCCTTCCGCCCATGCTCACCACATCATCTCTCCCCTTC"
                                           + "AACACCTCAATCCACCTCCCCCCAAATACACAATTCACACAAACAATACCAC";

            expectedAlignment["Chimp"] = "ACCCCATCCACCCATACAAACCAACATTACCCTCCATCCAATATACAAACTAACAACCTC"
                                         + "CCACTCTTCAGACCGAACACCAATCTCACAACCAACACGCCCCGTCAAAACACCCCTTCA"
                                         + "GCACAAATTCATACACCCCTACCTTTCCTACCCACGTTCACCACATCATCCCCCCCTCTC"
                                         + "AACATCTTGACTCGCCTCTCTCCAAACACACAATTCACGCAAACAACGCCAC";

            expectedAlignment["Human"] = "ACCCCACTCACCCATACAAACCAACACCACTCTCCACCTAATATACAAATTAATAACCTC"
                                         + "CCACCTTCAGAACTGAACGCCAATCTCATAACCAACACACCCCATCAAAGCACCCCTCCA"
                                         + "ACACAAACCCGCACACCTCCACCCCCCTCGTCTACGCTTACCACGTCATCCCTCCCTCTC"
                                         + "AACACCTTAACTCACCTTCTCCCAAACGCACAATTCGCACACACAACGCCAC";

            expectedOutput.Add(expectedAlignment);

            IList <ISequenceAlignment> actualOutput = null;
            ISequenceAlignmentParser   parser       = new PhylipParser();

            using (StreamReader reader = File.OpenText(filepath))
            {
                actualOutput = parser.Parse(reader);
            }

            CompareOutput(actualOutput, expectedOutput);
        }
示例#7
0
        /// <summary>
        /// Parsers the Phylip file for different test cases based
        /// on Additional parameter
        /// </summary>
        /// <param name="nodeName">Xml Node name</param>
        /// <param name="addParam">Additional parameter</param>
        void ParserGeneralTestCases(string nodeName, ParserTestAttributes addParam)
        {
            // Gets the Filename
            string filePath = utilityObj.xmlUtil.GetTextValue(nodeName, Constants.FilePathNode).TestDir();

            Assert.IsFalse(string.IsNullOrEmpty(filePath));
            ApplicationLog.WriteLine($"Phylip Parser BVT: Reading the File from location '{filePath}'");

            // Get the range list after parsing.
            PhylipParser parserObj = new PhylipParser();

            IEnumerable <ISequenceAlignment> sequenceAlignmentList = null;
            ISequenceAlignment sequenceAlignment = null;

            // Gets the SequenceAlignment list based on the parameters.
            switch (addParam)
            {
            case ParserTestAttributes.Parse:
                sequenceAlignmentList = parserObj.Parse(filePath);
                break;

            case ParserTestAttributes.ParseOne:
                sequenceAlignment = parserObj.ParseOne(filePath);
                break;

            case ParserTestAttributes.ParseTextReader:
                using (var rdrObj = File.OpenRead(filePath))
                {
                    sequenceAlignmentList = parserObj.Parse(rdrObj).ToList();
                }
                break;

            case ParserTestAttributes.ParseOneTextReader:
                using (var rdrObj = File.OpenRead(filePath))
                {
                    sequenceAlignment = parserObj.ParseOne(rdrObj);
                }
                break;

            default:
                break;
            }

            // Gets all the expected values from xml.
            var expectedAlignmentList = new List <Dictionary <string, string> >();
            var expectedAlignmentObj  = new Dictionary <string, string>();

            XElement      expectedAlignmentNodes = utilityObj.xmlUtil.GetNode(nodeName, Constants.ExpectedAlignmentNode);
            IList <XNode> nodes = expectedAlignmentNodes.Nodes().ToList();

            //Get all the values from the elements in the node.
            foreach (XElement node in nodes)
            {
                expectedAlignmentObj[node.Name.ToString()] = node.Value;
            }

            // Create a ISequenceAlignment List
            switch (addParam)
            {
            case ParserTestAttributes.ParseOne:
            case ParserTestAttributes.ParseOneTextReader:
                sequenceAlignmentList = new List <ISequenceAlignment> {
                    sequenceAlignment
                };
                break;

            default:
                break;
            }

            expectedAlignmentList.Add(expectedAlignmentObj);

            Assert.IsTrue(CompareOutput(sequenceAlignmentList.ToList(), expectedAlignmentList));
            ApplicationLog.WriteLine("Phylip Parser BVT: Successfully validated all the Alignment Sequences");
        }