Esempio n. 1
0
        public void TestFastQWhenParsingOneOfMany()
        {
            // parse
            ISequenceParser parser   = new FastQParser();
            string          filepath = @"testdata\FASTQ\SRR002012_5.fastq";
            ISequence       seq      = parser.ParseOne(filepath);

            FastQParser fqParser = new FastQParser();

            fqParser.AutoDetectFastQFormat = false;
            fqParser.FastqType             = FastQFormatType.Sanger;
            IQualitativeSequence qualSeq = fqParser.ParseOne(filepath);
        }
Esempio n. 2
0
        /// <summary>
        /// General method to Invalidate FastQ Parser.
        /// <param name="nodeName">xml node name.</param>
        /// <param name="IsParseOne">True for FastQParseOne validations, else false</param>
        /// </summary>
        void InValidateFastQParser(string nodeName, bool IsParseOne)
        {
            // Gets the expected sequence from the Xml
            string filePath = _utilityObj._xmlUtil.GetTextValue(
                nodeName, Constants.FilePathNode);
            FastQFormatType expectedFormatType = Utility.GetFastQFormatType(
                _utilityObj._xmlUtil.GetTextValue(nodeName, Constants.FastQFormatType));

            // Create a FastQ Parser object.
            using (FastQParser fastQParserObj = new FastQParser())
            {
                fastQParserObj.AutoDetectFastQFormat = true;
                fastQParserObj.FastqType             = expectedFormatType;

                if (IsParseOne)
                {
                    try
                    {
                        fastQParserObj.ParseOne(filePath);
                        Assert.Fail();
                    }
                    catch (Exception)
                    {
                        ApplicationLog.WriteLine(
                            "FastQ Parser P2 : Successfully validated the exception");
                        Console.WriteLine(
                            "FastQ Parser P2 : Successfully validated the exception");
                    }
                }
                else
                {
                    try
                    {
                        fastQParserObj.Parse(filePath);
                        Assert.Fail();
                    }
                    catch (Exception)
                    {
                        ApplicationLog.WriteLine(
                            "FastQ Parser P2 : Successfully validated the exception");
                        Console.WriteLine(
                            "FastQ Parser P2 : Successfully validated the exception");
                    }
                }
            }
        }
Esempio n. 3
0
        public void TestFormatingString()
        {
            string str =
                @"@SRR002012.1 Oct4:5:1:871:340 length=26
GGCGCACTTACACCCTACATCCATTG
+SRR002012.1 Oct4:5:1:871:340 length=26
IIIIG1?II;IIIII1IIII1%.I7I
";

            StringReader sr = new StringReader(str);

            FastQParser          parser    = new FastQParser();
            IQualitativeSequence seq       = parser.ParseOne(sr);
            FastQFormatter       formatter = new FastQFormatter();
            string formatterStr            = formatter.FormatString(seq);

            Assert.AreEqual(str, formatterStr);
        }
Esempio n. 4
0
        /// <summary>
        ///     General method to validate FastQ Formatter.
        ///     <param name="nodeName">xml node name.</param>
        ///     <param name="fileExtension">Different temporary file extensions</param>
        /// </summary>
        private void ValidateFastQFormatter(string nodeName, FastQFileParameters fileExtension)
        {
            // Gets the expected sequence from the Xml
            string filePath = utilityObj.xmlUtil.GetTextValue(nodeName, Constants.FilePathNode);
            string expectedQualitativeSequence = utilityObj.xmlUtil.GetTextValue(nodeName, Constants.ExpectedSequenceNode);
            string expectedSequenceId          = utilityObj.xmlUtil.GetTextValue(nodeName, Constants.SequenceIdNode);
            string tempFileName = Path.GetTempFileName();

            // Parse a FastQ file using parseOne method.
            var fastQParserObj = new FastQParser();

            using (fastQParserObj.Open(filePath))
            {
                IQualitativeSequence oneSequence = fastQParserObj.ParseOne();

                // Format Parsed Sequence to temp file with different extension.
                var fastQFormatter = new FastQFormatter();
                using (fastQFormatter.Open(tempFileName))
                {
                    fastQFormatter.Format(oneSequence);
                }

                string parsedValue;
                string parsedId;

                var fastQParserObjTemp = new FastQParser();
                using (fastQParserObjTemp.Open(tempFileName))
                {
                    oneSequence = fastQParserObjTemp.Parse().First();
                    parsedValue = oneSequence.ConvertToString();
                    parsedId    = oneSequence.ID;
                }

                // Validate qualitative parsing temporary file.
                Assert.AreEqual(expectedQualitativeSequence, parsedValue);
                Assert.AreEqual(expectedSequenceId, parsedId);
                ApplicationLog.WriteLine(string.Format("FastQ Formatter BVT: The FASTQ sequence '{0}' validation after Write() and Parse() is found to be as expected.",
                                                       parsedValue));
                ApplicationLog.WriteLine(string.Format("FastQ Formatter BVT: The FASTQ sequence '{0}' validation after Write() and Parse() is found to be as expected.",
                                                       parsedId));

                File.Delete(tempFileName);
            }
        }
