예제 #1
0
파일: GffTests.cs 프로젝트: cpatmoore/bio
        public void GffProperties()
        {
            GffParser parser = new GffParser();
            Assert.AreEqual(parser.Name, Resource.GFF_NAME);
            Assert.AreEqual(parser.Description, Resource.GFFPARSER_DESCRIPTION);
            Assert.AreEqual(parser.SupportedFileTypes, Resource.GFF_FILEEXTENSION);

            GffFormatter formatter = new GffFormatter();
            Assert.AreEqual(formatter.Name, Resource.GFF_NAME);
            Assert.AreEqual(formatter.Description, Resource.GFFFORMATTER_DESCRIPTION);
            Assert.AreEqual(formatter.SupportedFileTypes, Resource.GFF_FILEEXTENSION);
        }
예제 #2
0
파일: GffTests.cs 프로젝트: cpatmoore/bio
        public void TestGffWhenParsingOne()
        {
            // parse
            GffParser parser = new GffParser();
            ISequence seq = parser.Parse(_singleSeqGffFilename).FirstOrDefault();

            // test the non-metadata properties
            Assert.AreEqual(Alphabets.DNA, seq.Alphabet);
            Assert.AreEqual("NC_001133.7", seq.ID);

            // just test the formatting; if that's good, the parsing was good
            GffFormatter formatter = new GffFormatter();
            string actual = formatter.FormatString(seq);
            Assert.AreEqual(_singleSeqGffFileExpectedOutput.Replace("\r\n", Environment.NewLine), actual);
        }
예제 #3
0
파일: GffTests.cs 프로젝트: cpatmoore/bio
        public void TestGffForManyFiles()
        {
            // parser and formatter will be used for all files in input dir
            GffFormatter formatter = new GffFormatter();

            // iterate through the files in input dir, parsing and formatting each; write results
            // to log file
            DirectoryInfo inputDirInfo = new DirectoryInfo(_gffDataPath);
            foreach (FileInfo fileInfo in inputDirInfo.GetFiles("*.gff"))
            {
                ApplicationLog.WriteLine("Parsing file {0}...{1}", fileInfo.FullName, Environment.NewLine);
                ISequenceParser parser = new GffParser();
                foreach (ISequence sequence in parser.Parse(fileInfo.FullName))
                {
                    // don't do anything with it; just make sure it doesn't crash
                    formatter.FormatString(sequence);
                }

                ApplicationLog.WriteLine("Parse completed successfully." + Environment.NewLine);
            }
        }
예제 #4
0
        /// <summary>
        /// Validates the Format() method in Gff Formatter based on the parameters.
        /// </summary>
        /// <param name="nodeName">Xml Node name to be read.</param>
        /// <param name="isFilePath">Is file path passed as parameter?</param>
        /// <param name="isSequenceList">Is sequence list passed as parameter?</param>
        void ValidateFormatGeneralTestCases(string nodeName,
            bool isFilePath, bool isSequenceList)
        {
            // Gets the expected sequence from the Xml
            string filePath = utilityObj.xmlUtil.GetTextValue(nodeName,
                Constants.FilePathNode);

            Assert.IsTrue(File.Exists(filePath));
            IList<ISequence> seqs = null;
            GffParser parserObj = new GffParser();
            seqs = parserObj.Parse(filePath).ToList();
            Sequence originalSequence = (Sequence)seqs[0];

            // Use the formatter to write the original sequences to a temp file            
            ApplicationLog.WriteLine(string.Format("Gff Formatter BVT: Creating the Temp file '{0}'.",
                Constants.GffTempFileName));

            GffFormatter formatter = new GffFormatter { ShouldWriteSequenceData = true };
            if (isFilePath)
            {
                if (isSequenceList)
                    formatter.Format(seqs, Constants.GffTempFileName);
                else
                    formatter.Format(originalSequence, Constants.GffTempFileName);
            }
            else
            {
                if (isSequenceList)
                {
                    formatter.Format(seqs);
                }
                else
                {
                    formatter.Format(originalSequence);
                }
            }

            // Read the new file, then compare the sequences
            IList<ISequence> seqsNew = null;
            GffParser newParser = new GffParser();
            {
                seqsNew = newParser.Parse(Constants.GffTempFileName).ToList();
            }
            Assert.IsNotNull(seqsNew);
            ApplicationLog.WriteLine(string.Format("Gff Formatter BVT: New Sequence is '{0}'.",
                seqsNew[0].ToString()));

            bool val = ValidateFeatures(seqsNew[0], nodeName);
            Assert.IsTrue(val);
            ApplicationLog.WriteLine(
                "GFF Formatter BVT : All the features validated successfully.");

            // Now compare the sequences.
            int countNew = seqsNew.Count();
            int expectedCount = 1;
            Assert.AreEqual(expectedCount, countNew);
            ApplicationLog.WriteLine("The Number of sequences are matching.");

            Assert.AreEqual(originalSequence.ID, seqsNew[0].ID);          

            string orgSeq = new string(originalSequence.Select(x => (char)x).ToArray()); ; 
            ISequence newSeq = seqsNew.FirstOrDefault();           
            string newSeqString = new string(newSeq.Select(x => (char)x).ToArray());

            Assert.AreEqual(orgSeq, newSeqString);
            ApplicationLog.WriteLine(string.Format((IFormatProvider)null,
                "Gff Formatter BVT: The Gff sequences '{0}' are matching with Format() method.",
                seqsNew[0].ToString()));

            // Passed all the tests, delete the tmp file. If we failed an Assert,
            // the tmp file will still be there in case we need it for debugging.
            if (File.Exists(Constants.GffTempFileName))
                File.Delete(Constants.GffTempFileName);
            ApplicationLog.WriteLine("Deleted the temp file created.");
        }
