def displayed_subtree(tree, labels): #this is annoying, but Dendropy can consider the labels not matching depending on #underscore vs. space issues #Realized that using retain_taxa vs prune_taxa doesn't make any difference - dendropy #used prune behind the scenes regardless #DP3 vs. DP4 if hasattr(tree, 'taxon_namespace'): newtree = Tree(tree, taxon_namespace=tree.taxon_namespace) else: newtree = Tree(tree, taxon_set=tree.taxon_set) if isinstance(labels[0], str): newtree.retain_taxa_with_labels(labels) else: newtree.retain_taxa(labels) #compat_encode_bipartitions now maps delete_outdegree_one to collapse_unrooted_basal_bifurcation in DP 4 compat_encode_bipartitions(newtree, delete_outdegree_one=False) return newtree