microbiome / mia

Microbiome analysis
https://microbiome.github.io/mia/
Artistic License 2.0
45 stars 25 forks source link

mergeSEs: tree merging #558

Closed TuomasBorman closed 2 days ago

TuomasBorman commented 1 month ago

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

Daenarys8 commented 4 weeks 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])

Rplot01 Rplot Rplot02 Rplot03

TuomasBorman commented 4 weeks ago

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.