예제 #5
0
 public void GffFormatterValidateOpen()
 {
     GffFormatter formatter = new GffFormatter();
     {
         try
         {
             using(formatter.Open(Constants.GffTempFileName))
             {
             }
         }
         catch (System.IO.IOException exception)
         {
             Assert.Fail("Exception thrown on opening a file " + exception.Message);
         }
     }           
     
     ApplicationLog.WriteLine("Opened the file successfully");            
 }
예제 #6
0
        public void GffFormatterValidateFormatString()
        {
            // Gets the expected sequence from the Xml
            string filePath = utilityObj.xmlUtil.GetTextValue(Constants.SimpleGffNodeName,
                Constants.FilePathNode);

            Assert.IsTrue(File.Exists(filePath));
            IList<ISequence> seqs = null;
            GffParser parserObj = new GffParser();
            seqs = parserObj.Parse(filePath).ToList();
            ISequence originalSequence = seqs[0];

            // Use the formatter to write the original sequences to a temp file            
            ApplicationLog.WriteLine(string.Format((IFormatProvider)null,
                "Gff Formatter BVT: Creating the Temp file '{0}'.", Constants.GffTempFileName));

            GffFormatter formatter = new GffFormatter();
            formatter.ShouldWriteSequenceData = true;
            string formatString = formatter.FormatString(originalSequence);

            string expectedString = utilityObj.xmlUtil.GetTextValue(
                Constants.SimpleGffNodeName, Constants.FormatStringNode);

            expectedString = expectedString.Replace("current-date",
                DateTime.Today.ToString("yyyy-MM-dd", null));
            expectedString =
                expectedString.Replace("\r", "").Replace("\n", "").Replace(" ", "").Replace("\t", "").ToUpper(CultureInfo.CurrentCulture);
            string modifedformatString =
                formatString.Replace("\r", "").Replace("\n", "").Replace(" ", "").Replace("\t", "").ToUpper(CultureInfo.CurrentCulture);

            Assert.AreEqual(modifedformatString, expectedString);
            ApplicationLog.WriteLine(string.Format((IFormatProvider)null,
                "Gff Formatter BVT: The Gff Format String '{0}' are matching with FormatString() method and is as expected.",
                formatString));

            // Passed all the tests, delete the tmp file. If we failed an Assert,
            // the tmp file will still be there in case we need it for debugging.
            File.Delete(Constants.GffTempFileName);
            ApplicationLog.WriteLine("Deleted the temp file created.");
        }
예제 #7
0
        /// <summary>
        /// General method to invalidate Argument Null exceptions generated from different methods.
        /// </summary>
        /// <param name="nodeName">xml node name.</param>
        /// <param name="method">Gff Parse method parameters</param>
        void InvalidateGffWriteMethod(ArgumentNullExceptions method)            
        {
            ISequence sequence=null;
            List<ISequence> collection = new List<ISequence>();
            string sequenceData = null;
            GffFormatter gffFormatter = null;

            try
            {                
                switch (method)
                {
                    case ArgumentNullExceptions.writeWithEmptyFile:
                        sequenceData = utilityObj.xmlUtil.GetTextValue(
                        Constants.SimpleGffDnaNodeName, Constants.ExpectedSequenceNode);

                        gffFormatter = new GffFormatter();
                        {
                            gffFormatter.Format(new Sequence(DnaAlphabet.Instance, sequenceData));
                        }                        
                        break;
                    case ArgumentNullExceptions.writeWithEmptySequence:

                        gffFormatter = new GffFormatter();
                        {
                            gffFormatter.Format(sequence);
                        }                                                                        
                        break;
                    case ArgumentNullExceptions.FormatString:

                        gffFormatter = new GffFormatter();
                        {
                            gffFormatter.FormatString(sequence);
                        }                                                
                        break;
                    case ArgumentNullExceptions.writeCollectionWithEmptyFile:
                        sequenceData = utilityObj.xmlUtil.GetTextValue(
                        Constants.SimpleGffDnaNodeName, Constants.ExpectedSequenceNode);
                        collection.Add(new Sequence(DnaAlphabet.Instance, sequenceData));

                        gffFormatter = new GffFormatter();
                        {
                            gffFormatter.Format(collection);
                        }                                                                                        
                        break;
                    case ArgumentNullExceptions.writeCollectionWithEmptySequence:

                        gffFormatter = new GffFormatter();
                        {
                            gffFormatter.Format(collection);
                        }                          
                        break;
                    default:
                        break;
                }

                Assert.Fail();
            }
           
            catch (ArgumentNullException)
            {                
                ApplicationLog.WriteLine("GFF P2 : Exception is validated successfully.");
            }
            catch (Exception)
            {
                ApplicationLog.WriteLine("GFF P2 : Exception is validated successfully.");
            }
        }
