Skip to content

Instantly share code, notes, and snippets.

@clarle
Created June 29, 2016 13:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save clarle/ae158f005380576b92ad9ee3847589d9 to your computer and use it in GitHub Desktop.
Save clarle/ae158f005380576b92ad9ee3847589d9 to your computer and use it in GitHub Desktop.
Generate simulated phylogenetic data using DendroPy
import dendropy
from dendropy.simulate import treesim
from dendropy.model.discrete import Hky85, simulate_discrete_char_dataset
# Generate a simulated tree
taxa = dendropy.TaxonNamespace(['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h'])
tree_model = treesim.birth_death_tree(birth_rate=1.0, death_rate=0.5, taxon_namespace=taxa)
# Use the HKY85 model for character mutation
seq_model = Hky85()
# Simulate a data set with the given tree and model, with 50 character sequences
data = simulate_discrete_char_dataset(50, tree_model, seq_model)
# Print tree and sequences in FASTA format
tree_model.print_plot()
print(data.as_string('fasta'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment