Example #1
0
        /// <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();
            }
        }
Example #2
0
        /// <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());
                        }
                    }
                }
            }
        }
Example #3
0
        /// <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 = Utility._xmlUtil.GetTextValue(
                nodeName, Constants.FilePathNode);
            string expectedSequenceFile = Utility._xmlUtil.GetTextValue(
                nodeName, Constants.ExpectedSequence);
            ISequenceAlignmentParser   parser     = new SAMParser();
            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;

            case ParseOrFormatTypes.ParseOrFormatFileNameWithFlag:
                formatter.Format(alignments, Constants.SAMTempFileName);
                break;
            }
            alignments = parser.Parse(Constants.SAMTempFileName);

            // 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++;
                    }
                }
            }
        }
Example #4
0
        /// <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()));
                        }
                    }
                }
            }
        }
Example #5
0
        public void ValidateSAMFormatterWithTextWriterAndAlignments()
        {
            // Gets the expected sequence from the Xml
            string filePath = utilityObj.xmlUtil.GetTextValue(
                Constants.SmallSAMFileNode, Constants.FilePathNode);
            ISequenceAlignmentParser parser = new SAMParser();

            try
            {
                IList <ISequenceAlignment> alignments = parser.Parse(filePath);
                SAMFormatter formatter = new SAMFormatter();
                try
                {
                    using (TextWriter writer =
                               new StreamWriter(Constants.SAMTempFileName))
                    {
                        formatter.Format(alignments, writer);
                    }
                    Assert.Fail();
                }
                catch (NotSupportedException)
                {
                    ApplicationLog.WriteLine(string.Format((IFormatProvider)null,
                                                           "SAM Parser BVT : Validated the exception successfully"));
                    Console.WriteLine(string.Format((IFormatProvider)null,
                                                    "SAM Parser BVT : Validated the exception successfully"));
                }
            }
            finally
            {
                (parser as SAMParser).Dispose();
            }
        }
Example #6
0
 /// <summary>
 /// Writes the SAM object to file in SAM/BAM format.
 /// </summary>
 private void PerformFormat()
 {
     if (_isSAM)
     {
         BAMFormatter format = new BAMFormatter();
         try
         {
             format.Format(_sequenceAlignmentMap, OutputFilename);
         }
         catch (Exception ex)
         {
             throw new InvalidOperationException(Resources.WriteBAM + Environment.NewLine + ex.Message);
         }
     }
     else
     {
         SAMFormatter format = new SAMFormatter();
         try
         {
             format.Format(_sequenceAlignmentMap, OutputFilename);
         }
         catch (Exception ex)
         {
             throw new InvalidOperationException(Resources.WriteSAM + Environment.NewLine + ex.Message);
         }
     }
 }
Example #7
0
 /// <summary>
 /// Writes the SAM object to file in SAM/BAM format.
 /// </summary>
 private void PerformFormat()
 {
     if (_isSAM)
     {
         BAMFormatter format = new BAMFormatter();
         try
         {
             format.Format(_sequenceAlignmentMap, _outputFile);
         }
         catch
         {
             throw new InvalidOperationException(Resources.WriteBAM);
         }
     }
     else
     {
         SAMFormatter format = new SAMFormatter();
         try
         {
             format.Format(_sequenceAlignmentMap, _outputFile);
         }
         catch
         {
             throw new InvalidOperationException(Resources.WriteSAM);
         }
     }
 }
Example #8
0
        public void TestFormatter()
        {
            string filePath                       = @"TestUtils\SAM\SeqAlignment1.sam".TestDir();
            string outputfilePath                 = "samtest.sam";
            ISequenceAlignmentParser   parser     = new SAMParser();
            IList <ISequenceAlignment> alignments = parser.Parse(filePath).ToList();

            Assert.IsTrue(alignments != null);
            Assert.AreEqual(alignments.Count, 1);
            Assert.AreEqual(alignments[0].AlignedSequences.Count, 2);

            try
            {
                SAMFormatter formatter = new SAMFormatter();
                formatter.Format(alignments[0], outputfilePath);

                alignments = parser.Parse(outputfilePath).ToList();

                Assert.IsTrue(alignments != null);
                Assert.AreEqual(alignments.Count, 1);
                Assert.AreEqual(alignments[0].AlignedSequences.Count, 2);
            }
            finally
            {
                File.Delete(outputfilePath);
            }
        }
Example #9
0
        public void ValidateBAMToSAMConversionWithDVEnabled()
        {
            // Get values from xml config file.
            string expectedSamFilePath = _utilityObj._xmlUtil.GetTextValue(Constants.BAMToSAMConversionNode,
                                                                           Constants.FilePathNode1);
            string bamFilePath = _utilityObj._xmlUtil.GetTextValue(Constants.BAMToSAMConversionNode,
                                                                   Constants.FilePathNode);

            using (BAMParser bamParserObj = new BAMParser())
            {
                using (SAMParser samParserObj = new SAMParser())
                {
                    SAMFormatter         samFormatterObj = new SAMFormatter();
                    SequenceAlignmentMap samSeqAlignment = null;
                    SequenceAlignmentMap bamSeqAlignment = null;

                    // Parse expected SAM file.
                    SequenceAlignmentMap expextedSamAlignmentObj = samParserObj.Parse(
                        expectedSamFilePath);

                    // Parse a BAM file.
                    bamParserObj.EnforceDataVirtualization = true;
                    bamSeqAlignment = bamParserObj.Parse(bamFilePath);

                    // Format BAM sequenceAlignment object to SAM file.
                    samFormatterObj.Format(bamSeqAlignment, Constants.SAMTempFileName);

                    // Parse a formatted SAM file.
                    samSeqAlignment = samParserObj.Parse(Constants.SAMTempFileName);

                    // Validate converted SAM file with expected SAM file.
                    Assert.IsTrue(CompareSequencedAlignmentHeader(samSeqAlignment, expextedSamAlignmentObj));

                    // Validate SAM file aligned sequences.
                    Assert.IsTrue(CompareAlignedSequences(samSeqAlignment, expextedSamAlignmentObj));
                }
            }

            // Log message to NUnit GUI.
            ApplicationLog.WriteLine(string.Format((IFormatProvider)null,
                                                   "BAM Parser BVT : Validated the BAM->SAM conversion successfully"));
            Console.WriteLine(string.Format((IFormatProvider)null,
                                            "BAM Parser BVT : Validated the BAM->SAM conversion successfully"));

            // Delete temporary file.
            File.Delete(Constants.SAMTempFileName);
            ApplicationLog.WriteLine("Deleted the temp file created.");
        }
