def foo_test_mc_trees(self): print 'testing mc trees:' k = 4 for i in range(4, 4 + k): print 'N:', i all_bifurcating_trees = splitalg.get_bifurcating_trees(i) all_quartets = splitalg.get_quartets(i) # get multifurcating trees using the nine rules mc_trees_ben = set(get_mc_trees_ben(i)) print 'number of mc trees using the nine rules:', len(mc_trees_ben) tree_set_sets_ben = set( frozenset(mc_tree_to_trees(tree, all_bifurcating_trees)) for tree in mc_trees_ben) print 'number of unique bifurcating tree sets generated by these mc trees:', len( tree_set_sets_ben) # get multifurcating trees using a naive method mc_trees = set(get_mc_trees(i)) print 'number of mc trees using a naive search:', len(mc_trees) tree_set_sets = set( frozenset(mc_tree_to_trees(tree, all_bifurcating_trees)) for tree in mc_trees) print 'number of unique bifurcating tree sets generated by these mc trees:', len( tree_set_sets) # compare subsets symmetric_difference = mc_trees_ben ^ mc_trees print 'number of trees in the symmetric difference set:', len( symmetric_difference) if mc_trees_ben - mc_trees: print 'an mc tree using the rules but not the naive:' print(mc_trees_ben - mc_trees).pop() if mc_trees - mc_trees_ben: print 'an mc tree using the naive but not the rules:' print(mc_trees - mc_trees_ben).pop() # Look for a naive mc tree that generates a set of bifurcating trees that # is not representable by a multiconnected tree constructed from the rules. weird_naive_mc_trees = set() for mc_tree in mc_trees: if frozenset(mc_tree_to_trees( mc_tree, all_bifurcating_trees)) not in tree_set_sets_ben: weird_naive_mc_trees.add(mc_tree) if weird_naive_mc_trees: weird_tree = weird_naive_mc_trees.pop() print 'a naive mc tree that represents a set of trees not representable by any real mc tree:' print weird_tree mytrees = set(all_bifurcating_trees) for split in weird_tree: mytrees = get_compatible_trees(split, mytrees) print len(mytrees), 'trees compatible with the weird tree:' for tree in mytrees: print tree # find the quartets implied by the trees quartets = get_splits_implied_by_trees(mytrees, all_quartets) print len( quartets ), 'quartets implied by the set of bifurcating trees:' for q in quartets: print q print
def foo_test_rules_trees(self): """ Count mc trees computed using the nine rules. """ print 'testing mc trees:' k = 5 for i in range(4, 4+k): print 'N:', i all_bifurcating_trees = splitalg.get_bifurcating_trees(i) print len(all_bifurcating_trees), 'bifurcating trees' mc_trees_ben = set(get_mc_trees_ben(i)) print len(mc_trees_ben), 'multiconnected trees' tree_set_sets_ben = set(frozenset(mc_tree_to_trees(tree, all_bifurcating_trees)) for tree in mc_trees_ben) print len(tree_set_sets_ben), 'induced sets of bifurcating trees' print
def foo_test_mc_trees(self): print 'testing mc trees:' k = 4 for i in range(4, 4+k): print 'N:', i all_bifurcating_trees = splitalg.get_bifurcating_trees(i) all_quartets = splitalg.get_quartets(i) # get multifurcating trees using the nine rules mc_trees_ben = set(get_mc_trees_ben(i)) print 'number of mc trees using the nine rules:', len(mc_trees_ben) tree_set_sets_ben = set(frozenset(mc_tree_to_trees(tree, all_bifurcating_trees)) for tree in mc_trees_ben) print 'number of unique bifurcating tree sets generated by these mc trees:', len(tree_set_sets_ben) # get multifurcating trees using a naive method mc_trees = set(get_mc_trees(i)) print 'number of mc trees using a naive search:', len(mc_trees) tree_set_sets = set(frozenset(mc_tree_to_trees(tree, all_bifurcating_trees)) for tree in mc_trees) print 'number of unique bifurcating tree sets generated by these mc trees:', len(tree_set_sets) # compare subsets symmetric_difference = mc_trees_ben ^ mc_trees print 'number of trees in the symmetric difference set:', len(symmetric_difference) if mc_trees_ben - mc_trees: print 'an mc tree using the rules but not the naive:' print (mc_trees_ben - mc_trees).pop() if mc_trees - mc_trees_ben: print 'an mc tree using the naive but not the rules:' print (mc_trees - mc_trees_ben).pop() # Look for a naive mc tree that generates a set of bifurcating trees that # is not representable by a multiconnected tree constructed from the rules. weird_naive_mc_trees = set() for mc_tree in mc_trees: if frozenset(mc_tree_to_trees(mc_tree, all_bifurcating_trees)) not in tree_set_sets_ben: weird_naive_mc_trees.add(mc_tree) if weird_naive_mc_trees: weird_tree = weird_naive_mc_trees.pop() print 'a naive mc tree that represents a set of trees not representable by any real mc tree:' print weird_tree mytrees = set(all_bifurcating_trees) for split in weird_tree: mytrees = get_compatible_trees(split, mytrees) print len(mytrees), 'trees compatible with the weird tree:' for tree in mytrees: print tree # find the quartets implied by the trees quartets = get_splits_implied_by_trees(mytrees, all_quartets) print len(quartets), 'quartets implied by the set of bifurcating trees:' for q in quartets: print q print
def foo_test_rules_trees(self): """ Count mc trees computed using the nine rules. """ print 'testing mc trees:' k = 5 for i in range(4, 4 + k): print 'N:', i all_bifurcating_trees = splitalg.get_bifurcating_trees(i) print len(all_bifurcating_trees), 'bifurcating trees' mc_trees_ben = set(get_mc_trees_ben(i)) print len(mc_trees_ben), 'multiconnected trees' tree_set_sets_ben = set( frozenset(mc_tree_to_trees(tree, all_bifurcating_trees)) for tree in mc_trees_ben) print len(tree_set_sets_ben), 'induced sets of bifurcating trees' print
def get_mc_trees(N): """ A multiconnected tree is a frozenset of <= N-3 splits. The splits must satisfy various properties. The splits must be compatible. No split in the set implies another split in the set. The set of trees compatible with the split set must not imply a split not individually implied by a split in the set. @param N: the number of leaves """ assert N > 3 nsplits = N - 3 # initialize the set of quartets and the set of informative splits given N leaves mh = MultiHelper(N) # get all possible bifurcating trees with N leaves trees = splitalg.get_bifurcating_trees(N) # try each combination of <= N-3 informative partial splits mc_trees = [] initial_split_set = set() initial_compatible_trees = set(trees) initial_offset = 0 get_mc_trees_helper(initial_split_set, initial_compatible_trees, initial_offset, mh, mc_trees) return mc_trees