-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest_dendropy.py
executable file
·34 lines (27 loc) · 1.15 KB
/
test_dendropy.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#! /usr/bin/env python
from dendropy import Tree, TaxonNamespace
def node_label_method(tree, outgroup):
'''Interpret node labels as node attributes (default).'''
outgroup_node = tree.find_node_with_taxon_label(outgroup)
new_root = outgroup_node.parent_node
tree.reseed_at(new_root)
return tree
def rooted_bipartition_method(tree, outgroup):
'''Interpret node labels as branch support values.'''
benc = tree.encode_bipartitions()
support_values = {}
for nd in tree:
support_values[nd.bipartition] = float(nd.label) if nd.label is not None else 1.0
outgroup_node = tree.find_node_with_taxon_label(outgroup)
new_root = outgroup_node.parent_node
tree.reseed_at(new_root)
tree.encode_bipartitions()
for nd in tree:
nd.label = support_values.get(nd.bipartition, "not_specified")
tree.seed_node.edge.length = None
return tree
tree = Tree.get(file=open('test.nw'), schema="newick")#, rooting="force-rooted")
rooted_bipartition_method(tree, 'X')
nw = tree.as_string(schema='newick').strip()
print nw.replace('[&R] ', '')
# Related discussion: https://github.com/jeetsukumaran/DendroPy/issues/53