Ejemplo n.º 1
0
        public void XsvContigFormatter()
        {
            // Gets the expected sequence from the Xml
            string filePathObj     = XsvFilename.TestDir();
            string xsvTempFileName = Path.GetTempFileName();

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

            // Read the contigs
            Contig contig = new XsvContigParser(Alphabets.DNA, ',', '#')
                            .ParseContig(filePathObj);

            string seqId = contig.Sequences.Aggregate(string.Empty, (current, seq) => current + (seq.Sequence.ID + ","));

            // Format Xsv file.
            new XsvContigFormatter(',', '#')
            .Format(contig, xsvTempFileName);

            Contig expectedContig = new XsvContigParser(Alphabets.DNA, ',', '#')
                                    .ParseContig(xsvTempFileName);

            string expectedseqId = expectedContig.Sequences.Aggregate(string.Empty, (current, seq) => current + (seq.Sequence.ID + ","));

            // Validate parsed temp file with original Xsv file.
            Assert.AreEqual(contig.Length, expectedContig.Length);
            Assert.AreEqual(contig.Consensus.Count, expectedContig.Consensus.Count);
            Assert.AreEqual(contig.Consensus.ID, expectedContig.Consensus.ID);
            Assert.AreEqual(contig.Sequences.Count, expectedContig.Sequences.Count);
            Assert.AreEqual(seqId.Length, expectedseqId.Length);
            Assert.AreEqual(seqId, expectedseqId);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// XsvSparse parser generic method called by all the test cases
        /// to validate the test case based on the parameters passed.
        /// </summary>
        /// <param name="nodename">Xml node Name.</param>
        /// <param name="additionalParam">Additional parameter
        /// based on which the validation of  test case is done.</param>
        void XsvSparseParserGeneralTestCases(string nodename)
        {
            // Gets the expected file from the Xml
            string filePathObj = utilityObj.xmlUtil.GetTextValue(nodename,
                                                                 Constants.FilePathNode);

            Assert.IsTrue(File.Exists(filePathObj));
            // Logs information to the log file
            ApplicationLog.WriteLine(string.Format((IFormatProvider)null,
                                                   "XsvSparse Parser BVT: File Exists in the Path '{0}'.",
                                                   filePathObj));

            IEnumerable <ISequence> seqList   = null;
            SparseSequence          sparseSeq = null;
            XsvContigParser         parserObj = new XsvContigParser(filePathObj, Alphabets.DNA,
                                                                    Constants.CharSeperator, Constants.SequenceIDPrefix);

            string expectedSeqIds = utilityObj.xmlUtil.GetTextValue(nodename,
                                                                    Constants.SequenceIdNode);

            seqList   = parserObj.Parse();
            sparseSeq = (SparseSequence)seqList.ElementAt(0);

            if (null == sparseSeq)
            {
                string expCount = utilityObj.xmlUtil.GetTextValue(nodename,
                                                                  Constants.SequenceCountNode);

                Assert.IsNotNull(seqList);
                Assert.AreEqual(expCount, seqList.Count());
                ApplicationLog.WriteLine(string.Format((IFormatProvider)null,
                                                       "XsvSparse Parser BVT: Number of Sequences found are '{0}'.",
                                                       expCount));

                string[] expectedSeqIdArray = expectedSeqIds.Split(',');

                List <ISequence> sparseSeqList = seqList.ToList();
                for (int i = 0; i < expectedSeqIdArray.Length; i++)
                {
                    Assert.AreEqual(expectedSeqIdArray[i], sparseSeqList[i].ID);
                }
            }
            else
            {
                string[] idArray = expectedSeqIds.Split(',');
                Assert.AreEqual(sparseSeq.ID, idArray[0]);
            }

            ApplicationLog.WriteLine(
                "XsvSparse Parser BVT: The XsvSparse sequence is validated successfully with Parse() method.");

            Assert.IsNotNull(sparseSeq.Alphabet);
            Assert.AreEqual(sparseSeq.Alphabet.Name.ToLower(CultureInfo.InvariantCulture),
                            utilityObj.xmlUtil.GetTextValue(nodename,
                                                            Constants.AlphabetNameNode).ToLower(CultureInfo.InvariantCulture));

            ApplicationLog.WriteLine(string.Format((IFormatProvider)null,
                                                   "XsvSparse Parser BVT: The Sequence Alphabet is '{0}' and is as expected.",
                                                   sparseSeq.Alphabet.Name));
        }
Ejemplo n.º 3
0
        public void XsvSparseParseContig()
        {
            // Gets the expected file from the Xml
            string filePathObj = utilityObj.xmlUtil.GetTextValue(
                Constants.SimpleXsvSparseNodeName,
                Constants.FilePathNode);

            Assert.IsTrue(File.Exists(filePathObj));
            // Logs information to the log file
            ApplicationLog.WriteLine(string.Format((IFormatProvider)null,
                                                   "XsvSparse Formatter BVT: File Exists in the Path '{0}'.",
                                                   filePathObj));

            using (XsvContigParser parserObj = new XsvContigParser(filePathObj,
                                                                   Alphabets.DNA, ',', '#'))
            {
                parserObj.Parse();

                Contig contig = parserObj.ParseContig();

                // Validate parsed temp file with original Xsv file.
                Assert.AreEqual(26048682, contig.Length);
                Assert.AreEqual(26048682, contig.Consensus.Count);
                Assert.AreEqual("Chr22+Chr22+Chr22+Chr22", contig.Consensus.ID);
                Assert.AreEqual(56, contig.Sequences.Count);
            }
            // Log to GUI.
            Console.WriteLine("Successfully validated the ParseConting() method with Xsv file");
            ApplicationLog.WriteLine("Successfully validated the ParseConting() method with Xsv file");
        }
Ejemplo n.º 4
0
        public void XsvSparseContigFormatterWrite()
        {
            // Gets the expected sequence from the Xml
            string filePathObj = utilityObj.xmlUtil.GetTextValue(
                Constants.SimpleXsvSparseNodeName,
                Constants.FilePathNode);

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

            // Logs information to the log file
            ApplicationLog.WriteLine(string.Format((IFormatProvider)null,
                                                   "Xsv Contig Formatter BVT: File Exists in the Path '{0}'.",
                                                   filePathObj));
            Contig contig, expectedContig;

            using (XsvContigParser parserObj = new XsvContigParser(filePathObj, Alphabets.DNA,
                                                                   ',', '#'))
            {
                contig = parserObj.ParseContig();
            }

            string seqId = string.Empty;

            foreach (Contig.AssembledSequence seq in contig.Sequences)
            {
                seqId += seq.Sequence.ID + ",";
            }

            // Write Xsv file.
            using (XsvContigFormatter formatObj = new XsvContigFormatter(Constants.XsvTempFileName, ',', '#'))
            {
                formatObj.Write(contig);
            }

            using (XsvContigParser parserObjNew = new XsvContigParser(Constants.XsvTempFileName, Alphabets.DNA,
                                                                      ',', '#'))
            {
                expectedContig = parserObjNew.ParseContig();
            }

            string expectedseqId = string.Empty;

            foreach (Contig.AssembledSequence seq in expectedContig.Sequences)
            {
                expectedseqId += seq.Sequence.ID + ",";
            }

            // Validate parsed temp file with original Xsv file.
            Assert.AreEqual(contig.Length, expectedContig.Length);
            Assert.AreEqual(contig.Consensus.Count, expectedContig.Consensus.Count);
            Assert.AreEqual(contig.Consensus.ID, expectedContig.Consensus.ID);
            Assert.AreEqual(contig.Sequences.Count, expectedContig.Sequences.Count);
            Assert.AreEqual(seqId.Length, expectedseqId.Length);
            Assert.AreEqual(seqId, expectedseqId);

            // Log to VSTest GUI.
            Console.WriteLine("Successfully validated the Write Xsv file");
            ApplicationLog.WriteLine("Successfully validated the Write Xsv file");
        }
Ejemplo n.º 5
0
        /// <summary>
        /// XsvSparse formatter generic method called by all the test cases
        /// to validate the test case based on the parameters passed.
        /// </summary>
        /// <param name="nodename">Xml node Name.</param>
        /// <param name="additionalParam">Additional parameter
        /// based on which the validation of  test case is done.</param>
        void XsvSparseFormatterGeneralTestCases(string nodename,
                                                AdditionalParameters additionalParam)
        {
            // Gets the expected sequence from the Xml
            string filePathObj = this.utilityObj.xmlUtil.GetTextValue(nodename,
                                                                      Constants.FilePathNode).TestDir();

            Assert.IsTrue(File.Exists(filePathObj));
            // Logs information to the log file
            ApplicationLog.WriteLine(string.Format((IFormatProvider)null,
                                                   "XsvSparse Formatter BVT: File Exists in the Path '{0}'.",
                                                   filePathObj));

            IEnumerable <ISequence> seqList   = null;
            SparseSequence          sparseSeq = null;
            XsvContigParser         parserObj = new XsvContigParser(Alphabets.DNA, Constants.CharSeperator, Constants.SequenceIDPrefix);

            seqList   = parserObj.Parse(filePathObj);
            sparseSeq = (SparseSequence)seqList.ElementAt(0);

            IReadOnlyList <IndexedItem <byte> > sparseSeqItems = sparseSeq.GetKnownSequenceItems();

            string tempFile = Path.GetTempFileName();

            XsvSparseFormatter formatterObj = new XsvSparseFormatter(Constants.CharSeperator, Constants.SequenceIDPrefix);

            switch (additionalParam)
            {
            case AdditionalParameters.FormatFilePath:
                formatterObj.Format(sparseSeq, tempFile);
                break;

            default:
                break;

            case AdditionalParameters.ForamtListWithFilePath:
                formatterObj.Format(seqList.ToList(), tempFile);
                break;
            }
            XsvContigParser newParserObj = new XsvContigParser(Alphabets.DNA, Constants.CharSeperator, Constants.SequenceIDPrefix);

            // Parse a formatted Xsv file and validate.
            seqList = newParserObj.Parse(filePathObj);
            SparseSequence expectedSeq = (SparseSequence)seqList.ElementAt(0);

            IReadOnlyList <IndexedItem <byte> > expectedSparseSeqItems = expectedSeq.GetKnownSequenceItems();

            for (int i = 0; i < sparseSeqItems.Count; i++)
            {
                IndexedItem <byte> seqItem         = sparseSeqItems[i];
                IndexedItem <byte> expectedSeqItem = expectedSparseSeqItems[i];
                Assert.AreEqual(seqItem.Index, expectedSeqItem.Index);
            }

            ApplicationLog.WriteLine("Successfully validated the format Xsv file");
        }
Ejemplo n.º 6
0
        /// <summary>
        /// XsvSparse formatter generic method called by all the test cases
        /// to validate the test case based on the parameters passed.
        /// </summary>
        /// <param name="switchParam">Additional parameter
        /// based on which the validation of  test case is done.</param>
        private void XsvSparseFormatterGeneralTestCases(string switchParam)
        {
            // Gets the expected sequence from the Xml
            string filePathObj = XsvFilename.TestDir();

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

            XsvContigParser         parserObj = new XsvContigParser(Alphabets.DNA, ',', '#');
            IEnumerable <ISequence> seqList   = parserObj.Parse(filePathObj);
            SparseSequence          sparseSeq = (SparseSequence)seqList.FirstOrDefault();

            var sparseSeqItems = sparseSeq.GetKnownSequenceItems();

            string             xsvTempFileName = Path.GetTempFileName();
            XsvSparseFormatter formatterObj    = new XsvSparseFormatter(',', '#');

            using (formatterObj.Open(xsvTempFileName))
            {
                switch (switchParam)
                {
                case "FormatFilePath":
                    formatterObj.Format(sparseSeq);
                    break;

                case "ForamtListWithFilePath":
                    formatterObj.Format(sparseSeq);
                    break;
                }
            }

            // Parse a formatted Xsv file and validate.
            var parserObj1 = new XsvContigParser(Alphabets.DNA, ',', '#');

            using (parserObj1.Open(xsvTempFileName))
            {
                seqList = parserObj1.Parse();
                SparseSequence expectedSeq = (SparseSequence)seqList.FirstOrDefault();

                var expectedSparseSeqItems = expectedSeq.GetKnownSequenceItems();

                Assert.AreEqual(sparseSeqItems.Count, expectedSparseSeqItems.Count);
                for (int i = 0; i < sparseSeqItems.Count; i++)
                {
                    Assert.AreEqual(sparseSeqItems.ElementAt(i).Index, expectedSparseSeqItems.ElementAt(i).Index);
                    Assert.AreEqual(sparseSeqItems.ElementAt(i).Item, expectedSparseSeqItems.ElementAt(i).Item);
                }
            }

            // Delete the temporary file.
            if (File.Exists(xsvTempFileName))
            {
                File.Delete(xsvTempFileName);
            }
        }
Ejemplo n.º 7
0
        public void XsvSparseBvtParserProperties()
        {
            XsvContigParser xsvParser = new XsvContigParser(Alphabets.DNA, ',', '#');

            Assert.AreEqual(Constants.XsvSparseDescription, xsvParser.Description);
            Assert.AreEqual(Constants.XsvSparseFileTypes, xsvParser.SupportedFileTypes);
            Assert.AreEqual(Constants.XsvSparseName, xsvParser.Name);

            ApplicationLog.WriteLine
                ("Successfully validated all the properties of XsvSparse Parser class.");
        }
Ejemplo n.º 8
0
        public void XsvSparseBvtParserProperties()
        {
            // Gets the expected file from the Xml
            string filePathObj = utilityObj.xmlUtil.GetTextValue(Constants.SimpleXsvSparseNodeName,
                                                                 Constants.FilePathNode);

            XsvContigParser xsvParser = new XsvContigParser(filePathObj, Alphabets.DNA, ',', '#');

            Assert.AreEqual(Constants.XsvSparseDescription, xsvParser.Description);
            Assert.AreEqual(Constants.XsvSparseFileTypes, xsvParser.SupportedFileTypes);
            Assert.AreEqual(Constants.XsvSparseName, xsvParser.Name);

            ApplicationLog.WriteLine
                ("Successfully validated all the properties of XsvSparse Parser class.");
        }
Ejemplo n.º 9
0
        public void XsvContigFormatter()
        {
            // Gets the expected sequence from the Xml
            string filePathObj     = Directory.GetCurrentDirectory() + XsvFilename;
            string XsvTempFileName = Path.GetTempFileName();

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

            XsvContigParser parserObj = new XsvContigParser(filePathObj, Alphabets.DNA, ',', '#');

            Contig contig, expectedContig;

            contig = parserObj.ParseContig();
            string seqId = string.Empty;

            foreach (Contig.AssembledSequence seq in contig.Sequences)
            {
                seqId += seq.Sequence.ID + ",";
            }

            // Format Xsv file.
            XsvContigFormatter formatObj = new XsvContigFormatter(XsvTempFileName, ',', '#');

            formatObj.Write(contig);
            formatObj.Close();
            formatObj.Dispose();

            XsvContigParser parserObj1 = new XsvContigParser(XsvTempFileName, Alphabets.DNA, ',', '#');

            expectedContig = parserObj1.ParseContig();
            string expectedseqId = string.Empty;

            foreach (Contig.AssembledSequence seq in expectedContig.Sequences)
            {
                expectedseqId += seq.Sequence.ID + ",";
            }

            // Validate parsed temp file with original Xsv file.
            Assert.AreEqual(contig.Length, expectedContig.Length);
            Assert.AreEqual(contig.Consensus.Count, expectedContig.Consensus.Count);
            Assert.AreEqual(contig.Consensus.ID, expectedContig.Consensus.ID);
            Assert.AreEqual(contig.Sequences.Count, expectedContig.Sequences.Count);
            Assert.AreEqual(seqId.Length, expectedseqId.Length);
            Assert.AreEqual(seqId, expectedseqId);
        }
Ejemplo n.º 10
0
        public void XsvSparseContigFormatterWrite()
        {
            // Gets the expected sequence from the Xml
            string filePathObj = this.utilityObj.xmlUtil.GetTextValue(
                Constants.SimpleXsvSparseNodeName,
                Constants.FilePathNode).TestDir();

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

            // Logs information to the log file
            ApplicationLog.WriteLine(string.Format((IFormatProvider)null,
                                                   "Xsv Contig Formatter BVT: File Exists in the Path '{0}'.",
                                                   filePathObj));
            Contig expectedContig;

            XsvContigParser parserObj = new XsvContigParser(Alphabets.DNA, ',', '#');
            Contig          contig    = parserObj.ParseContig(filePathObj);

            string seqId = contig.Sequences.Aggregate(string.Empty, (current, seq) => current + (seq.Sequence.ID + ","));

            // Write Xsv file.
            XsvContigFormatter formatObj = new XsvContigFormatter(',', '#');

            formatObj.Format(contig, Constants.XsvTempFileName);

            XsvContigParser parserObjNew = new XsvContigParser(Alphabets.DNA, ',', '#');

            expectedContig = parserObjNew.ParseContig(Constants.XsvTempFileName);

            string expectedseqId = expectedContig.Sequences.Aggregate(string.Empty, (current, seq) => current + (seq.Sequence.ID + ","));

            // Validate parsed temp file with original Xsv file.
            Assert.AreEqual(contig.Length, expectedContig.Length);
            Assert.AreEqual(contig.Consensus.Count, expectedContig.Consensus.Count);
            Assert.AreEqual(contig.Consensus.ID, expectedContig.Consensus.ID);
            Assert.AreEqual(contig.Sequences.Count, expectedContig.Sequences.Count);
            Assert.AreEqual(seqId.Length, expectedseqId.Length);
            Assert.AreEqual(seqId, expectedseqId);
            File.Delete(Constants.XsvTempFileName);
            ApplicationLog.WriteLine("Successfully validated the Write Xsv file");
        }
Ejemplo n.º 11
0
        public void XsvSparseBvtFormatterFormatString()
        {
            // Gets the expected sequence from the Xml
            string filePathObj = Utility._xmlUtil.GetTextValue(Constants.SimpleXsvSparseNodeName,
                                                               Constants.FilePathNode);
            string expectedString = Utility._xmlUtil.GetTextValue(Constants.SimpleXsvSparseNodeName,
                                                                  Constants.expectedString);

            Assert.IsTrue(File.Exists(filePathObj));
            // Logs information to the log file
            ApplicationLog.WriteLine(string.Format(null,
                                                   "XsvSparse Formatter BVT: File Exists in the Path '{0}'.",
                                                   filePathObj));

            IList <ISequence> seqList   = null;
            SparseSequence    sparseSeq = null;
            XsvContigParser   parserObj = new XsvContigParser(Encodings.IupacNA, Alphabets.DNA,
                                                              Constants.CharSeperator, Constants.SequenceIDPrefix);

            seqList   = parserObj.Parse(filePathObj);
            sparseSeq = (SparseSequence)seqList[0];


            XsvSparseFormatter formatterObj = new XsvSparseFormatter(Constants.CharSeperator,
                                                                     Constants.SequenceIDPrefix);

            string formattedString = formatterObj.FormatString(sparseSeq);

            formattedString = formattedString.Replace("\r", "").Replace("\n", "");

            Assert.AreEqual(expectedString, formattedString);

            // Log to Nunit GUI.
            Console.WriteLine("Successfully validated the formatString Xsv file");
            ApplicationLog.WriteLine("Successfully validated the formatString Xsv file");
        }
Ejemplo n.º 12
0
        /// <summary>
        /// XsvSparse parser generic method called by all the test cases
        /// to validate the test case based on the parameters passed.
        /// </summary>
        private void XsvSparseParserGeneralTestCases()
        {
            // Gets the expected sequence from the Xml
            string filePathObj = XsvFilename.TestDir();

            Assert.IsTrue(File.Exists(filePathObj));
            XsvContigParser parserObj = new XsvContigParser(Alphabets.DNA, ',', '#');

            string expectedSeqIds = "Chr22+Chr22+Chr22+Chr22,m;Chr22;16,m;Chr22;17,m;Chr22;29,m;Chr22;32,m;Chr22;39,m;Chr22;54,m;Chr22;72,m;Chr22;82,m;Chr22;85,m;Chr22;96,m;Chr22;99,m;Chr22;118,m;Chr22;119,m;Chr22;129,m;Chr22;136,m;Chr22;146,m;Chr22;153,m;Chr22;161,m;Chr22;162,m;Chr22;174,m;Chr22;183,m;Chr22;209,m;Chr22;210,m;Chr22;224,m;Chr22;241,m;Chr22;243,m;Chr22;253,m;Chr22;267,m;Chr22;309,m;Chr22;310,m;Chr22;313,m;Chr22;331,m;Chr22;333,m;Chr22;338,m;Chr22;348,m;Chr22;352,m;Chr22;355,m;Chr22;357,m;Chr22;368,m;Chr22;370,m;Chr22;380,m;Chr22;382,m;Chr22;402,m;Chr22;418,m;Chr22;419,m;Chr22;429,m;Chr22;432,m;Chr22;450,m;Chr22;462,m;Chr22;482,m;Chr22;484,m;Chr22;485,m;Chr22;494,m;Chr22;508,m;Chr22;509,m;Chr22;512,";

            IEnumerable <ISequence> seqList   = parserObj.Parse(filePathObj);
            SparseSequence          sparseSeq = (SparseSequence)seqList.FirstOrDefault();

            if (null == sparseSeq)
            {
                string expCount = "57";
                Assert.IsNotNull(seqList);
                Assert.AreEqual(expCount, seqList.ToList().Count);

                StringBuilder actualId = new StringBuilder();
                foreach (ISequence seq in seqList)
                {
                    SparseSequence sps = (SparseSequence)seq;
                    actualId.Append(sps.ID);
                    actualId.Append(",");
                }

                Assert.AreEqual(expectedSeqIds, actualId.ToString());
            }
            else
            {
                string[] idArray = expectedSeqIds.Split(',');
                Assert.AreEqual(sparseSeq.ID, idArray[0]);
            }

            string             XsvTempFileName = Path.GetTempFileName();
            XsvSparseFormatter formatter       = new XsvSparseFormatter(',', '#');

            using (formatter.Open(XsvTempFileName))
            {
                formatter.Format(seqList.ToList());
            }

            string expectedOutput = string.Empty;

            using (StreamReader readerSource = new StreamReader(filePathObj))
            {
                expectedOutput = readerSource.ReadToEnd();
            }

            string actualOutput = string.Empty;

            using (StreamReader readerDest = new StreamReader(XsvTempFileName))
            {
                actualOutput = readerDest.ReadToEnd();
            }

            Assert.AreEqual(Utility.CleanupWhiteSpace(expectedOutput),
                            Utility.CleanupWhiteSpace(actualOutput));


            Assert.IsNotNull(sparseSeq.Alphabet);
            // Delete the temporary file.
            if (File.Exists(XsvTempFileName))
            {
                File.Delete(XsvTempFileName);
            }
        }
Ejemplo n.º 13
0
        /// <summary>
        /// XsvSparse formatter generic method called by all the test cases
        /// to validate the test case based on the parameters passed.
        /// </summary>
        /// <param name="nodename">Xml node Name.</param>
        /// <param name="additionalParam">Additional parameter
        /// based on which the validation of  test case is done.</param>
        static void XsvSparseFormatterGeneralTestCases(string nodename,
                                                       AdditionalParameters additionalParam)
        {
            // Gets the expected sequence from the Xml
            string filePathObj = Utility._xmlUtil.GetTextValue(nodename,
                                                               Constants.FilePathNode);

            Assert.IsTrue(File.Exists(filePathObj));
            // Logs information to the log file
            ApplicationLog.WriteLine(string.Format(null,
                                                   "XsvSparse Formatter BVT: File Exists in the Path '{0}'.",
                                                   filePathObj));

            IList <ISequence> seqList   = null;
            SparseSequence    sparseSeq = null;
            XsvContigParser   parserObj = new XsvContigParser(Encodings.IupacNA, Alphabets.DNA,
                                                              Constants.CharSeperator, Constants.SequenceIDPrefix);

            seqList   = parserObj.Parse(filePathObj);
            sparseSeq = (SparseSequence)seqList[0];

            IList <IndexedItem <ISequenceItem> > sparseSeqItems =
                sparseSeq.GetKnownSequenceItems();

            XsvSparseFormatter formatterObj = new XsvSparseFormatter(Constants.CharSeperator,
                                                                     Constants.SequenceIDPrefix);

            switch (additionalParam)
            {
            case AdditionalParameters.FormatFilePath:
                formatterObj.Format(sparseSeq, Constants.XsvTempFileName);
                break;

            default:
                break;

            case AdditionalParameters.ForamtListWithFilePath:
                formatterObj.Format(seqList, Constants.XsvTempFileName);
                break;

            case AdditionalParameters.FormatTextWriter:
                using (TextWriter writer = new StreamWriter(Constants.XsvTempFileName))
                {
                    formatterObj.Format(sparseSeq, writer);
                }
                break;

            case AdditionalParameters.FormatTextWriterWithOffset:
                using (TextWriter writer = new StreamWriter(Constants.XsvTempFileName))
                {
                    formatterObj.Format(sparseSeq, 0, writer);
                }
                break;

            case AdditionalParameters.FormatListTextWriter:
                using (TextWriter writer = new StreamWriter(Constants.XsvTempFileName))
                {
                    formatterObj.Format(seqList, writer);
                }
                break;
            }

            // Parse a formatted Xsv file and validate.
            SparseSequence expectedSeq;

            seqList     = parserObj.Parse(Constants.XsvTempFileName);
            expectedSeq = (SparseSequence)seqList[0];

            IList <IndexedItem <ISequenceItem> > expectedSparseSeqItems =
                expectedSeq.GetKnownSequenceItems();

            for (int i = 0; i < sparseSeqItems.Count; i++)
            {
                IndexedItem <ISequenceItem> seqItem         = sparseSeqItems[i];
                IndexedItem <ISequenceItem> expectedSeqItem = expectedSparseSeqItems[i];
                Assert.AreEqual(seqItem.Index, expectedSeqItem.Index);
            }

            // Log to Nunit GUI.
            Console.WriteLine("Successfully validated the format Xsv file");
            ApplicationLog.WriteLine("Successfully validated the format Xsv file");

            // Delete the temporary file.
            if (File.Exists(Constants.XsvTempFileName))
            {
                File.Delete(Constants.XsvTempFileName);
            }
        }
Ejemplo n.º 14
0
        /// <summary>
        /// XsvSparse parser generic method called by all the test cases
        /// to validate the test case based on the parameters passed.
        /// </summary>
        /// <param name="nodename">Xml node Name.</param>
        /// <param name="additionalParam">Additional parameter
        /// based on which the validation of  test case is done.</param>
        static void XsvSparseParserGeneralTestCases(string nodename,
                                                    AdditionalParameters additionalParam)
        {
            // Gets the expected sequence from the Xml
            string filePathObj = Utility._xmlUtil.GetTextValue(nodename,
                                                               Constants.FilePathNode);

            Assert.IsTrue(File.Exists(filePathObj));
            // Logs information to the log file
            ApplicationLog.WriteLine(string.Format(null,
                                                   "XsvSparse Parser BVT: File Exists in the Path '{0}'.",
                                                   filePathObj));

            IList <ISequence> seqList   = null;
            SparseSequence    sparseSeq = null;
            XsvContigParser   parserObj = new XsvContigParser(Encodings.IupacNA, Alphabets.DNA,
                                                              Constants.CharSeperator, Constants.SequenceIDPrefix);

            string expectedSeqIds = Utility._xmlUtil.GetTextValue(nodename,
                                                                  Constants.SequenceIdNode);

            switch (additionalParam)
            {
            case AdditionalParameters.ParseTextReader:
                seqList   = parserObj.Parse(new StreamReader(filePathObj));
                sparseSeq = (SparseSequence)seqList[0];
                break;

            case AdditionalParameters.ParseOneTextReader:
                sparseSeq =
                    (SparseSequence)parserObj.ParseOne(new StreamReader(filePathObj));
                break;

            case AdditionalParameters.ParseOneFilePath:
                sparseSeq = (SparseSequence)parserObj.ParseOne(filePathObj);
                break;

            case AdditionalParameters.ParseFilePath:
                seqList   = parserObj.Parse(filePathObj);
                sparseSeq = (SparseSequence)seqList[0];
                break;

            case AdditionalParameters.ParseTextReaderReadOnly:
                seqList   = parserObj.Parse(new StreamReader(filePathObj), false);
                sparseSeq = (SparseSequence)seqList[0];
                break;

            case AdditionalParameters.ParseOneTextReaderReadOnly:
                sparseSeq =
                    (SparseSequence)parserObj.ParseOne(new StreamReader(filePathObj),
                                                       false);
                break;

            case AdditionalParameters.ParseOneFilePathReadOnly:
                sparseSeq = (SparseSequence)parserObj.ParseOne(filePathObj,
                                                               false);
                break;

            default:
                seqList   = parserObj.Parse(filePathObj, false);
                sparseSeq = (SparseSequence)seqList[0];
                break;
            }

            if (null == sparseSeq)
            {
                string expCount = Utility._xmlUtil.GetTextValue(nodename,
                                                                Constants.SequenceCountNode);

                Assert.IsNotNull(seqList);
                Assert.AreEqual(expCount, seqList.Count);
                ApplicationLog.WriteLine(string.Format(null,
                                                       "XsvSparse Parser BVT: Number of Sequences found are '{0}'.",
                                                       expCount));

                StringBuilder actualId = new StringBuilder();
                foreach (ISequence seq in seqList)
                {
                    SparseSequence sps = (SparseSequence)seq;
                    actualId.Append(sps.ID);
                    actualId.Append(",");
                }

                Assert.AreEqual(expectedSeqIds, actualId.ToString());
            }
            else
            {
                string[] idArray = expectedSeqIds.Split(',');
                Assert.AreEqual(sparseSeq.DisplayID, idArray[0]);
            }

            ApplicationLog.WriteLine(
                "XsvSparse Parser BVT: The XsvSparse sequence is validated successfully with Parse() method.");
            // Logs to the NUnit GUI (Console.Out) window
            Console.WriteLine(
                "XsvSparse Parser BVT: The XsvSparse sequence is validated successfully with Parse() method.");

            Assert.IsNotNull(sparseSeq.Alphabet);
            Assert.AreEqual(sparseSeq.Alphabet.Name.ToLower(CultureInfo.CurrentCulture),
                            Utility._xmlUtil.GetTextValue(nodename,
                                                          Constants.AlphabetNameNode).ToLower(CultureInfo.CurrentCulture));

            ApplicationLog.WriteLine(string.Format(null,
                                                   "XsvSparse Parser BVT: The Sequence Alphabet is '{0}' and is as expected.",
                                                   sparseSeq.Alphabet.Name));
        }
Ejemplo n.º 15
0
        public void XsvSparseContigFormatterFormat()
        {
            // Gets the expected sequence from the Xml
            string filePathObj = Utility._xmlUtil.GetTextValue(
                Constants.SimpleXsvSparseNodeName,
                Constants.FilePathNode);

            Assert.IsTrue(File.Exists(filePathObj));
            // Logs information to the log file
            ApplicationLog.WriteLine(string.Format(null,
                                                   "XsvSparse Formatter BVT: File Exists in the Path '{0}'.",
                                                   filePathObj));

            IEncoding       encode    = Encodings.IupacNA;
            XsvContigParser parserObj = new XsvContigParser(encode,
                                                            Alphabets.DNA, ',', '#');
            Contig contig, expectedContig;

            // Parse a file.
            using (TextReader tr = new StreamReader(File.OpenRead(filePathObj)))
            {
                contig = parserObj.ParseContig(tr, false);
            }

            string seqId = string.Empty;

            foreach (Contig.AssembledSequence seq in contig.Sequences)
            {
                seqId += seq.Sequence.ID + ",";
            }

            // Format Xsv file.
            XsvContigFormatter formatObj = new XsvContigFormatter(',', '#');

            using (TextWriter tw = new StreamWriter(File.OpenWrite(
                                                        Constants.XsvTempFileName)))
            {
                formatObj.Format(contig, tw);
            }

            // Parse formatted TempFile.
            using (TextReader tr = new StreamReader(
                       File.OpenRead(Constants.XsvTempFileName)))
            {
                expectedContig = parserObj.ParseContig(tr, false);
            }


            string expectedseqId = string.Empty;

            foreach (Contig.AssembledSequence seq in expectedContig.Sequences)
            {
                expectedseqId += seq.Sequence.ID + ",";
            }

            // Validate parsed temp file with original Xsv file.
            Assert.AreEqual(contig.Length, expectedContig.Length);
            Assert.AreEqual(contig.Consensus.Count, expectedContig.Consensus.Count);
            Assert.AreEqual(contig.Consensus.DisplayID, expectedContig.Consensus.DisplayID);
            Assert.AreEqual(contig.Consensus.ID, expectedContig.Consensus.ID);
            Assert.AreEqual(contig.Sequences.Count, expectedContig.Sequences.Count);
            Assert.AreEqual(seqId.Length, expectedseqId.Length);
            Assert.AreEqual(seqId, expectedseqId);

            // Log to Nunit GUI.
            Console.WriteLine("Successfully validated the format Xsv file");
            ApplicationLog.WriteLine("Successfully validated the format Xsv file");
        }
Ejemplo n.º 16
0
        /// <summary>
        /// XsvSparse formatter generic method called by all the test cases
        /// to validate the test case based on the parameters passed.
        /// </summary>
        /// <param name="switchParam">Additional parameter
        /// based on which the validation of  test case is done.</param>
        private void XsvSparseFormatterGeneralTestCases(string switchParam)
        {
            // Gets the expected sequence from the Xml
            string filePathObj = Directory.GetCurrentDirectory() + XsvFilename;

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

            IEnumerable <ISequence> seqList   = null;
            SparseSequence          sparseSeq = null;
            XsvContigParser         parserObj = new XsvContigParser(filePathObj, Alphabets.DNA, ',', '#');

            seqList   = parserObj.Parse();
            sparseSeq = (SparseSequence)seqList.FirstOrDefault();

            IList <IndexedItem <byte> > sparseSeqItems =
                sparseSeq.GetKnownSequenceItems();

            string XsvTempFileName = Path.GetTempFileName();

            using (XsvSparseFormatter formatterObj = new XsvSparseFormatter(XsvTempFileName, ',', '#'))
            {
                switch (switchParam)
                {
                case "FormatFilePath":
                    formatterObj.Write(sparseSeq);
                    break;

                default:
                    break;

                case "ForamtListWithFilePath":
                    formatterObj.Write(sparseSeq);
                    break;
                }
            }

            // Parse a formatted Xsv file and validate.
            using (XsvContigParser parserObj1 = new XsvContigParser(XsvTempFileName, Alphabets.DNA, ',', '#'))
            {
                SparseSequence expectedSeq;
                seqList = parserObj1.Parse();


                expectedSeq = (SparseSequence)seqList.FirstOrDefault();

                IList <IndexedItem <byte> > expectedSparseSeqItems =
                    expectedSeq.GetKnownSequenceItems();

                Assert.AreEqual(sparseSeqItems.Count, expectedSparseSeqItems.Count);
                for (int i = 0; i < sparseSeqItems.Count; i++)
                {
                    Assert.AreEqual(sparseSeqItems.ElementAt(i).Index, expectedSparseSeqItems.ElementAt(i).Index);
                    Assert.AreEqual(sparseSeqItems.ElementAt(i).Item, expectedSparseSeqItems.ElementAt(i).Item);
                }
            }

            // Delete the temporary file.
            if (File.Exists(XsvTempFileName))
            {
                File.Delete(XsvTempFileName);
            }
        }