def generateCoalescentTrees(choice, num, fout, length): if choice == 1: sp_tree_str = """\ [&R] ((((((((A,B)%d,C)%d,D)%d,E)%d,F)%d,G)%d,H)%d); """ % (float(length),float(length),float(length),float(length),float(length),float(length),float(length)) elif choice == 2: sp_tree_str = """\ [&R] ((((((((A,B)%d,C)%d,D)%d,E)%d,F)%d,G)%d,H)%d); """ % (float(length),float(length),float(length),float(length),float(length),float(length),float(length)) sp_tree = dendropy.Tree.get_from_string(sp_tree_str, "newick") gene_to_species_map = dendropy.TaxonNamespaceMapping.create_contained_taxon_mapping( containing_taxon_namespace=sp_tree.taxon_namespace, num_contained=1) gene_tree_list = TreeList() for i in range(num): gene_tree = treesim.contained_coalescent_tree(containing_tree=sp_tree, gene_to_containing_taxon_map=gene_to_species_map) treesim.contained_coalescent_tree(containing_tree=sp_tree, gene_to_containing_taxon_map=gene_to_species_map) for t in gene_tree.leaf_nodes(): t.taxon.label = t.taxon.label.split( )[0] gene_tree_list.append(gene_tree) gene_tree_list.write_to_path(fout, 'newick')
def contained_coalescent(*args, **kwargs): deprecate.dendropy_deprecation_warning( preamble="Deprecated since DendroPy 4: The 'dendropy.treesim.contained_coalescent()' function has moved to 'dendropy.simulate.treesim.contained_coalescent_tree()'.", old_construct="from dendropy import treesim\ntree = treesim.contained_coalescent(...)", new_construct="from dendropy.simulate import treesim\ntree = treesim.contained_coalescent_tree(...)", ) return treesim.contained_coalescent_tree(*args, **kwargs)
def contained_coalescent(*args, **kwargs): deprecate.dendropy_deprecation_warning( preamble= "Deprecated since DendroPy 4: The 'dendropy.treesim.contained_coalescent()' function has moved to 'dendropy.simulate.treesim.contained_coalescent_tree()'.", old_construct= "from dendropy import treesim\ntree = treesim.contained_coalescent(...)", new_construct= "from dendropy.simulate import treesim\ntree = treesim.contained_coalescent_tree(...)" ) return treesim.contained_coalescent_tree(*args, **kwargs)
#! /usr/bin/env python # -*- coding: utf-8 -*- import dendropy from dendropy.simulate import treesim sp_tree_str = """\ [&R] (A:10,(B:6,(C:4,(D:2,E:2):2):2):4); """ sp_tree = dendropy.Tree.get(data=sp_tree_str, schema="newick") gene_to_species_map = dendropy.TaxonNamespaceMapping.create_contained_taxon_mapping( containing_taxon_namespace=sp_tree.taxon_namespace, num_contained=3) gene_tree = treesim.contained_coalescent_tree(containing_tree=sp_tree, gene_to_containing_taxon_map=gene_to_species_map) print(gene_tree.as_string(schema='newick')) print(gene_tree.as_ascii_plot())
genes_to_species = dendropy.TaxonNamespaceMapping.create_contained_taxon_mapping( containing_taxon_namespace=containing_taxa, num_contained=8) # convert to containing tree stepwise_tree = reconcile.ContainingTree(stepwise_tree, contained_taxon_namespace=genes_to_species.domain_taxon_namespace, contained_to_containing_taxon_map=genes_to_species) frag_tree = reconcile.ContainingTree(frag_tree, contained_taxon_namespace=genes_to_species.domain_taxon_namespace, contained_to_containing_taxon_map=genes_to_species) # for each rep for rep in range(num_reps): gene_tree1 = treesim.contained_coalescent_tree(containing_tree=stepwise_tree, gene_to_containing_taxon_map=genes_to_species, default_pop_size=40000) stepwise_tree.embed_tree(gene_tree1) gene_tree2 = treesim.contained_coalescent_tree(containing_tree=frag_tree, gene_to_containing_taxon_map=genes_to_species, default_pop_size=40000) frag_tree.embed_tree(gene_tree2) # write results # returns dictionary with contained trees as keys # and number of deep coalescences as values stepwise_deep_coals = stepwise_tree.deep_coalescences() stepwise_out = open("stepwise.txt", "w") for tree in stepwise_deep_coals: stepwise_out.write("%d\n" % stepwise_deep_coals[tree])
#! /usr/bin/env python import dendropy from dendropy.simulate import treesim sp_tree_str = """\ [&R] (A:10,(B:6,(C:4,(D:2,E:2):2):2):4); """ sp_tree = dendropy.Tree.get(data=sp_tree_str, schema="newick") gene_to_species_map = dendropy.TaxonNamespaceMapping.create_contained_taxon_mapping( containing_taxon_namespace=sp_tree.taxon_namespace, num_contained=[ 3, 4, 6, 2, 2, ]) gene_tree = treesim.contained_coalescent_tree( containing_tree=sp_tree, gene_to_containing_taxon_map=gene_to_species_map) print(gene_tree.as_string(schema='newick')) print(gene_tree.as_ascii_plot())
#! /usr/bin/env python import sys import dendropy from dendropy.simulate import treesim species_tree_file_name = sys.argv[1] population_size = int(sys.argv[2]) sample_size = int(sys.argv[3]) species_tree = dendropy.Tree.get_from_path(species_tree_file_name, "nexus") gene_to_species_map = dendropy.TaxonNamespaceMapping.create_contained_taxon_mapping(containing_taxon_namespace=species_tree.taxon_namespace, num_contained=sample_size) gene_tree = treesim.contained_coalescent_tree(containing_tree=species_tree, gene_to_containing_taxon_map=gene_to_species_map, default_pop_size=population_size) print(gene_tree.as_string(schema='newick'))
# convert to containing tree stepwise_tree = reconcile.ContainingTree( stepwise_tree, contained_taxon_namespace=genes_to_species.domain_taxon_namespace, contained_to_containing_taxon_map=genes_to_species, ) frag_tree = reconcile.ContainingTree( frag_tree, contained_taxon_namespace=genes_to_species.domain_taxon_namespace, contained_to_containing_taxon_map=genes_to_species, ) # for each rep for rep in range(num_reps): gene_tree1 = treesim.contained_coalescent_tree( containing_tree=stepwise_tree, gene_to_containing_taxon_map=genes_to_species, default_pop_size=40000 ) stepwise_tree.embed_tree(gene_tree1) gene_tree2 = treesim.contained_coalescent_tree( containing_tree=frag_tree, gene_to_containing_taxon_map=genes_to_species, default_pop_size=40000 ) frag_tree.embed_tree(gene_tree2) # write results # returns dictionary with contained trees as keys # and number of deep coalescences as values stepwise_deep_coals = stepwise_tree.deep_coalescences() stepwise_out = open("stepwise.txt", "w") for tree in stepwise_deep_coals: stepwise_out.write("%d\n" % stepwise_deep_coals[tree])