Example #1
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 #2
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 #3
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 #4
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 #5
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 #6
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 #7
0
        public void ValidateSAMFormatterProperties()
        {
            SAMFormatter parser = new SAMFormatter();

            Assert.AreEqual(Constants.SAMFormatterDescription, parser.Description.Replace("\r\n", "\n"));
            Assert.AreEqual(Constants.SAMFileType, parser.SupportedFileTypes);
            Assert.AreEqual(Constants.SAMName, parser.Name);

            ApplicationLog.WriteLine("Successfully validated all the properties of SAM Parser class.");
        }
Example #8
0
        /// <summary>
        /// Writes BAM header to the specified stream in BAM format.
        /// </summary>
        /// <param name="header">SAMAlignmentHeader object</param>
        /// <param name="writer">Stream to write.</param>
        public void WriteHeader(SAMAlignmentHeader header, Stream writer)
        {
            if (header == null)
            {
                throw new ArgumentNullException("header");
            }

            if (writer == null)
            {
                throw new ArgumentNullException("writer");
            }

            string samHeader;

            if (_refSequences == null)
            {
                _refSequences = SortSequenceRanges(header.GetReferenceSequenceRanges());
            }

            using (StringWriter strwriter = new StringWriter(CultureInfo.InvariantCulture))
            {
                SAMFormatter.WriteHeader(header, strwriter);
                samHeader = strwriter.ToString();
            }

            int samHeaderLen = samHeader.Length;

            byte[] bytes          = System.Text.ASCIIEncoding.ASCII.GetBytes(samHeader);
            byte[] bamMagicNumber = new byte[4] {
                66, 65, 77, 1
            };

            // write BAM magic number
            writer.Write(bamMagicNumber, 0, 4);

            // Length of the header text
            writer.Write(Helper.GetLittleEndianByteArray(samHeaderLen), 0, 4);

            //Plain header text in SAM
            writer.Write(bytes, 0, bytes.Length);
            // number of reference sequences
            writer.Write(Helper.GetLittleEndianByteArray(_refSequences.Count), 0, 4);

            for (int i = 0; i < _refSequences.Count; i++)
            {
                int len = _refSequences[i].ID.Length;

                byte[] array = System.Text.ASCIIEncoding.ASCII.GetBytes(_refSequences[i].ID);
                writer.Write(Helper.GetLittleEndianByteArray(len + 1), 0, 4);
                writer.Write(array, 0, len);
                writer.WriteByte((byte)'\0');
                writer.Write(Helper.GetLittleEndianByteArray((int)_refSequences[i].End), 0, 4);
            }
        }
Example #9
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 #10
0
 /// <summary>
 /// Writes aligned sequence to output stream.
 /// </summary>
 /// <param name="header">Alignment header.</param>
 /// <param name="alignedSequence">Aligned sequence to write.</param>
 private void WriteAlignedSequence(SAMAlignmentHeader header, SAMAlignedSequence alignedSequence)
 {
     if (UnCompressedBAM || BAMOutput)
     {
         // Incase of compressed bamoutput uncompressed file will be compressed before sending it to output stream.
         bamformatter.WriteAlignedSequence(header, alignedSequence, bamUncompressedOutStream);
     }
     else
     {
         SAMFormatter.WriteSAMAlignedSequence(alignedSequence, writer);
     }
 }
Example #11
0
        /// <summary>
        /// Writes BAM header to the specified stream in BAM format.
        /// </summary>
        /// <param name="header">SAMAlignmentHeader object</param>
        /// <param name="writer">Stream to write.</param>
        public void WriteHeader(SAMAlignmentHeader header, Stream writer)
        {
            if (header == null)
            {
                throw new ArgumentNullException("header");
            }

            if (writer == null)
            {
                throw new ArgumentNullException("writer");
            }

            string samHeader;

            if (this.refSequences == null)
            {
                this.refSequences = header.GetReferenceSequenceRanges();
            }

            using (StringWriter strwriter = new StringWriter(CultureInfo.InvariantCulture))
            {
                SAMFormatter.WriteHeader(strwriter, header);
                samHeader = strwriter.ToString();
            }

            int samHeaderLen = samHeader.Length;

            byte[] bytes          = Encoding.UTF8.GetBytes(samHeader);
            byte[] bamMagicNumber = { 66, 65, 77, 1 };

            // write BAM magic number
            writer.Write(bamMagicNumber, 0, 4);

            // Length of the header text
            writer.Write(Helper.GetLittleEndianByteArray(samHeaderLen), 0, 4);

            //Plain header text in SAM
            writer.Write(bytes, 0, bytes.Length);
            // number of reference sequences
            writer.Write(Helper.GetLittleEndianByteArray(this.refSequences.Count), 0, 4);

            foreach (SequenceRange range in this.refSequences)
            {
                int len = range.ID.Length;

                byte[] array = Encoding.UTF8.GetBytes(range.ID);
                writer.Write(Helper.GetLittleEndianByteArray(len + 1), 0, 4);
                writer.Write(array, 0, len);
                writer.WriteByte((byte)'\0');
                writer.Write(Helper.GetLittleEndianByteArray((int)range.End), 0, 4);
            }
        }
