Esempio n. 1
0
        public void XsvSparseBvtParserProperties()
        {
            XsvContigParser xsvParser = new XsvContigParser(Alphabets.DNA, ',', '#');
            Assert.AreEqual(Constants.XsvSparseDescription, xsvParser.Description);
            Assert.AreEqual(Constants.XsvSparseFileTypes, xsvParser.SupportedFileTypes);
            Assert.AreEqual(Constants.XsvSparseName, xsvParser.Name);

            ApplicationLog.WriteLine
                ("Successfully validated all the properties of XsvSparse Parser class.");
        }
Esempio n. 2
0
        /// <summary>
        /// Parse out a Contig from the given file.
        /// </summary>
        /// <param name="parser">Parser</param>
        /// <param name="filename">Filename</param>
        /// <returns>Contig</returns>
        public static Contig ParseContig(this XsvContigParser parser, string filename)
        {
            if (parser == null)
            {
                throw new ArgumentNullException("parser");
            }
            if (string.IsNullOrWhiteSpace(filename))
            {
                throw new ArgumentNullException("filename");
            }

            using (var fs = File.OpenRead(filename))
            {
                return(parser.ParseContig(fs));
            }
        }
Esempio n. 3
0
        public void XsvSparseParseContig()
        {
            // Gets the expected file 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,
                "XsvSparse Formatter BVT: File Exists in the Path '{0}'.",
                filePathObj));

            XsvContigParser parserObj = new XsvContigParser(Alphabets.DNA, ',', '#');
            parserObj.Parse(filePathObj);

            Contig contig = parserObj.ParseContig(filePathObj);

            // Validate parsed temp file with original Xsv file.
            Assert.AreEqual(26048682, contig.Length);
            Assert.AreEqual(26048682, contig.Consensus.Count);
            Assert.AreEqual("Chr22+Chr22+Chr22+Chr22", contig.Consensus.ID);
            Assert.AreEqual(56, contig.Sequences.Count);

            // Log to GUI.
            ApplicationLog.WriteLine("Successfully validated the ParseConting() method with Xsv file");
        }
Esempio n. 4
0
        /// <summary>
        /// XsvSparse formatter generic method called by all the test cases 
        /// to validate the test case based on the parameters passed.
        /// </summary>
        /// <param name="nodename">Xml node Name.</param>
        /// <param name="additionalParam">Additional parameter 
        /// based on which the validation of  test case is done.</param>
        void XsvSparseFormatterGeneralTestCases(string nodename,
            AdditionalParameters additionalParam)
        {
            // Gets the expected sequence from the Xml
            string filePathObj = this.utilityObj.xmlUtil.GetTextValue(nodename,
                Constants.FilePathNode);

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

            IEnumerable<ISequence> seqList = null;
            SparseSequence sparseSeq = null;
            XsvContigParser parserObj = new XsvContigParser(Alphabets.DNA, Constants.CharSeperator, Constants.SequenceIDPrefix);

            seqList = parserObj.Parse(filePathObj);
            sparseSeq = (SparseSequence)seqList.ElementAt(0);

            IReadOnlyList<IndexedItem<byte>> sparseSeqItems = sparseSeq.GetKnownSequenceItems();

            string tempFile = Path.GetTempFileName();

            XsvSparseFormatter formatterObj = new XsvSparseFormatter(Constants.CharSeperator, Constants.SequenceIDPrefix);
            switch (additionalParam)
            {
                case AdditionalParameters.FormatFilePath:
                    formatterObj.Format(sparseSeq, tempFile);
                    break;
                default:
                    break;
                case AdditionalParameters.ForamtListWithFilePath:
                    formatterObj.Format(seqList.ToList(), tempFile);
                    break;
            }
            XsvContigParser newParserObj = new XsvContigParser(Alphabets.DNA, Constants.CharSeperator, Constants.SequenceIDPrefix);
            // Parse a formatted Xsv file and validate.
            seqList = newParserObj.Parse(filePathObj);
            SparseSequence expectedSeq = (SparseSequence)seqList.ElementAt(0);

            IReadOnlyList<IndexedItem<byte>> expectedSparseSeqItems = expectedSeq.GetKnownSequenceItems();

            for (int i = 0; i < sparseSeqItems.Count; i++)
            {
                IndexedItem<byte> seqItem = sparseSeqItems[i];
                IndexedItem<byte> expectedSeqItem = expectedSparseSeqItems[i];
                Assert.AreEqual(seqItem.Index, expectedSeqItem.Index);
            }

            ApplicationLog.WriteLine("Successfully validated the format Xsv file");
        }
