Ejemplo n.º 1
0
        public void ValidateSeqFormatterProperties()
        {
            // Gets the expected sequence from the Xml
            string fastaFormatterName = this.utilityObj.xmlUtil.GetTextValue(Constants.FastAFileParserNode,
                                                                             Constants.ParserNameNode);
            string genBankFormatterName = this.utilityObj.xmlUtil.GetTextValue(Constants.GenBankFileParserNode,
                                                                               Constants.ParserNameNode);
            string gffFormatterName = this.utilityObj.xmlUtil.GetTextValue(Constants.GffFileParserNode,
                                                                           Constants.ParserNameNode);
            string fastQFormatterName = this.utilityObj.xmlUtil.GetTextValue(Constants.FastQFileParserNode,
                                                                             Constants.ParserNameNode);

            // Get SequenceFormatter class properties.
            FastAFormatter actualFastAFormatter = SequenceFormatters.Fasta;
            IReadOnlyList <ISequenceFormatter> allFormatters = SequenceFormatters.All;
            GenBankFormatter actualgenBankFormatterName      = SequenceFormatters.GenBank;
            FastQFormatter   actualFastQFormatterName        = SequenceFormatters.FastQ;
            GffFormatter     actualGffFormatterName          = SequenceFormatters.Gff;

            // Validate Sequence Formatter
            Assert.AreEqual(fastaFormatterName, actualFastAFormatter.Name);
            Assert.AreEqual(genBankFormatterName, actualgenBankFormatterName.Name);
            Assert.AreEqual(gffFormatterName, actualGffFormatterName.Name);
            Assert.AreEqual(fastQFormatterName, actualFastQFormatterName.Name);
            Assert.IsNotNull(allFormatters);
            ApplicationLog.WriteLine("Type of the parser is validated successfully");
        }
