public void ValidateSeqParserProperties() { // Gets the expected sequence from the Xml string fastaParserName = _utilityObj._xmlUtil.GetTextValue(Constants.FastAFileParserNode, Constants.ParserNameNode); string genBankParserName = _utilityObj._xmlUtil.GetTextValue(Constants.GenBankFileParserNode, Constants.ParserNameNode); string gffParserName = _utilityObj._xmlUtil.GetTextValue(Constants.GffFileParserNode, Constants.ParserNameNode); string fastQParserName = _utilityObj._xmlUtil.GetTextValue(Constants.FastQFileParserNode, Constants.ParserNameNode); // Get SequenceParser class properties. FastaParser actualFastAParser = SequenceParsers.Fasta; IList <ISequenceParser> allParser = SequenceParsers.All; GenBankParser actualgenBankParserName = SequenceParsers.GenBank; FastQParser actualFastQParserName = SequenceParsers.FastQ; GffParser actualGffParserName = SequenceParsers.Gff; // Validate Sequence parsers Assert.AreEqual(fastaParserName, actualFastAParser.Name); Assert.AreEqual(4, allParser.Count); Assert.AreEqual(genBankParserName, actualgenBankParserName.Name); Assert.AreEqual(gffParserName, actualGffParserName.Name); Assert.AreEqual(fastQParserName, actualFastQParserName.Name); Console.WriteLine(string.Format((IFormatProvider)null, "SequenceParser : Type of the parser is validated successfully")); ApplicationLog.WriteLine("Type of the parser is validated successfully"); }
/// <summary> /// Returns parser which supports the specified file. /// </summary> /// <param name="fileName">File name for which the parser is required.</param> /// <returns>If found returns the parser as ISequenceParser else returns null.</returns> public static ISequenceParser FindParserByFile(string fileName) { ISequenceParser parser = null; if (!string.IsNullOrEmpty(fileName)) { if (Helper.IsGenBank(fileName)) { parser = new GenBankParser(); } else if (fileName.EndsWith(Resource.GFF_FILEEXTENSION, StringComparison.OrdinalIgnoreCase)) { parser = new GffParser(); } else if (Helper.IsFasta(fileName)) { parser = new FastaParser(); } else if (Helper.IsFastQ(fileName)) { parser = new FastQParser(); } else { parser = null; } } return(parser); }
public void GffParserValidateParseWithOneLineFeatures() { // Gets the expected sequence from the Xml string filePath = utilityObj.xmlUtil.GetTextValue( Constants.SimpleGffFeaturesNode, Constants.FilePathNode); Assert.IsTrue(File.Exists(filePath)); IList <ISequence> seqs = null; GffParser parserObj = new GffParser(filePath); seqs = parserObj.Parse().ToList(); Sequence originalSequence = (Sequence)seqs[0]; bool val = ValidateFeatures(originalSequence, Constants.OneLineSeqGffNodeName); Assert.IsTrue(val); filePath = utilityObj.xmlUtil.GetTextValue( Constants.SimpleGffFeaturesReaderNode, Constants.FilePathNode); GffParser parserObj1 = new GffParser(filePath); seqs.Add(parserObj1.Parse().FirstOrDefault()); originalSequence = (Sequence)seqs[0]; val = ValidateFeatures(originalSequence, Constants.OneLineSeqGffNodeName); Assert.IsTrue(val); ApplicationLog.WriteLine( "GFF Parser BVT : All the features validated successfully."); Console.WriteLine( "GFF Parser BVT : All the features validated successfully."); }
/// <summary> /// Finds a suitable parser that supports the specified file, opens the file and returns the parser. /// </summary> /// <param name="fileName">File name for which the parser is required.</param> /// <returns>If found returns the parser as ISequenceParser else returns null.</returns> public static ISequenceParser FindParserByFileName(string fileName) { ISequenceParser parser = null; if (!string.IsNullOrEmpty(fileName)) { if (IsFasta(fileName)) { parser = new FastAParser(fileName); } else if (IsFastQ(fileName)) { parser = new FastQParser(fileName); } else if (IsGenBank(fileName)) { parser = new GenBankParser(fileName); } else if (fileName.EndsWith(Properties.Resource.GFF_FILEEXTENSION, StringComparison.InvariantCultureIgnoreCase)) { parser = new GffParser(fileName); } else { parser = null; } } return(parser); }
public void ValidateSeqParserProperties() { // Gets the expected sequence from the Xml string fastaParserName = this.utilityObj.xmlUtil.GetTextValue(Constants.FastAFileParserNode, Constants.ParserNameNode); string genBankParserName = this.utilityObj.xmlUtil.GetTextValue(Constants.GenBankFileParserNode, Constants.ParserNameNode); string gffParserName = this.utilityObj.xmlUtil.GetTextValue(Constants.GffFileParserNode, Constants.ParserNameNode); string fastQParserName = this.utilityObj.xmlUtil.GetTextValue(Constants.FastQFileParserNode, Constants.ParserNameNode); // Get SequenceParser class properties. FastAParser actualFastAParser = SequenceParsers.Fasta; IReadOnlyList <ISequenceParser> allParser = SequenceParsers.All; GenBankParser actualgenBankParserName = SequenceParsers.GenBank; FastQParser actualFastQParserName = SequenceParsers.FastQ; GffParser actualGffParserName = SequenceParsers.Gff; // Validate Sequence parsers Assert.AreEqual(fastaParserName, actualFastAParser.Name); Assert.AreEqual(genBankParserName, actualgenBankParserName.Name); Assert.AreEqual(gffParserName, actualGffParserName.Name); Assert.AreEqual(fastQParserName, actualFastQParserName.Name); Assert.IsNotNull(allParser); ApplicationLog.WriteLine("Type of the parser is validated successfully"); }
/// <summary> /// Returns parser which supports the specified file. /// </summary> /// <param name="fileName">File name for which the parser is required.</param> /// <param name="parserName">Name of the parser to use.</param> /// <returns>If found returns the parser as IParser else returns null.</returns> public static ISequenceParser FindParserByName(string fileName, string parserName) { ISequenceParser parser = null; if (!string.IsNullOrEmpty(fileName)) { if (parserName == Properties.Resource.FastAName) { parser = new FastAParser(fileName); } else if (parserName == Properties.Resource.FastQName) { parser = new FastQParser(fileName); } else if (parserName == Properties.Resource.GENBANK_NAME) { parser = new GenBankParser(fileName); } else if (parserName == Properties.Resource.GFF_NAME) { parser = new GffParser(fileName); } else { parser = null; } } return(parser); }
/// <summary> /// Gets chromsomes as ISequence objects, containing feature metadata contained in the gene model /// </summary> /// <param name="geneModelFile"></param> /// <returns></returns> public static List <ISequence> SimplerParse(string geneModelFile) { ForceGffVersionTo2(geneModelFile, out string geneModelWithVersion2MarkedPath); List <ISequence> geneFeatures = new GffParser().Parse(geneModelWithVersion2MarkedPath).ToList(); return(geneFeatures); }
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(filePath); seqs = parserObj.Parse().ToList(); ISequence originalSequence = (Sequence)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); Console.WriteLine(string.Format((IFormatProvider)null, "Gff Formatter BVT: The Gff Format String '{0}' are matching with FormatString() method and is as expected.", formatString)); 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 GffParserValidateOpen() { string filename = utilityObj.xmlUtil.GetTextValue(Constants.OneLineSeqGffNodeName, Constants.FilePathNode); using (GffParser parser = new GffParser()) { try { parser.Open(filename); } catch (System.IO.IOException exception) { Assert.Fail("Exception thrown on opening a file " + exception.Message); } } ApplicationLog.WriteLine("Opened the file successfully"); }
/// <summary> /// Finds a suitable parser that supports the specified file, opens the file and returns the parser. /// </summary> /// <param name="fileName">File name for which the parser is required.</param> /// <returns>If found returns the open parser as ISequenceParser else returns null.</returns> public static ISequenceParser FindParserByFileName(string fileName) { ISequenceParser parser = null; if (!string.IsNullOrEmpty(fileName)) { if (IsFasta(fileName)) { parser = new FastAParser(fileName); } else if (IsFastQ(fileName)) { parser = new FastQParser(fileName); } else if (IsGenBank(fileName)) { parser = new GenBankParser(fileName); } else if (fileName.EndsWith(Properties.Resource.GFF_FILEEXTENSION, StringComparison.InvariantCultureIgnoreCase)) { parser = new GffParser(fileName); } else { // Do a search through the known parsers to pick up custom parsers added through add-in. string fileExtension = Path.GetExtension(fileName); if (!string.IsNullOrEmpty(fileExtension)) { parser = All.FirstOrDefault(p => p.SupportedFileTypes.Contains(fileExtension)); // If we found a match based on extension, then open the file - this // matches the above behavior where a specific parser was created for // the passed filename - the parser is opened automatically in the constructor. if (parser != null) { parser.Open(fileName); } } } } return(parser); }
public void GffParserValidateParseWithOneLineFeatures() { // Gets the expected sequence from the Xml string filePath = Utility._xmlUtil.GetTextValue( Constants.SimpleGffFeaturesNode, Constants.FilePathNode); Assert.IsTrue(File.Exists(filePath)); IList <ISequence> seqs = null; BasicSequenceParser parserObj = new GffParser(Encodings.Ncbi4NA); seqs = parserObj.Parse(filePath); Sequence originalSequence = (Sequence)seqs[0]; bool val = ValidateFeatures(originalSequence, Constants.OneLineSeqGffNodeName); Assert.IsTrue(val); filePath = Utility._xmlUtil.GetTextValue( Constants.SimpleGffFeaturesReaderNode, Constants.FilePathNode); using (StreamReader reader = File.OpenText(filePath)) { seqs.Add(parserObj.ParseOne(reader)); } originalSequence = (Sequence)seqs[0]; val = ValidateFeatures(originalSequence, Constants.OneLineSeqGffNodeName); Assert.IsTrue(val); ApplicationLog.WriteLine( "GFF Parser BVT : All the features validated successfully."); Console.WriteLine( "GFF Parser BVT : All the features validated successfully."); }
/// <summary> /// Returns parser which supports the specified file. /// </summary> /// <param name="fileName">File name for which the parser is required.</param> /// <param name="parserName">Name of the parser to use.</param> /// <returns>If found returns the open parser as ISequenceParser else returns null.</returns> public static ISequenceParser FindParserByName(string fileName, string parserName) { ISequenceParser parser = null; if (!string.IsNullOrEmpty(fileName) && !string.IsNullOrEmpty(parserName)) { if (parserName == Properties.Resource.FastAName) { parser = new FastAParser(fileName); } else if (parserName == Properties.Resource.FastQName) { parser = new FastQParser(fileName); } else if (parserName == Properties.Resource.GENBANK_NAME) { parser = new GenBankParser(fileName); } else if (parserName == Properties.Resource.GFF_NAME) { parser = new GffParser(fileName); } else { // Do a search through the known parsers to pick up custom parsers added through add-in. parser = All.FirstOrDefault(p => p.Name == parserName); // If we found a match based on extension, then open the file - this // matches the above behavior where a specific parser was created for // the passed filename - the parser is opened automatically in the constructor. if (parser != null) { parser.Open(fileName); } } } return(parser); }
/// <summary> /// Parses all test cases related to ParseOne() method based on the /// parameters passed and validates the same. /// </summary> /// <param name="nodeName">Xml Node name to be read.</param> /// <param name="isFilePath">Is file path passed as parameter?</param> void ValidateParseOneGeneralTestCases(string nodeName, bool isFilePath) { // Gets the expected sequence from the Xml string filePath = utilityObj.xmlUtil.GetTextValue(nodeName, Constants.FilePathNode); Assert.IsTrue(File.Exists(filePath)); // Logs information to the log file ApplicationLog.WriteLine(string.Format((IFormatProvider)null, "Gff Parser BVT : File Exists in the Path '{0}'.", filePath)); ISequence originalSeq = null; GffParser parserObj = new GffParser(filePath); if (isFilePath) { originalSeq = parserObj.Parse().FirstOrDefault(); } else { using (StreamReader reader = File.OpenText(filePath)) { originalSeq = parserObj.Parse().FirstOrDefault(); } } Assert.IsNotNull(originalSeq); Assert.IsTrue(ValidateFeatures(originalSeq, nodeName)); ApplicationLog.WriteLine( "Gff Parser BVT : Successfully validated all the Features for a give Sequence in GFF File."); Console.WriteLine( "Gff Parser BVT : Successfully validated all the Features for a give Sequence in GFF File."); string expectedSequence = utilityObj.xmlUtil.GetTextValue(nodeName, Constants.ExpectedSequenceNode); Sequence seq = (Sequence)originalSeq; Assert.IsNotNull(seq); byte[] TempSeqData = new byte[seq.Count]; for (int i = 0; i < seq.Count; i++) { TempSeqData[i] = seq[i]; } string sequenceInString = ASCIIEncoding.ASCII.GetString(TempSeqData); Assert.AreEqual(expectedSequence, sequenceInString); ApplicationLog.WriteLine(string.Format((IFormatProvider)null, "Gff Parser BVT: The Gff sequence '{0}' validation after ParseOne() is found to be as expected.", seq.ToString())); // Logs to the NUnit GUI (Console.Out) window Console.WriteLine(string.Format((IFormatProvider)null, "Gff Parser BVT: The Gff sequence '{0}' validation after ParseOne() is found to be as expected.", seq.ToString())); byte[] tmpEncodedSeq = new byte[seq.Count]; for (int i = 0; i < seq.Count; i++) { tmpEncodedSeq[i] = seq[i]; } Assert.AreEqual(expectedSequence.Length, tmpEncodedSeq.Length); ApplicationLog.WriteLine(string.Format((IFormatProvider)null, "Gff Parser BVT: The Gff Length sequence '{0}' is as expected.", expectedSequence.Length)); string expectedAlphabet = utilityObj.xmlUtil.GetTextValue(nodeName, Constants.AlphabetNameNode).ToLower(CultureInfo.CurrentCulture); Assert.IsNotNull(seq.Alphabet); Assert.AreEqual(seq.Alphabet.Name.ToLower(CultureInfo.CurrentCulture), expectedAlphabet); ApplicationLog.WriteLine(string.Format((IFormatProvider)null, "Gff Parser BVT: The Sequence Alphabet is '{0}' and is as expected.", seq.Alphabet.Name)); string expectedSequenceId = utilityObj.xmlUtil.GetTextValue(nodeName, Constants.SequenceIdNode); Assert.AreEqual(expectedSequenceId, seq.ID); ApplicationLog.WriteLine(string.Format((IFormatProvider)null, "Gff Parser BVT: The Sequence ID is '{0}' and is as expected.", seq.ID)); // Logs to the NUnit GUI (Console.Out) window Console.WriteLine(string.Format((IFormatProvider)null, "Gff Parser BVT: The Sequence ID is '{0}' and is as expected.", seq.ID)); }
/// <summary> /// Parses all test cases related to ParseOne() method based on the /// parameters passed and validates the same. /// </summary> /// <param name="nodeName">Xml Node name to be read.</param> /// <param name="isFilePath">Is file path passed as parameter?</param> static void ValidateParseOneGeneralTestCases(string nodeName, bool isFilePath) { // Gets the expected sequence from the Xml string filePath = Utility._xmlUtil.GetTextValue(nodeName, Constants.FilePathNode); Assert.IsTrue(File.Exists(filePath)); // Logs information to the log file ApplicationLog.WriteLine(string.Format(null, "Gff Parser BVT : File Exists in the Path '{0}'.", filePath)); ISequence originalSeq = null; GffParser parserObj = new GffParser(); if (isFilePath) { originalSeq = parserObj.ParseOne(filePath); } else { using (StreamReader reader = File.OpenText(filePath)) { originalSeq = parserObj.ParseOne(reader); } } Assert.IsNotNull(originalSeq); Assert.IsTrue(ValidateFeatures(originalSeq, nodeName)); ApplicationLog.WriteLine( "Gff Parser BVT : Successfully validated all the Features for a give Sequence in GFF File."); Console.WriteLine( "Gff Parser BVT : Successfully validated all the Features for a give Sequence in GFF File."); string expectedSequence = Utility._xmlUtil.GetTextValue(nodeName, Constants.ExpectedSequenceNode); Sequence seq = (Sequence)originalSeq; Assert.IsNotNull(seq); Assert.AreEqual(expectedSequence, seq.ToString()); ApplicationLog.WriteLine(string.Format(null, "Gff Parser BVT: The Gff sequence '{0}' validation after ParseOne() is found to be as expected.", seq.ToString())); // Logs to the NUnit GUI (Console.Out) window Console.WriteLine(string.Format(null, "Gff Parser BVT: The Gff sequence '{0}' validation after ParseOne() is found to be as expected.", seq.ToString())); Assert.AreEqual(expectedSequence.Length, seq.EncodedValues.Length); ApplicationLog.WriteLine(string.Format(null, "Gff Parser BVT: The Gff Length sequence '{0}' is as expected.", expectedSequence.Length)); string expectedAlphabet = Utility._xmlUtil.GetTextValue(nodeName, Constants.AlphabetNameNode).ToLower(CultureInfo.CurrentCulture); Assert.IsNotNull(seq.Alphabet); Assert.AreEqual(seq.Alphabet.Name.ToLower(CultureInfo.CurrentCulture), expectedAlphabet); ApplicationLog.WriteLine(string.Format(null, "Gff Parser BVT: The Sequence Alphabet is '{0}' and is as expected.", seq.Alphabet.Name)); string expectedSequenceId = Utility._xmlUtil.GetTextValue(nodeName, Constants.SequenceIdNode); Assert.AreEqual(expectedSequenceId, seq.DisplayID); ApplicationLog.WriteLine(string.Format(null, "Gff Parser BVT: The Sequence ID is '{0}' and is as expected.", seq.DisplayID)); // Logs to the NUnit GUI (Console.Out) window Console.WriteLine(string.Format(null, "Gff Parser BVT: The Sequence ID is '{0}' and is as expected.", seq.DisplayID)); }
/// <summary> /// Parses all test cases related to Parse() method based on the /// parameters passed and validates the same. /// </summary> /// <param name="nodeName">Xml Node name to be read.</param> /// <param name="isFilePath">Is file path passed as parameter?</param> void ValidateParseGeneralTestCases(string nodeName, bool isFilePath) { // Gets the expected sequence from the Xml string filePath = _utilityObj._xmlUtil.GetTextValue(nodeName, Constants.FilePathNode); Assert.IsTrue(File.Exists(filePath)); // Logs information to the log file ApplicationLog.WriteLine(string.Format((IFormatProvider)null, "Gff Parser BVT : File Exists in the Path '{0}'.", filePath)); IList <ISequence> seqs = null; GffParser parserObj = new GffParser(); if (isFilePath) { seqs = parserObj.Parse(filePath); } else { using (StreamReader reader = File.OpenText(filePath)) { seqs = parserObj.Parse(reader); } } int expectedSequenceCount = 1; Assert.IsNotNull(seqs); Assert.AreEqual(expectedSequenceCount, seqs.Count); ApplicationLog.WriteLine(string.Format((IFormatProvider)null, "Gff Parser BVT : Number of Sequences found are '{0}'.", seqs.Count.ToString((IFormatProvider)null))); Assert.IsTrue(ValidateFeatures(seqs[0], nodeName)); ApplicationLog.WriteLine( "Gff Parser BVT : Successfully validated all the Features for a give Sequence in GFF File."); Console.WriteLine( "Gff Parser BVT : Successfully validated all the Features for a give Sequence in GFF File."); string expectedSequence = _utilityObj._xmlUtil.GetTextValue(nodeName, Constants.ExpectedSequenceNode); Sequence seq = (Sequence)seqs[0]; Assert.IsNotNull(seq); Assert.AreEqual(expectedSequence, seq.ToString()); ApplicationLog.WriteLine(string.Format((IFormatProvider)null, "Gff Parser BVT: The Gff sequence '{0}' validation after Parse() is found to be as expected.", seq.ToString())); // Logs to the NUnit GUI (Console.Out) window Console.WriteLine(string.Format((IFormatProvider)null, "Gff Parser BVT: The Gff sequence '{0}' validation after Parse() is found to be as expected.", seq.ToString())); byte[] tmpEncodedSeq = new byte[seq.Count]; (seq as IList <byte>).CopyTo(tmpEncodedSeq, 0); Assert.AreEqual(expectedSequence.Length, tmpEncodedSeq.Length); ApplicationLog.WriteLine(string.Format((IFormatProvider)null, "Gff Parser BVT: The Gff Length sequence '{0}' is as expected.", expectedSequence.Length)); string expectedAlphabet = _utilityObj._xmlUtil.GetTextValue(nodeName, Constants.AlphabetNameNode).ToLower(CultureInfo.CurrentCulture); Assert.IsNotNull(seq.Alphabet); Assert.AreEqual(seq.Alphabet.Name.ToLower(CultureInfo.CurrentCulture), expectedAlphabet); ApplicationLog.WriteLine(string.Format((IFormatProvider)null, "Gff Parser BVT: The Sequence Alphabet is '{0}' and is as expected.", seq.Alphabet.Name)); string expectedSequenceId = _utilityObj._xmlUtil.GetTextValue(nodeName, Constants.SequenceIdNode); Assert.AreEqual(expectedSequenceId, seq.DisplayID); ApplicationLog.WriteLine(string.Format((IFormatProvider)null, "Gff Parser BVT: The Sequence ID is '{0}' and is as expected.", seq.DisplayID)); // Logs to the NUnit GUI (Console.Out) window Console.WriteLine(string.Format((IFormatProvider)null, "Gff Parser BVT: The Sequence ID is '{0}' and is as expected.", seq.DisplayID)); }
public void GffFormatterValidateStreams() { // 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; Sequence originalSequence = null; GffParser parserObj = new GffParser(); { seqs = parserObj.Parse(filePath).ToList(); originalSequence = (Sequence)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)); using (var writer = File.Create(Constants.GffTempFileName)) { GffFormatter formatter = new GffFormatter() { ShouldWriteSequenceData = true }; formatter.Format(writer, 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])); bool val = ValidateFeatures(seqsNew[0], Constants.SimpleGffNodeName); 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); ISequence newSeq = seqsNew.FirstOrDefault(); Assert.AreEqual(new string(originalSequence.Select(x => (char)x).ToArray()), new string(newSeq.Select(x => (char)x).ToArray())); ApplicationLog.WriteLine(string.Format((IFormatProvider)null, "Gff Formatter BVT: The Gff sequences '{0}' are matching with Write() 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."); }
/// <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> static void ValidateFormatGeneralTestCases(string nodeName, bool isFilePath, bool isSequenceList) { // Gets the expected sequence from the Xml string filePath = Utility._xmlUtil.GetTextValue(nodeName, Constants.FilePathNode); Assert.IsTrue(File.Exists(filePath)); IList <ISequence> seqs = null; GffParser parserObj = new GffParser(); seqs = parserObj.Parse(filePath); Sequence originalSequence = (Sequence)seqs[0]; // Use the formatter to write the original sequences to a temp file ApplicationLog.WriteLine(string.Format(null, "Gff Formatter BVT: Creating the Temp file '{0}'.", Constants.GffTempFileName)); GffFormatter formatter = new GffFormatter(); formatter.ShouldWriteSequenceData = true; if (isFilePath) { if (isSequenceList) { formatter.Format(seqs, Constants.GffTempFileName); } else { formatter.Format(originalSequence, Constants.GffTempFileName); } } else { if (isSequenceList) { using (TextWriter writer = new StreamWriter(Constants.GffTempFileName)) { formatter.Format(seqs, writer); } } else { using (TextWriter writer = new StreamWriter(Constants.GffTempFileName)) { formatter.Format(originalSequence, writer); } } } // Read the new file, then compare the sequences IList <ISequence> seqsNew = null; GffParser newParser = new GffParser(); seqsNew = newParser.Parse(Constants.GffTempFileName); Assert.IsNotNull(seqsNew); ApplicationLog.WriteLine(string.Format(null, "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."); Console.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 = originalSequence.ToString(); string newSeq = seqsNew[0].ToString(); Assert.AreEqual(orgSeq, newSeq); Console.WriteLine(string.Format(null, "Gff Formatter BVT: The Gff sequences '{0}' are matching with Format() method and is as expected.", seqsNew[0].ToString())); ApplicationLog.WriteLine(string.Format(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."); }
/// <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(filePath); seqs = parserObj.Parse().ToList(); Sequence originalSequence = (Sequence)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(Constants.GffTempFileName); formatter.ShouldWriteSequenceData = true; if (isFilePath) { if (isSequenceList) { formatter.Write(seqs); } else { formatter.Write(originalSequence); } } else { if (isSequenceList) { formatter.Write(seqs); } else { formatter.Write(originalSequence); } } // Read the new file, then compare the sequences IList <ISequence> seqsNew = null; using (GffParser newParser = new GffParser(Constants.GffTempFileName)) { seqsNew = newParser.Parse().ToList(); } Assert.IsNotNull(seqsNew); ApplicationLog.WriteLine(string.Format((IFormatProvider)null, "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."); Console.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); byte[] TempSeqData = new byte[originalSequence.Count]; for (int i = 0; i < originalSequence.Count; i++) { TempSeqData[i] = originalSequence[i]; } string orgSeq = ASCIIEncoding.ASCII.GetString(TempSeqData); ISequence newSeq = seqsNew.FirstOrDefault(); byte[] TempSeqData1 = new byte[newSeq.Count]; for (int i = 0; i < newSeq.Count; i++) { TempSeqData1[i] = newSeq[i]; } string newSeqString = ASCIIEncoding.ASCII.GetString(TempSeqData1); Assert.AreEqual(orgSeq, newSeqString); Console.WriteLine(string.Format((IFormatProvider)null, "Gff Formatter BVT: The Gff sequences '{0}' are matching with Format() method and is as expected.", seqsNew[0].ToString())); 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."); }
/// <summary> /// Parses all test cases related to ParseOne() method based on the /// parameters passed and validates the same. /// </summary> /// <param name="nodeName">Xml Node name to be read.</param> /// <param name="isFilePath">Is file path passed as parameter?</param> void ValidateParseOneGeneralTestCases(string nodeName, bool isFilePath) { // Gets the expected sequence from the Xml string filePath = utilityObj.xmlUtil.GetTextValue(nodeName, Constants.FilePathNode); Assert.IsTrue(File.Exists(filePath)); // Logs information to the log file ApplicationLog.WriteLine(string.Format("Gff Parser BVT : File Exists in the Path '{0}'.", filePath)); ISequence originalSeq; GffParser parserObj = new GffParser(); if (isFilePath) { originalSeq = parserObj.Parse(filePath).First(); } else { using (var reader = File.OpenRead(filePath)) { originalSeq = parserObj.Parse(reader).First(); } } Assert.IsNotNull(originalSeq); Assert.IsTrue(ValidateFeatures(originalSeq, nodeName)); ApplicationLog.WriteLine( "Gff Parser BVT : Successfully validated all the Features for a give Sequence in GFF File."); string expectedSequence = utilityObj.xmlUtil.GetTextValue(nodeName, Constants.ExpectedSequenceNode); string sequenceInString = new string(originalSeq.Select(x => (char)x).ToArray()); Assert.AreEqual(expectedSequence, sequenceInString); ApplicationLog.WriteLine(string.Format("Gff Parser BVT: The Gff sequence '{0}' validation after ParseOne() is found to be as expected.", originalSeq.ToString())); byte[] tmpEncodedSeq = new byte[originalSeq.Count]; for (int i = 0; i < originalSeq.Count; i++) { tmpEncodedSeq[i] = originalSeq[i]; } Assert.AreEqual(expectedSequence.Length, tmpEncodedSeq.Length); ApplicationLog.WriteLine(string.Format("Gff Parser BVT: The Gff Length sequence '{0}' is as expected.", expectedSequence.Length)); string expectedAlphabet = utilityObj.xmlUtil.GetTextValue(nodeName, Constants.AlphabetNameNode).ToLower(CultureInfo.CurrentCulture); Assert.IsNotNull(originalSeq.Alphabet); Assert.AreEqual(originalSeq.Alphabet.Name.ToLower(CultureInfo.CurrentCulture), expectedAlphabet); ApplicationLog.WriteLine(string.Format((IFormatProvider)null, "Gff Parser BVT: The Sequence Alphabet is '{0}' and is as expected.", originalSeq.Alphabet.Name)); string expectedSequenceId = utilityObj.xmlUtil.GetTextValue(nodeName, Constants.SequenceIdNode); Assert.AreEqual(expectedSequenceId, originalSeq.ID); ApplicationLog.WriteLine(string.Format((IFormatProvider)null, "Gff Parser BVT: The Sequence ID is '{0}' and is as expected.", originalSeq.ID)); }
/// <summary> /// Parses all test cases related to Parse() method based on the /// parameters passed and validates the same. /// </summary> /// <param name="nodeName">Xml Node name to be read.</param> void ValidateParseWithStreams(string nodeName) { // Gets the expected sequence from the Xml string filePath = utilityObj.xmlUtil.GetTextValue(nodeName, Constants.FilePathNode); Assert.IsTrue(File.Exists(filePath)); // Logs information to the log file ApplicationLog.WriteLine(string.Format((IFormatProvider)null, "Gff Parser BVT : File Exists in the Path '{0}'.", filePath)); IList <ISequence> seqs = null; using (var reader = File.OpenRead(filePath)) { GffParser parserObj = new GffParser(); { seqs = parserObj.Parse(reader).ToList(); } } int expectedSequenceCount = 1; Assert.IsNotNull(seqs); Assert.AreEqual(expectedSequenceCount, seqs.Count); ApplicationLog.WriteLine(string.Format((IFormatProvider)null, "Gff Parser BVT : Number of Sequences found are '{0}'.", seqs.Count.ToString((IFormatProvider)null))); Assert.IsTrue(ValidateFeatures(seqs[0], nodeName)); ApplicationLog.WriteLine( "Gff Parser BVT : Successfully validated all the Features for a give Sequence in GFF File."); string expectedSequence = utilityObj.xmlUtil.GetTextValue(nodeName, Constants.ExpectedSequenceNode); Sequence seq = (Sequence)seqs[0]; Assert.IsNotNull(seq); byte[] TempSeqData = new byte[seq.Count]; for (int i = 0; i < seq.Count; i++) { TempSeqData[i] = seq[i]; } string sequenceInString = new string(TempSeqData.Select(x => (char)x).ToArray()); Assert.AreEqual(expectedSequence, sequenceInString); ApplicationLog.WriteLine(string.Format((IFormatProvider)null, "Gff Parser BVT: The Gff sequence '{0}' validation after Parse() is found to be as expected.", seq.ToString())); byte[] tmpEncodedSeq = new byte[seq.Count]; for (int i = 0; i < seq.Count; i++) { tmpEncodedSeq[i] = seq[i]; } Assert.AreEqual(expectedSequence.Length, tmpEncodedSeq.Length); ApplicationLog.WriteLine(string.Format((IFormatProvider)null, "Gff Parser BVT: The Gff Length sequence '{0}' is as expected.", expectedSequence.Length)); string expectedAlphabet = utilityObj.xmlUtil.GetTextValue(nodeName, Constants.AlphabetNameNode).ToLower(CultureInfo.CurrentCulture); Assert.IsNotNull(seq.Alphabet); Assert.AreEqual(seq.Alphabet.Name.ToLower(CultureInfo.CurrentCulture), expectedAlphabet); ApplicationLog.WriteLine(string.Format((IFormatProvider)null, "Gff Parser BVT: The Sequence Alphabet is '{0}' and is as expected.", seq.Alphabet.Name)); string expectedSequenceId = utilityObj.xmlUtil.GetTextValue(nodeName, Constants.SequenceIdNode); Assert.AreEqual(expectedSequenceId, seq.ID); ApplicationLog.WriteLine(string.Format((IFormatProvider)null, "Gff Parser BVT: The Sequence ID is '{0}' and is as expected.", seq.ID)); }