Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_internal_name_removal():
tree = loads('((B:0.2,(C:0.3,D:0.4)E:0.5)F:0.1)A;')[0]
tree.remove_internal_names()
assert dumps(tree) == '((B:0.2,(C:0.3,D:0.4):0.5):0.1);'
def test_all_removal():
tree = loads('((B:0.2,(C:0.3,D:0.4)E:0.5)F:0.1)A;')[0]
tree.remove_names()
tree.remove_lengths()
topology_only = dumps(tree)
assert topology_only == '((,(,)));'
def test_dumps(*trees):
for ex in [
'(,,(,));',
'(A,B,(C,D));',
'(A,B,(C,D)E)F;',
'(:0.1,:0.2,(:0.3,:0.4):0.5);',
'((B:0.2,(C:0.3,D:0.4)E:0.5)F:0.1)A;',
]:
assert ex == dumps(loads(ex)[0])
def test_leaf_name_removal():
tree = loads('((B:0.2,(C:0.3,D:0.4)E:0.5)F:0.1)A;')[0]
tree.remove_leaf_names()
assert dumps(tree) == '((:0.2,(:0.3,:0.4)E:0.5)F:0.1)A;'
def test_length_removal():
tree = loads('((B:0.2,(C:0.3,D:0.4)E:0.5)F:0.1)A;')[0]
tree.remove_lengths()
assert dumps(tree) == '((B,(C,D)E)F)A;'
def test_name_removal():
tree = loads('((B:0.2,(C:0.3,D:0.4)E:0.5)F:0.1)A;')[0]
tree.remove_names()
assert dumps(tree) == '((:0.2,(:0.3,:0.4):0.5):0.1);'
# and will be pruned." % tree_type.capitalize())
# Get the tree looking nice
tree.remove_redundant_nodes()
tree.remove_internal_names()
if tree_type == "starting":
tree.resolve_polytomies()
# Remove lengths for a monophyly tree
if tree_type == "monophyly":
for n in tree.walk():
n._length = None
# Checks
if tree_type == "starting":
assert all(len(n.descendants) in (0, 2) for n in tree.walk())
assert len(tree.get_leaves()) == len(languages)
assert all(l.name for l in tree.get_leaves())
return newick.dumps(tree)