Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dendropy.utility.error.UltrametricityError when using TACT #230

Closed
Cactusolo opened this issue Jun 30, 2021 · 14 comments · Fixed by #231
Closed

dendropy.utility.error.UltrametricityError when using TACT #230

Cactusolo opened this issue Jun 30, 2021 · 14 comments · Fixed by #231
Assignees

Comments

@Cactusolo
Copy link

Hi @jonchang ,

I'm trying to use TACT adding some species to GBMB.tre from Smith and Brown (2018). The backbone is fine, which was confirmed by phyx.

[cactus]$ pxlstr -t GBMB_bi-rmbadtip.tre [some tips are cleaned]
tree #: 0
rooted: true
binary: true
nterminal: 78929
ninternal: 78928
branch lengths: true
rttipvar: 2.23112e-10
treelength: 490017
ultrametric: true
rootheight: 325.05

When I run TACT with tact_add_taxa function, it gives error as below:

Traceback (most recent call last):
File "/home/cactus/.local/bin/tact_add_taxa", line 8, in
sys.exit(main())
File "/home/cactus/.local/pipx/venvs/tact/lib/python3.7/site-packages/click/core.py", line 829, in call
return self.main(*args, **kwargs)
File "/home/cactus/.local/pipx/venvs/tact/lib/python3.7/site-packages/click/core.py", line 782, in main
rv = self.invoke(ctx)
File "/home/cactus/.local/pipx/venvs/tact/lib/python3.7/site-packages/click/core.py", line 1066, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/home/cactus/.local/pipx/venvs/tact/lib/python3.7/site-packages/click/core.py", line 610, in invoke
return callback(*args, **kwargs)
File "/home/cactus/.local/pipx/venvs/tact/lib/python3.7/site-packages/tact/cli_add_taxa.py", line 392, in main
tree.calc_node_ages()
File "/home/cactus/.local/pipx/venvs/tact/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: 1.0000000017384991e-05.
Encountered in subtree of node <Node object at 0x7fc312709470: 'None' (None)> (edge length of 1.291905):

####huge newick tree skipped ...####

Age of children:

  • <Node object at 0x7fc3127094e0: 'None' (None)>: has age of 88.17562399999998 and edge length of 5.093615, resulting in parent node age of 93.26923899999998
  • <Node object at 0x7fc3126849b0: 'None' (None)>: has age of 25.721769000000002 and edge length of 67.54748, resulting in parent node age of 93.269249

I suspect it could be issues from dendropy, not really TACT, but would like to hear from your advice first. Thank you!

Happy to mail you my tree file and taxonomy data if you have time to check it.

Cheers,

Miao

@jonchang jonchang self-assigned this Jun 30, 2021
@jonchang
Copy link
Owner

ape, DendroPy, and phyx all compute ultrametricity in different ways. I disagree with DendroPy's approach since it looks at every single node in the tree and raises an error if the ages of the left and right children of the parent node differ by some threshold (set to 1e-5). I think ape looks at the relative maximum difference in root-to-tip distance and phyx looks at the variance in root-to-tip distances (which ape used to use).

I'll probably write something in tact to address this but for now you can use nnls.tree(cophenetic(phy), phy, TRUE) in the R package phangorn to fix the tree.

@Cactusolo
Copy link
Author

Cactusolo commented Jun 30, 2021

Thanks for your respond @jonchang ! I have tried with phytools::force.ultramtric() with "method = 'extend'" and it requires 45 Gb memory request; with "method = 'nnls'" and phangorn::nnls.tree(cophenetic(phy), phy, TRUE) raising the same error msg:

> library("phangorn")
Loading required package: ape
> tree <- read.tree("GBMB_bi-rmbadtip.tre")
> library("phytools")
Loading required package: maps
> tree2 <- force.ultrametric(tree, method="nnls")
Error in double(nm * nm) : vector size cannot be NA
In addition: Warning message:
In nm * nm : NAs produced by integer overflow
> tree3 <- nnls.tree(cophenetic(tree), tree, rooted =TRUE)
Error in double(nm * nm) : vector size cannot be NA
In addition: Warning message:
In nm * nm : NAs produced by integer overflow

