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(genBankParserName, actualgenBankParserName.Name); Assert.AreEqual(gffParserName, actualGffParserName.Name); Assert.AreEqual(fastQParserName, actualFastQParserName.Name); Assert.IsNotNull(allParser); Console.WriteLine(string.Format((IFormatProvider)null, "SequenceParser : Type of the parser is validated successfully")); ApplicationLog.WriteLine("Type of the parser is validated successfully"); }
/// <summary> /// General method to validate FastQ Parser. /// <param name="nodeName">xml node name.</param> /// </summary> private void ValidateFastQParser(string nodeName) { // Gets the expected sequence from the Xml string filePath = utilityObj.xmlUtil.GetTextValue( nodeName, Constants.FilePathNode).TestDir(); string expectedQualitativeSequence = utilityObj.xmlUtil.GetTextValue( nodeName, Constants.ExpectedSequenceNode); string expectedSequenceId = utilityObj.xmlUtil.GetTextValue( nodeName, Constants.SequenceIdNode); int expectedSeqCount = int.Parse(utilityObj.xmlUtil.GetTextValue(nodeName, Constants.SeqsCount)); // Parse a FastQ file. var fastQParserObj = new FastQParser(); using (fastQParserObj.Open(filePath)) { IList <IQualitativeSequence> qualSequenceList = fastQParserObj.Parse().ToList(); // Validate qualitative Sequence upon parsing FastQ file. Assert.AreEqual(expectedSeqCount, qualSequenceList.Count); Assert.AreEqual(expectedQualitativeSequence, qualSequenceList[0].ConvertToString()); Assert.AreEqual(expectedSequenceId, qualSequenceList[0].ID); ApplicationLog.WriteLine(string.Format("FastQ Parser BVT: The FASTQ sequence '{0}' validation after Parse() is found to be as expected.", qualSequenceList[0].ConvertToString())); ApplicationLog.WriteLine(string.Format("FastQ Parser BVT: The FASTQ sequence ID '{0}' validation after Parse() is found to be as expected.", qualSequenceList[0].ID)); } }
public void TestFastQWhenParsingOneOfMany() { string filepath = @"TestUtils\FASTQ\SRR002012_5.fastq"; // parse ISequenceParser parser = new FastQParser(filepath); try { ISequence seq = parser.Parse().First(); Assert.IsNotNull(seq); } finally { parser.Dispose(); } using (FastQParser fqParser = new FastQParser(filepath)) { fqParser.AutoDetectFastQFormat = false; fqParser.FormatType = FastQFormatType.Sanger; fqParser.Alphabet = Alphabets.DNA; QualitativeSequence qualSeq = fqParser.Parse().First(); Assert.IsNotNull(qualSeq); } }
/// <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 { // 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); }
public void InvalidateFastQParseRange() { try { using (FastQParser fqParserObj = new FastQParser()) { fqParserObj.ParseRange(-1, 0, new SequencePointer()); } Assert.Fail(); } catch (ArgumentOutOfRangeException) { ApplicationLog.WriteLine( "FastQ Parser P2 : Successfully validated the exception"); Console.WriteLine( "FastQ Parser P2 : Successfully validated the exception"); } try { using (FastQParser fqParserObj = new FastQParser()) { fqParserObj.ParseRange(0, -1, new SequencePointer()); } Assert.Fail(); } catch (ArgumentOutOfRangeException) { ApplicationLog.WriteLine( "FastQ Parser P2 : Successfully validated the exception"); Console.WriteLine( "FastQ Parser P2 : Successfully validated the exception"); } }
/// <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> /// 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); }
/// <summary> /// General method to validate FastQ Parser On Streams. /// <param name="nodeName">xml node name.</param> /// </summary> private void ValidateFastQParserOnAStream(string nodeName) { // Gets the expected sequence from the Xml string filePath = utilityObj.xmlUtil.GetTextValue( nodeName, Constants.FilePathNode).TestDir(); string expectedQualitativeSequence = utilityObj.xmlUtil.GetTextValue( nodeName, Constants.ExpectedSequenceNode); string expectedSequenceId = utilityObj.xmlUtil.GetTextValue( nodeName, Constants.SequenceIdNode); IList <IQualitativeSequence> qualSequenceList; using (var reader = File.OpenRead(filePath)) { // Parse a FastQ file. var fastQParserObj = new FastQParser(); qualSequenceList = fastQParserObj.Parse(reader).ToList(); } string actualQualitativeSequence = qualSequenceList[0].ConvertToString(); string actualId = qualSequenceList[0].ID; // Validate qualitative Sequence upon parsing FastQ file. Assert.AreEqual(expectedQualitativeSequence, actualQualitativeSequence); Assert.AreEqual(actualId, expectedSequenceId); ApplicationLog.WriteLine(string.Format("FastQ Parser BVT: The FASTQ sequence '{0}' validation after Parse(Stream) is found to be as expected.", actualQualitativeSequence)); ApplicationLog.WriteLine(string.Format("FastQ Parser BVT: The FASTQ sequence ID '{0}' validation after Parse(Stream) is found to be as expected.", actualId)); }
public void TestDefaultFastQFormatType() { using (FastQParser parser = new FastQParser()) { Assert.AreEqual(parser.FormatType, FastQFormatType.Illumina); } }
public void FastQFormatter() { string filepathOriginal = @"TestUtils\FASTQ\SRR002012_5.fastq"; Assert.IsTrue(File.Exists(filepathOriginal)); IList <QualitativeSequence> seqsOriginal = null; string filepathTmp = Path.GetTempFileName(); using (FastQParser parser = new FastQParser()) { parser.Open(filepathOriginal); // Read the original file seqsOriginal = parser.Parse().ToList(); Assert.IsNotNull(seqsOriginal); // Use the formatter to write the original sequences to a temp file using (FastQFormatter formatter = new FastQFormatter(filepathTmp)) { foreach (QualitativeSequence s in seqsOriginal) { formatter.Write(s); } } } // Read the new file, then compare the sequences IList <QualitativeSequence> seqsNew = null; using (FastQParser parser = new FastQParser(filepathTmp)) { seqsNew = parser.Parse().ToList(); Assert.IsNotNull(seqsNew); // Now compare the sequences. int countOriginal = seqsOriginal.Count(); int countNew = seqsNew.Count(); Assert.AreEqual(countOriginal, countNew); int i; for (i = 0; i < countOriginal; i++) { Assert.AreEqual(seqsOriginal[i].ID, seqsNew[i].ID); string orgSeq = ASCIIEncoding.ASCII.GetString(seqsOriginal[i].ToArray()); string newSeq = ASCIIEncoding.ASCII.GetString(seqsNew[i].ToArray()); string orgscores = ASCIIEncoding.ASCII.GetString(seqsOriginal[i].GetEncodedQualityScores()); string newscores = ASCIIEncoding.ASCII.GetString(seqsNew[i].GetEncodedQualityScores()); Assert.AreEqual(orgSeq, newSeq); Assert.AreEqual(orgscores, newscores); } // 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(filepathTmp); } }
/// <summary> /// General method to validate FastQ Formatter on a Stream. /// <param name="nodeName">xml node name.</param> /// </summary> void ValidateFastQFormatterOnAStream(string nodeName) { // Gets the expected sequence from the Xml string filePath = utilityObj.xmlUtil.GetTextValue( nodeName, Constants.FilePathNode); string expectedQualitativeSequence = utilityObj.xmlUtil.GetTextValue( nodeName, Constants.ExpectedSequenceNode); string expectedSequenceId = utilityObj.xmlUtil.GetTextValue( nodeName, Constants.SequenceIdNode); string tempFileName1 = System.IO.Path.GetTempFileName(); string parsedValue = string.Empty; string parsedID = string.Empty; IEnumerable <QualitativeSequence> qualSequence = null; // Parse a FastQ file using parseOne method. using (FastQParser fastQParserObj = new FastQParser(filePath)) { fastQParserObj.AutoDetectFastQFormat = false; qualSequence = fastQParserObj.Parse(); // New Sequence after formatting file. IEnumerable <QualitativeSequence> newQualSeq = null; using (StreamWriter writer = new StreamWriter(tempFileName1)) { using (FastQFormatter fastQFormatter = new FastQFormatter()) { fastQFormatter.Open(writer); fastQFormatter.Write(qualSequence.ElementAt(0)); } } using (FastQParser fastQParserObjTemp = new FastQParser(tempFileName1)) { newQualSeq = fastQParserObjTemp.Parse(); parsedValue = new string(newQualSeq.ElementAt(0).Select(a => (char)a).ToArray()); parsedID = newQualSeq.ElementAt(0).ID.ToString((IFormatProvider)null); } // Validate qualitative parsing temporary file. Assert.AreEqual(parsedValue, expectedQualitativeSequence); Assert.AreEqual(parsedID, expectedSequenceId); ApplicationLog.WriteLine(string.Format((IFormatProvider)null, "FastQ Formatter BVT: The FASTQ sequence '{0}' validation after Write() and Parse() is found to be as expected.", parsedValue)); // Logs to the VSTest GUI (Console.Out) window Console.WriteLine(string.Format((IFormatProvider)null, "FastQ Formatter BVT: The FASTQ sequence '{0}' validation after Write() and Parse() is found to be as expected.", parsedValue)); Console.WriteLine(string.Format((IFormatProvider)null, "FastQ Formatter BVT: The FASTQ sequence '{0}' validation after Write() and Parse() is found to be as expected.", parsedID)); qualSequence = null; File.Delete(tempFileName1); } }
/// <summary> /// General method to Invalidate FastQ Parser. /// <param name="nodeName">xml node name.</param> /// </summary> private void InValidateFastQParser(string nodeName) { // Gets the expected sequence from the Xml string filePath = utilityObj.xmlUtil.GetTextValue(nodeName, Constants.FilePathNode); // Create a FastQ Parser object. var fastQParserObj = new FastQParser(); { fastQParserObj.Parse(filePath).ToList(); } }
void InValidateFastQFormatter(FastQFormatParameters param) { // Gets the expected sequence from the Xml string filepath = utilityObj.xmlUtil.GetTextValue( Constants.MultiSeqSangerRnaProNode, Constants.FilePathNode); // Parse a FastQ file. using (FastQParser fastQParser = new FastQParser(filepath)) { fastQParser.AutoDetectFastQFormat = true; IEnumerable <QualitativeSequence> sequence = null; FastQFormatter fastQFormatter = null; switch (param) { case FastQFormatParameters.Sequence: try { fastQFormatter = new FastQFormatter(filepath); fastQFormatter.Write(null as ISequence); Assert.Fail(); } catch (ArgumentNullException) { fastQFormatter.Close(); ApplicationLog.WriteLine( "FastQ Parser P2 : Successfully validated the exception"); Console.WriteLine( "FastQ Parser P2 : Successfully validated the exception"); } break; default: try { sequence = fastQParser.Parse(); fastQFormatter = new FastQFormatter(Constants.FastQTempFileName); fastQFormatter.Write(sequence as QualitativeSequence); Assert.Fail(); } catch (ArgumentNullException) { fastQFormatter.Close(); ApplicationLog.WriteLine( "FastQ Parser P2 : Successfully validated the exception"); Console.WriteLine( "FastQ Parser P2 : Successfully validated the exception"); } break; } } }
public void FastQFormatter() { const string FilepathOriginal = @"TestUtils\FASTQ\SRR002012_5.fastq"; Assert.IsTrue(File.Exists(FilepathOriginal)); IList<IQualitativeSequence> seqsOriginal; string filepathTmp = Path.GetTempFileName(); FastQParser parser = new FastQParser(); using (parser.Open(FilepathOriginal)) { // Read the original file seqsOriginal = parser.Parse().ToList(); Assert.IsNotNull(seqsOriginal); // Use the formatter to write the original sequences to a temp file new FastQFormatter() .Format(seqsOriginal, filepathTmp); } // Read the new file, then compare the sequences using (parser.Open(filepathTmp)) { IList<IQualitativeSequence> seqsNew = parser.Parse().ToList(); Assert.IsNotNull(seqsNew); // Now compare the sequences. int countOriginal = seqsOriginal.Count(); int countNew = seqsNew.Count(); Assert.AreEqual(countOriginal, countNew); int i; for (i = 0; i < countOriginal; i++) { var orgSequence = seqsOriginal[i]; var sequence = seqsNew[i]; Assert.AreEqual(seqsOriginal[i].ID, sequence.ID); string orgSeq = Encoding.ASCII.GetString(orgSequence.ToArray()); string newSeq = Encoding.ASCII.GetString(sequence.ToArray()); string orgscores = Encoding.ASCII.GetString(orgSequence.GetEncodedQualityScores()); string newscores = Encoding.ASCII.GetString(sequence.GetEncodedQualityScores()); Assert.AreEqual(orgSeq, newSeq); Assert.AreEqual(orgscores, newscores); } } // 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(filepathTmp); }
public void TestFastQWhenParsingOneOfMany() { // parse ISequenceParser parser = new FastQParser(); string filepath = @"testdata\FASTQ\SRR002012_5.fastq"; ISequence seq = parser.ParseOne(filepath); FastQParser fqParser = new FastQParser(); fqParser.AutoDetectFastQFormat = false; fqParser.FastqType = FastQFormatType.Sanger; IQualitativeSequence qualSeq = fqParser.ParseOne(filepath); }
/// <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 (Helper.IsZippedFasta(fileName)) { parser = new FastAZippedParser(fileName); } else if (Helper.IsZippedFastQ(fileName)) { parser = new FastQZippedParser(fileName); } else if (IsFasta(fileName)) { parser = new FastAParser(fileName); } else if (IsFastQ(fileName)) { parser = new FastQParser(fileName); } else if (Helper.IsBAM(fileName)) { throw new NotImplementedException(); //parser = new BAMSequenceParser(fileName); } else if (IsGenBank(fileName)) { parser = new GenBankParser(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 FastQProperties() { FastQParser parser = new FastQParser(); Assert.AreEqual(parser.Name, Resource.FastQName); Assert.AreEqual(parser.Description, Resource.FASTQPARSER_DESCRIPTION); Assert.AreEqual(parser.SupportedFileTypes, Resource.FASTQ_FILEEXTENSION); FastQFormatter formatter = new FastQFormatter(); Assert.AreEqual(formatter.Name, Resource.FastQName); Assert.AreEqual(formatter.Description, Resource.FASTQFORMATTER_DESCRIPTION); Assert.AreEqual(formatter.SupportedFileTypes, Resource.FASTQ_FILEEXTENSION); }
public void FastQProperties() { ISequenceParser parser = new FastQParser(); Assert.AreEqual(parser.Name, Properties.Resource.FASTQ_NAME); Assert.AreEqual(parser.Description, Properties.Resource.FASTQPARSER_DESCRIPTION); Assert.AreEqual(parser.FileTypes, Properties.Resource.FASTQ_FILEEXTENSION); ISequenceFormatter formatter = new FastQFormatter(); Assert.AreEqual(formatter.Name, Properties.Resource.FASTQ_NAME); Assert.AreEqual(formatter.Description, Properties.Resource.FASTQFORMATTER_DESCRIPTION); Assert.AreEqual(formatter.FileTypes, Properties.Resource.FASTQ_FILEEXTENSION); }
/// <summary> /// Gets the VirtualSequenceProvider /// </summary> /// <returns>Virtual Sequence Provider</returns> static FileVirtualQualitativeSequenceProvider GetVirtualSequenceProvider() { string filePath = Utility._xmlUtil.GetTextValue( Constants.SingleSequenceSangerFastQNode, Constants.FilePathNode); FastQParser parserObj = new FastQParser(); parserObj.Parse(filePath); FileVirtualQualitativeSequenceProvider provObj = new FileVirtualQualitativeSequenceProvider(parserObj, GetSequencePointer()); return(provObj); }
GetVirtualQualitativeSequenceList(string nodeName) { // Gets the expected sequence from the Xml string filePath = Utility._xmlUtil.GetTextValue( nodeName, Constants.FilePathNode); FastQParser parserObj = new FastQParser(); parserObj.EnforceDataVirtualization = true; VirtualQualitativeSequenceList seqList = (VirtualQualitativeSequenceList)parserObj.Parse(filePath); return(seqList); }
private void InValidateFastQFormatter(FastQFormatParameters param) { // Gets the expected sequence from the Xml string filepath = utilityObj.xmlUtil.GetTextValue( Constants.MultiSeqSangerRnaProNode, Constants.FilePathNode); // Parse a FastQ file. var fastQParser = new FastQParser(); using (fastQParser.Open(filepath)) { FastQFormatter fastQFormatter = null; switch (param) { case FastQFormatParameters.Sequence: try { fastQFormatter = new FastQFormatter(); fastQFormatter.Format(null as ISequence, filepath); Assert.Fail(); } catch (ArgumentNullException) { fastQFormatter.Close(); ApplicationLog.WriteLine( "FastQ Parser P2 : Successfully validated the exception"); } break; default: try { IEnumerable <IQualitativeSequence> sequence = fastQParser.Parse(); fastQFormatter = new FastQFormatter(); fastQFormatter.Format(sequence, null); Assert.Fail(); } catch (ArgumentNullException) { ApplicationLog.WriteLine("FastQ Parser P2 : Successfully validated the exception"); } break; } } }
public void FastQFormatterUsingInterface() { string FilepathOriginal = @"TestUtils\FastQ\SRR002012_5.fastq".TestDir(); Assert.IsTrue(File.Exists(FilepathOriginal)); string filepathTmp = Path.GetTempFileName(); IList <QualitativeSequence> seqsOriginal = new FastQParser() .Parse(FilepathOriginal) .Cast <QualitativeSequence>() .ToList(); // Use the formatter to write the original sequences to a temp file new FastQFormatter() .Format(seqsOriginal, filepathTmp); // Read the new file, then compare the sequences IList <QualitativeSequence> seqsNew = new FastQParser() .Parse(filepathTmp) .Cast <QualitativeSequence>() .ToList(); // Now compare the sequences. int countOriginal = seqsOriginal.Count; int countNew = seqsNew.Count; Assert.AreEqual(countOriginal, countNew); int i; for (i = 0; i < countOriginal; i++) { Assert.AreEqual(seqsOriginal[i].ID, seqsNew[i].ID); string orgSeq = Encoding.ASCII.GetString(seqsOriginal[i].ToArray()); string newSeq = Encoding.ASCII.GetString(seqsNew[i].ToArray()); string orgscores = Encoding.ASCII.GetString(seqsOriginal[i].GetEncodedQualityScores()); string newscores = Encoding.ASCII.GetString(seqsNew[i].GetEncodedQualityScores()); Assert.AreEqual(orgSeq, newSeq); Assert.AreEqual(orgscores, newscores); } // 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(filepathTmp); }
/// <summary> /// General method to Invalidate FastQ Parser. /// <param name="nodeName">xml node name.</param> /// <param name="IsParseOne">True for FastQParseOne validations, else false</param> /// </summary> void InValidateFastQParser(string nodeName, bool IsParseOne) { // Gets the expected sequence from the Xml string filePath = _utilityObj._xmlUtil.GetTextValue( nodeName, Constants.FilePathNode); FastQFormatType expectedFormatType = Utility.GetFastQFormatType( _utilityObj._xmlUtil.GetTextValue(nodeName, Constants.FastQFormatType)); // Create a FastQ Parser object. using (FastQParser fastQParserObj = new FastQParser()) { fastQParserObj.AutoDetectFastQFormat = true; fastQParserObj.FastqType = expectedFormatType; if (IsParseOne) { try { fastQParserObj.ParseOne(filePath); Assert.Fail(); } catch (Exception) { ApplicationLog.WriteLine( "FastQ Parser P2 : Successfully validated the exception"); Console.WriteLine( "FastQ Parser P2 : Successfully validated the exception"); } } else { try { fastQParserObj.Parse(filePath); Assert.Fail(); } catch (Exception) { ApplicationLog.WriteLine( "FastQ Parser P2 : Successfully validated the exception"); Console.WriteLine( "FastQ Parser P2 : Successfully validated the exception"); } } } }
public void TestFormatingString() { string str = @"@SRR002012.1 Oct4:5:1:871:340 length=26 GGCGCACTTACACCCTACATCCATTG +SRR002012.1 Oct4:5:1:871:340 length=26 IIIIG1?II;IIIII1IIII1%.I7I "; StringReader sr = new StringReader(str); FastQParser parser = new FastQParser(); IQualitativeSequence seq = parser.ParseOne(sr); FastQFormatter formatter = new FastQFormatter(); string formatterStr = formatter.FormatString(seq); Assert.AreEqual(str, formatterStr); }
public static async void AssemblySequences(string fastqFileName) { var parser = new FastQParser(); List <IQualitativeSequence> sequences = new List <IQualitativeSequence>(); using (var fileStream = new FileStream(fastqFileName, FileMode.Open)) { sequences = parser.Parse(fileStream).ToList(); } OverlapDeNovoAssembler assembler = new OverlapDeNovoAssembler(); IDeNovoAssembly assembly = assembler.Assemble(sequences); FastAFormatter outputFormatter = new FastAFormatter(); outputFormatter.Open("assembled_sequences.fasta"); outputFormatter.Format(assembly.AssembledSequences); outputFormatter.Close(); }
public void InvalidateFastQParserGetSequenceId() { try { using (FastQParser fqParserObj = new FastQParser()) { fqParserObj.GetSequenceID(null); } Assert.Fail(); } catch (ArgumentNullException) { ApplicationLog.WriteLine( "FastQ Parser P2 : Successfully validated the exception"); Console.WriteLine( "FastQ Parser P2 : Successfully validated the exception"); } }
public void InvalidateFastQParseNoFileName() { try { using (FastQParser fqParserObj = new FastQParser()) { fqParserObj.Parse(null as string, true); } Assert.Fail(); } catch (ArgumentNullException) { ApplicationLog.WriteLine( "FastQ Parser P2 : Successfully validated the exception"); Console.WriteLine( "FastQ Parser P2 : Successfully validated the exception"); } }
/// <summary> /// General method to validate FastQ Parser On Streams. /// <param name="nodeName">xml node name.</param> /// </summary> void ValidateFastQParserOnAStream(string nodeName) { // Gets the expected sequence from the Xml string filePath = utilityObj.xmlUtil.GetTextValue( nodeName, Constants.FilePathNode); string expectedQualitativeSequence = utilityObj.xmlUtil.GetTextValue( nodeName, Constants.ExpectedSequenceNode); string expectedSequenceId = utilityObj.xmlUtil.GetTextValue( nodeName, Constants.SequenceIdNode); string actualQualitativeSequence = String.Empty; string actualId = String.Empty; IEnumerable <QualitativeSequence> qualSequence = null; IList <QualitativeSequence> qualSequenceList = null; using (StreamReader reader = new StreamReader(filePath)) { // Parse a FastQ file. using (FastQParser fastQParserObj = new FastQParser()) { fastQParserObj.AutoDetectFastQFormat = false; qualSequence = fastQParserObj.Parse(reader); qualSequenceList = qualSequence.ToList(); } } actualQualitativeSequence = new string(qualSequenceList[0].Select(a => (char)a).ToArray()); actualId = qualSequenceList[0].ID.ToString((IFormatProvider)null); // Validate qualitative Sequence upon parsing FastQ file. Assert.AreEqual(expectedQualitativeSequence, actualQualitativeSequence); Assert.AreEqual(actualId, expectedSequenceId); ApplicationLog.WriteLine(string.Format((IFormatProvider)null, "FastQ Parser BVT: The FASTQ sequence '{0}' validation after Parse(Stream) is found to be as expected.", actualQualitativeSequence)); // Logs to the VSTest GUI (Console.Out) window Console.WriteLine(string.Format((IFormatProvider)null, "FastQ Parser BVT: The FASTQ sequence ID '{0}' validation after Parse(Stream) is found to be as expected.", actualQualitativeSequence)); Console.WriteLine(string.Format((IFormatProvider)null, "FastQ Parser BVT: The FASTQ sequence ID '{0}' validation after Parse(Stream) is found to be as expected.", actualId)); }
/// <summary> /// General method to validate FastQ Formatter. /// <param name="nodeName">xml node name.</param> /// <param name="fileExtension">Different temporary file extensions</param> /// </summary> private void ValidateFastQFormatter(string nodeName, FastQFileParameters fileExtension) { // Gets the expected sequence from the Xml string filePath = utilityObj.xmlUtil.GetTextValue(nodeName, Constants.FilePathNode); string expectedQualitativeSequence = utilityObj.xmlUtil.GetTextValue(nodeName, Constants.ExpectedSequenceNode); string expectedSequenceId = utilityObj.xmlUtil.GetTextValue(nodeName, Constants.SequenceIdNode); string tempFileName = Path.GetTempFileName(); // Parse a FastQ file using parseOne method. var fastQParserObj = new FastQParser(); using (fastQParserObj.Open(filePath)) { IQualitativeSequence oneSequence = fastQParserObj.ParseOne(); // Format Parsed Sequence to temp file with different extension. var fastQFormatter = new FastQFormatter(); using (fastQFormatter.Open(tempFileName)) { fastQFormatter.Format(oneSequence); } string parsedValue; string parsedId; var fastQParserObjTemp = new FastQParser(); using (fastQParserObjTemp.Open(tempFileName)) { oneSequence = fastQParserObjTemp.Parse().First(); parsedValue = oneSequence.ConvertToString(); parsedId = oneSequence.ID; } // Validate qualitative parsing temporary file. Assert.AreEqual(expectedQualitativeSequence, parsedValue); Assert.AreEqual(expectedSequenceId, parsedId); ApplicationLog.WriteLine(string.Format("FastQ Formatter BVT: The FASTQ sequence '{0}' validation after Write() and Parse() is found to be as expected.", parsedValue)); ApplicationLog.WriteLine(string.Format("FastQ Formatter BVT: The FASTQ sequence '{0}' validation after Write() and Parse() is found to be as expected.", parsedId)); File.Delete(tempFileName); } }
public void TestFastQWhenParsingOneOfMany() { // parse ISequenceParser parser = new FastQParser(); string filepath = @"TestUtils\FASTQ\SRR002012_5.fastq"; ISequence seq = parser.ParseOne(filepath); Assert.IsNotNull(seq); FastQParser fqParser = new FastQParser(); fqParser.AutoDetectFastQFormat = false; fqParser.FastqType = FastQFormatType.Sanger; IQualitativeSequence qualSeq = fqParser.ParseOne(filepath); Assert.IsNotNull(qualSeq); ((FastQParser)parser).Dispose(); }
public void TestFastQWhenParsingOneOfMany() { string filepath = @"TestUtils\FASTQ\SRR002012_5.fastq"; // Parse ISequence seq = new FastQParser().ParseOne(filepath); Assert.IsNotNull(seq); FastQParser fqParser = new FastQParser { FormatType = FastQFormatType.Sanger, Alphabet = Alphabets.DNA }; using (fqParser.Open(filepath)) { var qualSeq = fqParser.Parse().First() as QualitativeSequence; Assert.IsNotNull(qualSeq); } }
public void InvalidateFastQParseWithQualityScore() { try { ISequenceParser parser = new FastQParser(); parser.ParseOne( Utility._xmlUtil.GetTextValue( Constants.FastQInvalidQualScoreFileNode, Constants.FilePathNode)); Assert.Fail(); } catch (FormatException) { ApplicationLog.WriteLine( "FastQ Parser P2 : Successfully validated the exception"); Console.WriteLine( "FastQ Parser P2 : Successfully validated the exception"); } }
public IEnumerable<ISequence> Parse(Stream stream) { FastQParser fqp = new FastQParser (); foreach (var seq in fqp.Parse (stream)) { var name = seq.ID; var sp = name.Split ('/'); var movie = sp [0]; var hole = sp [1]; SAMAlignedSequence sam = new SAMAlignedSequence (); sam.QuerySequence = seq; sam.OptionalFields.Add (new SAMOptionalField () { Tag = "sn", Value = "f,0,0,0,0" }); sam.OptionalFields.Add (new SAMOptionalField () { Tag = "rs", Value = "f,0,0,0,0,0,0" }); sam.OptionalFields.Add (new SAMOptionalField () { Tag = "zs", Value = "f,0,0,0,0,0,0" }); PacBioCCSRead read = new PacBioCCSRead (sam) { AvgZscore = Single.NaN, HoleNumber = Convert.ToInt32 (hole), Movie = movie }; yield return read; } }
/// <summary> /// General method to validate FastQ Parser On Streams. /// <param name="nodeName">xml node name.</param> /// </summary> private void ValidateFastQParserOnAStream(string nodeName) { // Gets the expected sequence from the Xml string filePath = utilityObj.xmlUtil.GetTextValue( nodeName, Constants.FilePathNode); string expectedQualitativeSequence = utilityObj.xmlUtil.GetTextValue( nodeName, Constants.ExpectedSequenceNode); string expectedSequenceId = utilityObj.xmlUtil.GetTextValue( nodeName, Constants.SequenceIdNode); IList<IQualitativeSequence> qualSequenceList; using (var reader = File.OpenRead(filePath)) { // Parse a FastQ file. var fastQParserObj = new FastQParser(); qualSequenceList = fastQParserObj.Parse(reader).ToList(); } string actualQualitativeSequence = qualSequenceList[0].ConvertToString(); string actualId = qualSequenceList[0].ID; // Validate qualitative Sequence upon parsing FastQ file. Assert.AreEqual(expectedQualitativeSequence, actualQualitativeSequence); Assert.AreEqual(actualId, expectedSequenceId); ApplicationLog.WriteLine(string.Format("FastQ Parser BVT: The FASTQ sequence '{0}' validation after Parse(Stream) is found to be as expected.", actualQualitativeSequence)); ApplicationLog.WriteLine(string.Format("FastQ Parser BVT: The FASTQ sequence ID '{0}' validation after Parse(Stream) is found to be as expected.", actualId)); }
/// <summary> /// General method to validate FastQ Formatter on a Stream. /// <param name="nodeName">xml node name.</param> /// </summary> private void ValidateFastQFormatterOnAStream(string nodeName) { // Gets the expected sequence from the Xml string filePath = utilityObj.xmlUtil.GetTextValue(nodeName, Constants.FilePathNode); string expectedQualitativeSequence = utilityObj.xmlUtil.GetTextValue(nodeName, Constants.ExpectedSequenceNode); string expectedSequenceId = utilityObj.xmlUtil.GetTextValue(nodeName, Constants.SequenceIdNode); string tempFileName1 = Path.GetTempFileName(); // Parse a FastQ file using parseOne method. var fastQParserObj = new FastQParser(); using (fastQParserObj.Open(filePath)) { var oneSequence = fastQParserObj.ParseOne(); // New Sequence after formatting file. var fastQFormatter = new FastQFormatter(); using (fastQFormatter.Open(tempFileName1)) fastQFormatter.Format(oneSequence); var fastQParserObjTemp = new FastQParser(); string parsedValue, parsedId; using (fastQParserObjTemp.Open(tempFileName1)) { oneSequence = fastQParserObjTemp.Parse().First(); parsedValue = oneSequence.ConvertToString(); parsedId = oneSequence.ID; } // Validate qualitative parsing temporary file. Assert.AreEqual(expectedQualitativeSequence, parsedValue); Assert.AreEqual(expectedSequenceId, parsedId); ApplicationLog.WriteLine(string.Format("FastQ Formatter BVT: The FASTQ sequence '{0}' validation after Write() and Parse() is found to be as expected.", parsedValue)); ApplicationLog.WriteLine(string.Format("FastQ Formatter BVT: The FASTQ sequence '{0}' validation after Write() and Parse() is found to be as expected.", parsedId)); File.Delete(tempFileName1); } }
private void InValidateFastQFormatter(FastQFormatParameters param) { // Gets the expected sequence from the Xml string filepath = utilityObj.xmlUtil.GetTextValue( Constants.MultiSeqSangerRnaProNode, Constants.FilePathNode); // Parse a FastQ file. var fastQParser = new FastQParser(); using (fastQParser.Open(filepath)) { FastQFormatter fastQFormatter = null; switch (param) { case FastQFormatParameters.Sequence: try { fastQFormatter = new FastQFormatter(); fastQFormatter.Format(null as ISequence, filepath); Assert.Fail(); } catch (ArgumentNullException) { fastQFormatter.Close(); ApplicationLog.WriteLine( "FastQ Parser P2 : Successfully validated the exception"); } break; default: try { IEnumerable<IQualitativeSequence> sequence = fastQParser.Parse(); fastQFormatter = new FastQFormatter(); fastQFormatter.Format(sequence, null); Assert.Fail(); } catch (ArgumentNullException) { ApplicationLog.WriteLine("FastQ Parser P2 : Successfully validated the exception"); } break; } } }
public void InvalidateFastQParseNoFileName() { var fqParserObj = new FastQParser(); Assert.Throws<ArgumentNullException>( () => fqParserObj.Parse(null).ToList()); }
/// <summary> /// General method to validate multi sequence FastQ Format. /// </summary> /// <param name="nodeName">xml node name.</param> private void ValidateMultiSeqFastQFormatter(string nodeName) { // Gets the expected sequence from the Xml string filePath = utilityObj.xmlUtil.GetTextValue(nodeName, Constants.FilePathNode); string expectedQualitativeSequence = utilityObj.xmlUtil.GetTextValue(nodeName, Constants.ExpectedSequenceNode); string expectedSequenceId = utilityObj.xmlUtil.GetTextValue(nodeName, Constants.SequenceIdNode); string expectedSecondQualitativeSequence = utilityObj.xmlUtil.GetTextValue(nodeName, Constants.ExpectedSequence2Node); string expectedSecondSeqID = utilityObj.xmlUtil.GetTextValue(nodeName, Constants.ExpectedSequenceId1Node); // Parse a FastQ file. var fastQParserObj = new FastQParser(); using (fastQParserObj.Open(filePath)) { var qualSequenceList = fastQParserObj.Parse().ToList(); // Format a first Qualitative sequence new FastQFormatter().Format(qualSequenceList[0], Constants.FastQTempFileName); // Read it back var seqsNew = new FastQParser().Parse(Constants.FastQTempFileName).ToList(); // Format a Second Qualitative sequence new FastQFormatter().Format(qualSequenceList[1], Constants.StreamWriterFastQTempFileName); var secondSeqsNew = new FastQParser().Parse(Constants.StreamWriterFastQTempFileName).ToList(); // Validate Second qualitative Sequence upon parsing FastQ file. Assert.AreEqual(expectedSecondQualitativeSequence, secondSeqsNew[0].ConvertToString()); Assert.AreEqual(expectedSecondSeqID, secondSeqsNew[0].ID); // Validate first qualitative Sequence upon parsing FastQ file. Assert.AreEqual(expectedQualitativeSequence, seqsNew[0].ConvertToString()); Assert.AreEqual(expectedSequenceId, seqsNew[0].ID); ApplicationLog.WriteLine(string.Format("FastQ Parser P1: The FASTQ sequence '{0}' validation after Parse() is found to be as expected.", seqsNew[0])); File.Delete(Constants.FastQTempFileName); File.Delete(Constants.StreamWriterFastQTempFileName); } }
public void TestDefaultFastQFormatType() { FastQParser parser = new FastQParser(); Assert.AreEqual(parser.FormatType, FastQFormatType.Illumina_v1_8); }
/// <summary> /// General method to validate FastQ Parser. /// <param name="nodeName">xml node name.</param> /// </summary> private void ValidateFastQParser(string nodeName) { // Gets the expected sequence from the Xml string filePath = utilityObj.xmlUtil.GetTextValue(nodeName, Constants.FilePathNode); string expectedQualitativeSequence = utilityObj.xmlUtil.GetTextValue(nodeName, Constants.ExpectedSequenceNode); string expectedSequenceId = utilityObj.xmlUtil.GetTextValue(nodeName, Constants.SequenceIdNode); string expectedSeqCount = utilityObj.xmlUtil.GetTextValue(nodeName, Constants.SeqsCount); IAlphabet alphabet = Utility.GetAlphabet(utilityObj.xmlUtil.GetTextValue(nodeName, Constants.AlphabetNameNodeV2)); var fastQParserObj = new FastQParser(); { // Validate qualitative Sequence upon parsing FastQ file. IList<IQualitativeSequence> qualSequenceList = fastQParserObj.Parse<IQualitativeSequence>(filePath).ToList(); Assert.AreEqual(expectedSeqCount, qualSequenceList.Count.ToString((IFormatProvider) null)); Assert.AreEqual(expectedQualitativeSequence, qualSequenceList[0].ConvertToString()); Assert.AreEqual(expectedSequenceId, qualSequenceList[0].ID.ToString(null)); Assert.AreEqual(alphabet, qualSequenceList[0].Alphabet); } }
/// <summary> /// General method to validate FastQ formatting /// Qualitative Sequence by passing TextWriter as a parameter /// <param name="nodeName">xml node name.</param> /// </summary> private void ValidateFastQFormatByFormattingQualSeqeunce(string nodeName) { // Gets the actual sequence and the alphabet from the Xml IAlphabet alphabet = Utility.GetAlphabet(utilityObj.xmlUtil.GetTextValue(nodeName, Constants.AlphabetNameNodeV2)); FastQFormatType expectedFormatType = Utility.GetFastQFormatType(utilityObj.xmlUtil.GetTextValue(nodeName, Constants.FastQFormatType)); string qualSequence = utilityObj.xmlUtil.GetTextValue(nodeName, Constants.ExpectedSequenceNode); string expectedQualitativeSequence = utilityObj.xmlUtil.GetTextValue(nodeName, Constants.ExpectedSequenceNode); string qualityScores = ""; int i; for (i = 0; i < qualSequence.Length; i++) qualityScores = qualityScores + "}"; byte[] seq = Encoding.UTF8.GetBytes(qualSequence); byte[] qScore = Encoding.UTF8.GetBytes(qualityScores); string tempFileName = Path.GetTempFileName(); // Create a Qualitative Sequence. var qualSeq = new QualitativeSequence(alphabet, expectedFormatType, seq, qScore); var formatter = new FastQFormatter(); using (formatter.Open(tempFileName)) { formatter.Format(qualSeq); formatter.Close(); var fastQParserObj = new FastQParser(); using (fastQParserObj.Open(tempFileName)) { // Read the new file and validate Sequences. var seqsNew = fastQParserObj.Parse(); var firstSequence = seqsNew.First(); // Validate qualitative Sequence upon parsing FastQ file. Assert.AreEqual(expectedQualitativeSequence, firstSequence.ConvertToString()); Assert.IsTrue(string.IsNullOrEmpty(firstSequence.ID)); ApplicationLog.WriteLine(string.Format("FastQ Parser P1: The FASTQ sequence '{0}' validation after Parse() is found to be as expected.", firstSequence)); } File.Delete(tempFileName); } }
private void ValidateFastQFormatter(string nodeName, bool writeMultipleSequences) { // Gets the expected sequence from the Xml string filePath = utilityObj.xmlUtil.GetTextValue(nodeName, Constants.FilePathNode); string expectedQualitativeSequence = utilityObj.xmlUtil.GetTextValue(nodeName, Constants.ExpectedSequenceNode); string expectedSequenceId = utilityObj.xmlUtil.GetTextValue(nodeName, Constants.SequenceIdNode); string tempFileName = Path.GetTempFileName(); // Parse a FastQ file. var fastQParserObj = new FastQParser(); using (fastQParserObj.Open(filePath)) { IEnumerable<IQualitativeSequence> qualSequenceList = fastQParserObj.Parse(); var fastQFormatter = new FastQFormatter(); using (fastQFormatter.Open(tempFileName)) { if (writeMultipleSequences) { foreach (IQualitativeSequence newQualSeq in qualSequenceList) { fastQFormatter.Format(newQualSeq); } } else { fastQFormatter.Format(qualSequenceList.First()); } } // temp file is closed. // Read the new file and validate the first Sequence. FastQParser fastQParserObjNew = new FastQParser(); IQualitativeSequence firstSequence = fastQParserObjNew.ParseOne(tempFileName); // Validate qualitative Sequence upon parsing FastQ file. Assert.AreEqual(expectedQualitativeSequence, firstSequence.ConvertToString()); Assert.AreEqual(expectedSequenceId, firstSequence.ID); ApplicationLog.WriteLine(string.Format("FastQ Parser P1: The FASTQ sequence '{0}' validation after Parse() is found to be as expected.", firstSequence)); File.Delete(tempFileName); } }
/// <summary> /// General method to validate FastQ Parser. /// <param name="nodeName">xml node name.</param> /// </summary> private void ValidateFastQParser(string nodeName) { // Gets the expected sequence from the Xml string filePath = utilityObj.xmlUtil.GetTextValue( nodeName, Constants.FilePathNode); string expectedQualitativeSequence = utilityObj.xmlUtil.GetTextValue( nodeName, Constants.ExpectedSequenceNode); string expectedSequenceId = utilityObj.xmlUtil.GetTextValue( nodeName, Constants.SequenceIdNode); int expectedSeqCount = int.Parse(utilityObj.xmlUtil.GetTextValue(nodeName, Constants.SeqsCount)); // Parse a FastQ file. var fastQParserObj = new FastQParser(); using (fastQParserObj.Open(filePath)) { IList<IQualitativeSequence> qualSequenceList = fastQParserObj.Parse().ToList(); // Validate qualitative Sequence upon parsing FastQ file. Assert.AreEqual(expectedSeqCount, qualSequenceList.Count); Assert.AreEqual(expectedQualitativeSequence, qualSequenceList[0].ConvertToString()); Assert.AreEqual(expectedSequenceId, qualSequenceList[0].ID); ApplicationLog.WriteLine(string.Format("FastQ Parser BVT: The FASTQ sequence '{0}' validation after Parse() is found to be as expected.", qualSequenceList[0].ConvertToString())); ApplicationLog.WriteLine(string.Format("FastQ Parser BVT: The FASTQ sequence ID '{0}' validation after Parse() is found to be as expected.", qualSequenceList[0].ID)); } }
/// <summary> /// General method to validate FastQ Parser for Multiple sequence with /// different alphabets. /// <param name="nodeName">xml node name.</param> /// <param name="triSeq">Tri Sequence</param> /// </summary> private void ValidateMulitpleSequenceFastQParser(string nodeName, string triSeq) { // Gets the expected sequence from the Xml string filePath = utilityObj.xmlUtil.GetTextValue(nodeName, Constants.FilePathNode); string expectedFirstQualitativeSequence = utilityObj.xmlUtil.GetTextValue(nodeName, Constants.ExpectedSequence1Node); string expectedSecondQualitativeSequence = utilityObj.xmlUtil.GetTextValue(nodeName, Constants.ExpectedSequence2Node); string expectedthirdQualitativeSequence = utilityObj.xmlUtil.GetTextValue(nodeName, Constants.ExpectedSequence3Node); string expectedSequenceId = utilityObj.xmlUtil.GetTextValue(nodeName, Constants.SequenceIdNode); int expectedSeqCount = int.Parse(utilityObj.xmlUtil.GetTextValue(nodeName, Constants.SeqsCount)); // Parse a multiple sequence FastQ file. var fastQParserObj = new FastQParser(); using (fastQParserObj.Open(filePath)) { IList<IQualitativeSequence> qualSequenceList = fastQParserObj.Parse().ToList(); // Validate first qualitative Sequence upon parsing FastQ file. Assert.AreEqual(expectedSeqCount, qualSequenceList.Count); Assert.AreEqual(expectedFirstQualitativeSequence, qualSequenceList[0].ConvertToString()); Assert.AreEqual(expectedSequenceId, qualSequenceList[0].ID); // Validate second qualitative Sequence upon parsing FastQ file. Assert.AreEqual(expectedSecondQualitativeSequence, qualSequenceList[1].ConvertToString()); Assert.AreEqual(expectedSequenceId, qualSequenceList[1].ID); // Validate third sequence in FastQ file if it is tri sequence FastQ file. if (0 == string.Compare(triSeq, "MultiSequenceFastQ", CultureInfo.CurrentCulture, CompareOptions.IgnoreCase)) { // Validate second qualitative Sequence upon parsing FastQ file. Assert.AreEqual(expectedthirdQualitativeSequence, qualSequenceList[2].ConvertToString()); Assert.AreEqual(expectedSequenceId, qualSequenceList[2].ID); } ApplicationLog.WriteLine(string.Format("FastQ Parser P1: The FASTQ sequence '{0}' validation after Parse() is found to be as expected.", qualSequenceList[0])); } }
/// <summary> /// General method to validate BasicSequence Parser. /// <param name="nodeName">xml node name.</param> /// </summary> private void ValidateBasicSequenceParser(string nodeName) { // Gets the expected sequence from the Xml string filepathOriginal = utilityObj.xmlUtil.GetTextValue(nodeName, Constants.FilePathNode); string expectedQualitativeSequence = utilityObj.xmlUtil.GetTextValue(nodeName, Constants.ExpectedSequenceNode); string expectedSequenceId = utilityObj.xmlUtil.GetTextValue(nodeName, Constants.SequenceIdNode); IAlphabet alphabet = Utility.GetAlphabet(utilityObj.xmlUtil.GetTextValue(nodeName, Constants.AlphabetNameNode)); Assert.IsTrue(File.Exists(filepathOriginal)); string tempPath = Path.GetTempFileName(); try { ISequenceParser fastQParserObj = SequenceParsers.FindParserByFileName("temp.fq"); // Read the original file IEnumerable<ISequence> seqsOriginal = fastQParserObj.Parse(filepathOriginal); Assert.IsNotNull(seqsOriginal); // Use the formatter to write the original sequences to a temp file var formatter = new FastQFormatter(); formatter.Format(seqsOriginal.ElementAt(0), tempPath); // Read the new file, then compare the sequences var fastQParserObjNew = new FastQParser(); IEnumerable<IQualitativeSequence> seqsNew = fastQParserObjNew.Parse(tempPath); Assert.IsNotNull(seqsNew); // Validate qualitative Sequence upon parsing FastQ file. Assert.AreEqual(expectedQualitativeSequence, new string(seqsOriginal.ElementAt(0).Select(a => (char) a).ToArray())); Assert.AreEqual( seqsOriginal.ElementAt(0).ID.ToString(null), expectedSequenceId); Assert.AreEqual( seqsOriginal.ElementAt(0).Alphabet.Name, alphabet.Name); ApplicationLog.WriteLine(string.Format("FastQ Parser P1: The FASTQ sequence '{0}' validation after Parse() is found to be as expected.", seqsOriginal.ElementAt(0))); } finally { File.Delete(tempPath); } }