コード例 #1
0
        // 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);
        }
コード例 #2
0
        // 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);
        }
コード例 #3
0
ファイル: WiggleBvtTestCases.cs プロジェクト: cpatmoore/bio
        public void ValidateWiggleParserPublicProperties()
        {
            // Gets the filepath  from the Xml
            string filePath = this.utilityObj.xmlUtil.GetTextValue(Constants.
                              SimpleWiggleWithFixedStepNodeName, Constants.FilePathNode);
            Assert.IsTrue(File.Exists(filePath));

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

            //Get the expected values from configuration file.
            string expectedDescription = this.utilityObj.xmlUtil.GetTextValue(Constants.
                        SimpleWiggleWithFixedStepNodeName, Constants.ParserDescriptionNode);
            string expectedName = this.utilityObj.xmlUtil.GetTextValue(Constants.
                        SimpleWiggleWithFixedStepNodeName, Constants.NameNode);
            string expectedFileType = this.utilityObj.xmlUtil.GetTextValue(Constants.
                        SimpleWiggleWithFixedStepNodeName, Constants.FileTypesNode);

            WiggleParser parser = new WiggleParser();

            //Parse the file
            var annotation = parser.Parse(filePath);

            Assert.IsNotNull(annotation);
            Assert.AreEqual(expectedDescription, parser.Description);
            Assert.AreEqual(expectedName, parser.Name);
            Assert.AreEqual(expectedFileType, parser.SupportedFileTypes);

            ApplicationLog.WriteLine(string.Format((IFormatProvider)null,
                "Wiggle Parser BVT: Validation of all public properties is successful"));
        }
コード例 #4
0
        public void TestWiggleFormatter()
        {
            string filepathTmp = Path.GetTempFileName();

            using (WiggleFormatter formatter = new WiggleFormatter(filepathTmp))
            {
                formatter.Write(CreateDummyAnnotation());
            }

            WiggleParser parser = new WiggleParser();

            VerifyDummyAnnotation(parser.Parse(filepathTmp));
        }
コード例 #5
0
ファイル: WiggleTests.cs プロジェクト: cpatmoore/bio
        public void TestWiggleFormatter()
        {
            string filepathTmp = Path.GetTempFileName();
            WiggleFormatter formatter = new WiggleFormatter();

            using (formatter.Open(filepathTmp))
            {
                formatter.Format(CreateDummyAnnotation());
            }

            WiggleParser parser = new WiggleParser();
            VerifyDummyAnnotation(parser.Parse(filepathTmp).First());
        }
コード例 #6
0
ファイル: WiggleTests.cs プロジェクト: cpatmoore/bio
        // 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;
        }
コード例 #7
0
ファイル: WiggleTests.cs プロジェクト: cpatmoore/bio
        // 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;
        }
コード例 #8
0
ファイル: WiggleP2TestCases.cs プロジェクト: cpatmoore/bio
        /// <summary>
        /// Validate Exceptions from Wiggle Parser with invalid metadata.
        /// </summary>
        /// <param name="nodeName">Node containing the invalid file name.</param>
        public void ValidateFormatException(string nodeName)
        {
            // Gets the filepath.
            String filePath = this.utilityObj.xmlUtil.GetTextValue(Constants.
                              InValidFileNamesNode, nodeName);
            Assert.IsTrue(File.Exists(filePath));

            WiggleParser parser=new WiggleParser();

            try
            {
                parser.Parse(filePath);
            }
            catch (FormatException exception)
            {
                ApplicationLog.WriteLine(
                    "Wiggle P2 test cases : Successfully validated Format exception:", exception.Message);
            }
        }
コード例 #9
0
ファイル: WiggleP2TestCases.cs プロジェクト: cpatmoore/bio
        /// <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);
            }
        }
コード例 #10
0
ファイル: WiggleBvtTestCases.cs プロジェクト: cpatmoore/bio
        /// <summary>
        /// Validate Wiggle Formatter for fixed and variable steps.
        /// </summary>
        /// <param name="nodeName">Nodename</param>
        /// <param name="formatType">Write using a stream/File Name.</param>
        private void ValidateWiggleFormatter(string nodeName, FormatType formatType)
        {
            // Gets the filepath.
            String filePath = this.utilityObj.xmlUtil.GetTextValue(nodeName, Constants.FilePathNode);
            Assert.IsTrue(File.Exists(filePath));
            WiggleAnnotation annotation = null, annotationNew = null;

            string[] expectedValues = this.utilityObj.xmlUtil.GetTextValue(nodeName,
                                     Constants.ExpectedValuesNode).Split(',');
            string[] expectedPoints = this.utilityObj.xmlUtil.GetTextValue(nodeName,
                                     Constants.ExpectedKeysNode).Split(',');

            //Parse the file.
            WiggleParser parser = new WiggleParser();
            annotation = parser.ParseOne(filePath);

            WiggleFormatter formatter = null;

            //Write to a new file.                    
            switch (formatType)
            {
                case FormatType.Stream:
                    using (var writer = File.Create(Constants.WiggleTempFileName))
                    {
                        formatter = new WiggleFormatter();
                        formatter.Format(writer, annotation);
                        formatter.Close();
                    }
                    break;
                default:
                    formatter = new WiggleFormatter();
                    formatter.Format(annotation, Constants.WiggleTempFileName);
                    formatter.Close();
                    break;
            }

            //Read the new file and then compare the annotations.
            WiggleParser parserNew = new WiggleParser();
            annotationNew = parserNew.ParseOne(Constants.WiggleTempFileName);
            int index = 0;

            //Validate keys and values of the parsed file.
            foreach (KeyValuePair<long, float> keyvaluePair in annotationNew)
            {
                Assert.AreEqual(long.Parse(expectedPoints[index],
                            CultureInfo.InvariantCulture), keyvaluePair.Key);
                Assert.AreEqual(float.Parse(expectedValues[index],
                            CultureInfo.InvariantCulture), keyvaluePair.Value);
                index++;
            }
            File.Delete(Constants.WiggleTempFileName);
            ApplicationLog.WriteLine(string.Format((IFormatProvider)null,
               "Wiggle Formatter BVT: Successfully validated the written file"));
        }
