khabbazian / l1ou

Detection of evolutionary shifts in Ornstein-Uhlenbeck models

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

sqrt_OU_covariance: tree reordering

cecileane opened this issue · comments

on line 38 of sqrt_OU_covariance (in my fork), the command re-orders the edges in the tree:

tree <- reorder(tree, "prun")
  1. It would be safer to use a postorder instead of a 'pruningwise' order (in most cases it would not matter, but in some cases it could)
  2. When the user needs to use the function over and over on the same tree, but different alpha values, it would be faster if this re-ordering could be avoided: add an option check.order=T or F, and turn off the re-ordering of edges if check.order=F. The function would then be a lot faster when re-used on the same tree, if that tree is known to have its edges in post-order traversal already.
  3. Add a comment: the function assumes that reorder(...) does not change the order of the nodes, just the order of edges, so that column i in each matrix still corresponds to internal node i, etc. (and the last column corresponds to the root edge instead of an internal node).

Then on line 41 the branch lengths are transformed, (only if alpha>0 though):

tre <- transf.branch.lengths(tree, model=root.model, parameters=list(alpha=alpha))$tree
  1. Add a comment: this is the step that requires an ultrametric tree. If the tree is not ultrametric, the function returns a wrong result with no warning (see example below).
  2. For now, add to the documentation that the tree needs not be ultrametric for the BM model, i.e. with default value alpha=0.
  3. There should be a way to allow for non-ultrametric trees, for the BM at the very least, and for the OU model in general too: see related trick in phylolm. Otherwise, add code to check that the tree is ultrametric if alpha>0, but also an option to turn off this check (for same purpose as above).

Example of wrong result:

tre1 <- read.tree(text="((Strix_aluco:4.2,Asio_otus:4.2):3.1,Athene_noctua:7.3);")
tre1$edge.length[3] <- 8 # was 4.2 originally: tre1 no longer ultrametric
res1 <- sqrt_OU_covariance(tre1, alpha=50); # large alpha: almost like iid model
res1$sqrtSigma %*% t(res1$sqrtSigma) # should be close to identity matrix, but far from it!!