Hi Joseph, Thanks for reporting this. It seems indeed that reordering the output of bind.tree() fixes it. A way to do it is:
attr(t2, "order") <- NULL t2 <- reorder(t2) It seems to solve the different problems (balance(t2) doesn't work correctly too). I'll add these 2 lines as the end bind.tree(). Best, Emmanuel ----- Le 22 Oct 20, à 22:42, Joseph Brown josep...@umich.edu a écrit : > I came across the following error: when trying to ladderize a tree that had > gone through bind.tree, the tree becomes corrupted. Specifically, I added a > single tip to an internal node (code to replicate below). > > Note: > 1) this error did not seem to occur when attaching the tip sister to an > original tip (i.e., an external edge). > 2) when the binded tree involved multiple tips attached to the same > internal position, the same edge/edge.length issues arise (see below), but > R crashes completely when trying to plot > 3) if the tree is written out and read back in prior to ladderizing, no > problems occur > > tl;dr: when ladderizing the binded tree, the edge matrix and edge.length > vectors are missing rows/elements corresponding to edges of tree "y" (the > second tree) in bind.tree. forcing a reordering seems to get around things, > but cladewise ordering alone fails. > > Perhaps bind.tree needs to incorporate a reordering step? > > HTH. > Joseph. > > ##################################### > library(ape); > set.seed(31459); > t1 <- rtree(10); > > # let's add a terminal with bind.tree > term <- rtree(1, tip.label="gnu_tip"); > t2 <- bind.tree(x=t1, y=term, where=12, position=0.5); > > # plot > plot(t2); axisPhylo(); > > # looks correct. but let's ladderize to make things pretty > plot(ladderize(t2)); axisPhylo(); > # Warning message: > # In yy[TIPS] <- 1:Ntip : > # number of items to replace is not a multiple of replacement length > > # huh? looks like the edge matrix is incorrect > dim(t2$edge); > # [1] 20 2 > dim(ladderize(t2)$edge); > # [1] 19 2 > # the new terminal is missing from the edge matrix > # same with the edge.length vector: > length(t2$edge.length) > # [1] 20 > length(ladderize(t2)$edge.length) > # [1] 19 > # but tip.label vector is ok: > length(t2$tip.label) == length(ladderize(t2)$tip.label) > # [1] TRUE > > # so: we do not have enough edges for the number of terminals > > # can we fix it by reordering? > plot(ladderize(reorder(t2, "cladewise"))); > # nope: same error. note that attributes(t2)$order was already "cladewise" > # i'm guessing the reorder command is ignored because of its current status? > > # try a different ordering to force processing > plot(ladderize(reorder(t2, "pruningwise"))); > # success > > # what if we want "cladewise" ordering for downstream analyses? > # maybe we can pass it through reorder.phylo twice? > plot(ladderize(reorder(reorder(t2, "pruningwise"), "cladewise"))); > # yup! > > [[alternative HTML version deleted]] > > _______________________________________________ > R-sig-phylo mailing list - R-sig-phylo@r-project.org > https://stat.ethz.ch/mailman/listinfo/r-sig-phylo > Searchable archive at http://www.mail-archive.com/r-sig-phylo@r-project.org/ _______________________________________________ R-sig-phylo mailing list - R-sig-phylo@r-project.org https://stat.ethz.ch/mailman/listinfo/r-sig-phylo Searchable archive at http://www.mail-archive.com/r-sig-phylo@r-project.org/