Example #12
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 #13
0
        public void ValidateSAMFormatterFormatString()
        {
            string filePath = Utility._xmlUtil.GetTextValue(
                Constants.SamFormatterFileNode,
                Constants.FilePathNode);
            ISequenceAlignmentParser   parser    = new SAMParser();
            IList <ISequenceAlignment> alignment = parser.Parse(filePath);

            SAMFormatter formatter = new SAMFormatter();
            string       writer    = formatter.FormatString(alignment[0]);

            Assert.AreEqual(writer, Constants.FormatterString);
        }
Example #14
0
        public void ValidateSAMFormatterFormatString()
        {
            string filePath = utilityObj.xmlUtil.GetTextValue(
                Constants.SamFormatterFileNode,
                Constants.FilePathNode).TestDir();
            ISequenceAlignmentParser   parser    = new SAMParser();
            IList <ISequenceAlignment> alignment = parser.Parse(filePath).ToList();

            SAMFormatter formatter = new SAMFormatter();
            string       writer    = formatter.FormatString(alignment[0]);

            Assert.AreEqual(writer, Constants.FormatterString.Replace("\r\n", Environment.NewLine));
        }
Example #15
0
        public void SAMProperties()
        {
            ISequenceAlignmentParser parser = new SAMParser();

            Assert.AreEqual(parser.Name, Properties.Resource.SAM_NAME);
            Assert.AreEqual(parser.Description, Properties.Resource.SAMPARSER_DESCRIPTION);
            Assert.AreEqual(parser.FileTypes, Properties.Resource.SAM_FILEEXTENSION);

            ISequenceAlignmentFormatter formatter = new SAMFormatter();

            Assert.AreEqual(formatter.Name, Properties.Resource.SAM_NAME);
            Assert.AreEqual(formatter.Description, Properties.Resource.SAMFORMATTER_DESCRIPTION);
            Assert.AreEqual(formatter.FileTypes, Properties.Resource.SAM_FILEEXTENSION);
        }
Example #16
0
        public void InvalidateSAMWriteTextWriter()
        {
            SAMAlignmentHeader header = new SAMAlignmentHeader();

            try
            {
                SAMFormatter.WriteHeader(null, header);
                Assert.Fail();
            }
            catch (ArgumentNullException)
            {
                ApplicationLog.WriteLine(
                    "SAM Formatter P2 : Successfully validated the exception");
            }
        }
Example #17
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 #18
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 #19
0
        /// <summary>
        /// Writes the header to output stream
        /// </summary>
        /// <param name="header"></param>
        private void WriteHeader(SAMAlignmentHeader header)
        {
            if (!Header && !HeaderOnly)
            {
                return;
            }

            if (UnCompressedBAM || BAMOutput)
            {
                // Incase of compressed bamoutput uncompressed file will be compressed before sending it to output stream.
                bamformatter.WriteHeader(header, bamUncompressedOutStream);
            }
            else
            {
                SAMFormatter.WriteHeader(header, writer);
            }
        }
Example #20
0
        /// <summary>
        /// Returns sequence alignment formatter which supports the specified file.
        /// </summary>
        /// <param name="fileName">File name for which the formatter is required.</param>
        /// <returns>If found returns the formatter as ISequenceAlignmentFormatter else returns null.</returns>
        public static ISequenceAlignmentFormatter FindFormatterByFile(string fileName)
        {
            ISequenceAlignmentFormatter formatter = null;

            if (!string.IsNullOrEmpty(fileName))
            {
                if (Helper.IsSAM(fileName))
                {
                    formatter = new SAMFormatter();
                }
                else
                {
                    formatter = null;
                }
            }

            return(formatter);
        }
Example #21
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 #22
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 #23
0
        public void ValidateSeqFormatterProperties()
        {
            // Gets the expected sequence from the Xml
            string samFormatterName = _utilityObj._xmlUtil.GetTextValue(Constants.SamFileParserNode,
                                                                        Constants.ParserNameNode);
            string bamFormatterName = _utilityObj._xmlUtil.GetTextValue(Constants.BamFileParserNode,
                                                                        Constants.ParserNameNode);

            // Get SequenceAlignmentFormatter class properties.
            SAMFormatter actualSamFormatter = SequenceAlignmentFormatters.SAM;
            IList <ISequenceAlignmentFormatter> allFormatters = SequenceAlignmentFormatters.All;

            BAMFormatter actualBamFormatterName = SequenceAlignmentFormatters.BAM;

            // Validate Sequence Formatter
            Assert.AreEqual(samFormatterName, actualSamFormatter.Name);
            Assert.IsNotNull(allFormatters);
            Assert.AreEqual(bamFormatterName, actualBamFormatterName.Name);
            Console.WriteLine(string.Format((IFormatProvider)null,
                                            "SequenceAlignmentFormatter : Type of the parser is validated successfully"));
            ApplicationLog.WriteLine("Type of the parser is validated successfully");
        }
Example #24
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 #25
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 #26
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());
                }
            }
        }