Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
nutrimol opened this issue May 8, 2024 · 2 comments
Open
Labels
Not a Bug - Solution Provided This behavior is intentional as part of our design. However, we've provided a solution to accommodat

Comments

@nutrimol
Copy link

nutrimol commented May 8, 2024

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
Copy link
Owner

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

@cafferychen777 cafferychen777 added bug Something isn't working Bug Fixed This bug has been addressed and resolved in the latest update. Not a Bug - Solution Provided This behavior is intentional as part of our design. However, we've provided a solution to accommodat and removed bug Something isn't working Bug Fixed This bug has been addressed and resolved in the latest update. labels May 9, 2024
@nutrimol
Copy link
Author

nutrimol commented May 9, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Not a Bug - Solution Provided This behavior is intentional as part of our design. However, we've provided a solution to accommodat
Projects
None yet
Development

No branches or pull requests

2 participants