Exemplo n.º 1
0
        public void XsvSparseContigFormatterWrite()
        {
            // Gets the expected sequence from the Xml
            string filePathObj = this.utilityObj.xmlUtil.GetTextValue(
                Constants.SimpleXsvSparseNodeName,
                Constants.FilePathNode).TestDir();

            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");
        }
Exemplo n.º 2
0
        public void XsvSparseContigFormatterFormat()
        {
            // Gets the expected sequence from the Xml
            string filePathObj = Utility._xmlUtil.GetTextValue(
                Constants.SimpleXsvSparseNodeName,
                Constants.FilePathNode);

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

            IEncoding       encode    = Encodings.IupacNA;
            XsvContigParser parserObj = new XsvContigParser(encode,
                                                            Alphabets.DNA, ',', '#');
            Contig contig, expectedContig;

            // Parse a file.
            using (TextReader tr = new StreamReader(File.OpenRead(filePathObj)))
            {
                contig = parserObj.ParseContig(tr, false);
            }

            string seqId = string.Empty;

            foreach (Contig.AssembledSequence seq in contig.Sequences)
            {
                seqId += seq.Sequence.ID + ",";
            }

            // Format Xsv file.
            XsvContigFormatter formatObj = new XsvContigFormatter(',', '#');

            using (TextWriter tw = new StreamWriter(File.OpenWrite(
                                                        Constants.XsvTempFileName)))
            {
                formatObj.Format(contig, tw);
            }

            // Parse formatted TempFile.
            using (TextReader tr = new StreamReader(
                       File.OpenRead(Constants.XsvTempFileName)))
            {
                expectedContig = parserObj.ParseContig(tr, false);
            }


            string expectedseqId = string.Empty;

            foreach (Contig.AssembledSequence seq in expectedContig.Sequences)
            {
                expectedseqId += 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.DisplayID, expectedContig.Consensus.DisplayID);
            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);

            // Log to Nunit GUI.
            Console.WriteLine("Successfully validated the format Xsv file");
            ApplicationLog.WriteLine("Successfully validated the format Xsv file");
        }