# NOT RUN {
set.seed(1, kind = "Mersenne-Twister", normal.kind = "Inversion")
tree <- PCMTree(ape::rtree(25))
PCMTreeSetPartRegimes(
tree, c(`26`="a", `28`="b", `45`="c", `47`="d"), setPartition = TRUE)
# }
# NOT RUN {
PCMTreePlot(
tree,
palette=c(a = "red", b = "green", c = "blue", d = "magenta")) +
ggtree::geom_nodelab(angle = 45) + ggtree::geom_tiplab(angle = 45)
# }
# NOT RUN {
cbind(tree$edge, PCMTreeEdgeTimes(tree))
id47 <- PCMTreeMatchLabels(tree, "47")
length47 <- PCMTreeGetBranchLength(tree, id47)
# insert a singleton at 0.55 (root-ward) from node 47
tree <- PCMTreeInsertSingletons(tree, nodes = "47", positions = (length47/2))
# }
# NOT RUN {
PCMTreePlot(
tree,
palette=c(a = "red", b = "green", c = "blue", d = "magenta")) +
ggtree::geom_nodelab(angle = 45) + ggtree::geom_tiplab(angle = 45)
# }
# NOT RUN {
# this fails, because the branch leading to node "47" is shorter now (0.55).
ggplot2::should_stop(
tree <- PCMTreeInsertSingletons(
tree, nodes = "47", positions= 2* length47 / 3))
# the tree is the same
# }
# NOT RUN {
PCMTreePlot(
tree, palette=c(a = "red", b = "green", c = "blue", d = "magenta")) +
ggtree::geom_nodelab(angle = 45) + ggtree::geom_tiplab(angle = 45)
# }
# NOT RUN {
# we can insert at a position within the edge:
tree <- PCMTreeInsertSingletons(tree, nodes = "47", positions = length47/3)
# }
# NOT RUN {
PCMTreePlot(
tree, palette=c(a = "red", b = "green", c = "blue", d = "magenta")) +
ggtree::geom_nodelab(angle = 45) + ggtree::geom_tiplab(angle = 45)
# }
# NOT RUN {
# Insert singletons at all branches crossing a given epoch. This will skip
# inserting singleton nodes where the resulting branches would be shorter
# than 0.1.
tree <- PCMTreeInsertSingletonsAtEpoch(tree, 2.3)
# }
# NOT RUN {
PCMTreePlot(
tree, palette=c(a = "red", b = "green", c = "blue", d = "magenta")) +
ggtree::geom_nodelab(angle = 45) + ggtree::geom_tiplab(angle = 45)
# }
# NOT RUN {
# Insert singletons at all branches crossing a given epoch
tree <- PCMTreeInsertSingletonsAtEpoch(tree, 2.3, minLength = 0.001)
# }
# NOT RUN {
PCMTreePlot(
tree,
palette=c(a = "red", b = "green", c = "blue", d = "magenta")) +
ggtree::geom_nodelab(angle = 45) + ggtree::geom_tiplab(angle = 45)
# }
Run the code above in your browser using DataLab