role-model / roleR

R package implementing the RoLE model
https://role-model.github.io/roleR
GNU General Public License v3.0
1 stars 2 forks source link

role_msprime.py - ValueError if phylogeny is not exactly ultrametric #87

Open isaacovercast opened 1 year ago

isaacovercast commented 1 year ago

msprime.Demography.from_species_tree() is very picky about ultrametricity. All nodes must be within 1e-8 of time zero. The role phylogeny sometimes results in tips that violate this requirement and it errors out:

ValueError: All leaf populations must be at time 0: time=2.8421709430404007e-08

role_msprime.py includes a function called _force_ultrametric(tree) which walks the newick tree and sets all leaf nodes to exactly the same depth. It "works" in the sense that it seems to work, but I remain unconvinced. If ValueErrors start popping up we'll need to triage this a bit more.

I have a hunch that the phylogeny occasionally fails to be exactly ultrametric because of extinction and pruning in the metacommunity process, but I haven't explored this further, just to document the thought.