Пример #1
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);

                        gffFormatter = new GffFormatter();
                        {
                            gffFormatter.Format(new Sequence(DnaAlphabet.Instance, sequenceData));
                        }                        
                        break;
                    case ArgumentNullExceptions.writeWithEmptySequence:

                        gffFormatter = new GffFormatter();
                        {
                            gffFormatter.Format(sequence);
                        }                                                                        
                        break;
                    case ArgumentNullExceptions.FormatString:

                        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));

                        gffFormatter = new GffFormatter();
                        {
                            gffFormatter.Format(collection);
                        }                                                                                        
                        break;
                    case ArgumentNullExceptions.writeCollectionWithEmptySequence:

                        gffFormatter = new GffFormatter();
                        {
                            gffFormatter.Format(collection);
                        }                          
                        break;
                    default:
                        break;
                }

                Assert.Fail();
            }
           
            catch (ArgumentNullException)
            {                
                ApplicationLog.WriteLine("GFF P2 : Exception is validated successfully.");
            }
            catch (Exception)
            {
                ApplicationLog.WriteLine("GFF P2 : Exception is validated successfully.");
            }
        }
Пример #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();
            seqs = parserObj.Parse(filePath).ToList();
            Sequence originalSequence = (Sequence)seqs[0];

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

            GffFormatter formatter = new GffFormatter { ShouldWriteSequenceData = true };
            if (isFilePath)
            {
                if (isSequenceList)
                    formatter.Format(seqs, Constants.GffTempFileName);
                else
                    formatter.Format(originalSequence, Constants.GffTempFileName);
            }
            else
            {
                if (isSequenceList)
                {
                    formatter.Format(seqs);
                }
                else
                {
                    formatter.Format(originalSequence);
                }
            }

            // Read the new file, then compare the sequences
            IList<ISequence> seqsNew = null;
            GffParser newParser = new GffParser();
            {
                seqsNew = newParser.Parse(Constants.GffTempFileName).ToList();
            }
            Assert.IsNotNull(seqsNew);
            ApplicationLog.WriteLine(string.Format("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.");

            // 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);          

            string orgSeq = new string(originalSequence.Select(x => (char)x).ToArray()); ; 
            ISequence newSeq = seqsNew.FirstOrDefault();           
            string newSeqString = new string(newSeq.Select(x => (char)x).ToArray());

            Assert.AreEqual(orgSeq, newSeqString);
            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.");
        }
Пример #3
0
        /// <summary>
        /// Validates the Format() method in Gff Formatter for Multi sequences based on the parameters.
        /// </summary>
        /// <param name="nodeName">Xml Node name to be read.</param>
        void ValidateFormatMultiSequencesTestCases(string nodeName)
        {
            // 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();
            seqs = parserObj.Parse(filePath).ToList();

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

            GffFormatter formatter = new GffFormatter { ShouldWriteSequenceData = true };
            formatter.Format(seqs, Constants.GffTempFileName);

            int noOfSeqs = int.Parse(utilityObj.xmlUtil.GetTextValue(nodeName,
                Constants.NumberOfSequencesNode), null);
            Assert.IsNotNull(seqs);
            Assert.AreEqual(noOfSeqs, seqs.Count);
            ApplicationLog.WriteLine(string.Format("Gff Formatter P1 : Number of Sequences found are '{0}'.",
                seqs.Count.ToString((IFormatProvider)null)));

            string[] expectedSequences = utilityObj.xmlUtil.GetTextValues(nodeName,
                Constants.ExpectedSequenesNode);
            string[] alphabets = utilityObj.xmlUtil.GetTextValues(nodeName,
                Constants.AlphabetsNode);
            string[] seqIds = utilityObj.xmlUtil.GetTextValues(nodeName,
                Constants.SequenceIdsNode);

            for (int i = 0; i < noOfSeqs; i++)
            {
                bool valFeat = ValidateMultiSequenceFeatures(seqs[i], i + 1, nodeName);

                Assert.IsTrue(valFeat);
                ApplicationLog.WriteLine(
                    "Gff Formatter P1 : Successfully validated all the Features for a give Sequence in GFF File.");

                Sequence seq = (Sequence)seqs[i];
                Assert.IsNotNull(seq);

                string newSeq = new string(seq.Select(x => (char)x).ToArray());

                if (string.Compare(newSeq, newSeq.ToUpper(CultureInfo.CurrentCulture)) == 0)
                {
                    expectedSequences[i] = expectedSequences[i].ToUpper(CultureInfo.CurrentCulture);
                }
                else
                {
                    expectedSequences[i] = expectedSequences[i].ToLower(CultureInfo.CurrentCulture);
                }
                Assert.AreEqual(expectedSequences[i], newSeq);
                ApplicationLog.WriteLine(string.Format((IFormatProvider)null,
                    "Gff Formatter P1: The Gff sequence '{0}' validation after Parse() is found to be as expected.",
                    newSeq));

                byte[] TempSeqData = new byte[seq.Count];
                for (int j = 0; j < seq.Count; j++)
                {
                    TempSeqData[j] = seq[j];
                }

                Assert.AreEqual(expectedSequences[i].Length, TempSeqData.Length);
                ApplicationLog.WriteLine(string.Format((IFormatProvider)null,
                    "Gff Formatter P1: The Gff Length sequence '{0}' is as expected.",
                    expectedSequences[i].Length));

                Assert.IsNotNull(seq.Alphabet);
                Assert.AreEqual(seq.Alphabet.Name.ToLower(CultureInfo.CurrentCulture),
                    alphabets[i]);
                ApplicationLog.WriteLine(string.Format((IFormatProvider)null,
                    "Gff Formatter P1: The Sequence Alphabet is '{0}' and is as expected.",
                    seq.Alphabet.Name));

                Assert.AreEqual(seqIds[i], seq.ID);
                ApplicationLog.WriteLine(string.Format((IFormatProvider)null,
                    "Gff Formatter P1: The Sequence ID is '{0}' and is as expected.",
                    seq.ID));
            }

            // 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.");
        }