Esempio n. 5
0
 public void InvalidateFastQParseWithQualityScore()
 {
     try
     {
         ISequenceParser parser = new FastQParser();
         parser.ParseOne(
             Utility._xmlUtil.GetTextValue(
                 Constants.FastQInvalidQualScoreFileNode,
                 Constants.FilePathNode));
         Assert.Fail();
     }
     catch (FormatException)
     {
         ApplicationLog.WriteLine(
             "FastQ Parser P2 : Successfully validated the exception");
         Console.WriteLine(
             "FastQ Parser P2 : Successfully validated the exception");
     }
 }
Esempio n. 6
0
        public void TestFastQWhenParsingOneOfMany()
        {
            // parse
            ISequenceParser parser   = new FastQParser();
            string          filepath = @"TestUtils\FASTQ\SRR002012_5.fastq";
            ISequence       seq      = parser.ParseOne(filepath);

            Assert.IsNotNull(seq);

            FastQParser fqParser = new FastQParser();

            fqParser.AutoDetectFastQFormat = false;
            fqParser.FastqType             = FastQFormatType.Sanger;
            IQualitativeSequence qualSeq = fqParser.ParseOne(filepath);

            Assert.IsNotNull(qualSeq);

            ((FastQParser)parser).Dispose();
        }
Esempio n. 7
0
        public void TestFastQWhenParsingString()
        {
            string str =
                @"@SRR002012.1 Oct4:5:1:871:340 length=26
GGCGCACTTACACCCTACATCCATTG
+SRR002012.1 Oct4:5:1:871:340 length=26
IIIIG1?II;IIIII1IIII1%.I7I
";

            StringReader    sr     = new StringReader(str);
            ISequenceParser parser = new FastQParser();
            ISequence       seq    = parser.ParseOne(sr);

            sr = new StringReader(str);
            FastQParser fqParser = new FastQParser();

            fqParser.AutoDetectFastQFormat = false;
            fqParser.FastqType             = FastQFormatType.Sanger;
            IQualitativeSequence qualSeq = fqParser.ParseOne(sr);
        }
Esempio n. 8
0
        public void TestDefaultFastQFormatType()
        {
            QualitativeSequence qualSeq = new QualitativeSequence(Alphabets.DNA);

            Assert.AreEqual(qualSeq.Type, FastQFormatType.Illumina);

            string str =
                @"@Seq1
GGCGCACTTACACCCTACATCCATTG
+
ABCDEFGHIJKLMNOPQRSTUVWZYZ
";

            StringReader sr = new StringReader(str);

            FastQParser          parser = new FastQParser();
            IQualitativeSequence seq    = parser.ParseOne(sr);

            Assert.AreEqual(seq.Type, FastQFormatType.Illumina);
        }
Esempio n. 9
0
        public void InvalidateFastQParseOneWithFastQFormat()
        {
            ISequenceParser parser = new FastQParser();

            try
            {
                parser.ParseOne(
                    _utilityObj._xmlUtil.GetTextValue(
                        Constants.FastQInvalidFormatFileNode,
                        Constants.FilePathNode));
                Assert.Fail();
            }
            catch (FormatException)
            {
                ApplicationLog.WriteLine(
                    "FastQ Parser P2 : Successfully validated the exception");
                Console.WriteLine(
                    "FastQ Parser P2 : Successfully validated the exception");
            }
            finally
            {
                (parser as FastQParser).Dispose();
            }
        }
Esempio n. 10
0
        /// <summary>
        /// General method to Invalidate FastQ Parser.
        /// <param name="nodeName">xml node name.</param>
        /// <param name="param">FastQ Formatter different parameters</param>
        /// </summary>
        void InValidateFastQFormatter(FastQFormatParameters param)
        {
            // Gets the expected sequence from the Xml
            string filepath = _utilityObj._xmlUtil.GetTextValue(
                Constants.MultiSeqSangerRnaProNode, Constants.FilePathNode);
            FastQFormatType expectedFormatType = Utility.GetFastQFormatType(
                _utilityObj._xmlUtil.GetTextValue(Constants.MultiSeqSangerRnaProNode,
                                                  Constants.FastQFormatType));

            // Parse a FastQ file.
            using (FastQParser fastQParser = new FastQParser())
            {
                fastQParser.AutoDetectFastQFormat = true;
                fastQParser.FastqType             = expectedFormatType;

                IQualitativeSequence sequence = null;
                sequence = fastQParser.ParseOne(filepath);
                FastQFormatter fastQFormatter = new FastQFormatter();
                TextWriter     txtWriter      = null;

                switch (param)
                {
                case FastQFormatParameters.TextWriter:
                    try
                    {
                        fastQFormatter.Format(sequence, null as TextWriter);
                        Assert.Fail();
                    }

                    catch (Exception)
                    {
                        ApplicationLog.WriteLine(
                            "FastQ Parser P2 : Successfully validated the exception");
                        Console.WriteLine(
                            "FastQ Parser P2 : Successfully validated the exception");
                    }
                    break;

                case FastQFormatParameters.Sequence:
                    try
                    {
                        fastQFormatter.Format(null as ISequence, txtWriter);
                        Assert.Fail();
                    }

                    catch (Exception)
                    {
                        ApplicationLog.WriteLine(
                            "FastQ Parser P2 : Successfully validated the exception");
                        Console.WriteLine(
                            "FastQ Parser P2 : Successfully validated the exception");
                    }
                    break;

                case FastQFormatParameters.QualitativeSequence:
                    try
                    {
                        fastQFormatter.Format(null as IQualitativeSequence, txtWriter);
                        Assert.Fail();
                    }

                    catch (Exception)
                    {
                        ApplicationLog.WriteLine(
                            "FastQ Parser P2 : Successfully validated the exception");
                        Console.WriteLine(
                            "FastQ Parser P2 : Successfully validated the exception");
                    }
                    break;

                default:
                    try
                    {
                        fastQFormatter.Format(sequence as QualitativeSequence, null as TextWriter);
                        Assert.Fail();
                    }
                    catch (Exception)
                    {
                        ApplicationLog.WriteLine(
                            "FastQ Parser P2 : Successfully validated the exception");
                        Console.WriteLine(
                            "FastQ Parser P2 : Successfully validated the exception");
                    }
                    break;
                }
            }
        }
