Exemplo n.º 1
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);
            }
        }
Exemplo n.º 2
0
        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.
            using (var fastQParserObj = new FastQParser(filePath))
            {
                IEnumerable <QualitativeSequence> qualSequence = null;
                qualSequence = fastQParserObj.Parse();

                // New Sequence after formatting file.
                IEnumerable <QualitativeSequence> newQualSeq = null;
                string parsedValue = null;
                string parsedID    = null;

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

                    break;

                case FastQFileParameters.Fq:
                    using (var fastQFormatterFq = new FastQFormatter(tempFileName))
                    {
                        fastQFormatterFq.Write(qualSequence.ElementAt(0));
                    }
                    using (var fastQParserObjTemp1 = new FastQParser(tempFileName))
                    {
                        newQualSeq  = fastQParserObjTemp1.Parse();
                        parsedValue = new string(newQualSeq.ElementAt(0).Select(a => (char)a).ToArray());
                        parsedID    = newQualSeq.ElementAt(0).ID.ToString(null);
                    }
                    break;

                default:
                    break;
                }

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

                qualSequence = null;
                File.Delete(tempFileName);
            }
        }
Exemplo n.º 3
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);
            }
        }