Beispiel #1
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");
        }
Beispiel #2
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);
            }
        }
Beispiel #3
0
        public void XsvSparseBvtFormatterProperties()
        {
            XsvSparseFormatter formatterObj = new XsvSparseFormatter(Constants.CharSeperator,
                                                                     Constants.SequenceIDPrefix);

            Assert.AreEqual(Constants.XsvSparseFormatterDescription, formatterObj.Description);
            Assert.AreEqual(Constants.XsvSparseFileTypes, formatterObj.SupportedFileTypes);
            Assert.AreEqual(Constants.XsvSparseFormatterNode, formatterObj.Name);
            Assert.AreEqual(Constants.XsvSeperator, formatterObj.Separator);
            Assert.AreEqual(Constants.XsvSeqIdPrefix, formatterObj.SequenceIDPrefix);

            ApplicationLog.WriteLine
                ("Successfully validated all the properties of XsvSparse Formatter class.");
        }
Beispiel #4
0
        public void XsvSparseFormatterProperties()
        {
            string XsvTempFileName = Path.GetTempFileName();

            using (XsvSparseFormatter formatterObj = new XsvSparseFormatter(XsvTempFileName, ',', '#'))
            {
                Assert.AreEqual("Sparse Sequence formatter to character separated value file", formatterObj.Description);
                Assert.AreEqual("csv,tsv", formatterObj.SupportedFileTypes);
                Assert.AreEqual("XsvSparseFormatter", formatterObj.Name);
                Assert.AreEqual(',', formatterObj.Separator);
                Assert.AreEqual('#', formatterObj.SequenceIDPrefix);
            }

            if (File.Exists(XsvTempFileName))
            {
                File.Delete(XsvTempFileName);
            }
        }
Beispiel #5
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");
        }
Beispiel #6
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);
            }
        }
Beispiel #7
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);
            }
        }
Beispiel #8
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);
            }
        }