But no worries, I'm looking forward to your update.

Thank you so much!
Miao

@jonchang
Copy link
Owner

jonchang commented Jul 1, 2021

Miao, can you see if #231 fixes the ultrametricity check?

@Cactusolo
Copy link
Author

Cactusolo commented Jul 1, 2021

Hi, I'm trying now. Should I re-install tact and rerun again?

I'm on a Ubuntu machine.

I have upgraded TACT:

[cactus]$ pipx upgrade tact
upgraded package tact from 0.3.1 to 0.3.4 (location: /home/cactus/.local/pipx/venvs/tact)

And reran it, and the issue remains.

Miao

@jonchang
Copy link
Owner

jonchang commented Jul 1, 2021

You'll need to install it from the branch, like so:

pipx install git+https://github.com/jonchang/tact.git@fix-ultrametricity

@Cactusolo
Copy link
Author

Hi,

Thanks for the tip! I have upgraded the tact. Now the error message is new, said:

[cactus]$ cat tacted.test.log.txt
Reading taxonomy
Reading backbone
Tree is not ultrametric!

However, phyx said the tree is ultrametric:

[cactus]$ pxlstr -t GBMB_bi-rmbadtip.tre
tree #: 0
rooted: true
binary: true
nterminal: 78929
ninternal: 78928
branch lengths: true
rttipvar: 2.23112e-10
treelength: 490017
ultrametric: true
rootheight: 325.05

Thanks!

Miao

@jonchang
Copy link
Owner

jonchang commented Jul 1, 2021

Can you email me the tree?

@Cactusolo
Copy link
Author

Can you email me the tree?

Yes, I send the data to you at "me@jonathanchang.org" [not sure about the email address :P].

Thanks!

Miao

@jonchang
Copy link
Owner

jonchang commented Jul 2, 2021

Tree is not ultrametric: (('Platea latifolia', 325.0477049999999), ('Ginkgo biloba', 325.05001799999997))

I think I'll solve this by just letting you set an ultrametricity precision.

@jonchang
Copy link
Owner

jonchang commented Jul 2, 2021

Ok, try pipx uninstall tact && pipx install git+https://github.com/jonchang/tact.git@fix-ultrametricity again and try passing --ultrametricity-precision. Note that this will coerce your ages to be a bit older (so the root-to-tip distance for Platea latifolia will be slightly larger).

@Cactusolo
Copy link
Author

Cactusolo commented Jul 3, 2021

Hey @jonchang , I have done as what you instructed pipx uninstall tact && pipx install git+https://github.com/jonchang/tact.git@fix-ultrametricity, and pass --ultrametricity-precision.

please let me know if I did anything wrong here, the program has not finished with error msg:

Tree is not ultrametric!
Platea latifolia has a root distance of 325.0477049999999, but Ginkgo biloba has 325.05001799999997
If this is unexpected, consider setting --ultrametricity-precision or using phytools::force.ultrametric in R
allTaxoPlantsTrees.gbmb.tacted.test.log.txt (END)

tact_add_taxa --backbone backbone.tre --taxonomy taxonomy.ed.tre --output tacted.test --ultrametricity-precision 1e-6

@jonchang
Copy link
Owner

jonchang commented Jul 3, 2021

Try with a higher number. 1e-6 implies six figs of similarity, so you'd need something like 1e-3 or 1e-2.

@Cactusolo
Copy link
Author

Try with a higher number. 1e-6 implies six figs of similarity, so you'd need something like 1e-3 or 1e-2.

Thanks for the detailed instruction @jonchang !! it worked and finished this time. 👍

@jonchang
Copy link
Owner

jonchang commented Jul 9, 2021

This fix is now released as part of tact 0.4.0: https://github.com/jonchang/tact/releases/tag/v0.4.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants