jeetsukumaran / DendroPy

A Python library for phylogenetic scripting, simulation, data processing and manipulation.
https://pypi.org/project/DendroPy/.
BSD 3-Clause "New" or "Revised" License
210 stars 61 forks source link

dendropy.utility.error.UltrametricityError #121

Open nick-youngblut opened 5 years ago

nick-youngblut commented 5 years ago

I'm getting the following error when reading in a tree:

Traceback (most recent call last):
  File "./bin/scripts/treeRenameNodes.py", line 45, in <module>
    main(args)
  File "./bin/scripts/treeRenameNodes.py", line 39, in main
    tree = load_tree(args.tree)
  File "./bin/scripts/treeRenameNodes.py", line 31, in load_tree
    for i,node in enumerate(tree.ageorder_node_iter(include_leaves=False)):
  File "/ebio/abt3_projects/software/dev/miniconda3_dev/envs/phylo/lib/python3.7/site-packages/dendropy/datamodel/treemodel.py", line 4310, in ageorder_node_iter
    self.calc_node_ages()
  File "/ebio/abt3_projects/software/dev/miniconda3_dev/envs/phylo/lib/python3.7/site-packages/dendropy/datamodel/treemodel.py", line 5666, in calc_node_ages
    subtree=subtree,
dendropy.utility.error.UltrametricityError: Tree is not ultrametric within threshold of 1e-05: 0.024889999999999995.
Encountered in subtree of node <Node object at 0x7f7cd923ec18: 'NODE 0000005' (None)> (edge length of 0.03805):

    (JJOOJKAF:0.1839,BMGJBFJO:0.15901)NODE_0000005:0.03805

Age of children:
-   <Node object at 0x7f7cdb1eca90: 'None' (<Taxon 0x7f7cd92b3710 'JJOOJKAF'>)>: has age of 0.0 and edge length of 0.1839, resulting in parent node age of 0.1839
-   <Node object at 0x7f7cd923e1d0: 'None' (<Taxon 0x7f7cd923ec88 'BMGJBFJO'>)>: has age of 0.0 and edge length of 0.15901, resulting in parent node age of 0.15901

I can't tell from the documentation on how to read in a non-ultrametric tree.

nick-youngblut commented 3 years ago

Is it actually possible to read in a non-ultrametric tree and then convert it to ultrametric? The package docs make a lot of statements about how ultrametric trees are needed for most (all?) functions, but I couldn't find any info on how to convert a tree to ultrametric.

jeetsukumaran commented 3 years ago

Sure. There's an entire body of theory, divergence time estimation, devoted to inferring ultrametric trees (or "converting" non-ultrametric trees to ultrametric ones). You need a model of evolution that decouples time and substitution rate (which would typically be of the strict or relaxed molecular clock variety) and probably some additional data (for calibration points, though you can calibrate the root to some arbitrary value if you don't care about absolute time).

https://revbayes.github.io/tutorials/dating/

https://beast2-dev.github.io/beast-docs/beast2/DivergenceDating/DivergenceDatingTutorial.html

http://ib.berkeley.edu/courses/ib200b/labs/ib200b_lab07_testing_molecular_clock.pdf