Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Genomics/exp.py
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
43 lines (37 sloc)
1.34 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import random | |
import dendropy | |
from dendropy import treesim | |
def generate(birth_rates, death_rates): | |
assert len(birth_rates) == len(death_rates) | |
tree = dendropy.Tree() | |
for i, br in enumerate(birth_rates): | |
tree = treesim.birth_death(birth_rates[i], | |
death_rates[i], | |
max_time=random.randint(1,8), | |
tree=tree, | |
assign_taxa=False, | |
repeat_until_success=True) | |
print(tree.as_string('newick')) | |
tree.randomly_assign_taxa(create_required_taxa=True) | |
return tree | |
tree = generate([0.1, 0.6, 0.1], [0.1, 0.6, 0.1]) | |
print(tree.as_string('newick')) | |
import dendropy | |
citation = """\ | |
@article{HeathHH2012, | |
Author = {Tracy A. Heath and Mark T. Holder and John P. Huelsenbeck}, | |
Doi = {10.1093/molbev/msr255}, | |
Journal = {Molecular Biology and Evolution}, | |
Number = {3}, | |
Pages = {939-955}, | |
Title = {A {Dirichlet} Process Prior for Estimating Lineage-Specific Substitution Rates.}, | |
Url = {http://mbe.oxfordjournals.org/content/early/2011/11/04/molbev.msr255.abstract}, | |
Volume = {29}, | |
Year = {2012} | |
} | |
""" | |
dataset = dendropy.DataSet.get_from_string( | |
"(A,(B,(C,(D,E))));", | |
"newick") | |
dataset.annotations.add_citation(citation) | |
print dataset.as_string("nexml") |