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 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() { 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> /// 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 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); // Parse a FastQ file. using (var fastQParserObj = new FastQParser(filePath)) { IEnumerable <QualitativeSequence> qualSequenceList = null; qualSequenceList = fastQParserObj.Parse(); // Validate qualitative Sequence upon parsing FastQ file. Assert.AreEqual(qualSequenceList.Count().ToString((IFormatProvider)null), expectedSeqCount); Assert.AreEqual(new String(qualSequenceList.ElementAt(0).Select(a => (char)a).ToArray()), expectedQualitativeSequence); Assert.AreEqual(qualSequenceList.ElementAt(0).ID.ToString(null), expectedSequenceId); ApplicationLog.WriteLine(string.Format(null, "FastQ Parser BVT: The FASTQ sequence '{0}' validation after Parse() is found to be as expected.", qualSequenceList.ElementAt(0).Select(a => (char)a).ToArray())); ApplicationLog.WriteLine(string.Format(null, "FastQ Parser BVT: The FASTQ sequence ID '{0}' validation after Parse() is found to be as expected.", qualSequenceList.ElementAt(0).ID.ToString(null))); } }
public void InvalidateFastQParseNoFileName() { using (var fqParserObj = new FastQParser(null)) { fqParserObj.Parse(); } }
void InValidateFastQParser(string nodeName) { // Gets the expected sequence from the Xml string filePath = utilityObj.xmlUtil.GetTextValue( nodeName, Constants.FilePathNode); string outputId = null; // Create a FastQ Parser object. FastQParser fastQParserObj = new FastQParser(filePath); fastQParserObj.AutoDetectFastQFormat = true; IEnumerable <QualitativeSequence> parse = null; try { parse = fastQParserObj.Parse(); outputId = parse.ElementAt(0).ID; Assert.Fail(); } catch (FileFormatException) { 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. /// <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)); } }
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); } }
public void FastQFormatter() { string filepathOriginal = @"TestUtils\FASTQ\SRR002012_5.fastq"; Assert.IsTrue(File.Exists(filepathOriginal)); FastQParser parser = new FastQParser(); FastQFormatter formatter = new FastQFormatter(); // Read the original file IList <IQualitativeSequence> seqsOriginal = null; parser = new FastQParser(); seqsOriginal = parser.Parse(filepathOriginal); Assert.IsNotNull(seqsOriginal); // Use the formatter to write the original sequences to a temp file string filepathTmp = Path.GetTempFileName(); using (TextWriter writer = new StreamWriter(filepathTmp)) { foreach (IQualitativeSequence s in seqsOriginal) { formatter.Format(s, writer); } } // Read the new file, then compare the sequences IList <IQualitativeSequence> seqsNew = null; parser = new FastQParser(); seqsNew = parser.Parse(filepathTmp); 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 = seqsOriginal[i].ToString(); string newSeq = seqsNew[i].ToString(); string orgscores = ASCIIEncoding.ASCII.GetString(seqsOriginal[i].Scores); string newscores = ASCIIEncoding.ASCII.GetString(seqsNew[i].Scores); 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); ((FastQParser)parser).Dispose(); }
/// <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; } } }
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); }
/// <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); }
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; } } }
/// <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 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 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 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); } }
/// <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)); }
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 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; } }
public void FastQParserForManyFiles() { string path = @"testdata\FASTQ"; Assert.IsTrue(Directory.Exists(path)); int count = 0; FastQParser parser = new FastQParser(); FastQFormatter formatter = new FastQFormatter(); DirectoryInfo di = new DirectoryInfo(path); foreach (FileInfo fi in di.GetFiles("*.fastq")) { using (StreamReader reader = File.OpenText(fi.FullName)) { foreach (IQualitativeSequence seq in parser.Parse(reader)) { count++; } } } Assert.IsTrue(count >= 3); }
public void FastQParserForManyFiles() { string path = @"TestUtils\FASTQ"; Assert.IsTrue(Directory.Exists(path)); int count = 0; DirectoryInfo di = new DirectoryInfo(path); foreach (FileInfo fi in di.GetFiles("*.fastq")) { using (FastQParser parser = new FastQParser(fi.FullName)) { foreach (QualitativeSequence seq in parser.Parse()) { Assert.IsNotNull(seq); count++; } } } Assert.IsTrue(count >= 3); }
public void AllEditableScenarios() { string filepathOriginal = @"TestData\FastQ\SRR002012_5.fastq"; FastQParser fastqParser = new FastQParser(); IList <IQualitativeSequence> qualitativeSequences; string[] expectedSequences = new string[] { "GGCGCACTTACACCCTACATCCATTG", "GTCTGCATTATCTACCAGCACTTCCC", "GCTGTCTTCCCGCTGTTTTATCCCCC", "GTAGTTTACCTGTTCATATGTTTCTG", "GGAAGGAAGAGGCTAGCCCAGCCTTT" }; fastqParser.EnforceDataVirtualization = true; fastqParser.AutoDetectFastQFormat = false; fastqParser.FastqType = FastQFormatType.Sanger; qualitativeSequences = fastqParser.Parse(filepathOriginal, true); int sequenceCount = qualitativeSequences.Count; for (int i = 0; i < sequenceCount; i++) { QualitativeSequence actualSequence = qualitativeSequences[i] as QualitativeSequence; actualSequence.IsReadOnly = false; ISequenceItem item = actualSequence[1]; actualSequence.Add(item); expectedSequences[i] += item.Symbol; Assert.AreEqual(expectedSequences[i], actualSequence.ToString()); actualSequence.Remove(item); int indexOfItem = expectedSequences[i].IndexOf(item.Symbol); expectedSequences[i] = expectedSequences[i].Remove(indexOfItem, 1); Assert.AreEqual(expectedSequences[i], actualSequence.ToString()); actualSequence.RemoveAt(0); expectedSequences[i] = expectedSequences[i].Remove(0, 1); Assert.AreEqual(expectedSequences[i], actualSequence.ToString()); actualSequence.RemoveRange(2, 5); expectedSequences[i] = expectedSequences[i].Remove(2, 5); Assert.AreEqual(expectedSequences[i], actualSequence.ToString()); actualSequence.Replace(0, 'C'); expectedSequences[i] = expectedSequences[i].Remove(0, 1); expectedSequences[i] = expectedSequences[i].Insert(0, "C"); Assert.AreEqual(expectedSequences[i], actualSequence.ToString()); actualSequence.ReplaceRange(5, "GG"); expectedSequences[i] = expectedSequences[i].Remove(5, 2); expectedSequences[i] = expectedSequences[i].Insert(5, "GG"); Assert.AreEqual(expectedSequences[i], actualSequence.ToString()); actualSequence.Insert(10, item); expectedSequences[i] = expectedSequences[i].Insert(10, item.Symbol.ToString()); Assert.AreEqual(expectedSequences[i], actualSequence.ToString()); actualSequence.InsertRange(2, "CC"); expectedSequences[i] = expectedSequences[i].Insert(2, "CC"); Assert.AreEqual(expectedSequences[i], actualSequence.ToString()); bool actualContainsValue = actualSequence.Contains(actualSequence[3]); bool expectedContainsValue = expectedSequences[i].Contains(actualSequence[3].Symbol.ToString()); Assert.AreEqual(actualContainsValue, expectedContainsValue); } }
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 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); } }
/// <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); } }
/// <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 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 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); } }
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); } }
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. using (var fastQParserObj = new FastQParser(filePath)) { IEnumerable <QualitativeSequence> qualSequence = null; qualSequence = fastQParserObj.Parse(); // New Sequence after formatting file. IEnumerable <QualitativeSequence> newQualSeq = null; string parsedValue = null; string parsedID = null; // Format Parsed Sequence to temp file with different extension. switch (fileExtension) { case FastQFileParameters.FastQ: using (var fastQFormatter = new FastQFormatter(tempFileName)) { fastQFormatter.Write(qualSequence.ElementAt(0)); } using (var fastQParserObjTemp = new FastQParser(tempFileName)) { newQualSeq = fastQParserObjTemp.Parse(); parsedValue = new string(newQualSeq.ElementAt(0).Select(a => (char)a).ToArray()); parsedID = newQualSeq.ElementAt(0).ID.ToString(null); } break; case FastQFileParameters.Fq: using (var fastQFormatterFq = new FastQFormatter(tempFileName)) { fastQFormatterFq.Write(qualSequence.ElementAt(0)); } using (var fastQParserObjTemp1 = new FastQParser(tempFileName)) { newQualSeq = fastQParserObjTemp1.Parse(); parsedValue = new string(newQualSeq.ElementAt(0).Select(a => (char)a).ToArray()); parsedID = newQualSeq.ElementAt(0).ID.ToString(null); } break; default: break; } // Validate qualitative parsing temporary file. Assert.AreEqual(parsedValue, expectedQualitativeSequence); Assert.AreEqual(parsedID, expectedSequenceId); ApplicationLog.WriteLine(string.Format(null, "FastQ Formatter BVT: The FASTQ sequence '{0}' validation after Write() and Parse() is found to be as expected.", parsedValue)); ApplicationLog.WriteLine(string.Format(null, "FastQ Formatter BVT: The FASTQ sequence '{0}' validation after Write() and Parse() is found to be as expected.", parsedID)); qualSequence = null; File.Delete(tempFileName); } }
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 tempFileName1 = System.IO.Path.GetTempFileName(); string tempFileName2 = System.IO.Path.GetTempFileName(); // Parse a FastQ file using parseOne method. using (FastQParser fastQParserObj = new FastQParser(filePath)) { fastQParserObj.AutoDetectFastQFormat = false; IEnumerable <ISequence> qualSequence = null; qualSequence = fastQParserObj.Parse(); // New Sequence after formatting file. IEnumerable <ISequence> newQualSeq = null; FastQFormatter fastQFormatter = new FastQFormatter(tempFileName1); FastQFormatter fastQFormatterFq = new FastQFormatter(tempFileName2); string parsedValue = null; string parsedID = null; // Format Parsed Sequence to temp file with different extension. switch (fileExtension) { case FastQFileParameters.FastQ: fastQFormatter.Write(qualSequence.ElementAt(0)); fastQFormatter.Close(); 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); fastQParserObjTemp.Dispose(); break; case FastQFileParameters.Fq: fastQFormatterFq.Write(qualSequence.ElementAt(0)); fastQFormatterFq.Close(); FastQParser fastQParserObjTemp1 = new FastQParser(tempFileName2); newQualSeq = fastQParserObjTemp1.Parse(); parsedValue = new string(newQualSeq.ElementAt(0).Select(a => (char)a).ToArray()); parsedID = newQualSeq.ElementAt(0).ID.ToString((IFormatProvider)null); break; default: break; } // 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 NUnit 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; fastQFormatter = null; fastQFormatterFq = null; GC.Collect(); GC.WaitForPendingFinalizers(); File.Delete(tempFileName1); File.Delete(tempFileName2); } }
public void FastQFormatterUsingInterface() { 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 ISequenceFormatter formatter = null; try { formatter = new FastQFormatter(); formatter.Open(filepathTmp); foreach (ISequence s in seqsOriginal) { formatter.Write(s); } formatter.Close(); } finally { if (formatter != null) { ((FastQFormatter)formatter).Dispose(); } } } // 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 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 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)); }