def test_ibifurcation_point_upstream(): leaves = [l for l in ileaf(REF_TREE2)] ref_paths = [[11, 0], [11, 0], [11, 0], [11, 0], [1211, 12, 0], [1211, 12, 0], [12, 0]] for l, ref in zip(leaves, ref_paths): nt.assert_equal( [s for s in val_iter(ibifurcation_point(l, iupstream))], ref)
def test_ibifurcation_point_upstream(): leaves = [l for l in ileaf(REF_TREE2)] ref_paths = [ [11, 0], [11, 0], [11, 0], [11, 0], [1211, 12, 0], [1211, 12, 0], [12, 0] ] for l, ref in zip(leaves, ref_paths): nt.assert_equal([s for s in val_iter(ibifurcation_point(l, iupstream))], ref)
def i_remote_bifurcation_angle(tree): '''Return the opening angle between the last segments of two out-going sections of a bifurcation point ''' def _remangle(t): '''Helper to calculate the remote angle''' end_points = tuple(p for p in tr.i_branch_end_points(t)) return mm.angle_3points(t.value, end_points[0].value, end_points[1].value) return imap(_remangle, tr.ibifurcation_point(tree))
def partition(tree): '''Measures the distribution of sections to the children subtrees at each bifurcation point. Partition is defined as the max/min number of sections between the children subtrees of a bifurcation point. Returns: List of partition for each bifurcation point. ''' def partition_at_point(bif_point): '''Partition at each bif point.''' n = n_sections(bif_point.children[0]) m = n_sections(bif_point.children[1]) return max(n, m) / min(n, m) return [partition_at_point(i) for i in tr.ibifurcation_point(tree)]
def test_valiter_bifurcation_point(): nt.ok_(list(val_iter(ibifurcation_point(REF_TREE2))) == [0, 11, 12, 1211])
def test_ibifurcation_point_postorder(): nt.assert_equal([n.value for n in ibifurcation_point(REF_TREE2, ipostorder)], [11, 1211, 12, 0])
def test_ibifurcation_point(): nt.assert_equal([n.value for n in ibifurcation_point(REF_TREE2)], [0, 11, 12, 1211])
def n_bifurcations(tree): """ Return number of bifurcations in tree """ return sum(1 for _ in tr.ibifurcation_point(tree))
def i_local_bifurcation_angle(tree): '''Return the opening angle between two out-going segments in a bifurcation point ''' return imap(local_bifurcation_angle, tr.ibifurcation_point(tree))
def test_ibifurcation_point_postorder(): nt.assert_equal( [n.value for n in ibifurcation_point(REF_TREE2, ipostorder)], [11, 1211, 12, 0])