예제 #8
0
        /// <summary>
        /// Validates the Format() method in Gff Formatter for Multi sequences based on the parameters.
        /// </summary>
        /// <param name="nodeName">Xml Node name to be read.</param>
        void ValidateFormatMultiSequencesTestCases(string nodeName)
        {
            // Gets the expected sequence from the Xml
            string filePath = utilityObj.xmlUtil.GetTextValue(nodeName,
                Constants.FilePathNode);

            Assert.IsTrue(File.Exists(filePath));
            IList<ISequence> seqs = null;
            GffParser parserObj = new GffParser();
            seqs = parserObj.Parse(filePath).ToList();

            // Use the formatter to write the original sequences to a temp file            
            ApplicationLog.WriteLine(string.Format((IFormatProvider)null,
                "Gff Formatter P1: Creating the Temp file '{0}'.",
                Constants.GffTempFileName));

            GffFormatter formatter = new GffFormatter { ShouldWriteSequenceData = true };
            formatter.Format(seqs, Constants.GffTempFileName);

            int noOfSeqs = int.Parse(utilityObj.xmlUtil.GetTextValue(nodeName,
                Constants.NumberOfSequencesNode), null);
            Assert.IsNotNull(seqs);
            Assert.AreEqual(noOfSeqs, seqs.Count);
            ApplicationLog.WriteLine(string.Format("Gff Formatter P1 : Number of Sequences found are '{0}'.",
                seqs.Count.ToString((IFormatProvider)null)));

            string[] expectedSequences = utilityObj.xmlUtil.GetTextValues(nodeName,
                Constants.ExpectedSequenesNode);
            string[] alphabets = utilityObj.xmlUtil.GetTextValues(nodeName,
                Constants.AlphabetsNode);
            string[] seqIds = utilityObj.xmlUtil.GetTextValues(nodeName,
                Constants.SequenceIdsNode);

            for (int i = 0; i < noOfSeqs; i++)
            {
                bool valFeat = ValidateMultiSequenceFeatures(seqs[i], i + 1, nodeName);

                Assert.IsTrue(valFeat);
                ApplicationLog.WriteLine(
                    "Gff Formatter P1 : Successfully validated all the Features for a give Sequence in GFF File.");

                Sequence seq = (Sequence)seqs[i];
                Assert.IsNotNull(seq);

                string newSeq = new string(seq.Select(x => (char)x).ToArray());

                if (string.Compare(newSeq, newSeq.ToUpper(CultureInfo.CurrentCulture)) == 0)
                {
                    expectedSequences[i] = expectedSequences[i].ToUpper(CultureInfo.CurrentCulture);
                }
                else
                {
                    expectedSequences[i] = expectedSequences[i].ToLower(CultureInfo.CurrentCulture);
                }
                Assert.AreEqual(expectedSequences[i], newSeq);
                ApplicationLog.WriteLine(string.Format((IFormatProvider)null,
                    "Gff Formatter P1: The Gff sequence '{0}' validation after Parse() is found to be as expected.",
                    newSeq));

                byte[] TempSeqData = new byte[seq.Count];
                for (int j = 0; j < seq.Count; j++)
                {
                    TempSeqData[j] = seq[j];
                }

                Assert.AreEqual(expectedSequences[i].Length, TempSeqData.Length);
                ApplicationLog.WriteLine(string.Format((IFormatProvider)null,
                    "Gff Formatter P1: The Gff Length sequence '{0}' is as expected.",
                    expectedSequences[i].Length));

                Assert.IsNotNull(seq.Alphabet);
                Assert.AreEqual(seq.Alphabet.Name.ToLower(CultureInfo.CurrentCulture),
                    alphabets[i]);
                ApplicationLog.WriteLine(string.Format((IFormatProvider)null,
                    "Gff Formatter P1: The Sequence Alphabet is '{0}' and is as expected.",
                    seq.Alphabet.Name));

                Assert.AreEqual(seqIds[i], seq.ID);
                ApplicationLog.WriteLine(string.Format((IFormatProvider)null,
                    "Gff Formatter P1: The Sequence ID is '{0}' and is as expected.",
                    seq.ID));
            }

            // Passed all the tests, delete the tmp file. If we failed an Assert,
            // the tmp file will still be there in case we need it for debugging.
            if (File.Exists(Constants.GffTempFileName))
                File.Delete(Constants.GffTempFileName);
            ApplicationLog.WriteLine("Deleted the temp file created.");
        }