Exemplo n.º 1
0
        /// <summary>
        /// General method to validate FastQ Formatter on a Stream.
        /// <param name="nodeName">xml node name.</param>
        /// </summary>
        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 = System.IO.Path.GetTempFileName();
            string parsedValue   = string.Empty;
            string parsedID      = string.Empty;
            IEnumerable <QualitativeSequence> qualSequence = null;

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

                // New Sequence after formatting file.
                IEnumerable <QualitativeSequence> newQualSeq = null;
                using (StreamWriter writer = new StreamWriter(tempFileName1))
                {
                    using (FastQFormatter fastQFormatter = new FastQFormatter())
                    {
                        fastQFormatter.Open(writer);
                        fastQFormatter.Write(qualSequence.ElementAt(0));
                    }
                }

                using (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);
                }

                // 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 VSTest 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;
                File.Delete(tempFileName1);
            }
        }
Exemplo n.º 2
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);
            }
        }
Exemplo n.º 3
0
        public void FastQFormatterUsingInterface()
        {
            string filepathOriginal = @"TestUtils\FASTQ\SRR002012_5.fastq";

            Assert.IsTrue(File.Exists(filepathOriginal));

            IList <QualitativeSequence> seqsOriginal = null;
            string filepathTmp = Path.GetTempFileName();

            using (FastQParser parser = new FastQParser())
            {
                parser.Open(filepathOriginal);

                // Read the original file
                seqsOriginal = parser.Parse().ToList();
                Assert.IsNotNull(seqsOriginal);

                // Use the formatter to write the original sequences to a temp file
                ISequenceFormatter formatter = null;
                try
                {
                    formatter = new FastQFormatter();
                    formatter.Open(filepathTmp);
                    foreach (ISequence s in seqsOriginal)
                    {
                        formatter.Write(s);
                    }

                    formatter.Close();
                }
                finally
                {
                    if (formatter != null)
                    {
                        ((FastQFormatter)formatter).Dispose();
                    }
                }
            }

            // Read the new file, then compare the sequences
            IList <QualitativeSequence> seqsNew = null;

            using (FastQParser parser = new FastQParser(filepathTmp))
            {
                seqsNew = parser.Parse().ToList();
                Assert.IsNotNull(seqsNew);

                // Now compare the sequences.
                int countOriginal = seqsOriginal.Count();
                int countNew      = seqsNew.Count();
                Assert.AreEqual(countOriginal, countNew);

                int i;
                for (i = 0; i < countOriginal; i++)
                {
                    Assert.AreEqual(seqsOriginal[i].ID, seqsNew[i].ID);
                    string orgSeq    = ASCIIEncoding.ASCII.GetString(seqsOriginal[i].ToArray());
                    string newSeq    = ASCIIEncoding.ASCII.GetString(seqsNew[i].ToArray());
                    string orgscores = ASCIIEncoding.ASCII.GetString(seqsOriginal[i].GetEncodedQualityScores());
                    string newscores = ASCIIEncoding.ASCII.GetString(seqsNew[i].GetEncodedQualityScores());
                    Assert.AreEqual(orgSeq, newSeq);
                    Assert.AreEqual(orgscores, newscores);
                }

                // Passed all the tests, delete the tmp file. If we failed an Assert,
                // the tmp file will still be there in case we need it for debugging.
                File.Delete(filepathTmp);
            }
        }
Exemplo n.º 4
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);
            }
        }
Exemplo n.º 5
0
        /// <summary>
        ///     General method to validate FastQ formatting
        ///     Qualitative Sequence by passing TextWriter as a parameter
        ///     <param name="nodeName">xml node name.</param>
        /// </summary>
        private void ValidateFastQFormatByFormattingQualSeqeunce(string nodeName)
        {
            // Gets the actual sequence and the alphabet from the Xml
            IAlphabet alphabet = Utility.GetAlphabet(utilityObj.xmlUtil.GetTextValue(nodeName, Constants.AlphabetNameNodeV2));
            FastQFormatType expectedFormatType = Utility.GetFastQFormatType(utilityObj.xmlUtil.GetTextValue(nodeName, Constants.FastQFormatType));
            string qualSequence = utilityObj.xmlUtil.GetTextValue(nodeName, Constants.ExpectedSequenceNode);
            string expectedQualitativeSequence = utilityObj.xmlUtil.GetTextValue(nodeName, Constants.ExpectedSequenceNode);
            string qualityScores = "";
            int i;

            for (i = 0; i < qualSequence.Length; i++)
                qualityScores = qualityScores + "}";

            byte[] seq = Encoding.UTF8.GetBytes(qualSequence);
            byte[] qScore = Encoding.UTF8.GetBytes(qualityScores);
            string tempFileName = Path.GetTempFileName();

            // Create a Qualitative Sequence.
            var qualSeq = new QualitativeSequence(alphabet, expectedFormatType, seq, qScore);

            var formatter = new FastQFormatter();
            using (formatter.Open(tempFileName))
            {
                formatter.Format(qualSeq);
                formatter.Close();

                var fastQParserObj = new FastQParser();
                using (fastQParserObj.Open(tempFileName))
                {
                    // Read the new file and validate Sequences.
                    var seqsNew = fastQParserObj.Parse();
                    var firstSequence = seqsNew.First();

                    // Validate qualitative Sequence upon parsing FastQ file.
                    Assert.AreEqual(expectedQualitativeSequence, firstSequence.ConvertToString());
                    Assert.IsTrue(string.IsNullOrEmpty(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);
            }
        }
Exemplo n.º 6
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);
            }
        }