public void PhylogeneticTreeP1ParserValidateAllProperties() { // Gets the expected sequence from the Xml string filePath = _utilityObj.xmlUtil.GetTextValue(Constants.OneNodePhyloTreeNodeName, Constants.FilePathNode); Assert.IsTrue(File.Exists(filePath)); // Logs information to the log file ApplicationLog.WriteLine(string.Format((IFormatProvider)null, "Phylogenetic Tree Parser P1: File Exists in the Path '{0}'.", filePath)); using (NewickParser parser = new NewickParser()) { parser.Parse(filePath); string name = parser.Name; string fileTypes = parser.FileTypes; string description = parser.Description; Assert.AreEqual(Constants.ParserName, name); Assert.AreEqual(Constants.ParserFileTypes, fileTypes); Assert.AreEqual(Constants.ParserDescription, description); } ApplicationLog.WriteLine( "Phylogenetic Tree Parser P1: Validated all properties in Parser class."); // Logs to the NUnit GUI (Console.Out) window Console.WriteLine( "Phylogenetic Tree Parser P1: Validated all properties in Parser class."); }
public void TestNamesOnInternalNodes() { string filename = @"TestUtils\\positives.newick".TestDir(); var parser = new NewickParser(); var tree = parser.Parse(filename); Assert.AreEqual(3, tree.Root.Children.Count); }
public static void LoadTree(int treeIndex) { if (treeIndex >= 0 && treeIndex < TreeFiles.Length) { CurrentTreeFileName = TreeFiles[treeIndex].name; CurrentTreeIndex = treeIndex; Node.clearMaxDepth(); CurrentTree = NewickParser.Parse(NEWICK_RELATIVE_DIRECTORY_PATH + "/" + TreeFiles[treeIndex].name); if (CurrentTree != null) { DBQueries.ExtractMetaInformation(CurrentTree, CurrentTreeFileName + ".db"); } } }
/// <summary> /// General method to invalidate Newick Parser. /// <param name="nodeName">xml node name.</param> /// <param name="method">Newick Parse method parameters</param> /// </summary> void PhylogeneticTreeParserGeneralTests( string nodeName, AdditionalParameters method) { try { string filePath = _utilityObj.xmlUtil.GetTextValue( nodeName, Constants.FilePathNode); switch (method) { case AdditionalParameters.TextReader: using (StreamReader reader = File.OpenText(filePath)) { using (NewickParser nwParserObj = new NewickParser()) { nwParserObj.Parse(reader); } } break; case AdditionalParameters.StringBuilder: using (StreamReader reader = File.OpenText(filePath)) { StringBuilder strBuilderObj = new StringBuilder(reader.ReadToEnd()); using (NewickParser nwParserObj = new NewickParser()) { nwParserObj.Parse(strBuilderObj); } } break; default: break; } Assert.Fail(); } catch (FormatException) { ApplicationLog.WriteLine( "GFF Parser P2 : All the features validated successfully."); Console.WriteLine( "GFF Parser P2 : All the features validated successfully."); } }
public void PhylogeneticTreeP2ParserInvalidateParseBuilder() { try { using (NewickParser nwParserObj = new NewickParser()) { nwParserObj.Parse(null as StringBuilder); } Assert.Fail(); } catch (ArgumentNullException) { ApplicationLog.WriteLine( "GFF Parser P2 : All the features validated successfully."); } }
public void PhylogeneticTreeP1ParserValidateAllProperties() { NewickParser parser = new NewickParser(); { string name = parser.Name; string fileTypes = parser.SupportedFileTypes; string description = parser.Description; Assert.AreEqual(Constants.ParserName, name); Assert.AreEqual(Constants.ParserFileTypes, fileTypes); Assert.AreEqual(Constants.ParserDescription, description.Replace("\r\n", "\n")); } ApplicationLog.WriteLine( "Phylogenetic Tree Parser P1: Validated all properties in Parser class."); }
public void NewickFileTest() { // parse Perf.Start("Parsing..."); string filepath = @"TestData\PhylogeneticTree\tree.txt"; NewickParser parser = new NewickParser(); Tree phylogeneticTree = parser.Parse(filepath); Perf.End(); string outpath = @"TestData\PhylogeneticTree\out.txt"; Perf.Start("Formatting..."); NewickFormatter formatter = new NewickFormatter(); formatter.Format(phylogeneticTree, outpath); Perf.End(); Assert.AreEqual(true, FileCompare(filepath, outpath)); }
public void NewickStringTest() { StringBuilder input = new StringBuilder("(A:0.1,B:0.2,(C:0.3,D:0.4):0.5);"); // parse Perf.Start("Parsing..."); using (NewickParser parser = new NewickParser()) { Tree phylogeneticTree = parser.Parse(input); Perf.End(); Perf.Start("Formatting..."); NewickFormatter formatter = new NewickFormatter(); string output = formatter.FormatString(phylogeneticTree); Perf.End(); Assert.AreEqual(input.ToString(), output); } }
public void PhylogeneticTreeBvtParserValidateNewickExtended() { NewickParser parser = new NewickParser(); { using (var reader = File.OpenRead(@"TestUtils\NewickExtended.nhx".TestDir())) { Tree rootTree = parser.Parse(reader); //Verify metadata at root Assert.AreEqual("40", rootTree.Root.MetaData["N"]); //Verify name at root Assert.AreEqual("Euteleostomi", rootTree.Root.Name); //now verify it also worked for a somewhat arbitrary internal node var internalNode = rootTree.Root.Children.Keys.First().Children.Keys.First(); Assert.AreEqual("Tetrapoda", internalNode.Name); Assert.AreEqual("0.00044378", internalNode.MetaData["PVAL"]); Assert.AreEqual(8, internalNode.MetaData.Count); } } }
/// <summary> /// Phylogenetic Tree Formatter General Tests /// </summary> /// <param name="nodeName">Xml node Name.</param> /// <param name="formatParam">Additional parameter</param> void PhylogeneticTreeFormatterGeneralTests(string nodeName, FormatterParameters formatParam) { // Gets the expected sequence from the Xml string filePath = string.Empty; using (NewickParser parser = new NewickParser()) { Tree rootTree = null; switch (formatParam) { case FormatterParameters.Object: rootTree = GetFormattedObject(false); break; case FormatterParameters.ObjectSingleNode: rootTree = GetFormattedObject(true); break; case FormatterParameters.ParseTextReader: filePath = _utilityObj.xmlUtil.GetTextValue(nodeName, Constants.FilePathNode); Assert.IsTrue(File.Exists(filePath)); // Logs information to the log file ApplicationLog.WriteLine(string.Format((IFormatProvider)null, "Phylogenetic Tree Formatter P1: File Exists in the Path '{0}'.", filePath)); using (StreamReader reader = File.OpenText(filePath)) { rootTree = parser.Parse(reader); } break; case FormatterParameters.ParseStringBuilder: filePath = _utilityObj.xmlUtil.GetTextValue(nodeName, Constants.FilePathNode); Assert.IsTrue(File.Exists(filePath)); // Logs information to the log file ApplicationLog.WriteLine(string.Format((IFormatProvider)null, "Phylogenetic Tree Formatter P1: File Exists in the Path '{0}'.", filePath)); using (StreamReader reader = File.OpenText(filePath)) { StringBuilder strBuilderObj = new StringBuilder(reader.ReadToEnd()); rootTree = parser.Parse(strBuilderObj); } break; default: filePath = _utilityObj.xmlUtil.GetTextValue(nodeName, Constants.FilePathNode); Assert.IsTrue(File.Exists(filePath)); // Logs information to the log file ApplicationLog.WriteLine(string.Format((IFormatProvider)null, "Phylogenetic Tree Formatter P1: File Exists in the Path '{0}'.", filePath)); rootTree = parser.Parse(filePath); break; } string outputFilepath = _utilityObj.xmlUtil.GetTextValue(nodeName, Constants.OutputFilePathNode); NewickFormatter format = new NewickFormatter(); switch (formatParam) { case FormatterParameters.TextWriter: using (TextWriter writer = new StreamWriter(outputFilepath)) { format.Format(rootTree, writer); } break; case FormatterParameters.FormatString: // Validate format String string formatString = format.FormatString(rootTree); string expectedFormatString = _utilityObj.xmlUtil.GetTextValue(nodeName, Constants.FormatStringNode); Assert.AreEqual(expectedFormatString, formatString); ApplicationLog.WriteLine(string.Format((IFormatProvider)null, "Phylogenetic Tree Formatter P1: Format string '{0}' is as expected.", formatString)); Console.WriteLine(string.Format((IFormatProvider)null, "Phylogenetic Tree Formatter P1: Format string '{0}' is as expected.", formatString)); break; default: format.Format(rootTree, outputFilepath); break; } // Validate only if not a Format String if (FormatterParameters.FormatString != formatParam) { // Re-parse the created file and validate the tree. using (NewickParser newparserObj = new NewickParser()) { Tree newrootTreeObj = null; Assert.IsTrue(File.Exists(outputFilepath)); // Logs information to the log file ApplicationLog.WriteLine(string.Format((IFormatProvider)null, "Phylogenetic Tree Formatter P1: New File Exists in the Path '{0}'.", outputFilepath)); newrootTreeObj = newparserObj.Parse(outputFilepath); Node rootNode = newrootTreeObj.Root; string rootBranchCount = _utilityObj.xmlUtil.GetTextValue(nodeName, Constants.RootBranchCountNode); // Validate the root branch count Assert.AreEqual(rootBranchCount, rootNode.Children.Count.ToString((IFormatProvider)null)); ApplicationLog.WriteLine(string.Format((IFormatProvider)null, "Phylogenetic Tree Formatter P1: Number of Root Branches found are '{0}'.", rootNode.Children.Count.ToString((IFormatProvider)null))); List <string> leavesName = new List <string>(); List <double> leavesDistance = new List <double>(); // Gets all the leaves in the root node list GetAllNodesAndEdges(rootNode, ref leavesName, ref leavesDistance); string[] expectedLeavesName = _utilityObj.xmlUtil.GetTextValue(nodeName, Constants.NodeNamesNode).Split(','); string[] expectedLeavesDistance = _utilityObj.xmlUtil.GetTextValue(nodeName, Constants.EdgeDistancesNode).Split(','); for (int i = 0; i < expectedLeavesName.Length; i++) { Assert.AreEqual(expectedLeavesName[i], leavesName[i]); } for (int i = 0; i < expectedLeavesDistance.Length; i++) { Assert.AreEqual(expectedLeavesDistance[i], leavesDistance[i].ToString((IFormatProvider)null)); } ApplicationLog.WriteLine( "Phylogenetic Tree Parser P1: The Node Names and Distance are as expected."); // Logs to the NUnit GUI (Console.Out) window Console.WriteLine( "Phylogenetic Tree Parser P1: The Node Names and Distance are as expected."); } if (File.Exists(outputFilepath)) { File.Delete(outputFilepath); } } } }
/// <summary> /// Phylogenetic Tree Parsers General Tests /// </summary> /// <param name="nodeName">Xml node Name.</param> /// <param name="addParam">Additional parameter</param> void PhylogeneticTreeParserGeneralTests(string nodeName, AdditionalParameters addParam) { // Gets the expected sequence from the Xml string filePath = _utilityObj.xmlUtil.GetTextValue(nodeName, Constants.FilePathNode); Assert.IsTrue(File.Exists(filePath)); // Logs information to the log file ApplicationLog.WriteLine(string.Format((IFormatProvider)null, "Phylogenetic Tree Parser P1: File Exists in the Path '{0}'.", filePath)); using (NewickParser parser = new NewickParser()) { Tree rootTree = null; switch (addParam) { case AdditionalParameters.TextReader: using (StreamReader reader = File.OpenText(filePath)) { rootTree = parser.Parse(reader); } break; case AdditionalParameters.StringBuilder: using (StreamReader reader = File.OpenText(filePath)) { StringBuilder strBuilderObj = new StringBuilder( reader.ReadToEnd()); rootTree = parser.Parse(strBuilderObj); } break; default: rootTree = parser.Parse(filePath); break; } Node rootNode = rootTree.Root; string rootBranchCount = _utilityObj.xmlUtil.GetTextValue(nodeName, Constants.RootBranchCountNode); // Validate the root branch count Assert.AreEqual(rootBranchCount, rootNode.Children.Count.ToString((IFormatProvider)null)); ApplicationLog.WriteLine(string.Format((IFormatProvider)null, "Phylogenetic Tree Parser P1: Number of Root Branches found are '{0}'.", rootNode.Children.Count.ToString((IFormatProvider)null))); List <string> leavesName = new List <string>(); List <double> leavesDistance = new List <double>(); // Gets all the leaves in the root node list GetAllNodesAndEdges(rootNode, ref leavesName, ref leavesDistance); string[] expectedLeavesName = _utilityObj.xmlUtil.GetTextValue(nodeName, Constants.NodeNamesNode).Split(','); string[] expectedLeavesDistance = _utilityObj.xmlUtil.GetTextValue(nodeName, Constants.EdgeDistancesNode).Split(','); for (int i = 0; i < expectedLeavesName.Length; i++) { Assert.AreEqual(expectedLeavesName[i], leavesName[i]); } for (int i = 0; i < expectedLeavesDistance.Length; i++) { Assert.AreEqual(expectedLeavesDistance[i], leavesDistance[i].ToString((IFormatProvider)null)); } } ApplicationLog.WriteLine( "Phylogenetic Tree Parser P1: The Node Names and Distance are as expected."); // Logs to the NUnit GUI (Console.Out) window Console.WriteLine( "Phylogenetic Tree Parser P1: The Node Names and Distance are as expected."); }