/// <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)); 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); }
/// <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); 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"); }
/// <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 = Directory.GetCurrentDirectory() + XsvFilename; 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(expectedOutput.Replace("\r\n", System.Environment.NewLine), actualOutput); Assert.IsNotNull(sparseSeq.Alphabet); // Delete the temporary file. if (File.Exists(XsvTempFileName)) File.Delete(XsvTempFileName); }