// Test wiggle fixed step private static WiggleAnnotation TestParserFixedStep(string filename) { WiggleParser p = new WiggleParser(); WiggleAnnotation an = p.Parse(filename).First(); Assert.IsTrue(an.Chromosome == "chr19"); Assert.IsTrue(an.BasePosition == 59307401); Assert.IsTrue(an.Step == 300); Assert.IsTrue(an.Span == 200); Assert.IsTrue(an.Metadata["type"] == "wiggle_0"); Assert.IsTrue(an.Metadata["name"] == "ArrayExpt1"); Assert.IsTrue(an.Metadata["description"] == "20 degrees, 2 hr"); float[] values = an.GetValueArray(0, 3); Assert.IsTrue(values[0] == 1000); Assert.IsTrue(values[1] == 900); Assert.IsTrue(values[2] == 800); values = an.GetValueArray(7, 3); Assert.IsTrue(values[0] == 300); Assert.IsTrue(values[1] == 200); Assert.IsTrue(values[2] == 100); return(an); }
// Test wiggle variable step private static WiggleAnnotation TestParserVariableStep(string filename) { WiggleParser p = new WiggleParser(); WiggleAnnotation an = p.Parse(filename).First(); Assert.IsTrue(an.Chromosome == "chr19"); Assert.IsTrue(an.Step == 0); Assert.IsTrue(an.BasePosition == 0); Assert.IsTrue(an.Span == 150); Assert.IsTrue(an.Metadata["type"] == "wiggle_0"); Assert.IsTrue(an.Metadata["name"] == "ArrayExpt1"); Assert.IsTrue(an.Metadata["description"] == "20 degrees, 2 hr"); var x = an.GetEnumerator(); x.MoveNext(); Assert.IsTrue(x.Current.Key == 59304701); Assert.IsTrue(x.Current.Value == 10.0); x.MoveNext(); Assert.IsTrue(x.Current.Key == 59304901); Assert.IsTrue(x.Current.Value == 12.5); x.MoveNext(); Assert.IsTrue(x.Current.Key == 59305401); Assert.IsTrue(x.Current.Value == 15.0); x.MoveNext(); x.MoveNext(); x.MoveNext(); x.MoveNext(); x.MoveNext(); x.MoveNext(); Assert.IsTrue(x.Current.Key == 59307871); Assert.IsTrue(x.Current.Value == 10.0); return(an); }
/// <summary> /// Writes a single sequence to the formatter. /// </summary> /// <param name="formatter">Formatter</param> /// <param name="annotation">Wiggle Annotation</param> public static void Format(this WiggleFormatter formatter, WiggleAnnotation annotation) { var fs = ParserFormatterExtensions<WiggleFormatter>.GetOpenStream(formatter, true); if (fs != null) formatter.Format(fs, annotation); else throw new Exception("You must open a formatter before calling Write."); }
/// <summary> /// Verifies an annotation object against a pre-defined set of values. /// </summary> /// <param name="an"></param> private static void VerifyDummyAnnotation(WiggleAnnotation an) { Assert.IsTrue(an.Chromosome == "chromeee"); Assert.IsTrue(an.Span == 100); try { an.GetValueArray(0, 3); Assert.Fail(); } catch(NotSupportedException) { } var x = an.GetEnumerator(); x.MoveNext(); Assert.IsTrue(x.Current.Key == 100); Assert.IsTrue(x.Current.Value == 10); x.MoveNext(); Assert.IsTrue(x.Current.Key == 200); Assert.IsTrue(x.Current.Value == 20); x.MoveNext(); Assert.IsTrue(x.Current.Key == 300); Assert.IsTrue(x.Current.Value == 30); }
/// <summary> /// Verifies an annotation object against a pre-defined set of values. /// </summary> /// <param name="an"></param> private static void VerifyDummyAnnotation(WiggleAnnotation an) { Assert.IsTrue(an.Chromosome == "chromeee"); Assert.IsTrue(an.Span == 100); try { an.GetValueArray(0, 3); Assert.Fail(); } catch (NotSupportedException) { } var x = an.GetEnumerator(); x.MoveNext(); Assert.IsTrue(x.Current.Key == 100); Assert.IsTrue(x.Current.Value == 10); x.MoveNext(); Assert.IsTrue(x.Current.Key == 200); Assert.IsTrue(x.Current.Value == 20); x.MoveNext(); Assert.IsTrue(x.Current.Key == 300); Assert.IsTrue(x.Current.Value == 30); }
public void TestAnnotationObject() { WiggleAnnotation an = CreateDummyAnnotation(); VerifyDummyAnnotation(an); }
/// <summary> /// Writes a single sequence to the formatter. /// </summary> /// <param name="formatter">Formatter</param> /// <param name="annotation">Wiggle Annotation</param> /// <param name="filename">Filename</param> public static void Format(this WiggleFormatter formatter, WiggleAnnotation annotation, string filename) { using (var fs = File.Create(filename)) formatter.Format(fs,annotation); }
/// <summary> /// Validate Exceptions from Wiggle Parser and Formatter for General test cases. /// </summary> /// <param name="exceptionType"></param> public void ValidateArgumentNullException(ExceptionType exceptionType) { // Gets the filepath. String filePath = this.utilityObj.xmlUtil.GetTextValue(Constants. SimpleWiggleWithFixedStepNodeName, Constants.FilePathNode); Assert.IsTrue(File.Exists(filePath)); WiggleAnnotation annotation =null; try { switch (exceptionType) { case ExceptionType.NullFormatter: WiggleFormatter formatter = new WiggleFormatter(); formatter.Format(null, annotation); break; case ExceptionType.NullParser: WiggleParser parser = new WiggleParser(); string valueForParse = null; parser.ParseOne(valueForParse); break; case ExceptionType.NullAnnotationWithData: annotation = new WiggleAnnotation(null, Constants.StringByteArray); break; case ExceptionType.NullAnnotationWithChromosomeName: float[] data = new float[2] { 1.0F, 2.0F }; annotation = new WiggleAnnotation(data, null,0,0); break; } } catch (ArgumentNullException exception) { ApplicationLog.WriteLine( "Wiggle P2 test cases : Successfully validated the exception:", exception.Message); } }
public void ValidateGetValueArray() { string[] expectedValues = this.utilityObj.xmlUtil.GetTextValue(Constants. AnnotationValuesNode, Constants.ExpectedValuesNode).Split(','); string stepValue = this.utilityObj.xmlUtil.GetTextValue(Constants. AnnotationValuesNode, Constants.ExpectedStepNode); string startValue = this.utilityObj.xmlUtil.GetTextValue(Constants. AnnotationValuesNode, Constants.ExpectedStartNode); int index = 0; float[] data = new float[expectedValues.Length]; for (index = 0; index < expectedValues.Length; index++) { data[index] = float.Parse(expectedValues[index], CultureInfo.InvariantCulture); } WiggleAnnotation annotation = new WiggleAnnotation(data, Constants. ChromosomeNode, long.Parse(startValue, CultureInfo.InvariantCulture), int.Parse(stepValue, CultureInfo.InvariantCulture)); //Get the values. float[] dataNew = annotation.GetValueArray(0, expectedValues.Length); index = 0; //Validate the values from GetValueArray. foreach (float value in dataNew) { Assert.AreEqual(data[index], value); index++; } }
public void ValidateWiggleAnnotation() { string[] expectedValues = this.utilityObj.xmlUtil.GetTextValue(Constants. AnnotationValuesNode, Constants.ExpectedValuesNode).Split(','); string[] annotationKeys = this.utilityObj.xmlUtil.GetTextValue(Constants. AnnotationValuesNode, Constants.ExpectedKeysNode).Split(','); string stepValue = this.utilityObj.xmlUtil.GetTextValue(Constants. AnnotationValuesNode, Constants.ExpectedStepNode); string startValue = this.utilityObj.xmlUtil.GetTextValue(Constants. AnnotationValuesNode, Constants.ExpectedStartNode); int index = 0; float[] data = new float[expectedValues.Length]; for (index = 0; index < expectedValues.Length; index++) { data[index] = float.Parse(expectedValues[index], CultureInfo.InvariantCulture); } WiggleAnnotation annotation = new WiggleAnnotation(data, Constants. ChromosomeNode, long.Parse(startValue, CultureInfo.InvariantCulture), int.Parse(stepValue, CultureInfo.InvariantCulture)); index = 0; //Validate keys and values of the parsed file. foreach (KeyValuePair<long, float> keyvaluePair in annotation) { Assert.AreEqual(float.Parse(annotationKeys[index], CultureInfo.InvariantCulture), keyvaluePair.Key); Assert.AreEqual(long.Parse(expectedValues[index], CultureInfo.InvariantCulture), keyvaluePair.Value); index++; } ApplicationLog.WriteLine(string.Format((IFormatProvider)null, "Wiggle Annotation BVT: Validation of Annotation creation is successfull")); }