Esempio n. 5
0
        /// <summary>
        /// XsvSparse parser generic method called by all the test cases 
        /// to validate the test case based on the parameters passed.
        /// </summary>
        /// <param name="nodename">Xml node Name.</param>
        /// based on which the validation of  test case is done.</param>
        void XsvSparseParserGeneralTestCases(string nodename)
        {
            // Gets the expected file from the Xml
            string filePathObj = this.utilityObj.xmlUtil.GetTextValue(nodename,
                Constants.FilePathNode);

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

            IEnumerable<ISequence> seqList = null;
            SparseSequence sparseSeq = null;
            XsvContigParser parserObj = new XsvContigParser(Alphabets.DNA, Constants.CharSeperator, Constants.SequenceIDPrefix);

            string expectedSeqIds = this.utilityObj.xmlUtil.GetTextValue(nodename,
                Constants.SequenceIdNode);

            seqList = parserObj.Parse(filePathObj);
            sparseSeq = (SparseSequence)seqList.ElementAt(0);

            if (null == sparseSeq)
            {
                string expCount = this.utilityObj.xmlUtil.GetTextValue(nodename,
                    Constants.SequenceCountNode);

                Assert.IsNotNull(seqList);
                Assert.AreEqual(expCount, seqList.Count());
                ApplicationLog.WriteLine(string.Format((IFormatProvider)null,
                    "XsvSparse Parser BVT: Number of Sequences found are '{0}'.",
                    expCount));

                string[] expectedSeqIdArray = expectedSeqIds.Split(',');

                List<ISequence> sparseSeqList = seqList.ToList();
                for (int i = 0; i < expectedSeqIdArray.Length; i++)
                {
                    Assert.AreEqual(expectedSeqIdArray[i], sparseSeqList[i].ID);
                }
            }
            else
            {
                string[] idArray = expectedSeqIds.Split(',');
                Assert.AreEqual(sparseSeq.ID, idArray[0]);
            }

            ApplicationLog.WriteLine(
                "XsvSparse Parser BVT: The XsvSparse sequence is validated successfully with Parse() method.");

            Assert.IsNotNull(sparseSeq.Alphabet);
            Assert.AreEqual(sparseSeq.Alphabet.Name.ToLower(CultureInfo.InvariantCulture),
                this.utilityObj.xmlUtil.GetTextValue(nodename,
                Constants.AlphabetNameNode).ToLower(CultureInfo.InvariantCulture));

            ApplicationLog.WriteLine(string.Format((IFormatProvider)null,
                "XsvSparse Parser BVT: The Sequence Alphabet is '{0}' and is as expected.",
                sparseSeq.Alphabet.Name));
        }
Esempio n. 6
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");
        }
Esempio n. 7
0
        public void XsvContigFormatter()
        {
            // Gets the expected sequence from the Xml
            string filePathObj = Directory.GetCurrentDirectory() + XsvFilename;
            string xsvTempFileName = Path.GetTempFileName();
            Assert.IsTrue(File.Exists(filePathObj));

            // Read the contigs
            Contig contig = new XsvContigParser(Alphabets.DNA, ',', '#')
                .ParseContig(filePathObj);

            string seqId = contig.Sequences.Aggregate(string.Empty, (current, seq) => current + (seq.Sequence.ID + ","));

            // Format Xsv file.
            new XsvContigFormatter(',', '#')
                .Format(contig, xsvTempFileName);

            Contig expectedContig = new XsvContigParser(Alphabets.DNA, ',', '#')
                .ParseContig(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);
        }
Esempio n. 8
0
        /// <summary>
        /// XsvSparse formatter generic method called by all the test cases 
        /// to validate the test case based on the parameters passed.
        /// </summary>
        /// <param name="switchParam">Additional parameter 
        /// based on which the validation of  test case is done.</param>
        private void XsvSparseFormatterGeneralTestCases(string switchParam)
        {
            // Gets the expected sequence from the Xml
            string filePathObj = Directory.GetCurrentDirectory() + XsvFilename;

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

            XsvContigParser parserObj = new XsvContigParser(Alphabets.DNA, ',', '#');
            IEnumerable<ISequence> seqList = parserObj.Parse(filePathObj);
            SparseSequence sparseSeq = (SparseSequence) seqList.FirstOrDefault();

            var sparseSeqItems = sparseSeq.GetKnownSequenceItems();

            string xsvTempFileName = Path.GetTempFileName();
            XsvSparseFormatter formatterObj = new XsvSparseFormatter(',', '#');
            using (formatterObj.Open(xsvTempFileName))
            {
                switch (switchParam)
                {
                    case "FormatFilePath":
                        formatterObj.Format(sparseSeq);
                        break;
                    case "ForamtListWithFilePath":
                        formatterObj.Format(sparseSeq);
                        break;
                }
            }

            // Parse a formatted Xsv file and validate.
            var parserObj1 = new XsvContigParser(Alphabets.DNA, ',', '#');
            using (parserObj1.Open(xsvTempFileName))
            {
                seqList = parserObj1.Parse();
                SparseSequence expectedSeq = (SparseSequence)seqList.FirstOrDefault();

                var expectedSparseSeqItems = expectedSeq.GetKnownSequenceItems();

                Assert.AreEqual(sparseSeqItems.Count, expectedSparseSeqItems.Count);
                for (int i = 0; i < sparseSeqItems.Count; i++)
                {
                    Assert.AreEqual(sparseSeqItems.ElementAt(i).Index, expectedSparseSeqItems.ElementAt(i).Index);
                    Assert.AreEqual(sparseSeqItems.ElementAt(i).Item, expectedSparseSeqItems.ElementAt(i).Item);
                }

            }

            // Delete the temporary file.
            if (File.Exists(xsvTempFileName))
                File.Delete(xsvTempFileName);
        }
