Closed marwa38 closed 1 year ago
Hi @marwa38 The discussion in https://github.com/joey711/phyloseq/issues/936 will be of interest to you.
In short, the distance calculation only works when your tree is a binary tree. Hence after pruning, you might need to re-construct the phylogenetic tree to obtain a binary tree, or in the example below uses multi2di()
to transforms multichotomies into a series of dichotomies.
library(phyloseq)
library(ape) # is.binary, multi2di
ps = readRDS(file = "ps.prev.intes.tree.rare.rds")
ps
#> phyloseq-class experiment-level object
#> otu_table() OTU Table: [ 1314 taxa and 79 samples ]
#> sample_data() Sample Data: [ 79 samples by 10 sample variables ]
#> tax_table() Taxonomy Table: [ 1314 taxa by 7 taxonomic ranks ]
#> phy_tree() Phylogenetic Tree: [ 1314 tips and 1302 internal nodes ]
ps_tree = phy_tree(ps)
ps_tree
#>
#> Phylogenetic tree with 1314 tips and 1302 internal nodes.
#>
#> Tip labels:
#> ASV4394, ASV1361, ASV5153, ASV1082, ASV4334, ASV5021, ...
#> Node labels:
#> Root, 0.000, 0.966, 0.862, 0.917, 0.911, ...
#>
#> Rooted; includes branch lengths.
# Check if binary (dichotomy) & multifurcating (polytomy) trees
sprintf("Is tree binary: %s", is.binary(ps_tree))
#> [1] "Is tree binary: FALSE"
# If FASLE, randomly resolve polytomies and replace tree in "ps"
phy_tree(ps) = multi2di(ps_tree)
sprintf("Is tree binary: %s", is.binary(phy_tree(ps)))
#> [1] "Is tree binary: TRUE"
dist = phyloseq::distance(ps, method = "unifrac", weighted = F)
sprintf("`dist` class: %s", class(dist))
#> [1] "`dist` class: dist"
Created on 2022-11-29 by the reprex package (v2.0.1)
thank you so much
Hi .. I have the same issue as #643 and #1574 but you were not able to help I think because of the lack of reproducible example? so here I share a reproducible example to help find out the reason behind this error Cheers
attached the input data (phyloseq object) zipped .rds ps.prev.intes.tree.rare.zip @ycl6