def get_trees(tree_type, tree_size, tree_path): if tree_type == "binary": tree = utils.balanced_binary(tree_size) elif tree_type == "catepillar": tree = utils.lopsided_tree(tree_size) elif tree_type == "birthdeath": tree = utils.unrooted_birth_death_tree(tree_size) elif tree_type == "kingman": tree = utils.unrooted_pure_kingman_tree(tree_size) elif tree_type == "path": tree = dendropy.Tree.get(path=args.path, schema="nexus") return tree
import sys, os sys.path.append(os.path.join(os.path.dirname(sys.path[0]), 'spectraltree')) sys.path.append(os.path.join(sys.path[0], 'spectraltree')) import utils import generation import reconstruct_tree N = 1000 num_taxa = 256 jc = generation.Jukes_Cantor() mutation_rate = [jc.p2t(0.95)] # Construct data of type 'tree' from class dendropy namespace = utils.default_namespace(num_taxa) tree = utils.unrooted_birth_death_tree(num_taxa, birth_rate=1) for x in tree.preorder_edge_iter(): x.length = 1 #tree = utils.lopsided_tree(num_taxa=num_taxa, namespace=namespace) #tree = utils.balanced_binary(num_taxa, namespace=namespace) tree.is_rooted = True for i in tree.bipartition_edge_map: if tree.bipartition_edge_map[i] == tree.seed_node.child_edges()[0]: taxa_half1 = set(i.leafset_taxa(tree.taxon_namespace)) if tree.bipartition_edge_map[i] == tree.seed_node.child_edges()[1]: taxa_half2 = set(i.leafset_taxa(tree.taxon_namespace)) tree.is_rooted = False #taxa_half1 = set([taxon for taxon in tree.taxon_namespace if int(taxon.label)<num_taxa/2]) #taxa_half2 = set([taxon for taxon in tree.taxon_namespace if int(taxon.label)>=num_taxa/2])