예제 #1
0
        public void TestFastQWhenParsingOneOfMany()
        {
            string filepath = @"TestUtils\FASTQ\SRR002012_5.fastq";
            // parse
            ISequenceParser parser = new FastQParser(filepath);

            try
            {
                ISequence seq = parser.Parse().First();
                Assert.IsNotNull(seq);
            }
            finally
            {
                parser.Dispose();
            }

            using (FastQParser fqParser = new FastQParser(filepath))
            {
                fqParser.AutoDetectFastQFormat = false;
                fqParser.FormatType            = FastQFormatType.Sanger;
                fqParser.Alphabet = Alphabets.DNA;
                QualitativeSequence qualSeq = fqParser.Parse().First();
                Assert.IsNotNull(qualSeq);
            }
        }
예제 #2
0
        void ValidateFastQFormatter(string nodeName,
                                    FastQFileParameters fileExtension)
        {
            // Gets the expected sequence from the Xml
            string filePath = utilityObj.xmlUtil.GetTextValue(
                nodeName, Constants.FilePathNode);
            string expectedQualitativeSequence = utilityObj.xmlUtil.GetTextValue(
                nodeName, Constants.ExpectedSequenceNode);
            string expectedSequenceId = utilityObj.xmlUtil.GetTextValue(
                nodeName, Constants.SequenceIdNode);
            string tempFileName1 = System.IO.Path.GetTempFileName();
            string tempFileName2 = System.IO.Path.GetTempFileName();

            // Parse a FastQ file using parseOne method.
            using (FastQParser fastQParserObj = new FastQParser(filePath))
            {
                fastQParserObj.AutoDetectFastQFormat = false;
                IEnumerable <ISequence> qualSequence = null;
                qualSequence = fastQParserObj.Parse();

                // New Sequence after formatting file.
                IEnumerable <ISequence> newQualSeq       = null;
                FastQFormatter          fastQFormatter   = new FastQFormatter(tempFileName1);
                FastQFormatter          fastQFormatterFq = new FastQFormatter(tempFileName2);
                string parsedValue = null;
                string parsedID    = null;

                // Format Parsed Sequence to temp file with different extension.
                switch (fileExtension)
                {
                case FastQFileParameters.FastQ:
                    fastQFormatter.Write(qualSequence.ElementAt(0));
                    fastQFormatter.Close();
                    FastQParser fastQParserObjTemp = new FastQParser(tempFileName1);
                    newQualSeq  = fastQParserObjTemp.Parse();
                    parsedValue = new string(newQualSeq.ElementAt(0).Select(a => (char)a).ToArray());
                    parsedID    = newQualSeq.ElementAt(0).ID.ToString((IFormatProvider)null);
                    fastQParserObjTemp.Dispose();
                    break;

                case FastQFileParameters.Fq:
                    fastQFormatterFq.Write(qualSequence.ElementAt(0));
                    fastQFormatterFq.Close();
                    FastQParser fastQParserObjTemp1 = new FastQParser(tempFileName2);
                    newQualSeq  = fastQParserObjTemp1.Parse();
                    parsedValue = new string(newQualSeq.ElementAt(0).Select(a => (char)a).ToArray());
                    parsedID    = newQualSeq.ElementAt(0).ID.ToString((IFormatProvider)null);
                    break;

                default:
                    break;
                }

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

                // Logs to the NUnit GUI (Console.Out) window
                Console.WriteLine(string.Format((IFormatProvider)null,
                                                "FastQ Formatter BVT: The FASTQ sequence '{0}' validation after Write() and Parse() is found to be as expected.",
                                                parsedValue));
                Console.WriteLine(string.Format((IFormatProvider)null,
                                                "FastQ Formatter BVT: The FASTQ sequence '{0}' validation after Write() and Parse() is found to be as expected.",
                                                parsedID));

                qualSequence     = null;
                fastQFormatter   = null;
                fastQFormatterFq = null;
                GC.Collect();
                GC.WaitForPendingFinalizers();
                File.Delete(tempFileName1);
                File.Delete(tempFileName2);
            }
        }