Example #10
0
        /// <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 ValidateSAMFormatter(string nodeName)
        {
            // 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();

                using (TextWriter writer =
                           new StreamWriter(Constants.SAMTempFileName))
                {
                    formatter.Format(alignments, writer);
                }

                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
                    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()));
                        }
                    }
                }
            }
        }
Example #11
0
        public void ValidateSAMFormatterWithFileNameAndAlignments()
        {
            // Gets the expected sequence from the Xml
            string filePath = utilityObj.xmlUtil.GetTextValue(
                Constants.SmallSAMFileNode.Replace("\r\n", System.Environment.NewLine), Constants.FilePathNode);
            ISequenceAlignmentParser         parser     = new SAMParser();
            IEnumerable <ISequenceAlignment> alignments = parser.Parse(filePath);
            SAMFormatter formatter = new SAMFormatter();

            try
            {
                formatter.Format(alignments, Constants.SAMTempFileName);
                Assert.Fail();
            }
            catch (NotSupportedException)
            {
                ApplicationLog.WriteLine("SAM Parser BVT : Validated the exception successfully");
            }
        }
Example #12
0
        public void TestFormatter()
        {
            string filePath                       = @"TestData\SAM\SeqAlignment1.sam";
            string outputfilePath                 = "samtest.sam";
            ISequenceAlignmentParser   parser     = new SAMParser();
            SAMFormatter               formatter  = new SAMFormatter();
            IList <ISequenceAlignment> alignments = parser.Parse(filePath);

            Assert.IsTrue(alignments != null);
            Assert.AreEqual(alignments.Count, 1);
            Assert.AreEqual(alignments[0].AlignedSequences.Count, 2);

            formatter.Format(alignments[0], outputfilePath);

            alignments = parser.Parse(outputfilePath);

            Assert.IsTrue(alignments != null);
            Assert.AreEqual(alignments.Count, 1);
            Assert.AreEqual(alignments[0].AlignedSequences.Count, 2);
        }
Example #13
0
        public void ValidateSAMFormatterWithFileNameAndAlignments()
        {
            // Gets the expected sequence from the Xml
            string filePath = Utility._xmlUtil.GetTextValue(
                Constants.SmallSAMFileNode, Constants.FilePathNode);
            ISequenceAlignmentParser   parser     = new SAMParser();
            IList <ISequenceAlignment> alignments = parser.Parse(filePath);
            SAMFormatter formatter = new SAMFormatter();

            try
            {
                formatter.Format(alignments, Constants.SAMTempFileName);
                Assert.Fail();
            }
            catch (NotSupportedException)
            {
                ApplicationLog.WriteLine(string.Format(null,
                                                       "SAM Parser BVT : Validated the exception successfully"));
                Console.WriteLine(string.Format(null,
                                                "SAM Parser BVT : Validated the exception successfully"));
            }
        }
Example #14
0
        public void ValidateSAMFormatterWithTextWriterAndAlignments()
        {
            // Gets the expected sequence from the Xml
            string filePath = utilityObj.xmlUtil.GetTextValue(
                Constants.SmallSAMFileNode, Constants.FilePathNode);
            ISequenceAlignmentParser         parser     = new SAMParser();
            IEnumerable <ISequenceAlignment> alignments = parser.Parse(filePath);
            SAMFormatter formatter = new SAMFormatter();

            try
            {
                using (var writer = File.Create(Constants.SAMTempFileName))
                {
                    formatter.Format(writer, alignments);
                }
                Assert.Fail();
            }
            catch (NotSupportedException)
            {
                ApplicationLog.WriteLine("SAM Parser BVT : Validated the exception successfully");
            }
        }
Example #15
0
        /// <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 ValidateSAMFormatter(string nodeName)
        {
            // Gets the expected sequence from the Xml
            string filePath = Utility._xmlUtil.GetTextValue(
                nodeName, Constants.FilePathNode);
            string expectedSequenceFile = Utility._xmlUtil.GetTextValue(
                nodeName, Constants.ExpectedSequence);
            SAMParser            parser     = new SAMParser();
            SequenceAlignmentMap alignments = parser.Parse(filePath);
            SAMFormatter         formatter  = new SAMFormatter();

            using (TextWriter writer =
                       new StreamWriter(Constants.SAMTempFileName))
            {
                formatter.Format(alignments, writer);
            }

            alignments = parser.Parse(Constants.SAMTempFileName);

            // Get expected sequences
            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());
                }
            }
        }