def testBasicDocumentFromInit(self): test_dataset = dendropy.DataSet(stream=pathmap.tree_source_stream( datagen.reference_trees_filename(schema="newick")), schema="newick") self.assertDistinctButEqual(self.reference_dataset, test_dataset, ignore_taxon_order=True)
def testBasicDocumentParseFromReader(self): reader = newick.NewickReader() test_dataset = reader.read(stream=pathmap.tree_source_stream( datagen.reference_trees_filename(schema="newick"))) self.assertDistinctButEqual(self.reference_dataset, test_dataset, ignore_taxon_order=True)
def testReferenceTreeFileDistinctTaxa(self): ref_tree_list = datagen.reference_tree_list() t_tree_list = dendropy.TreeList.get_from_stream(pathmap.tree_source_stream(datagen.reference_trees_filename(schema="nexus")), "nexus") self.assertDistinctButEqualTreeList( ref_tree_list, t_tree_list, distinct_taxa=True, equal_oids=None)
def testReferenceTreeFileSameTaxa(self): ref_tree_list = datagen.reference_tree_list() t_tree_list = dendropy.TreeList.get_from_stream(pathmap.tree_source_stream("pythonidae.reference-trees.no-taxa-block.nexus"), "nexus", taxon_set=ref_tree_list.taxon_set) self.assertDistinctButEqualTreeList( ref_tree_list, t_tree_list, distinct_taxa=False, equal_oids=None)
def testNexusDistinctTaxa(self): stream = pathmap.tree_source_stream( datagen.reference_trees_filename(schema="nexus")) for idx, test_tree in enumerate( dataio.tree_source_iter(stream=stream, schema='nexus/newick')): self.assertDistinctButEqualTree(self.ref_tree_list[idx], test_tree, distinct_taxa=True)
def testReferenceTreeFileNoTaxaBlockNoTranslateBlockSameTaxa(self): ref_tree_list = datagen.reference_tree_list() reader = dataio.get_reader("nexus", taxon_set=ref_tree_list.taxon_set) dataset = reader.read( stream=pathmap.tree_source_stream("pythonidae.reference-trees.no-taxa-no-translate-block.nexus") ) self.assertEqual(len(dataset.tree_lists), 1) self.assertDistinctButEqualTreeList(ref_tree_list, dataset.tree_lists[0], distinct_taxa=False, equal_oids=None)
def testReferenceTreeFileNoTaxaBlockNoTranslateBlockDistinctTaxa(self): ref_tree_list = datagen.reference_tree_list() t_tree_list = dendropy.TreeList.get_from_stream(pathmap.tree_source_stream("pythonidae.reference-trees.no-taxa-no-translate-block.nexus"), "nexus") self.assertDistinctButEqualTreeList( ref_tree_list, t_tree_list, distinct_taxa=True, equal_oids=None)
def testReferenceTreeFileNoTaxaBlockDistinctTaxa(self): ref_tree_list = datagen.reference_tree_list() t_tree_list = dendropy.TreeList.get_from_stream( pathmap.tree_source_stream( "pythonidae.reference-trees.no-taxa-block.nexus"), "nexus") self.assertDistinctButEqualTreeList(ref_tree_list, t_tree_list, distinct_taxa=True, equal_oids=None)
def testReferenceTreeFileDistinctTaxa(self): ref_tree_list = datagen.reference_tree_list() t_tree_list = dendropy.TreeList.get_from_stream( pathmap.tree_source_stream( datagen.reference_trees_filename(schema="nexus")), "nexus") self.assertDistinctButEqualTreeList(ref_tree_list, t_tree_list, distinct_taxa=True, equal_oids=None)
def test_ultrametric(self): trees = dendropy.TreeList.get_from_stream(pathmap.tree_source_stream("pythonidae.reference-trees.nexus"), "nexus") for tree in trees: dists = tree.calc_node_root_distances() min_dist, max_dist = tree.minmax_leaf_distance_from_root() trunc_dists = [(max_dist * f) for f in (0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9)] for td in trunc_dists: num_lineages = tree.num_lineages_at(td) self.check_tree(tree, td, num_lineages)
def testReferenceTreeFileNoTaxaBlockNoTranslateBlockSameTaxa(self): ref_tree_list = datagen.reference_tree_list() reader = dataio.get_reader('nexus', taxon_set=ref_tree_list.taxon_set) dataset = reader.read(stream=pathmap.tree_source_stream( "pythonidae.reference-trees.no-taxa-no-translate-block.nexus")) self.assertEqual(len(dataset.tree_lists), 1) self.assertDistinctButEqualTreeList(ref_tree_list, dataset.tree_lists[0], distinct_taxa=False, equal_oids=None)
def testReferenceTreeFileDistinctTaxa(self): ref_tree_list = datagen.reference_tree_list() reader = dataio.get_reader('nexus') dataset = reader.read(stream=pathmap.tree_source_stream( datagen.reference_trees_filename(schema="nexus"))) self.assertEqual(len(dataset.tree_lists), 1) self.assertDistinctButEqualTreeList(ref_tree_list, dataset.tree_lists[0], distinct_taxa=True, equal_oids=None)
def testReferenceTreeFileNoTaxaBlockDistinctTaxa(self): ref_tree_list = datagen.reference_tree_list() reader = dataio.get_reader('nexus') dataset = reader.read(stream=pathmap.tree_source_stream("pythonidae.reference-trees.no-taxa-block.nexus")) self.assertEqual(len(dataset.tree_lists), 1) self.assertDistinctButEqualTreeList( ref_tree_list, dataset.tree_lists[0], distinct_taxa=True, equal_oids=None)
def testReferenceTreeFileDistinctTaxa(self): ref_tree_list = datagen.reference_tree_list() reader = dataio.get_reader('nexus') dataset = reader.read(stream=pathmap.tree_source_stream(datagen.reference_trees_filename(schema="nexus"))) self.assertEqual(len(dataset.tree_lists), 1) self.assertDistinctButEqualTreeList( ref_tree_list, dataset.tree_lists[0], distinct_taxa=True, equal_oids=None)
def test_ultrametric(self): trees = dendropy.TreeList.get_from_stream( pathmap.tree_source_stream("pythonidae.reference-trees.nexus"), "nexus") for tree in trees: dists = tree.calc_node_root_distances() min_dist, max_dist = tree.minmax_leaf_distance_from_root() trunc_dists = [(max_dist * f) for f in (0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9)] for td in trunc_dists: num_lineages = tree.num_lineages_at(td) self.check_tree(tree, td, num_lineages)
def setUp(self): self.trees = dendropy.TreeList.get_from_stream(pathmap.tree_source_stream("pythonidae.reference-trees.nexus"), "nexus")
def testNewickSameTaxa(self): stream = pathmap.tree_source_stream(datagen.reference_trees_filename(schema="newick")) for idx, test_tree in enumerate(dataio.tree_source_iter(stream=stream, schema='nexus/newick', taxon_set=self.ref_tree_list.taxon_set)): self.assertDistinctButEqualTree(self.ref_tree_list[idx], test_tree, distinct_taxa=False)
def testNewickDistinctTaxa(self): stream = pathmap.tree_source_stream(datagen.reference_trees_filename(schema="newick")) for idx, test_tree in enumerate(dataio.tree_source_iter(stream=stream, schema='nexus/newick')): self.assertDistinctButEqualTree(self.ref_tree_list[idx], test_tree, distinct_taxa=True, ignore_taxon_order=True)
def main(): tlist = dendropy.TreeList(stream=pathmap.tree_source_stream(datagen.reference_trees_filename("nexus")), schema="nexus") for idx, t in enumerate(tlist): t.label = "Tree%02d" % (idx+1) t.assign_node_labels_from_taxon_or_oid() result = [] result.append("def reference_tree_list_postorder_node_labels():") result.append(" return [") for t in tlist: nodes = [("'" + nd.label + "'") for nd in t.postorder_node_iter()] result.append(" [%s]," % (",".join(nodes))) result.append(" ]") result.append("") result.append("def reference_tree_list_newick_string(taxon_set=None):") result.append(' return """\\') for t in tlist: result.append(' %s;' % t.as_newick_string(include_internal_labels=True)) result.append(' """') result.append("") result.append("def reference_tree_list_node_relationships():") result.append(" treelist_node_references = [") for t in tlist: result.append(" {") for nd in t: if nd.parent_node is not None: pn_label = "'" + nd.parent_node.label + "'" else: pn_label = 'None' if nd.taxon is not None: t_label = "'" + nd.taxon.label + "'" else: t_label = 'None' result.append(" '%s' : NodeRelationship(parent_label=%s, child_labels=[%s], edge_length=%s, taxon_label=%s)," % \ (nd.label, pn_label, ",".join(["'"+c.label+"'" for c in nd.child_nodes()]), nd.edge.length, t_label)) result.append(" },") result.append(" ]") result.append(" return treelist_node_references") result.append("") tree_list_name = 'tree_list' src_lines = tlist.as_python_source(tree_list_name=tree_list_name, oids=True).split("\n") result.append("def reference_tree_list(taxon_set=None):") src_lines[0] = re.sub("(dendropy\.TreeList\(label\=.*)\)", "\g<1>, taxon_set=taxon_set)", src_lines[0]) for s in src_lines: result.append(" %s" % s) result.append("""\ # set labels of nodes with taxa to taxon label, else oid (for consistent # identification in debugging) for t in %s: t.assign_node_labels_from_taxon_or_oid() return %s """ % (tree_list_name, tree_list_name)) result.append("") sys.stdout.write("\n".join(result))
def setUp(self): s = pathmap.tree_source_stream("pythonidae.annotated.nexml") self.dataset = dendropy.DataSet.get_from_stream(s, "nexml")
def testReadSummaryTree(self): tree = dendropy.Tree.get_from_stream(pathmap.tree_source_stream('pythonidae.beast.summary.tre'), 'beast-summary-tree') self.verify_node_info(tree)
def testBasicDocumentFromInit(self): test_dataset = dendropy.DataSet(stream=pathmap.tree_source_stream(datagen.reference_trees_filename(schema="newick")), schema="newick") self.assertDistinctButEqual(self.reference_dataset, test_dataset, ignore_taxon_order=True)
def testBasicDocumentParseFromReader(self): reader = newick.NewickReader() test_dataset = reader.read(stream=pathmap.tree_source_stream(datagen.reference_trees_filename(schema="newick"))) self.assertDistinctButEqual(self.reference_dataset, test_dataset, ignore_taxon_order=True)
def setUp(self): self.trees = dendropy.TreeList.get_from_stream( pathmap.tree_source_stream("pythonidae.reference-trees.nexus"), "nexus")
def testParseNexmlAnnotations(self): s = pathmap.tree_source_stream("treebase_s373.xml") dataset = dendropy.DataSet(stream=s, schema="nexml") self.verify_dataset(dataset)
def testSummaryTreeIter(self): stream = pathmap.tree_source_stream('pythonidae.beast.summary.tre') for tree in dendropy.tree_source_iter(stream, 'beast-summary-tree'): self.verify_node_info(tree)
def main(): tlist = dendropy.TreeList(stream=pathmap.tree_source_stream( datagen.reference_trees_filename("nexus")), schema="nexus") for idx, t in enumerate(tlist): t.label = "Tree%02d" % (idx + 1) t.assign_node_labels_from_taxon_or_oid() result = [] result.append("def reference_tree_list_postorder_node_labels():") result.append(" return [") for t in tlist: nodes = [("'" + nd.label + "'") for nd in t.postorder_node_iter()] result.append(" [%s]," % (",".join(nodes))) result.append(" ]") result.append("") result.append("def reference_tree_list_newick_string(taxon_set=None):") result.append(' return """\\') for t in tlist: result.append(' %s;' % t.as_newick_string(include_internal_labels=True)) result.append(' """') result.append("") result.append("def reference_tree_list_node_relationships():") result.append(" treelist_node_references = [") for t in tlist: result.append(" {") for nd in t: if nd.parent_node is not None: pn_label = "'" + nd.parent_node.label + "'" else: pn_label = 'None' if nd.taxon is not None: t_label = "'" + nd.taxon.label + "'" else: t_label = 'None' result.append(" '%s' : NodeRelationship(parent_label=%s, child_labels=[%s], edge_length=%s, taxon_label=%s)," % \ (nd.label, pn_label, ",".join(["'"+c.label+"'" for c in nd.child_nodes()]), nd.edge.length, t_label)) result.append(" },") result.append(" ]") result.append(" return treelist_node_references") result.append("") tree_list_name = 'tree_list' src_lines = tlist.as_python_source(tree_list_name=tree_list_name, oids=True).split("\n") result.append("def reference_tree_list(taxon_set=None):") src_lines[0] = re.sub("(dendropy\.TreeList\(label\=.*)\)", "\g<1>, taxon_set=taxon_set)", src_lines[0]) for s in src_lines: result.append(" %s" % s) result.append("""\ # set labels of nodes with taxa to taxon label, else oid (for consistent # identification in debugging) for t in %s: t.assign_node_labels_from_taxon_or_oid() return %s """ % (tree_list_name, tree_list_name)) result.append("") sys.stdout.write("\n".join(result))