Esempio n. 9
0
        /// <summary>
        /// XsvSparse parser generic method called by all the test cases 
        /// to validate the test case based on the parameters passed.
        /// </summary>
        private void XsvSparseParserGeneralTestCases()
        {
            // Gets the expected sequence from the Xml
            string filePathObj = Directory.GetCurrentDirectory() + XsvFilename;

            Assert.IsTrue(File.Exists(filePathObj));
            XsvContigParser parserObj = new XsvContigParser(Alphabets.DNA, ',', '#');
            
            string expectedSeqIds = "Chr22+Chr22+Chr22+Chr22,m;Chr22;16,m;Chr22;17,m;Chr22;29,m;Chr22;32,m;Chr22;39,m;Chr22;54,m;Chr22;72,m;Chr22;82,m;Chr22;85,m;Chr22;96,m;Chr22;99,m;Chr22;118,m;Chr22;119,m;Chr22;129,m;Chr22;136,m;Chr22;146,m;Chr22;153,m;Chr22;161,m;Chr22;162,m;Chr22;174,m;Chr22;183,m;Chr22;209,m;Chr22;210,m;Chr22;224,m;Chr22;241,m;Chr22;243,m;Chr22;253,m;Chr22;267,m;Chr22;309,m;Chr22;310,m;Chr22;313,m;Chr22;331,m;Chr22;333,m;Chr22;338,m;Chr22;348,m;Chr22;352,m;Chr22;355,m;Chr22;357,m;Chr22;368,m;Chr22;370,m;Chr22;380,m;Chr22;382,m;Chr22;402,m;Chr22;418,m;Chr22;419,m;Chr22;429,m;Chr22;432,m;Chr22;450,m;Chr22;462,m;Chr22;482,m;Chr22;484,m;Chr22;485,m;Chr22;494,m;Chr22;508,m;Chr22;509,m;Chr22;512,";

            IEnumerable<ISequence> seqList = parserObj.Parse(filePathObj);
            SparseSequence sparseSeq = (SparseSequence) seqList.FirstOrDefault();
                 
            if (null == sparseSeq)
            {
                string expCount = "57";
                Assert.IsNotNull(seqList);
                Assert.AreEqual(expCount, seqList.ToList().Count);

                StringBuilder actualId = new StringBuilder();
                foreach (ISequence seq in seqList)
                {
                    SparseSequence sps = (SparseSequence)seq;
                    actualId.Append(sps.ID);
                    actualId.Append(",");
                }

                Assert.AreEqual(expectedSeqIds, actualId.ToString());
            }
            else
            {
                string[] idArray = expectedSeqIds.Split(',');
                Assert.AreEqual(sparseSeq.ID, idArray[0]);
            }

            string XsvTempFileName = Path.GetTempFileName();
            XsvSparseFormatter formatter = new XsvSparseFormatter(',', '#');
            using (formatter.Open(XsvTempFileName))
            {
                formatter.Format(seqList.ToList());
            }

            string expectedOutput = string.Empty;
            using (StreamReader readerSource = new StreamReader(filePathObj))
            {
                expectedOutput = readerSource.ReadToEnd();
            }

            string actualOutput = string.Empty;
            using (StreamReader readerDest = new StreamReader(XsvTempFileName))
            {
                actualOutput = readerDest.ReadToEnd();
            }
           
            Assert.AreEqual(expectedOutput.Replace("\r\n", System.Environment.NewLine), actualOutput);


            Assert.IsNotNull(sparseSeq.Alphabet);
            // Delete the temporary file.
            if (File.Exists(XsvTempFileName))
                File.Delete(XsvTempFileName);
        }