Closed TuomasBorman closed 2 days ago
Create random trees:
x <- ape::rtree(5)
y <- ape::rtree(10)
x <- ape::makeNodeLabel(x, prefix = "x_")
y <- ape::makeNodeLabel(y, prefix = "y_")
combined_tree <- tree1
Get unique taxa in both trees
taxax <- x$tip.label
taxay <- y$tip.label
common_taxa <- intersect(taxax, taxay)
common_mapping <- match(common_taxa, y$tip.label)
Remove common taxa from y to avoid duplication
z <- drop.tip(y, common_taxa)
Bind the remaining part of tree2 to tree1 at the common taxa nodes
combined_tree <- bind.tree(combined_tree, z, where = common_mapping[i])
I don't have now time to check in detail, but row can be also linked with internal node. Then the row cannot be found from tip. If you then use drop.tip, it might remove also internal node that represent row. We have .prune_tree function that takes this into account. Explore that.
Tree merging part just check if tree row can be found from set of trees. It finds the smallest number of trees that can present the rows and adds them to TreeSE. However, correct way is to merge the tree into single tree https://www.rdocumentation.org/packages/ape/versions/5.8/topics/bind.tree