def yule(n): """ Returns a list of tuples containing all the shapes of n leaves that can be obtained under the Yule model and their corresponding probability. :param n: `int` instance. :return: `list` instance. """ for t, p in phylo_yule.yule(n): yield phylotree_to_shape(t), p
def yule_from_t(sh, prob): """ Returns a list of tuples containing each shape obtained from `Shape` sh (assuming sh has probability prob) with their associate probability under the Yule model. :param sh: `Shape` instance. :param prob: `function` instance. :return: `list` instance. """ for t, p in phylo_yule.yule_from_t(shape_to_phylotree(sh), prob): yield phylotree_to_shape(t), p
def cherry_picking(tree, k): if tree.is_leaf(): return [tree] elif tree == Shape.CHERRY: return [Shape.LEAF] else: def go(t, i, d): # for binary eyes only if d != k and not (t.is_leaf() or t.is_cherry()): chs = [go(ch, i, d + 1) for ch in t.children] if any(ch is None for ch in chs): return None else: return PhyloTree(None, sorted(chs)) elif d != k and (t == PhyloTree( None, [PhyloTree(i), PhyloTree(i + 1)]) or t == PhyloTree( None, [PhyloTree(i - 1), PhyloTree(i)])): return None elif d == k and (t == PhyloTree( None, [PhyloTree(i), PhyloTree(i + 1)]) or t == PhyloTree( None, [PhyloTree(i - 1), PhyloTree(i)])): return PhyloTree(i) elif t == PhyloTree(i): return None else: return t n = count_leaves(tree) phyl = shape_to_phylotree(tree, gen=int) ts = [] for i in range(n): t = go(phyl, i, 1) if t: ts.append(phylotree_to_shape(t)) return unique(sorted(ts))
def sim_yule_from_t(t): return phylotree_to_shape(phylo_yule.sim_yule_from_t( shape_to_phylotree(t)))
def sim_yule(n): return phylotree_to_shape(phylo_yule.sim_yule(n))