cafferychen777 / MicrobiomeStat

Track, Analyze, Visualize: Unravel Your Microbiome's Temporal Pattern with MicrobiomeStat
https://www.microbiomestat.wiki/
31 stars 4 forks source link

Error in midpoint(data.obj$tree) : could not find function "midpoint" #49

Open nutrimol opened 4 months ago

nutrimol commented 4 months ago

Dear developer,

Congratulations for this great tool. I have a problem while trying to convert my phyloseq object to microbiomeStat object. It seems it does not found midpoint function.

I installed all the dependencies following the installation guide. Then, I execute the code below. Do you have any clue of what is going on here?

Thank you for your time!

library(MicrobiomeStat) library(tidyverse) library(phyloseq)

Required package

library(microbiome) library(ape)

setwd("/Users/virginia/Dropbox/rrr/emu_phyloseq/") # mac

################################################################################

load Phyloseq object

################################################################################ ps <- readRDS(file= "./phylo_obj/ps.rds")

Check if taxa are rows in the Phyloseq object

phyloseq::taxa_are_rows(ps) str(ps)

Convert the Phyloseq object to a MicrobiomeStat data object

data.obj <- mStat_convert_phyloseq_to_data_obj(ps)

output:

``

phyloseq::taxa_are_rows(ps) [1] TRUE str(ps) Formal class 'phyloseq' [package "phyloseq"] with 5 slots ..@ otu_table:Formal class 'otu_table' [package "phyloseq"] with 2 slots .. .. ..@ .Data : num [1:275, 1:24] 0 0 14 0 0 0 0 0 0 0 ... .. .. .. ..- attr(, "dimnames")=List of 2 .. .. .. .. ..$ : chr [1:275] "100176" "1042156" "105841" "106588" ... .. .. .. .. ..$ : chr [1:24] "AC.16" "TC.16" "DC.16" "AC.18" ... .. .. ..@ taxa_are_rows: logi TRUE .. .. ..$ dim : int [1:2] 275 24 .. .. ..$ dimnames:List of 2 .. .. .. ..$ : chr [1:275] "100176" "1042156" "105841" "106588" ... .. .. .. ..$ : chr [1:24] "AC.16" "TC.16" "DC.16" "AC.18" ... ..@ tax_table:Formal class 'taxonomyTable' [package "phyloseq"] with 1 slot .. .. ..@ .Data: chr [1:275, 1:7] "Bacteria" "Bacteria" "Bacteria" "Bacteria" ... .. .. .. ..- attr(, "dimnames")=List of 2 .. .. .. .. ..$ : chr [1:275] "100176" "1042156" "105841" "106588" ... .. .. .. .. ..$ : chr [1:7] "Kingdom" "Phylum" "Class" "Order" ... .. .. ..$ dim : int [1:2] 275 7 .. .. ..$ dimnames:List of 2 .. .. .. ..$ : chr [1:275] "100176" "1042156" "105841" "106588" ... .. .. .. ..$ : chr [1:7] "Kingdom" "Phylum" "Class" "Order" ... ..@ sam_data :'data.frame': 24 obs. of 6 variables: Formal class 'sample_data' [package "phyloseq"] with 4 slots .. .. ..@ .Data :List of 6 .. .. .. ..$ : Factor w/ 3 levels "AC","TC","DC": 1 2 3 1 2 3 1 2 3 1 ... .. .. .. ..$ : num [1:24] 16 16 16 18 18 18 1 1 1 2 ... .. .. .. ..$ : chr [1:24] "AC.16" "TC.16" "DC.16" "AC.18" ... .. .. .. ..$ : Factor w/ 3 levels "stage1","stage2",..: 3 3 3 3 3 3 1 1 1 1 ... .. .. .. ..$ : Factor w/ 2 levels "distal","proximal": 2 1 1 2 1 1 2 1 1 2 ... .. .. .. ..$ : chr [1:24] "1" "2" "3" "4" ... .. .. ..@ names : chr [1:6] "Compartment" "Day" "label" "Stage" ... .. .. ..@ row.names: chr [1:24] "AC.16" "TC.16" "DC.16" "AC.18" ... .. .. ..@ .S3Class : chr "data.frame" ..@ phy_tree :List of 4 .. ..$ edge : int [1:547, 1:2] 276 276 276 277 278 296 298 341 341 298 ... .. ..$ edge.length: num [1:547] 0.0811 0.1241 0.0112 0.0166 0.0134 ... .. ..$ tip.label : chr [1:275] "100176" "1042156" "105841" "106588" ... .. ..$ Nnode : int 273 .. ..- attr(, "class")= chr "phylo" .. ..- attr(, "order")= chr "cladewise" ..@ refseq : NULL

Convert the Phyloseq object to a MicrobiomeStat data object

data.obj <- mStat_convert_phyloseq_to_data_obj(ps) Root the tree by midpointing ... Error in midpoint(data.obj$tree) : could not find function "midpoint" ``

cafferychen777 commented 4 months ago

Dear user,

Thank you for your report and for trying out the MicrobiomeStat package. I apologize for the inconvenience caused by the error you encountered.

It looks like the error occurred because the midpoint function from the phangorn package could not be found when trying to root the phylogenetic tree. The mStat_convert_phyloseq_to_data_obj function expects a rooted tree.

If your phyloseq object ps already contains a phylogenetic tree (phy_tree), please make sure to load the phangorn package before running the conversion:

library(phangorn)
data.obj <- mStat_convert_phyloseq_to_data_obj(ps) 

Loading phangorn will make the midpoint function available for rooting the tree during the conversion process. I apologize for not making this clear in the package documentation. I will update the wiki to mention this dependency when a tree is present.

Please let me know if loading phangorn resolves the issue for you. If you encounter any further problems, feel free to open a new issue on the GitHub repository.

Thank you for your patience and for bringing this to my attention. I appreciate your interest in using MicrobiomeStat.

Best regards, Chen YANG

nutrimol commented 4 months ago

Dear Chen, Thank you for your prompt response! I loaded phangorn and it worked smoothly. Thank you and congratulations for developing such a useful tool Best regards, Virginia