Ejemplo n.º 2
0
        public void ValidateSeqFormatterProperties()
        {
            // Gets the expected sequence from the Xml
            string fastaFormatterName = _utilityObj._xmlUtil.GetTextValue(Constants.FastAFileParserNode,
                                                                          Constants.ParserNameNode);
            string genBankFormatterName = _utilityObj._xmlUtil.GetTextValue(Constants.GenBankFileParserNode,
                                                                            Constants.ParserNameNode);
            string gffFormatterName = _utilityObj._xmlUtil.GetTextValue(Constants.GffFileParserNode,
                                                                        Constants.ParserNameNode);
            string fastQFormatterName = _utilityObj._xmlUtil.GetTextValue(Constants.FastQFileParserNode,
                                                                          Constants.ParserNameNode);

            // Get SequenceFormatter class properties.
            FastaFormatter             actualFastAFormatter       = SequenceFormatters.Fasta;
            IList <ISequenceFormatter> allFormatters              = SequenceFormatters.All;
            GenBankFormatter           actualgenBankFormatterName = SequenceFormatters.GenBank;
            FastQFormatter             actualFastQFormatterName   = SequenceFormatters.FastQ;
            GffFormatter actualGffFormatterName = SequenceFormatters.Gff;

            // Validate Sequence Formatter
            Assert.AreEqual(fastaFormatterName, actualFastAFormatter.Name);
            Assert.AreEqual(4, allFormatters.Count);
            Assert.AreEqual(genBankFormatterName, actualgenBankFormatterName.Name);
            Assert.AreEqual(gffFormatterName, actualGffFormatterName.Name);
            Assert.AreEqual(fastQFormatterName, actualFastQFormatterName.Name);
            Console.WriteLine(string.Format((IFormatProvider)null,
                                            "SequenceFormatter : Type of the parser is validated successfully"));
            ApplicationLog.WriteLine("Type of the parser is validated successfully");
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Returns formatter which supports the specified file.
        /// </summary>
        /// <param name="fileName">File name for which the formatter is required.</param>
        /// <returns>If found returns the formatter as ISequenceFormatter else returns null.</returns>
        public static ISequenceFormatter FindFormatterByFile(string fileName)
        {
            ISequenceFormatter formatter = null;

            if (!string.IsNullOrEmpty(fileName))
            {
                if (Helper.IsGenBank(fileName))
                {
                    formatter = new GenBankFormatter();
                }
                else if (fileName.EndsWith(Resource.GFF_FILEEXTENSION, StringComparison.InvariantCultureIgnoreCase))
                {
                    formatter = new GffFormatter();
                }
                else if (Helper.IsFasta(fileName))
                {
                    formatter = new FastaFormatter();
                }
                else if (Helper.IsFastQ(fileName))
                {
                    formatter = new FastQFormatter();
                }
                else
                {
                    formatter = null;
                }
            }

            return(formatter);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Returns parser which supports the specified file.
        /// </summary>
        /// <param name="fileName">File name for which the parser is required.</param>
        /// <param name="formatterName">Name of the formatter to use.</param>
        /// <returns>If found returns the formatter as ISequenceFormatter else returns null.</returns>
        public static ISequenceFormatter FindFormatterByName(string fileName, string formatterName)
        {
            ISequenceFormatter formatter = null;

            if (!string.IsNullOrEmpty(fileName))
            {
                if (formatterName == Properties.Resource.FastAName)
                {
                    formatter = new FastAFormatter(fileName);
                }
                else if (formatterName == Properties.Resource.FastQName)
                {
                    formatter = new FastQFormatter(fileName);
                }
                else if (formatterName == Properties.Resource.GENBANK_NAME)
                {
                    formatter = new GenBankFormatter(fileName);
                }
                else if (formatterName == Properties.Resource.GFF_NAME)
                {
                    formatter = new GffFormatter(fileName);
                }
                else
                {
                    formatter = null;
                }
            }

            return(formatter);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Filters GTF or GFF entries that lack strand information
        /// Can filter also by zero abundance stringtie estimates
        /// Add CDS at the end
        /// </summary>
        /// <param name="gtfPath"></param>
        /// <param name="gtfOutPath"></param>
        public static void FilterGtfEntriesWithoutStrand(string gtfPath, string referenceGenomePath, string referenceGeneModelPath, bool filterEntriesWithZeroAbundanceStringtieEstimates = false)
        {
            var    chromFeatures   = GeneModel.SimplerParse(gtfPath);
            string filteredGtfPath = Path.Combine(Path.GetDirectoryName(gtfPath), Path.GetFileNameWithoutExtension(gtfPath) + ".filtered.gtf");

            using (var file = File.Create(filteredGtfPath))
            {
                var formatter = new GffFormatter();
                foreach (var chromISeq in chromFeatures)
                {
                    List <MetadataListItem <List <string> > > filteredFeatures = new List <MetadataListItem <List <string> > >();
                    bool isMetadata = chromISeq.Metadata.TryGetValue("features", out object featuresObj);
                    if (isMetadata)
                    {
                        bool okayTranscript = false;
                        var  features       = featuresObj as List <MetadataListItem <List <string> > >;
                        foreach (var feature in features)
                        {
                            if (!feature.SubItems.TryGetValue("strand", out List <string> strandish))
                            {
                                continue;
                            }
                            var attributes = GeneModel.SplitAttributes(feature.FreeText);
                            if (feature.Key == "transcript")
                            {
                                bool okayFpkm = !filterEntriesWithZeroAbundanceStringtieEstimates ||
                                                attributes.TryGetValue("FPKM", out string fpkm) && double.TryParse(fpkm, out double fpkmValue) && fpkmValue > 0;
                                bool okayTpm = !filterEntriesWithZeroAbundanceStringtieEstimates ||
                                               attributes.TryGetValue("TPM", out string tpm) && double.TryParse(tpm, out double tpmValue) && tpmValue > 0;
                                okayTranscript = okayFpkm && okayTpm;
                            }
                            if (okayTranscript)
                            {
                                filteredFeatures.Add(feature);
                            }
                        }
                    }
                    chromISeq.Metadata["features"] = filteredFeatures;
                }
                formatter.Format(file, chromFeatures);
            }
            Genome    ensemblGenome      = new Genome(referenceGenomePath);
            GeneModel newGeneModel       = new GeneModel(ensemblGenome, filteredGtfPath);
            GeneModel referenceGeneModel = new GeneModel(ensemblGenome, referenceGeneModelPath);

            newGeneModel.CreateCDSFromAnnotatedStartCodons(referenceGeneModel);
            string filteredGtfWithCdsPath = Path.Combine(Path.GetDirectoryName(filteredGtfPath), Path.GetFileNameWithoutExtension(filteredGtfPath) + ".withcds.gtf");

            newGeneModel.PrintToGTF(filteredGtfWithCdsPath);
        }
Ejemplo n.º 6
0
        public void GffFormatterValidateOpen()
        {
            using (GffFormatter formatter = new GffFormatter())
            {
                try
                {
                    formatter.Open(Constants.GffTempFileName);
                }
                catch (System.IO.IOException exception)
                {
                    Assert.Fail("Exception thrown on opening a file " + exception.Message);
                }
            }

            ApplicationLog.WriteLine("Opened the file successfully");
        }
Ejemplo n.º 7
0
 /// <summary>
 /// Print out to a
 /// </summary>
 /// <param name="outGffFilePath"></param>
 public void PrintToGTF(string outGffFilePath)
 {
     using (FileStream stream = new FileStream(outGffFilePath, FileMode.Create))
     {
         GffFormatter gff = new GffFormatter();
         foreach (Chromosome chrom in Genome.Chromosomes)
         {
             if (GenomeForest.Forest.TryGetValue(chrom.FriendlyName, out var tree))
             {
                 IEnumerable <Gene> genes = tree.Intervals.OfType <Gene>().OrderBy(g => g.OneBasedStart);
                 chrom.Sequence.Metadata["features"] = genes.SelectMany(g => g.GetFeatures()).ToList();
                 chrom.Sequence.ID = chrom.FriendlyName; // shortens to "1" from "1 dna:chromosome chromosome:GRCh37:1:1:249250621:1 REF"
                 gff.Format(stream, chrom.Sequence);
             }
         }
     }
 }
Ejemplo n.º 8
0
        public void GffFormatterValidateFormatString()
        {
            // 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;
            GffParser         parserObj = new GffParser(filePath);

            seqs = parserObj.Parse().ToList();
            ISequence 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();

            formatter.ShouldWriteSequenceData = true;
            string formatString = formatter.FormatString(originalSequence);

            string expectedString = utilityObj.xmlUtil.GetTextValue(
                Constants.SimpleGffNodeName, Constants.FormatStringNode);

            expectedString = expectedString.Replace("current-date",
                                                    DateTime.Today.ToString("yyyy-MM-dd", null));
            expectedString =
                expectedString.Replace("\r", "").Replace("\n", "").Replace(" ", "").Replace("\t", "").ToUpper(CultureInfo.CurrentCulture);
            string modifedformatString =
                formatString.Replace("\r", "").Replace("\n", "").Replace(" ", "").Replace("\t", "").ToUpper(CultureInfo.CurrentCulture);

            Assert.AreEqual(modifedformatString, expectedString);
            Console.WriteLine(string.Format((IFormatProvider)null,
                                            "Gff Formatter BVT: The Gff Format String '{0}' are matching with FormatString() method and is as expected.",
                                            formatString));
            ApplicationLog.WriteLine(string.Format((IFormatProvider)null,
                                                   "Gff Formatter BVT: The Gff Format String '{0}' are matching with FormatString() method and is as expected.",
                                                   formatString));

            // 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(Constants.GffTempFileName);
            ApplicationLog.WriteLine("Deleted the temp file created.");
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Filters GTF or GFF entries that lack strand information
        /// </summary>
        /// <param name="gtfPath"></param>
        /// <param name="gtfOutPath"></param>
        public void FilterGtfEntriesWithoutStrand(string gtfPath, string gtfOutPath, bool filterEntriesWithZeroAbundanceStringtieEstimates)
        {
            var chromFeatures = GeneModel.SimplerParse(gtfPath);

            //if (!File.Exists(gtfOutPath))
            //{
            using (var file = File.Create(gtfOutPath))
            {
                var formatter = new GffFormatter();
                foreach (var chromISeq in chromFeatures)
                {
                    List <MetadataListItem <List <string> > > filteredFeatures = new List <MetadataListItem <List <string> > >();
                    bool isMetadata = chromISeq.Metadata.TryGetValue("features", out object featuresObj);
                    if (isMetadata)
                    {
                        bool okayTranscript = false;
                        var  features       = featuresObj as List <MetadataListItem <List <string> > >;
                        foreach (var feature in features)
                        {
                            if (!feature.SubItems.TryGetValue("strand", out List <string> strandish))
                            {
                                continue;
                            }
                            var attributes = GeneModel.SplitAttributes(feature.FreeText);
                            if (feature.Key == "transcript")
                            {
                                bool okayFpkm = !filterEntriesWithZeroAbundanceStringtieEstimates ||
                                                attributes.TryGetValue("FPKM", out string fpkm) && double.TryParse(fpkm, out double fpkmValue) && fpkmValue > 0;
                                bool okayTpm = !filterEntriesWithZeroAbundanceStringtieEstimates ||
                                               attributes.TryGetValue("TPM", out string tpm) && double.TryParse(tpm, out double tpmValue) && tpmValue > 0;
                                okayTranscript = okayFpkm && okayTpm;
                            }
                            if (okayTranscript)
                            {
                                filteredFeatures.Add(feature);
                            }
                        }
                    }
                    chromISeq.Metadata["features"] = filteredFeatures;
                }
                formatter.Format(file, chromFeatures);
            }
            //}
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Returns formatter which supports the specified file.
        /// </summary>
        /// <param name="fileName">File name for which the formatter is required.</param>
        /// <returns>If found returns the formatter as ISequenceFormatter else returns null.</returns>
        public static ISequenceFormatter FindFormatterByFileName(string fileName)
        {
            ISequenceFormatter formatter = null;

            if (!string.IsNullOrEmpty(fileName))
            {
                if (IsFasta(fileName))
                {
                    formatter = new FastAFormatter(fileName);
                }
                else if (IsFastQ(fileName))
                {
                    formatter = new FastQFormatter(fileName);
                }
                else if (IsGenBank(fileName))
                {
                    formatter = new GenBankFormatter(fileName);
                }
                else if (fileName.EndsWith(Properties.Resource.GFF_FILEEXTENSION, StringComparison.InvariantCultureIgnoreCase))
                {
                    formatter = new GffFormatter(fileName);
                }
                else
                {
                    // Do a search through the known formatters to pick up custom formatters added through add-in.
                    string fileExtension = Path.GetExtension(fileName);
                    if (!string.IsNullOrEmpty(fileExtension))
                    {
                        formatter = All.FirstOrDefault(p => p.SupportedFileTypes.Contains(fileExtension));
                        // If we found a match based on extension, then open the file - this
                        // matches the above behavior where a specific formatter was created for
                        // the passed filename - the formatter is opened automatically in the constructor.
                        if (formatter != null)
                        {
                            formatter.Open(fileName);
                        }
                    }
                }
            }

            return(formatter);
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Returns parser which supports the specified file.
        /// </summary>
        /// <param name="fileName">File name for which the parser is required.</param>
        /// <param name="formatterName">Name of the formatter to use.</param>
        /// <returns>If found returns the formatter as ISequenceFormatter else returns null.</returns>
        public static ISequenceFormatter FindFormatterByName(string fileName, string formatterName)
        {
            ISequenceFormatter formatter = null;

            if (!string.IsNullOrEmpty(fileName))
            {
                if (formatterName == Properties.Resource.FastAName)
                {
                    formatter = new FastAFormatter(fileName);
                }
                else if (formatterName == Properties.Resource.FastQName)
                {
                    formatter = new FastQFormatter(fileName);
                }
                else if (formatterName == Properties.Resource.GENBANK_NAME)
                {
                    formatter = new GenBankFormatter(fileName);
                }
                else if (formatterName == Properties.Resource.GFF_NAME)
                {
                    formatter = new GffFormatter(fileName);
                }
                else
                {
                    // Do a search through the known formatters to pick up custom formatters added through add-in.
                    formatter = All.FirstOrDefault(p => p.Name == formatterName);
                    // If we found a match based on extension, then open the file - this
                    // matches the above behavior where a specific formatter was created for
                    // the passed filename - the formatter is opened automatically in the constructor.
                    if (formatter != null)
                    {
                        formatter.Open(fileName);
                    }
                }
            }

            return(formatter);
        }
Ejemplo n.º 12
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.");
        }
Ejemplo n.º 13
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;

            GffParser parserObj = new GffParser();

            {
                seqs             = parserObj.Parse(filePath).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 (var writer = File.Create(Constants.GffTempFileName))
            {
                GffFormatter formatter = new GffFormatter()
                {
                    ShouldWriteSequenceData = true
                };
                formatter.Format(writer, 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]));

            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.");
        }
Ejemplo n.º 14
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>
        static void ValidateFormatGeneralTestCases(string nodeName,
                                                   bool isFilePath, bool isSequenceList)
        {
            // Gets the expected sequence from the Xml
            string filePath = Utility._xmlUtil.GetTextValue(nodeName,
                                                            Constants.FilePathNode);

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

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

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

            GffFormatter formatter = new GffFormatter();

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

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

            seqsNew = newParser.Parse(Constants.GffTempFileName);
            Assert.IsNotNull(seqsNew);
            ApplicationLog.WriteLine(string.Format(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);
            string orgSeq = originalSequence.ToString();
            string newSeq = seqsNew[0].ToString();

            Assert.AreEqual(orgSeq, newSeq);
            Console.WriteLine(string.Format(null,
                                            "Gff Formatter BVT: The Gff sequences '{0}' are matching with Format() method and is as expected.",
                                            seqsNew[0].ToString()));
            ApplicationLog.WriteLine(string.Format(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.");
        }
Ejemplo n.º 15
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.");
            }
        }