// // Read a Bed file into memory // public static SequenceRangeGrouping ReadBedFile(string filename) { var parser = new BedParser(); IList <ISequenceRange> listSequenceRange = parser.ParseRange(filename); if (verbose) { //listSequenceRange.ToString(); Console.Error.WriteLine("Processed File: {0}", filename); ListSequenceRangeToString(listSequenceRange); } var srg = new SequenceRangeGrouping(listSequenceRange); if (arguments.normalizeInputs) { srg.MergeOverlaps(); // could be called Normalize() or Cannonicalize() } return(srg); }
/// <summary> /// Formats the Range/RangeGroup for different test cases based /// on Additional parameter /// </summary> /// <param name="nodeName">Xml Node name</param> /// <param name="addParam">Additional parameter</param> private void FormatterGeneralTestCases(string nodeName, AdditionalParameters addParam) { IList <ISequenceRange> rangeList = new List <ISequenceRange>(); var rangeGroup = new SequenceRangeGrouping(); // Gets the file name. string filePath = utilityObj.xmlUtil.GetTextValue(nodeName, Constants.FilePathNode).TestDir(); // Condition to check if Parse() happens before Format() switch (addParam) { case AdditionalParameters.ParseRangeGroup: var initialParserGroupObj = new BedParser(); rangeGroup = initialParserGroupObj.ParseRangeGrouping(filePath); break; case AdditionalParameters.ParseRange: var initialParserObj = new BedParser(); rangeList = initialParserObj.ParseRange(filePath); break; default: // Gets all the expected values from xml. string expectedID = utilityObj.xmlUtil.GetTextValue( nodeName, Constants.IDNode); string expectedStart = utilityObj.xmlUtil.GetTextValue( nodeName, Constants.StartNode); string expectedEnd = utilityObj.xmlUtil.GetTextValue( nodeName, Constants.EndNode); string[] expectedIDs = expectedID.Split(','); string[] expectedStarts = expectedStart.Split(','); string[] expectedEnds = expectedEnd.Split(','); // Gets the Range Group or Range based on the additional parameter switch (addParam) { case AdditionalParameters.RangeGroupTextWriter: case AdditionalParameters.RangeGroupFileName: for (int i = 0; i < expectedIDs.Length; i++) { var rangeObj1 = new SequenceRange(expectedIDs[i], long.Parse(expectedStarts[i], null), long.Parse(expectedEnds[i], null)); rangeGroup.Add(rangeObj1); } break; default: for (int i = 0; i < expectedIDs.Length; i++) { var rangeObj2 = new SequenceRange(expectedIDs[i], long.Parse(expectedStarts[i], null), long.Parse(expectedEnds[i], null)); rangeList.Add(rangeObj2); } break; } break; } var formatterObj = new BedFormatter(); // Gets the Range list/Range Group based on the parameters. switch (addParam) { case AdditionalParameters.RangeFileName: case AdditionalParameters.ParseRange: formatterObj.Format(rangeList, Constants.BedTempFileName); break; case AdditionalParameters.RangeTextWriter: using (var txtWriter = File.Create(Constants.BedTempFileName)) { formatterObj.Format(txtWriter, rangeList); } break; case AdditionalParameters.RangeGroupFileName: case AdditionalParameters.ParseRangeGroup: formatterObj.Format(rangeGroup, Constants.BedTempFileName); break; case AdditionalParameters.RangeGroupTextWriter: using (var txtWriter = File.Create(Constants.BedTempFileName)) { formatterObj.Format(txtWriter, rangeGroup); } break; default: break; } // Reparse to validate the results var parserObj = new BedParser(); IList <ISequenceRange> newRangeList = parserObj.ParseRange(Constants.BedTempFileName); // Validation of all the properties. for (int i = 0; i < rangeList.Count; i++) { Assert.AreEqual(rangeList[i].ID, newRangeList[i].ID); Assert.AreEqual(rangeList[i].Start, newRangeList[i].Start); Assert.AreEqual(rangeList[i].End, newRangeList[i].End); // Validation of all metadata information. if (rangeList[i].Metadata.Count > 0) { if (rangeList[i].Metadata.ContainsKey("Name")) { Assert.AreEqual(rangeList[i].Metadata["Name"], newRangeList[i].Metadata["Name"]); } if (rangeList[i].Metadata.ContainsKey("Score")) { Assert.AreEqual(rangeList[i].Metadata["Score"], newRangeList[i].Metadata["Score"]); } if (rangeList[i].Metadata.ContainsKey("Strand")) { Assert.AreEqual(rangeList[i].Metadata["Strand"], newRangeList[i].Metadata["Strand"]); } if (rangeList[i].Metadata.ContainsKey("ThickStart")) { Assert.AreEqual(rangeList[i].Metadata["ThickStart"], newRangeList[i].Metadata["ThickStart"]); } if (rangeList[i].Metadata.ContainsKey("ThickEnd")) { Assert.AreEqual(rangeList[i].Metadata["ThickEnd"], newRangeList[i].Metadata["ThickEnd"]); } if (rangeList[i].Metadata.ContainsKey("ItemRGB")) { Assert.AreEqual(rangeList[i].Metadata["ItemRGB"], newRangeList[i].Metadata["ItemRGB"]); } if (rangeList[i].Metadata.ContainsKey("BlockCount")) { Assert.AreEqual(rangeList[i].Metadata["BlockCount"], newRangeList[i].Metadata["BlockCount"]); } if (rangeList[i].Metadata.ContainsKey("BlockSizes")) { Assert.AreEqual(rangeList[i].Metadata["BlockSizes"], newRangeList[i].Metadata["BlockSizes"]); } if (rangeList[i].Metadata.ContainsKey("BlockStarts")) { Assert.AreEqual(rangeList[i].Metadata["BlockStarts"], newRangeList[i].Metadata["BlockStarts"]); } ApplicationLog.WriteLine( "Bed Formatter BVT: Successfully validated all the metadata information"); } } ApplicationLog.WriteLine( "Bed Formatter BVT: Successfully validated the ID, Start and End Ranges"); // Cleanup the file. if (File.Exists(Constants.BedTempFileName)) { File.Delete(Constants.BedTempFileName); } }
/// <summary> /// Parsers the Bed file for different test cases based /// on Additional parameter /// </summary> /// <param name="nodeName">Xml Node name</param> /// <param name="addParam">Additional parameter</param> private void ParserGeneralTestCases(string nodeName, AdditionalParameters addParam) { // Gets the Filename string filePath = utilityObj.xmlUtil.GetTextValue(nodeName, Constants.FilePathNode).TestDir(); Assert.IsFalse(string.IsNullOrEmpty(filePath)); ApplicationLog.WriteLine($"Bed Parser BVT: Reading the File from location '{filePath}'"); // Get the rangelist after parsing. var parserObj = new BedParser(); IList <ISequenceRange> rangeList = null; SequenceRangeGrouping rangeGroup = null; // Gets the Range list/Range Group based on the parameters. switch (addParam) { case AdditionalParameters.RangeFileName: rangeList = parserObj.ParseRange(filePath); break; case AdditionalParameters.RangeTextReader: using (var strObj = File.OpenRead(filePath)) { rangeList = parserObj.ParseRange(strObj); } break; case AdditionalParameters.RangeGroupFileName: rangeGroup = parserObj.ParseRangeGrouping(filePath); break; case AdditionalParameters.RangeGroupTextReader: using (var strObj = File.OpenRead(filePath)) { rangeGroup = parserObj.ParseRangeGrouping(strObj); } break; default: break; } // Gets the Range list from Group switch (addParam) { case AdditionalParameters.RangeGroupTextReader: case AdditionalParameters.RangeGroupFileName: IEnumerable <string> grpIDsObj = rangeGroup.GroupIDs; string rangeID = string.Empty; foreach (string grpID in grpIDsObj) { rangeID = grpID; } rangeList = rangeGroup.GetGroup(rangeID); break; default: break; } // Gets all the expected values from xml. string[] expectedIDs = utilityObj.xmlUtil.GetTextValue( nodeName, Constants.IDNode).Split(','); string[] expectedStarts = utilityObj.xmlUtil.GetTextValue( nodeName, Constants.StartNode).Split(','); string[] expectedEnds = utilityObj.xmlUtil.GetTextValue( nodeName, Constants.EndNode).Split(','); int i = 0; // Reads all the ranges with comma seperated for validation foreach (ISequenceRange range in rangeList) { Assert.AreEqual(expectedStarts[i], range.Start.ToString((IFormatProvider)null)); Assert.AreEqual(expectedEnds[i], range.End.ToString((IFormatProvider)null)); Assert.AreEqual(expectedIDs[i], range.ID.ToString(null)); i++; } ApplicationLog.WriteLine( "Bed Parser BVT: Successfully validated the ID, Start and End Ranges"); }
/// <summary> /// Parsers the Bed 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, AdditionalParameters addParam) { // Gets the Filename string filePath = Utility._xmlUtil.GetTextValue( nodeName, Constants.FilePathNode); Assert.IsNotEmpty(filePath); ApplicationLog.WriteLine(string.Format( "Bed Parser BVT: Reading the File from location '{0}'", filePath)); // Get the rangelist after parsing. BedParser parserObj = new BedParser(); IList <ISequenceRange> rangeList = null; SequenceRangeGrouping rangeGroup = null; // Gets the Range list/Range Group based on the parameters. switch (addParam) { case AdditionalParameters.RangeFileName: rangeList = parserObj.ParseRange(filePath); break; case AdditionalParameters.RangeTextReader: rangeList = parserObj.ParseRange(new StreamReader(filePath)); break; case AdditionalParameters.RangeGroupFileName: rangeGroup = parserObj.ParseRangeGrouping(filePath); break; case AdditionalParameters.RangeGroupTextReader: rangeGroup = parserObj.ParseRangeGrouping( new StreamReader(filePath)); break; default: break; } // Gets the Range list from Group switch (addParam) { case AdditionalParameters.RangeGroupTextReader: case AdditionalParameters.RangeGroupFileName: IEnumerable <string> grpIDsObj = rangeGroup.GroupIDs; string rangeID = string.Empty; foreach (string grpID in grpIDsObj) { rangeID = grpID; } rangeList = rangeGroup.GetGroup(rangeID); break; default: break; } // Gets all the expected values from xml. string expectedIDs = Utility._xmlUtil.GetTextValue( nodeName, Constants.IDNode); string expectedStarts = Utility._xmlUtil.GetTextValue( nodeName, Constants.StartNode); string expectedEnds = Utility._xmlUtil.GetTextValue( nodeName, Constants.EndNode); string actualStarts = string.Empty; string actualEnds = string.Empty; string actualIDs = string.Empty; // Reads all the ranges with comma seperated for validation foreach (ISequenceRange range in rangeList) { actualStarts = string.Concat( actualStarts, range.Start.ToString(), ","); actualEnds = string.Concat( actualEnds, range.End.ToString(), ","); actualIDs = string.Concat( actualIDs, range.ID.ToString(), ","); } Assert.AreEqual(expectedIDs, actualIDs.Substring(0, actualIDs.Length - 1)); Assert.AreEqual(expectedStarts, actualStarts.Substring(0, actualStarts.Length - 1)); Assert.AreEqual(expectedEnds, actualEnds.Substring(0, actualEnds.Length - 1)); ApplicationLog.WriteLine( "Bed Parser BVT: Successfully validated the ID, Start and End Ranges"); Console.WriteLine( "Bed Parser BVT: Successfully validated the ID, Start and End Ranges"); }
/// <summary> /// Formats the Range/RangeGroup for different test cases based /// on Additional parameter /// </summary> /// <param name="nodeName">Xml Node name</param> /// <param name="addParam">Additional parameter</param> void FormatterGeneralTestCases(string nodeName, AdditionalParameters addParam) { IList <ISequenceRange> rangeList = new List <ISequenceRange>(); SequenceRangeGrouping rangeGroup = new SequenceRangeGrouping(); // Gets the file name. string filePath = utilityObj.xmlUtil.GetTextValue( nodeName, Constants.FilePathNode); // Condition to check if Parse() happens before Format() switch (addParam) { case AdditionalParameters.ParseRangeGroup: case AdditionalParameters.ParseRangeGroupTextWriter: BedParser initialParserGroupObj = new BedParser(); rangeGroup = initialParserGroupObj.ParseRangeGrouping(filePath); break; case AdditionalParameters.ParseRange: case AdditionalParameters.ParseRangeTextWriter: BedParser initialParserObj = new BedParser(); rangeList = initialParserObj.ParseRange(filePath); break; default: // Gets all the expected values from xml. string expectedID = utilityObj.xmlUtil.GetTextValue( nodeName, Constants.IDNode); string expectedStart = utilityObj.xmlUtil.GetTextValue( nodeName, Constants.StartNode); string expectedEnd = utilityObj.xmlUtil.GetTextValue( nodeName, Constants.EndNode); string[] expectedIDs = expectedID.Split(','); string[] expectedStarts = expectedStart.Split(','); string[] expectedEnds = expectedEnd.Split(','); // Gets the Range Group or Range based on the additional parameter switch (addParam) { case AdditionalParameters.RangeGroupTextWriter: case AdditionalParameters.RangeGroupFileName: for (int i = 0; i < expectedIDs.Length; i++) { SequenceRange rangeObj1 = new SequenceRange(expectedIDs[i], long.Parse(expectedStarts[i], (IFormatProvider)null), long.Parse(expectedEnds[i], (IFormatProvider)null)); rangeGroup.Add(rangeObj1); } break; default: for (int i = 0; i < expectedIDs.Length; i++) { SequenceRange rangeObj2 = new SequenceRange(expectedIDs[i], long.Parse(expectedStarts[i], (IFormatProvider)null), long.Parse(expectedEnds[i], (IFormatProvider)null)); rangeList.Add(rangeObj2); } break; } break; } BedFormatter formatterObj = new BedFormatter(); // Gets the Range list/Range Group based on the parameters. switch (addParam) { case AdditionalParameters.RangeFileName: case AdditionalParameters.ParseRange: formatterObj.Format(rangeList, Constants.BedTempFileName); break; case AdditionalParameters.RangeTextWriter: case AdditionalParameters.ParseRangeTextWriter: using (TextWriter txtWriter = new StreamWriter(Constants.BedTempFileName)) { formatterObj.Format(rangeList, txtWriter); } break; case AdditionalParameters.RangeGroupFileName: case AdditionalParameters.ParseRangeGroup: formatterObj.Format(rangeGroup, Constants.BedTempFileName); break; case AdditionalParameters.RangeGroupTextWriter: case AdditionalParameters.ParseRangeGroupTextWriter: using (TextWriter txtWriter = new StreamWriter(Constants.BedTempFileName)) { formatterObj.Format(rangeGroup, txtWriter); } break; default: break; } // Reparse to validate the results BedParser parserObj = new BedParser(); IList <ISequenceRange> newRangeList = parserObj.ParseRange(Constants.BedTempFileName); // Validation of all the properties. for (int i = 0; i < rangeList.Count; i++) { Assert.AreEqual(rangeList[0].ID, newRangeList[0].ID); Assert.AreEqual(rangeList[0].Start, newRangeList[0].Start); Assert.AreEqual(rangeList[0].End, newRangeList[0].End); } ApplicationLog.WriteLine( "Bed Formatter P1: Successfully validated the ID, Start and End Ranges"); Console.WriteLine( "Bed Formatter P1: Successfully validated the ID, Start and End Ranges"); // Cleanup the file. if (File.Exists(Constants.BedTempFileName)) { File.Delete(Constants.BedTempFileName); } }