Take an unrooted ten-leaf tree: ```{R backbone, echo=FALSE, fig.width=2, fig.asp=1.2, message=FALSE, fig.align='center'} library('Quartet', exclude = 'RobinsonFoulds') library('TreeTools', quietly = TRUE, warn.conflicts = FALSE) library('TreeDist') library('TreeDistData')
origPar <- par(mar = rep(0, 4))
backbone <- ape::read.tree(text='(a, (b, (c, (d, (((e, f), g), (h, (i, j)))))));') plot(UnrootTree(backbone)) nTip <- length(backbone$tip.label) add3 <- structure(lapply(lapply(AddTipEverywhere(backbone, '11th leaf'), AddTip, 11L, '12th leaf'), AddTip, 12L, '13th leaf'), class = 'multiPhylo') add1then2 <- lapply(AddTipEverywhere(backbone, '11th leaf'), function (tr) structure(lapply(AddTipEverywhere(tr, '12th leaf'), AddTip, 12L, '13th leaf'), class='multiPhylo')) add2then1 <- lapply(AddTipEverywhere(backbone, '12th leaf'), function (tr) structure(lapply(AddTipEverywhere(tr, '11th leaf'), AddTip, 11L, '13th leaf'), class = 'multiPhylo') )
The backbone tree has `r length(backbone$tip.label)` leaves; `r length(add3)` test trees were generated by adding an clade of three leaves at each of the `r length(add3)` edges of the unrooted backbone tree. These are trees T<sub>1</sub>--T<sub>17</sub>. ```r par(mfrow = c(3, 6), mar = rep(0.2, 4)) urt <- lapply(add3, unroot) lapply(urt, plot) -> XX
For each of these trees -- we'll consider T1 first -- we can then move the eleventh leaf to each of the other edges of the tree, giving trees U1.1-U1.19:
par(mfrow = c(4, 5), mar = rep(0.2, 4)) urt <- lapply(add1then2[[1]], unroot) lapply(urt, plot) -> XX
or the cherry containing the twelfth and thirteenth, giving trees V1.1 to V1.19:
par(mfrow = c(4, 5), mar = rep(0.2, 4)) urt <- lapply(add2then1[[1]], unroot) lapply(urt, plot) -> XX par(origPar)
Two trees occur in both Ui and Vi, i.e. they can be generated by moving one leaf or moving two leaves. These trees are excluded from further analysis.
We then expect the distance from Ti to Ui.j (i.e. move one tip to a new location) to be less than the distance from Ti to Vi.j (i.e. move two tips to the same location)
baddies <- vapply(seq_along(add3), function(i) { move1 <- AllDists(add2then1[[i]], add3[[i]]) move2 <- AllDists(add1then2[[i]], add3[[i]]) move1[c('mast', 'masti'), ] <- -move1[c('mast', 'masti'), ] move2[c('mast', 'masti'), ] <- -move2[c('mast', 'masti'), ] rowSums(move2 <= move1) }, double(25))
errors <- t(t(rowSums(baddies) - (2L * length(add3)))) dimnames(errors) <- list(tdMdAbbrevs[rownames(errors)], 'Inconsistencies') .TDDTable(DT::datatable, errors)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.