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); } }
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."); }
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); }
/// <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."); } }