/// <summary> /// Genaral method to Invalidate SAM Parser /// <param name="method">enum type to execute different overload</param> /// </summary> private static void ValidateSAMParser(ParseOrFormatTypes method) { try { switch (method) { case ParseOrFormatTypes.ParseOrFormatText: new SAMParser().Parse(null); break; case ParseOrFormatTypes.ParseOrFormatFileName: new SAMParser().Parse(null as string).First(); break; case ParseOrFormatTypes.ParseOneOrFormatText: new SAMParser().ParseOne(null); break; case ParseOrFormatTypes.ParseOneOrFormatFileName: new SAMParser().ParseOne(null as string); break; default: break; } Assert.Fail(); } catch (ArgumentNullException) { ApplicationLog.WriteLine( "SAM Parser P2 : Successfully validated the exception"); } }
/// <summary> /// Validate formatter all format method overloads with filePath\textwriter /// </summary> /// <param name="nodeName">xml node name</param> /// <param name="formatTypes">enum type to execute different overload</param> void ValidateSAMFormatter(string nodeName, ParseOrFormatTypes formatTypes) { // Gets the expected sequence from the Xml string filePath = utilityObj.xmlUtil.GetTextValue( nodeName, Constants.FilePathNode); string expectedSequenceFile = utilityObj.xmlUtil.GetTextValue( nodeName, Constants.ExpectedSequence); ISequenceAlignmentParser parser = new SAMParser(); try { IList <ISequenceAlignment> alignments = parser.Parse(filePath); SAMFormatter formatter = new SAMFormatter(); switch (formatTypes) { case ParseOrFormatTypes.ParseOrFormatText: using (TextWriter writer = new StreamWriter(Constants.SAMTempFileName)) { formatter.Format(alignments[0], writer); } break; case ParseOrFormatTypes.ParseOrFormatFileName: formatter.Format(alignments[0], Constants.SAMTempFileName); break; } alignments = parser.Parse(Constants.SAMTempFileName); // Get expected sequences using (FastAParser parserObj = new FastAParser(expectedSequenceFile)) { IEnumerable <ISequence> expectedSequences = parserObj.Parse(); IList <ISequence> expectedSequencesList = expectedSequences.ToList(); // Validate parsed output with expected output int count = 0; for (int index = 0; index < alignments.Count; index++) { for (int ialigned = 0; ialigned < alignments[index].AlignedSequences.Count; ialigned++) { for (int iseq = 0; iseq < alignments[index].AlignedSequences[ialigned].Sequences.Count; iseq++) { Assert.AreEqual(new string(expectedSequencesList[count].Select(a => (char)a).ToArray()), new string(alignments[index].AlignedSequences[ialigned].Sequences[iseq].Select(a => (char)a).ToArray())); count++; } } } } } finally { (parser as SAMParser).Dispose(); } }
/// <summary> /// Validate parser parse method overloads with filePath\textreader /// </summary> /// <param name="nodeName">xml node name</param> /// <param name="parseTypes">enum type to execute different overload</param> void ValidateSAMParser(string nodeName, ParseOrFormatTypes parseTypes) { // Gets the expected sequence from the Xml string filePath = Utility._xmlUtil.GetTextValue( nodeName, Constants.FilePathNode); string expectedSequenceFile = Utility._xmlUtil.GetTextValue( nodeName, Constants.ExpectedSequence); ISequenceAlignmentParser parser = new SAMParser(); IList <ISequenceAlignment> alignments = null; // Parse SAM File switch (parseTypes) { case ParseOrFormatTypes.ParseOrFormatText: using (TextReader reader = new StreamReader(filePath)) { alignments = parser.Parse(reader); } break; case ParseOrFormatTypes.ParseOrFormatTextWithFlag: using (TextReader reader = new StreamReader(filePath)) { alignments = parser.Parse(reader, true); } break; case ParseOrFormatTypes.ParseOrFormatFileName: alignments = parser.Parse(filePath); break; case ParseOrFormatTypes.ParseOrFormatFileNameWithFlag: alignments = parser.Parse(filePath, true); break; } // Get expected sequences FastaParser parserObj = new FastaParser(); IList <ISequence> expectedSequences = parserObj.Parse(expectedSequenceFile); // Validate parsed output with expected output int count = 0; for (int index = 0; index < alignments.Count; index++) { for (int ialigned = 0; ialigned < alignments[index].AlignedSequences.Count; ialigned++) { for (int iseq = 0; iseq < alignments[index].AlignedSequences[ialigned].Sequences.Count; iseq++) { Assert.AreEqual(expectedSequences[count].ToString(), alignments[index].AlignedSequences[ialigned].Sequences[iseq].ToString()); count++; } } } }
/// <summary> /// General method to validate SAM Formatter method. /// </summary> /// <param name="nodeName">xml node name</param> /// <param name="parseTypes">enum type to execute different overload</param> void ValidateSAMFormatterSeqAlign( string nodeName, ParseOrFormatTypes parseTypes) { // Gets the expected sequence from the Xml string filePath = _utilityObj._xmlUtil.GetTextValue( nodeName, Constants.FilePathNode); string expectedSequenceFile = _utilityObj._xmlUtil.GetTextValue( nodeName, Constants.ExpectedSequence); using (SAMParser parser = new SAMParser()) { SequenceAlignmentMap alignments = parser.Parse(filePath); SAMFormatter formatter = new SAMFormatter(); switch (parseTypes) { case ParseOrFormatTypes.ParseOrFormatText: using (TextWriter writer = new StreamWriter(Constants.SAMTempFileName)) { formatter.Format(alignments, writer); } break; case ParseOrFormatTypes.ParseOrFormatFileName: formatter.Format(alignments, Constants.SAMTempFileName); break; case ParseOrFormatTypes.ParseOrFormatFileNameWithFlag: formatter.Format(alignments, Constants.SAMTempFileName); break; } alignments = parser.Parse(Constants.SAMTempFileName); // Get expected sequences using (FastaParser parserObj = new FastaParser()) { IList <ISequence> expectedSequences = parserObj.Parse(expectedSequenceFile); // Validate parsed output with expected output for (int index = 0; index < alignments.QuerySequences.Count; index++) { for (int count = 0; count < alignments.QuerySequences[index].Sequences.Count; count++) { Assert.AreEqual(expectedSequences[index].ToString(), alignments.QuerySequences[index].Sequences[count].ToString()); } } } } }
/// <summary> /// Validate parser parse one method overloads with filePath\textreader /// </summary> /// <param name="nodeName">xml node name</param> /// <param name="parseTypes">enum type to execute different overload</param> void ValidateSAMParserWithParseOne(string nodeName, ParseOrFormatTypes parseTypes) { // Gets the expected sequence from the Xml string filePath = utilityObj.xmlUtil.GetTextValue( nodeName, Constants.FilePathNode); string expectedSequenceFile = utilityObj.xmlUtil.GetTextValue( nodeName, Constants.ExpectedSequence); ISequenceAlignmentParser parser = new SAMParser(); try { ISequenceAlignment alignment = null; // Parse SAM File switch (parseTypes) { case ParseOrFormatTypes.ParseOrFormatText: using (TextReader reader = new StreamReader(filePath)) { alignment = parser.ParseOne(reader); } break; case ParseOrFormatTypes.ParseOrFormatFileName: alignment = parser.ParseOne(filePath); break; } // Get expected sequences using (FastAParser parserObj = new FastAParser(expectedSequenceFile)) { IEnumerable <ISequence> expectedSequences = parserObj.Parse(); IList <ISequence> expectedSequencesList = expectedSequences.ToList(); // Validate parsed output with expected output int count = 0; for (int ialigned = 0; ialigned < alignment.AlignedSequences.Count; ialigned++) { for (int iseq = 0; iseq < alignment.AlignedSequences[ialigned].Sequences.Count; iseq++) { Assert.AreEqual(new string(expectedSequencesList[count].Select(a => (char)a).ToArray()), new string(alignment.AlignedSequences[ialigned].Sequences[iseq].Select(a => (char)a).ToArray())); count++; } } } } finally { (parser as SAMParser).Dispose(); } }
/// <summary> /// General method to validate SAM parser method. /// </summary> /// <param name="nodeName">xml node name</param> /// <param name="parseTypes">enum type to execute different overload</param> void ValidateSAMParserSeqAlign( string nodeName, ParseOrFormatTypes method) { // Gets the expected sequence from the Xml string filePath = utilityObj.xmlUtil.GetTextValue( nodeName, Constants.FilePathNode); string expectedSequenceFile = utilityObj.xmlUtil.GetTextValue( nodeName, Constants.ExpectedSequence); using (SAMParser parser = new SAMParser()) { SequenceAlignmentMap alignments = null; // Parse SAM File switch (method) { case ParseOrFormatTypes.ParseOrFormatText: using (TextReader reader = new StreamReader(filePath)) { alignments = parser.Parse(reader); } break; case ParseOrFormatTypes.ParseOrFormatFileName: alignments = parser.Parse(filePath); break; } // Get expected sequences using (FastAParser parserObj = new FastAParser(expectedSequenceFile)) { IEnumerable <ISequence> expectedSequences = parserObj.Parse(); IList <ISequence> expectedSequencesList = expectedSequences.ToList(); // Validate parsed output with expected output for (int index = 0; index < alignments.QuerySequences.Count; index++) { for (int count = 0; count < alignments.QuerySequences[index].Sequences.Count; count++) { Assert.AreEqual(new string(expectedSequencesList[index].Select(a => (char)a).ToArray()), new string(alignments.QuerySequences[index].Sequences[count].Select(a => (char)a).ToArray())); } } } } }
/// <summary> /// General method to validate SAM Formatter method. /// </summary> /// <param name="nodeName">xml node name</param> /// <param name="parseTypes">enum type to execute different overload</param> void ValidateSAMFormatterSeqAlign( string nodeName, ParseOrFormatTypes parseTypes) { // Gets the expected sequence from the Xml string filePath = utilityObj.xmlUtil.GetTextValue( nodeName, Constants.FilePathNode).TestDir(); string expectedSequenceFile = utilityObj.xmlUtil.GetTextValue( nodeName, Constants.ExpectedSequence).TestDir(); SAMParser parser = new SAMParser(); { SequenceAlignmentMap alignments = parser.ParseOne <SequenceAlignmentMap>(filePath); SAMFormatter formatter = new SAMFormatter(); switch (parseTypes) { case ParseOrFormatTypes.ParseOrFormatText: using (var writer = File.Create(Constants.SAMTempFileName)) { formatter.Format(writer, alignments); } break; case ParseOrFormatTypes.ParseOrFormatFileName: formatter.Format(alignments, Constants.SAMTempFileName); break; } alignments = parser.ParseOne <SequenceAlignmentMap>(Constants.SAMTempFileName); // Get expected sequences FastAParser parserObj = new FastAParser(); { IEnumerable <ISequence> expectedSequences = parserObj.Parse(expectedSequenceFile); IList <ISequence> expectedSequencesList = expectedSequences.ToList(); // Validate parsed output with expected output for (int index = 0; index < alignments.QuerySequences.Count; index++) { for (int count = 0; count < alignments.QuerySequences[index].Sequences.Count; count++) { Assert.AreEqual(new string(expectedSequencesList[index].Select(a => (char)a).ToArray()), new string(alignments.QuerySequences[index].Sequences[count].Select(a => (char)a).ToArray())); } } } } }
/// <summary> /// Genaral method to Invalidate SAM Parser /// <param name="method">enum type to execute different overload</param> /// </summary> void ValidateSAMParser(ParseOrFormatTypes method) { try { switch (method) { case ParseOrFormatTypes.ParseOrFormatText: new SAMParser().Parse(null as TextReader); break; case ParseOrFormatTypes.ParseOrFormatTextWithFlag: new SAMParser().Parse(null as TextReader, true); break; case ParseOrFormatTypes.ParseOrFormatFileName: new SAMParser().Parse(null as string); break; case ParseOrFormatTypes.ParseOrFormatFileNameWithFlag: new SAMParser().Parse(null as string, true); break; case ParseOrFormatTypes.ParseOneOrFormatText: new SAMParser().ParseOne(null as TextReader); break; case ParseOrFormatTypes.ParseOneOrFormatTextWithFlag: new SAMParser().ParseOne(null as TextReader, true); break; case ParseOrFormatTypes.ParseOneOrFormatFileName: new SAMParser().ParseOne(null as string); break; case ParseOrFormatTypes.ParseOneOrFormatFileNameWithFlag: new SAMParser().ParseOne(null as string, true); break; default: break; } Assert.Fail(); } catch (ArgumentNullException) { ApplicationLog.WriteLine( "SAM Parser P2 : Successfully validated the exception"); Console.WriteLine( "SAM Parser P2 : Successfully validated the exception"); } }
/// <summary> /// Genaral method to Invalidate SAM Parser /// <param name="method">enum type to execute different overload</param> /// </summary> private static void ValidateSAMParser(ParseOrFormatTypes method) { try { switch (method) { case ParseOrFormatTypes.ParseOrFormatText: using (SAMParser sParserObj = new SAMParser()) { sParserObj.Parse(null as TextReader); } break; case ParseOrFormatTypes.ParseOrFormatFileName: using (SAMParser sParserObj = new SAMParser()) { sParserObj.Parse(null as string); } break; case ParseOrFormatTypes.ParseOneOrFormatText: using (SAMParser sParserObj = new SAMParser()) { sParserObj.ParseOne(null as TextReader); } break; case ParseOrFormatTypes.ParseOneOrFormatFileName: using (SAMParser sParserObj = new SAMParser()) { sParserObj.ParseOne(null as string); } break; default: break; } Assert.Fail(); } catch (ArgumentNullException) { ApplicationLog.WriteLine( "SAM Parser P2 : Successfully validated the exception"); Console.WriteLine( "SAM Parser P2 : Successfully validated the exception"); } }
/// <summary> /// Validate parser parse method overloads with filePath\textreader /// </summary> /// <param name="nodeName">xml node name</param> /// <param name="parseTypes">enum type to execute different overload</param> void ValidateSAMParser(string nodeName, ParseOrFormatTypes parseTypes) { // Gets the expected sequence from the Xml string filePath = utilityObj.xmlUtil.GetTextValue( nodeName, Constants.FilePathNode).TestDir(); string expectedSequenceFile = utilityObj.xmlUtil.GetTextValue( nodeName, Constants.ExpectedSequence).TestDir(); ISequenceAlignmentParser parser = new SAMParser(); IList <ISequenceAlignment> alignments = null; // Parse SAM File switch (parseTypes) { case ParseOrFormatTypes.ParseOrFormatText: using (var reader = File.OpenRead(filePath)) { alignments = parser.Parse(reader).ToList(); } break; case ParseOrFormatTypes.ParseOrFormatFileName: alignments = parser.Parse(filePath).ToList(); break; } // Get expected sequences FastAParser parserObj = new FastAParser(); var expectedSequencesList = parserObj.Parse(expectedSequenceFile).ToList(); // Validate parsed output with expected output int count = 0; for (int index = 0; index < alignments.Count; index++) { for (int ialigned = 0; ialigned < alignments[index].AlignedSequences.Count; ialigned++) { for (int iseq = 0; iseq < alignments[index].AlignedSequences[ialigned].Sequences.Count; iseq++) { Assert.AreEqual(new string(expectedSequencesList[count].Select(a => (char)a).ToArray()), new string(alignments[index].AlignedSequences[ialigned].Sequences[iseq].Select(a => (char)a).ToArray())); count++; } } } }
/// <summary> /// Genaral method to Invalidate ISequence Alignment /// <param name="method">enum type to execute different overload</param> /// </summary> void ValidateISeqAlignParser(ParseOrFormatTypes method) { ISequenceAlignmentParser parser = new SAMParser(); try { switch (method) { case ParseOrFormatTypes.ParseOrFormatText: parser.Parse(null as TextReader); break; case ParseOrFormatTypes.ParseOrFormatTextWithFlag: parser.Parse(null as TextReader, true); break; case ParseOrFormatTypes.ParseOrFormatFileName: parser.Parse(null as string); break; case ParseOrFormatTypes.ParseOrFormatFileNameWithFlag: parser.Parse(null as string, true); break; case ParseOrFormatTypes.ParseOneOrFormatHeader: SAMParser.ParserSAMHeader(null as TextReader); break; case ParseOrFormatTypes.ParseOneOrFormatHeaderFn: SAMParser.ParserSAMHeader(null as string); break; default: break; } Assert.Fail(); } catch (ArgumentNullException) { ApplicationLog.WriteLine( "SAM Parser P2 : Successfully validated the exception"); Console.WriteLine( "SAM Parser P2 : Successfully validated the exception"); } }
/// <summary> /// Validate parser parse one method overloads with filePath\textreader /// </summary> /// <param name="nodeName">xml node name</param> /// <param name="parseTypes">enum type to execute different overload</param> void ValidateSAMParserWithParseOne(string nodeName, ParseOrFormatTypes parseTypes) { // Gets the expected sequence from the Xml string filePath = utilityObj.xmlUtil.GetTextValue( nodeName, Constants.FilePathNode).TestDir(); string expectedSequenceFile = utilityObj.xmlUtil.GetTextValue( nodeName, Constants.ExpectedSequence).TestDir(); ISequenceAlignmentParser parser = new SAMParser(); ISequenceAlignment alignment = null; // Parse SAM File switch (parseTypes) { case ParseOrFormatTypes.ParseOrFormatText: using (var reader = File.OpenRead(filePath)) { alignment = parser.ParseOne(reader); } break; case ParseOrFormatTypes.ParseOrFormatFileName: alignment = parser.ParseOne(filePath); break; } // Get expected sequences FastAParser parserObj = new FastAParser(); { IEnumerable <ISequence> expectedSequences = parserObj.Parse(expectedSequenceFile); IList <ISequence> expectedSequencesList = expectedSequences.ToList(); // Validate parsed output with expected output int count = 0; foreach (IAlignedSequence alignedSequence in alignment.AlignedSequences) { foreach (ISequence sequence in alignedSequence.Sequences) { Assert.AreEqual(expectedSequencesList[count].ConvertToString(), sequence.ConvertToString()); count++; } } } }
/// <summary> /// Genaral method to Invalidate SAM Formatter /// <param name="method">enum type to execute different overload</param> /// </summary> void ValidateSamFormatter(ParseOrFormatTypes method) { string filePath = utilityObj.xmlUtil.GetTextValue( Constants.SmallSAMFileNode, Constants.FilePathNode); ISequenceAlignmentParser parser = new SAMParser(); ISequenceAlignment alignment = null; try { switch (method) { case ParseOrFormatTypes.ParseOrFormatSeqText: new SAMFormatter().Format( null as ISequenceAlignment, null as TextWriter); break; case ParseOrFormatTypes.ParseOrFormatSeqTextWithFlag: alignment = parser.ParseOne(filePath); new SAMFormatter().Format( alignment, null as TextWriter); break; case ParseOrFormatTypes.ParseOrFormatIseq: new SAMFormatter().Format( null as ISequenceAlignment, null as string); break; case ParseOrFormatTypes.ParseOrFormatIseqFile: alignment = parser.ParseOne(filePath); new SAMFormatter().Format( alignment, null as string); break; case ParseOrFormatTypes.ParseOrFormatCollString: new SAMFormatter().Format( null as ICollection <ISequenceAlignment>, null as string); break; case ParseOrFormatTypes.ParseOrFormatCollection: new SAMFormatter().Format( null as ICollection <ISequenceAlignment>, null as TextWriter); break; case ParseOrFormatTypes.ParseOneOrFormatSeq: SequenceAlignmentMap align = new SequenceAlignmentMap(); new SAMFormatter().Format( align, null as string); break; case ParseOrFormatTypes.ParseOneOrFormatSeqFile: new SAMFormatter().Format( null as SequenceAlignmentMap, null as string); break; case ParseOrFormatTypes.ParseOrFormatIseqT: SequenceAlignmentMap alignments = new SequenceAlignmentMap(); new SAMFormatter().Format( alignments, null as string); break; case ParseOrFormatTypes.ParseOrFormatIseqText: new SAMFormatter().Format( null as SequenceAlignmentMap, null as string); break; case ParseOrFormatTypes.ParseOrFormatFormatString: new SAMFormatter().FormatString(null); break; default: break; } } catch (ArgumentNullException) { ApplicationLog.WriteLine( "SAM Formatter P2 : Successfully validated the exception"); Console.WriteLine( "SAM Formatter P2 : Successfully validated the exception"); } catch (NotSupportedException) { ApplicationLog.WriteLine( "SAM Formatter P2 : Successfully validated the exception"); Console.WriteLine( "SAM Formatter P2 : Successfully validated the exception"); } finally { (parser as SAMParser).Dispose(); } }
/// <summary> /// General method to validate SAM Formatter method. /// </summary> /// <param name="nodeName">xml node name</param> /// <param name="parseTypes">enum type to execute different overload</param> void ValidateSAMFormatterSeqAlign( string nodeName, ParseOrFormatTypes parseTypes) { // Gets the expected sequence from the Xml string filePath = utilityObj.xmlUtil.GetTextValue( nodeName, Constants.FilePathNode); string expectedSequenceFile = utilityObj.xmlUtil.GetTextValue( nodeName, Constants.ExpectedSequence); SAMParser parser = new SAMParser(); { SequenceAlignmentMap alignments = parser.ParseOne<SequenceAlignmentMap>(filePath); SAMFormatter formatter = new SAMFormatter(); switch (parseTypes) { case ParseOrFormatTypes.ParseOrFormatText: using (var writer = File.Create(Constants.SAMTempFileName)) { formatter.Format(writer, alignments); } break; case ParseOrFormatTypes.ParseOrFormatFileName: formatter.Format(alignments, Constants.SAMTempFileName); break; } alignments = parser.ParseOne<SequenceAlignmentMap>(Constants.SAMTempFileName); // Get expected sequences FastAParser parserObj = new FastAParser(); { IEnumerable<ISequence> expectedSequences = parserObj.Parse(expectedSequenceFile); IList<ISequence> expectedSequencesList = expectedSequences.ToList(); // Validate parsed output with expected output for (int index = 0; index < alignments.QuerySequences.Count; index++) { for (int count = 0; count < alignments.QuerySequences[index].Sequences.Count; count++) { Assert.AreEqual(new string(expectedSequencesList[index].Select(a => (char)a).ToArray()), new string(alignments.QuerySequences[index].Sequences[count].Select(a => (char)a).ToArray())); } } } } }
/// <summary> /// General method to validate SAM parser method. /// </summary> /// <param name="nodeName">xml node name</param> /// <param name="parseTypes">enum type to execute different overload</param> void ValidateSAMParserSeqAlign( string nodeName, ParseOrFormatTypes method) { // Gets the expected sequence from the Xml string filePath = utilityObj.xmlUtil.GetTextValue( nodeName, Constants.FilePathNode); string expectedSequenceFile = utilityObj.xmlUtil.GetTextValue( nodeName, Constants.ExpectedSequence); SAMParser parser = new SAMParser(); { SequenceAlignmentMap alignments = null; // Parse SAM File switch (method) { case ParseOrFormatTypes.ParseOrFormatText: using (var reader = File.OpenRead(filePath)) { alignments = parser.Parse(reader); } break; case ParseOrFormatTypes.ParseOrFormatFileName: alignments = (SequenceAlignmentMap) parser.ParseOne(filePath); break; } // Get expected sequences FastAParser parserObj = new FastAParser(); { IEnumerable<ISequence> expectedSequences = parserObj.Parse(expectedSequenceFile); IList<ISequence> expectedSequencesList = expectedSequences.ToList(); // Validate parsed output with expected output for (int index = 0; index < alignments.QuerySequences.Count; index++) { for (int count = 0; count < alignments.QuerySequences[index].Sequences.Count; count++) { Assert.AreEqual(new string(expectedSequencesList[index].Select(a => (char)a).ToArray()), new string(alignments.QuerySequences[index].Sequences[count].Select(a => (char)a).ToArray())); } } } } }
/// <summary> /// Validate formatter all format method overloads with filePath\textwriter /// </summary> /// <param name="nodeName">xml node name</param> /// <param name="formatTypes">enum type to execute different overload</param> void ValidateSAMFormatter(string nodeName, ParseOrFormatTypes formatTypes) { // Gets the expected sequence from the Xml string filePath = utilityObj.xmlUtil.GetTextValue( nodeName, Constants.FilePathNode); string expectedSequenceFile = utilityObj.xmlUtil.GetTextValue( nodeName, Constants.ExpectedSequence); ISequenceAlignmentParser parser = new SAMParser(); try { IList<ISequenceAlignment> alignments = parser.Parse(filePath).ToList(); SAMFormatter formatter = new SAMFormatter(); switch (formatTypes) { case ParseOrFormatTypes.ParseOrFormatText: using (var writer = File.Create(Constants.SAMTempFileName)) { formatter.Format(writer, alignments[0]); } break; case ParseOrFormatTypes.ParseOrFormatFileName: formatter.Format(alignments[0], Constants.SAMTempFileName); break; } alignments = parser.Parse(Constants.SAMTempFileName).ToList(); // Get expected sequences FastAParser parserObj = new FastAParser(); { IEnumerable<ISequence> expectedSequences = parserObj.Parse(expectedSequenceFile); IList<ISequence> expectedSequencesList = expectedSequences.ToList(); // Validate parsed output with expected output int count = 0; for (int index = 0; index < alignments.Count; index++) { for (int ialigned = 0; ialigned < alignments[index].AlignedSequences.Count; ialigned++) { for (int iseq = 0; iseq < alignments[index].AlignedSequences[ialigned].Sequences.Count; iseq++) { Assert.AreEqual(new string(expectedSequencesList[count].Select(a => (char)a).ToArray()), new string(alignments[index].AlignedSequences[ialigned].Sequences[iseq].Select(a => (char)a).ToArray())); count++; } } } } } finally { } }
/// <summary> /// Validate parser parse one method overloads with filePath\textreader /// </summary> /// <param name="nodeName">xml node name</param> /// <param name="parseTypes">enum type to execute different overload</param> void ValidateSAMParserWithParseOne(string nodeName, ParseOrFormatTypes parseTypes) { // Gets the expected sequence from the Xml string filePath = utilityObj.xmlUtil.GetTextValue( nodeName, Constants.FilePathNode); string expectedSequenceFile = utilityObj.xmlUtil.GetTextValue( nodeName, Constants.ExpectedSequence); ISequenceAlignmentParser parser = new SAMParser(); ISequenceAlignment alignment = null; // Parse SAM File switch (parseTypes) { case ParseOrFormatTypes.ParseOrFormatText: using (var reader = File.OpenRead(filePath)) { alignment = parser.ParseOne(reader); } break; case ParseOrFormatTypes.ParseOrFormatFileName: alignment = parser.ParseOne(filePath); break; } // Get expected sequences FastAParser parserObj = new FastAParser(); { IEnumerable<ISequence> expectedSequences = parserObj.Parse(expectedSequenceFile); IList<ISequence> expectedSequencesList = expectedSequences.ToList(); // Validate parsed output with expected output int count = 0; foreach (IAlignedSequence alignedSequence in alignment.AlignedSequences) { foreach (ISequence sequence in alignedSequence.Sequences) { Assert.AreEqual(expectedSequencesList[count].ConvertToString(), sequence.ConvertToString()); count++; } } } }
/// <summary> /// Genaral method to Invalidate ISequence Alignment /// <param name="method">enum type to execute different overload</param> /// </summary> private static void ValidateISeqAlignParser(ParseOrFormatTypes method) { ISequenceAlignmentParser parser = new SAMParser(); try { switch (method) { case ParseOrFormatTypes.ParseOrFormatText: parser.Parse(null).First(); break; case ParseOrFormatTypes.ParseOrFormatFileName: parser.Parse(null as string).First(); break; case ParseOrFormatTypes.ParseOneOrFormatHeader: SAMParser.ParseSAMHeader(null as TextReader); break; case ParseOrFormatTypes.ParseOneOrFormatHeaderFn: SAMParser.ParseSAMHeader(null as Stream); break; default: break; } Assert.Fail(); } catch (ArgumentNullException) { ApplicationLog.WriteLine( "SAM Parser P2 : Successfully validated the exception"); } }
/// <summary> /// Validate parser parse method overloads with filePath\textreader /// </summary> /// <param name="nodeName">xml node name</param> /// <param name="parseTypes">enum type to execute different overload</param> void ValidateSAMParser(string nodeName, ParseOrFormatTypes parseTypes) { // Gets the expected sequence from the Xml string filePath = utilityObj.xmlUtil.GetTextValue( nodeName, Constants.FilePathNode); string expectedSequenceFile = utilityObj.xmlUtil.GetTextValue( nodeName, Constants.ExpectedSequence); ISequenceAlignmentParser parser = new SAMParser(); IList<ISequenceAlignment> alignments = null; // Parse SAM File switch (parseTypes) { case ParseOrFormatTypes.ParseOrFormatText: using (var reader = File.OpenRead(filePath)) { alignments = parser.Parse(reader).ToList(); } break; case ParseOrFormatTypes.ParseOrFormatFileName: alignments = parser.Parse(filePath).ToList(); break; } // Get expected sequences FastAParser parserObj = new FastAParser(); var expectedSequencesList = parserObj.Parse(expectedSequenceFile).ToList(); // Validate parsed output with expected output int count = 0; for (int index = 0; index < alignments.Count; index++) { for (int ialigned = 0; ialigned < alignments[index].AlignedSequences.Count; ialigned++) { for (int iseq = 0; iseq < alignments[index].AlignedSequences[ialigned].Sequences.Count; iseq++) { Assert.AreEqual(new string(expectedSequencesList[count].Select(a => (char)a).ToArray()), new string(alignments[index].AlignedSequences[ialigned].Sequences[iseq].Select(a => (char)a).ToArray())); count++; } } } }
/// <summary> /// Genaral method to Invalidate SAM Formatter /// <param name="method">enum type to execute different overload</param> /// </summary> void ValidateSamFormatter(ParseOrFormatTypes method) { string filePath = utilityObj.xmlUtil.GetTextValue( Constants.SmallSAMFileNode, Constants.FilePathNode); ISequenceAlignmentParser parser = new SAMParser(); ISequenceAlignment alignment = null; try { switch (method) { case ParseOrFormatTypes.ParseOrFormatSeqText: new SAMFormatter().Format(null, null as ISequenceAlignment); break; case ParseOrFormatTypes.ParseOrFormatSeqTextWithFlag: alignment = parser.ParseOne(filePath); new SAMFormatter().Format(null, alignment); break; case ParseOrFormatTypes.ParseOrFormatIseq: new SAMFormatter().Format( null as ISequenceAlignment, null as string); break; case ParseOrFormatTypes.ParseOrFormatIseqFile: alignment = parser.ParseOne(filePath); new SAMFormatter().Format( alignment, null as string); break; case ParseOrFormatTypes.ParseOrFormatCollString: new SAMFormatter().Format( null as ICollection<ISequenceAlignment>, null as string); break; case ParseOrFormatTypes.ParseOrFormatCollection: new SAMFormatter().Format(null, null as ICollection<ISequenceAlignment>); break; case ParseOrFormatTypes.ParseOneOrFormatSeq: SequenceAlignmentMap align = new SequenceAlignmentMap(); new SAMFormatter().Format(align, null as string); break; case ParseOrFormatTypes.ParseOneOrFormatSeqFile: new SAMFormatter().Format(null as SequenceAlignmentMap, null as string); break; case ParseOrFormatTypes.ParseOrFormatIseqT: SequenceAlignmentMap alignments = new SequenceAlignmentMap(); new SAMFormatter().Format(alignments, null as string); break; case ParseOrFormatTypes.ParseOrFormatIseqText: new SAMFormatter().Format(null as SequenceAlignmentMap, null as string); break; case ParseOrFormatTypes.ParseOrFormatFormatString: break; default: break; } } catch (ArgumentNullException) { ApplicationLog.WriteLine( "SAM Formatter P2 : Successfully validated the exception"); } catch (NotSupportedException) { ApplicationLog.WriteLine( "SAM Formatter P2 : Successfully validated the exception"); } }
/// <summary> /// General method to validate SAM parser method. /// </summary> /// <param name="nodeName">xml node name</param> /// <param name="parseTypes">enum type to execute different overload</param> void ValidateSAMParserSeqAlign( string nodeName, ParseOrFormatTypes method) { // Gets the expected sequence from the Xml string filePath = _utilityObj._xmlUtil.GetTextValue( nodeName, Constants.FilePathNode); string expectedSequenceFile = _utilityObj._xmlUtil.GetTextValue( nodeName, Constants.ExpectedSequence); using (SAMParser parser = new SAMParser()) { SequenceAlignmentMap alignments = null; // Parse SAM File switch (method) { case ParseOrFormatTypes.ParseOrFormatText: using (TextReader reader = new StreamReader(filePath)) { alignments = parser.Parse(reader); } break; case ParseOrFormatTypes.ParseOrFormatTextWithFlag: using (TextReader reader = new StreamReader(filePath)) { alignments = parser.Parse(reader, true); } break; case ParseOrFormatTypes.ParseOrFormatFileName: alignments = parser.Parse(filePath); break; case ParseOrFormatTypes.ParseOrFormatFileNameWithFlag: alignments = parser.Parse(filePath, true); break; } // Get expected sequences using (FastaParser parserObj = new FastaParser()) { IList <ISequence> expectedSequences = parserObj.Parse(expectedSequenceFile); // Validate parsed output with expected output for (int index = 0; index < alignments.QuerySequences.Count; index++) { for (int count = 0; count < alignments.QuerySequences[index].Sequences.Count; count++) { Assert.AreEqual(expectedSequences[index].ToString(), alignments.QuerySequences[index].Sequences[count].ToString()); } } } } }