コード例 #11
0
ファイル: WiggleBvtTestCases.cs プロジェクト: cpatmoore/bio
        /// <summary>
        /// Validate Wiggle Parser for fixed and variable steps.
        /// </summary>
        /// <param name="nodeName">Nodename</param>
        /// <param name="parseType">Read using a stream/File Name.</param>
        private void ValidateWiggleParser(string nodeName, ParseType parseType)
        {
            // Gets the filepath.
            String filePath = this.utilityObj.xmlUtil.GetTextValue(nodeName, Constants.FilePathNode);
            Assert.IsTrue(File.Exists(filePath));

            int index = 0;
            WiggleAnnotation annotation = null;

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

            string[] expectedValues = this.utilityObj.xmlUtil.GetTextValue(nodeName,
                                     Constants.ExpectedValuesNode).Split(',');
            string[] expectedPoints = this.utilityObj.xmlUtil.GetTextValue(nodeName,
                                     Constants.ExpectedKeysNode).Split(',');

            WiggleParser parser = new WiggleParser();

            switch (parseType)
            {
                case ParseType.Stream:
                    using (var stream = File.OpenRead(filePath))
                    {
                        annotation = parser.ParseOne(stream);
                    }
                    break;
                default:
                    annotation = parser.ParseOne(filePath);
                    break;
            }

            //Validate keys and values of the parsed file.
            foreach (KeyValuePair<long, float> keyvaluePair in annotation)
            {
                Assert.AreEqual(long.Parse(expectedPoints[index],
                            CultureInfo.InvariantCulture), keyvaluePair.Key);
                Assert.AreEqual(float.Parse(expectedValues[index],
                            CultureInfo.InvariantCulture), keyvaluePair.Value);
                index++;
            }

            ApplicationLog.WriteLine(string.Format((IFormatProvider)null,
               "Wiggle Parser BVT: Successfully validated the parsed file"));
        }
コード例 #12
0
ファイル: WiggleBvtTestCases.cs プロジェクト: cpatmoore/bio
        public void ValidateAnnotationPublicProperties()
        {
            WiggleAnnotation annotation = null;

            // Gets the filepath  from the Xml
            string filePath = this.utilityObj.xmlUtil.GetTextValue(Constants.
                              SimpleWiggleWithFixedStepNodeName, Constants.FilePathNode);
            Assert.IsTrue(File.Exists(filePath));

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

            string expectedbasePosition = this.utilityObj.xmlUtil.GetTextValue(Constants.
                        SimpleWiggleWithFixedStepNodeName, Constants.BasePositionNode);
            string expectedchromosome = this.utilityObj.xmlUtil.GetTextValue(Constants.
                        SimpleWiggleWithFixedStepNodeName, Constants.ChromosomeNode);
            string expectedannotationCount = this.utilityObj.xmlUtil.GetTextValue(Constants.
                        SimpleWiggleWithFixedStepNodeName, Constants.AnnotationCountNode);
            string expectedSpan = this.utilityObj.xmlUtil.GetTextValue(Constants.
                        SimpleWiggleWithFixedStepNodeName, Constants.ExpectedSpanNode);
            string expectedStep = this.utilityObj.xmlUtil.GetTextValue(Constants.
                        SimpleWiggleWithFixedStepNodeName, Constants.ExpectedStepNode);
            string annotationTypeNode = this.utilityObj.xmlUtil.GetTextValue(Constants.
                        SimpleWiggleWithFixedStepNodeName, Constants.AnnotationTypeNode);

            string[] annotationKeys = this.utilityObj.xmlUtil.GetTextValues(Constants.
                        SimpleWiggleWithFixedStepNodeName, Constants.AnnotationMetadataNode);

            string[] values = annotationKeys[0].Split(',');
            string[] keys = annotationKeys[1].Split(',');

            WiggleParser parser = new WiggleParser();

            //Parse the file
            annotation = parser.ParseOne(filePath);

            Assert.AreEqual(long.Parse(expectedbasePosition, CultureInfo.InvariantCulture)
                            , annotation.BasePosition);
            Assert.AreEqual(expectedchromosome, annotation.Chromosome);
            Assert.AreEqual(long.Parse(expectedannotationCount, CultureInfo.InvariantCulture)
                            , annotation.Count);
            Assert.AreEqual(int.Parse(expectedSpan,
                            CultureInfo.InvariantCulture), annotation.Span);
            Assert.AreEqual(int.Parse(expectedStep,
                            CultureInfo.InvariantCulture), annotation.Step);
            Assert.AreEqual(annotationTypeNode, annotation.AnnotationType.ToString());

            Dictionary<string, string> annotationMetadata = annotation.Metadata;

            //Validate Annotation Metadata.
            for (int i = 0; i < annotationMetadata.Count; i++)
            {
                Assert.AreEqual(keys[i], annotationMetadata.ElementAt(i).Key);
                Assert.AreEqual(values[i], annotationMetadata.ElementAt(i).Value);
            }

            ApplicationLog.WriteLine(string.Format((IFormatProvider)null,
                "Wiggle Parser BVT: Validation of Annotation public properties is successfull"));
        }