Esempio n. 11
0
        private void ValidateFastQFormatter(string nodeName, bool writeMultipleSequences)
        {
            // Gets the expected sequence from the Xml
            string filePath = utilityObj.xmlUtil.GetTextValue(nodeName, Constants.FilePathNode);
            string expectedQualitativeSequence = utilityObj.xmlUtil.GetTextValue(nodeName, Constants.ExpectedSequenceNode);
            string expectedSequenceId = utilityObj.xmlUtil.GetTextValue(nodeName, Constants.SequenceIdNode);
            string tempFileName = Path.GetTempFileName();

            // Parse a FastQ file.
            var fastQParserObj = new FastQParser();
            using (fastQParserObj.Open(filePath))
            {
                IEnumerable<IQualitativeSequence> qualSequenceList = fastQParserObj.Parse();

                var fastQFormatter = new FastQFormatter();
                using (fastQFormatter.Open(tempFileName))
                {
                    if (writeMultipleSequences)
                    {
                        foreach (IQualitativeSequence newQualSeq in qualSequenceList)
                        {
                            fastQFormatter.Format(newQualSeq);
                        }
                    }                    
                    else
                    {
                        fastQFormatter.Format(qualSequenceList.First());
                    }
                } // temp file is closed.

                // Read the new file and validate the first Sequence.
                FastQParser fastQParserObjNew = new FastQParser();
                IQualitativeSequence firstSequence = fastQParserObjNew.ParseOne(tempFileName);

                // Validate qualitative Sequence upon parsing FastQ file.
                Assert.AreEqual(expectedQualitativeSequence, firstSequence.ConvertToString());
                Assert.AreEqual(expectedSequenceId, firstSequence.ID);

                ApplicationLog.WriteLine(string.Format("FastQ Parser P1: The FASTQ sequence '{0}' validation after Parse() is found to be as expected.", firstSequence));

                File.Delete(tempFileName);
            }
        }
Esempio n. 12
0
        /// <summary>
        ///     General method to validate FastQ Formatter on a Stream.
        ///     <param name="nodeName">xml node name.</param>
        /// </summary>
        private void ValidateFastQFormatterOnAStream(string nodeName)
        {
            // Gets the expected sequence from the Xml
            string filePath = utilityObj.xmlUtil.GetTextValue(nodeName, Constants.FilePathNode);
            string expectedQualitativeSequence = utilityObj.xmlUtil.GetTextValue(nodeName, Constants.ExpectedSequenceNode);
            string expectedSequenceId = utilityObj.xmlUtil.GetTextValue(nodeName, Constants.SequenceIdNode);
            string tempFileName1 = Path.GetTempFileName();

            // Parse a FastQ file using parseOne method.
            var fastQParserObj = new FastQParser();
            using (fastQParserObj.Open(filePath))
            {
                var oneSequence = fastQParserObj.ParseOne();

                // New Sequence after formatting file.                
                var fastQFormatter = new FastQFormatter();
                using (fastQFormatter.Open(tempFileName1))
                    fastQFormatter.Format(oneSequence);

                var fastQParserObjTemp = new FastQParser();
                string parsedValue, parsedId;
                using (fastQParserObjTemp.Open(tempFileName1))
                {
                    oneSequence = fastQParserObjTemp.Parse().First();
                    parsedValue = oneSequence.ConvertToString();
                    parsedId = oneSequence.ID;
                }

                // Validate qualitative parsing temporary file.                
                Assert.AreEqual(expectedQualitativeSequence, parsedValue);
                Assert.AreEqual(expectedSequenceId, parsedId);
                ApplicationLog.WriteLine(string.Format("FastQ Formatter BVT: The FASTQ sequence '{0}' validation after Write() and Parse() is found to be as expected.", parsedValue));
                ApplicationLog.WriteLine(string.Format("FastQ Formatter BVT: The FASTQ sequence '{0}' validation after Write() and Parse() is found to be as expected.", parsedId));

                File.Delete(tempFileName1);
            }
        }