Example #1
0
        public void GffFormatterValidateStreams()
        {
            // Gets the expected sequence from the Xml
            string filePath = utilityObj.xmlUtil.GetTextValue(Constants.SimpleGffNodeName,
                                                              Constants.FilePathNode);

            Assert.IsTrue(File.Exists(filePath));
            IList <ISequence> seqs             = null;
            Sequence          originalSequence = null;

            using (GffParser parserObj = new GffParser(filePath))
            {
                seqs             = parserObj.Parse().ToList();
                originalSequence = (Sequence)seqs[0];
            }

            // Use the formatter to write the original sequences to a temp file
            ApplicationLog.WriteLine(string.Format((IFormatProvider)null,
                                                   "Gff Formatter BVT: Creating the Temp file '{0}'.",
                                                   Constants.GffTempFileName));

            using (StreamWriter writer = new StreamWriter(Constants.GffTempFileName))
            {
                using (GffFormatter formatter = new GffFormatter())
                {
                    formatter.ShouldWriteSequenceData = true;
                    formatter.Open(writer);
                    formatter.Write(originalSequence);
                }
            }

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

            using (GffParser newParser = new GffParser(Constants.GffTempFileName))
            {
                seqsNew = newParser.Parse().ToList();
            }

            Assert.IsNotNull(seqsNew);
            ApplicationLog.WriteLine(string.Format((IFormatProvider)null,
                                                   "Gff Formatter BVT: New Sequence is '{0}'.",
                                                   seqsNew[0].ToString()));

            bool val = ValidateFeatures(seqsNew[0], Constants.SimpleGffNodeName);

            Assert.IsTrue(val);
            ApplicationLog.WriteLine(
                "GFF Formatter BVT : All the features validated successfully.");

            // Now compare the sequences.
            int countNew      = seqsNew.Count();
            int expectedCount = 1;

            Assert.AreEqual(expectedCount, countNew);
            ApplicationLog.WriteLine("The Number of sequences are matching.");

            Assert.AreEqual(originalSequence.ID, seqsNew[0].ID);
            ISequence newSeq = seqsNew.FirstOrDefault();

            Assert.AreEqual(new string(originalSequence.Select(x => (char)x).ToArray()),
                            new string(newSeq.Select(x => (char)x).ToArray()));
            ApplicationLog.WriteLine(string.Format((IFormatProvider)null,
                                                   "Gff Formatter BVT: The Gff sequences '{0}' are matching with Write() method.",
                                                   seqsNew[0].ToString()));

            // 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.
            if (File.Exists(Constants.GffTempFileName))
            {
                File.Delete(Constants.GffTempFileName);
            }

            ApplicationLog.WriteLine("Deleted the temp file created.");
        }
