microbiome / mia

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

agglomerateByPrevalence does not return rowTree #573

Closed thpralas closed 2 days ago

thpralas commented 3 weeks ago

agglomerateByPrevalence returns a TSE object without rowTree, no matter the value of the agglomerate.tree argument.

library(mia)
data("GlobalPatterns")
tse <- GlobalPatterns
tse <- agglomerateByPrevalence(tse, rank = "Phylum", agglomerate.tree = TRUE)
rowTree(tse)

NULL

library(mia)
data("GlobalPatterns")
tse <- GlobalPatterns
tse <- agglomerateByPrevalence(tse, rank = "Phylum", agglomerate.tree = FALSE)
rowTree(tse)

NULL

It should return a TSE object with its rowTree, agglomerated or not depending on the agglomerate.tree argument.

It is worth nothing that the agglomerateByRank function works correctly and returns a TSE object with its rowTree:

library(mia)
data("GlobalPatterns")
tse <- GlobalPatterns
tse <- agglomerateByRank(tse, rank = "Phylum", agglomerate.tree = TRUE)
rowTree(tse)

Phylogenetic tree with 67 tips and 66 internal nodes. Tip labels: 549322, 173903, 368907, 51888, 591769, 249529, ... Node labels: , 0.858.4, 1.000.21479, 0.946.619, 0.953.588, 0.940.473, ... Rooted; includes branch lengths.

TuomasBorman commented 3 weeks ago

Cool! This is caused because of this https://github.com/microbiome/mia/blob/c629462bf92e2c8cd48e878667dbd08a34b23fa1/R/getPrevalence.R#L592

This converts TreeSE to SCE which removes the tree. It seems that the code is very old and there is now support for rbind for TreeSE.

So the class-checking and conversion could be removed and just call rbind. Can you check this @thpralas ?