/// <summary>
        /// Write out a set of contigs to the given file.
        /// </summary>
        /// <param name="formatter">Formatter</param>
        /// <param name="contig">Contig to write</param>
        /// <param name="filename">Filename</param>
        public static void Format(this XsvContigFormatter formatter, Contig contig, string filename)
        {
            if (formatter == null)
            {
                throw new ArgumentNullException("formatter");
            }
            if (contig == null)
            {
                throw new ArgumentNullException("contig");
            }
            if (string.IsNullOrWhiteSpace(filename))
            {
                throw new ArgumentNullException("filename");
            }

            using (var fs = File.Create(filename))
            {
                formatter.Write(fs, contig);
            }
        }
        /// <summary>
        /// Write out a set of contigs to the given file.
        /// </summary>
        /// <param name="formatter">Formatter</param>
        /// <param name="contig">Contig to write</param>
        public static void Format(this XsvContigFormatter formatter, Contig contig)
        {
            if (formatter == null)
            {
                throw new ArgumentNullException("formatter");
            }
            if (contig == null)
            {
                throw new ArgumentNullException("contig");
            }
            var fs = ParserFormatterExtensions <ISequenceFormatter> .GetOpenStream(formatter, true);

            if (fs != null)
            {
                formatter.Write(fs, contig);
            }
            else
            {
                throw new Exception("You must open a formatter before calling Write.");
            }
        }
예제 #3
0
        public void XsvSparseContigFormatterWrite()
        {
            // Gets the expected sequence from the Xml
            string filePathObj = this.utilityObj.xmlUtil.GetTextValue(
                Constants.SimpleXsvSparseNodeName,
                Constants.FilePathNode);

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

            // Logs information to the log file
            ApplicationLog.WriteLine(string.Format((IFormatProvider)null,
                "Xsv Contig Formatter BVT: File Exists in the Path '{0}'.",
                filePathObj));
            Contig expectedContig;

            XsvContigParser parserObj = new XsvContigParser(Alphabets.DNA, ',', '#');
            Contig contig = parserObj.ParseContig(filePathObj);                
            
            string seqId = contig.Sequences.Aggregate(string.Empty, (current, seq) => current + (seq.Sequence.ID + ","));

            // Write Xsv file.            
            XsvContigFormatter formatObj = new XsvContigFormatter(',', '#');
            formatObj.Format(contig, Constants.XsvTempFileName);

            XsvContigParser parserObjNew = new XsvContigParser(Alphabets.DNA, ',', '#');
            expectedContig = parserObjNew.ParseContig(Constants.XsvTempFileName);
             
            string expectedseqId = expectedContig.Sequences.Aggregate(string.Empty, (current, seq) => current + (seq.Sequence.ID + ","));

            // Validate parsed temp file with original Xsv file.
            Assert.AreEqual(contig.Length, expectedContig.Length);
            Assert.AreEqual(contig.Consensus.Count, expectedContig.Consensus.Count);            
            Assert.AreEqual(contig.Consensus.ID, expectedContig.Consensus.ID);
            Assert.AreEqual(contig.Sequences.Count, expectedContig.Sequences.Count);
            Assert.AreEqual(seqId.Length, expectedseqId.Length);
            Assert.AreEqual(seqId, expectedseqId);
            File.Delete(Constants.XsvTempFileName);
            ApplicationLog.WriteLine("Successfully validated the Write Xsv file");
        }