Example #2
0
        /// <summary>
        /// Validates the Format() method in Gff Formatter based on the parameters.
        /// </summary>
        /// <param name="nodeName">Xml Node name to be read.</param>
        /// <param name="isFilePath">Is file path passed as parameter?</param>
        /// <param name="isSequenceList">Is sequence list passed as parameter?</param>
        void ValidateFormatGeneralTestCases(string nodeName,
                                            bool isFilePath, bool isSequenceList)
        {
            // Gets the expected sequence from the Xml
            string filePath = utilityObj.xmlUtil.GetTextValue(nodeName,
                                                              Constants.FilePathNode);

            Assert.IsTrue(File.Exists(filePath));
            IList <ISequence> seqs      = null;
            GffParser         parserObj = new GffParser(filePath);

            seqs = parserObj.Parse().ToList();
            Sequence originalSequence = (Sequence)seqs[0];

            // Use the formatter to write the original sequences to a temp file
            ApplicationLog.WriteLine(string.Format((IFormatProvider)null,
                                                   "Gff Formatter BVT: Creating the Temp file '{0}'.",
                                                   Constants.GffTempFileName));

            GffFormatter formatter = new GffFormatter(Constants.GffTempFileName);

            formatter.ShouldWriteSequenceData = true;
            if (isFilePath)
            {
                if (isSequenceList)
                {
                    formatter.Write(seqs);
                }
                else
                {
                    formatter.Write(originalSequence);
                }
            }
            else
            {
                if (isSequenceList)
                {
                    formatter.Write(seqs);
                }
                else
                {
                    formatter.Write(originalSequence);
                }
            }

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

            using (GffParser newParser = new GffParser(Constants.GffTempFileName))
            {
                seqsNew = newParser.Parse().ToList();
            }
            Assert.IsNotNull(seqsNew);
            ApplicationLog.WriteLine(string.Format((IFormatProvider)null,
                                                   "Gff Formatter BVT: New Sequence is '{0}'.",
                                                   seqsNew[0].ToString()));

            bool val = ValidateFeatures(seqsNew[0], nodeName);

            Assert.IsTrue(val);
            ApplicationLog.WriteLine(
                "GFF Formatter BVT : All the features validated successfully.");
            Console.WriteLine(
                "GFF Formatter BVT : All the features validated successfully.");

            // Now compare the sequences.
            int countNew      = seqsNew.Count();
            int expectedCount = 1;

            Assert.AreEqual(expectedCount, countNew);
            ApplicationLog.WriteLine("The Number of sequences are matching.");

            Assert.AreEqual(originalSequence.ID, seqsNew[0].ID);
            byte[] TempSeqData = new byte[originalSequence.Count];
            for (int i = 0; i < originalSequence.Count; i++)
            {
                TempSeqData[i] = originalSequence[i];
            }
            string    orgSeq = ASCIIEncoding.ASCII.GetString(TempSeqData);
            ISequence newSeq = seqsNew.FirstOrDefault();

            byte[] TempSeqData1 = new byte[newSeq.Count];
            for (int i = 0; i < newSeq.Count; i++)
            {
                TempSeqData1[i] = newSeq[i];
            }
            string newSeqString = ASCIIEncoding.ASCII.GetString(TempSeqData1);

            Assert.AreEqual(orgSeq, newSeqString);
            Console.WriteLine(string.Format((IFormatProvider)null,
                                            "Gff Formatter BVT: The Gff sequences '{0}' are matching with Format() method and is as expected.",
                                            seqsNew[0].ToString()));
            ApplicationLog.WriteLine(string.Format((IFormatProvider)null,
                                                   "Gff Formatter BVT: The Gff sequences '{0}' are matching with Format() method.",
                                                   seqsNew[0].ToString()));

            // 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.
            if (File.Exists(Constants.GffTempFileName))
            {
                File.Delete(Constants.GffTempFileName);
            }
            ApplicationLog.WriteLine("Deleted the temp file created.");
        }
Example #3
0
        /// <summary>
        /// General method to invalidate Argument Null exceptions generated from different methods.
        /// </summary>
        /// <param name="nodeName">xml node name.</param>
        /// <param name="method">Gff Parse method parameters</param>
        void InvalidateGffWriteMethod(ArgumentNullExceptions method)
        {
            ISequence        sequence     = null;
            List <ISequence> collection   = new List <ISequence>();
            string           sequenceData = null;
            GffFormatter     gffFormatter = null;

            try
            {
                switch (method)
                {
                case ArgumentNullExceptions.writeWithEmptyFile:
                    sequenceData = utilityObj.xmlUtil.GetTextValue(
                        Constants.SimpleGffDnaNodeName, Constants.ExpectedSequenceNode);

                    using (gffFormatter = new GffFormatter())
                    {
                        gffFormatter.Write(new Sequence(DnaAlphabet.Instance, sequenceData));
                    }
                    break;

                case ArgumentNullExceptions.writeWithEmptySequence:

                    using (gffFormatter = new GffFormatter())
                    {
                        gffFormatter.Write(sequence);
                    }
                    break;

                case ArgumentNullExceptions.FormatString:

                    using (gffFormatter = new GffFormatter())
                    {
                        gffFormatter.FormatString(sequence);
                    }
                    break;

                case ArgumentNullExceptions.writeCollectionWithEmptyFile:
                    sequenceData = utilityObj.xmlUtil.GetTextValue(
                        Constants.SimpleGffDnaNodeName, Constants.ExpectedSequenceNode);
                    collection.Add(new Sequence(DnaAlphabet.Instance, sequenceData));

                    using (gffFormatter = new GffFormatter())
                    {
                        gffFormatter.Write(collection);
                    }
                    break;

                case ArgumentNullExceptions.writeCollectionWithEmptySequence:

                    using (gffFormatter = new GffFormatter())
                    {
                        gffFormatter.Write(collection);
                    }
                    break;

                default:
                    break;
                }

                Assert.Fail();
            }

            catch (ArgumentNullException)
            {
                ApplicationLog.WriteLine(
                    "GFF P2 : Exception is validated successfully.");
            }
        }