YuLab-SMU / MicrobiotaProcess

:microbe: A comprehensive R package for deep mining microbiome
https://www.sciencedirect.com/science/article/pii/S2666675823000164
178 stars 37 forks source link

How to get the phylo tree for pcoa plot #8

Open FenghuJi opened 4 years ago

FenghuJi commented 4 years ago

Hello, when I use the get_pcoa() function

pcoares <- get_pcoa(obj=ps_qiime2, distmethod="unifrac", method="hellinger")

It raised error:

Error in get_dist.phyloseq(obj, distmethod = distmethod, ...) : 
  The tree should be required when the distmethod is `WeightUniFrac` or `UnWeightUniFrac`

But how can I get the phylo class tree? Could you please help me ? Thanks a lot.

xiangpin commented 4 years ago

MicrobiotaProcess provides build_tree function to build tree, this function is developed based on DECIPHER (alignment) and phangorn (phyDat, dist.ml, NJ, pml, optim.pml) packages. The input can be the fasta file (nucleotide sequence). You can provide your represent sequences. Or you can use other tools such as muscle, etc to build the tree, then use treeio to make a phylo class tree.

FenghuJi commented 4 years ago

Thanks a lot. But it seems that the phylo class genrated from both build_tree() and treeio read.newick doesn't work. When I print the phylo tree, the consolo outputs

> tree
Phylogenetic tree with 2295 tips and 2293 internal nodes.

Tip labels:
        2f4a2b08eec8d8d5f66dc0d20552881f, cc1f106dae404eca16e3b7d588d58645, 135ea3e4d147e2cf6e381bd218ca38c2, eb3357232ee140b5bd5de0c3babd10ca, 9b44baa49a601fb4b6c50c312c901778, 5881bb20a5699e35017633aa882befb5, ...

Unrooted; includes branch lengths.

and when I use the get_pcoa() function, it outputs

> pcoares <- get_pcoa(obj=ps_qiime2,tree=tree_rooted,distmethod="unifrac", method="hellinger",tree=tree)
Error in get_dist.phyloseq(obj, distmethod = distmethod, ...) : 
  The tree should be required when the distmethod is `WeightUniFrac` or `UnWeightUniFrac`

The version of R is 4.0.0. Can you tell me what is the problem.

xiangpin commented 4 years ago

Ok, get_pcoa is S3 method, when the obj is phyloseq class. The tree should be in the phyloseq class. So you can use ps <- phyloseq(otu_table(ps_qiime2), sample_data(ps_qiime2),tax_table(ps_qiime2), yourtree), or ps <- phyloseq(otu_table(ps_qiime2), sample_data(ps_qiime2), tax_table(ps_qiime2), refseq(ps_qiime2)) if the represent sequences is in ps_qiime2, to build the phyloseq class.