YuLab-SMU / ggtree

:christmas_tree:Visualization and annotation of phylogenetic trees
https://yulab-smu.top/contribution-tree-data/
838 stars 173 forks source link

Problems with Collapse function #609

Open nedwalsh opened 6 months ago

nedwalsh commented 6 months ago

Hi There,

I'm having some issues with the collapse function during my analysis. I want to collapse a node, but I am unable.

First, there is an issue when I run the 'collapse' example:

> x <- rtree(15)
> p <- ggtree(x) + geom_tiplab()
> p1 <- collapse(p, node = 17)
Error in offspring.tbl_tree_item(.data = .data, .node = .node, tiponly = tiponly,  : 
  could not find function "offspring.tbl_tree_item"

Also here:

> set.seed(2017-02-16)
> tree<-rtree(50)
> treexample <- ggtree(tree)
> treexample1 <- collapse(treexample, node = 68)
Error in offspring.tbl_tree_item(.data = .data, .node = .node, tiponly = tiponly,  : 
  could not find function "offspring.tbl_tree_item"

I get an issue on the collapse function whilst working on my tree. I cannot collapse an interior node in a ggtree created from a tibble tree:

>mytree <- read.delim("treedata.csv", sep=",")
>my_tree <- ggtree(mytree)
> p <- my_tree %>% collapse(node=35)
Error in UseMethod("offspring") : 
  no applicable method for 'offspring' applied to an object of class "c('tbl_df', 'tbl', 'data.frame')"
> collapse(my_tree, 35)
Error in UseMethod("offspring") : 
  no applicable method for 'offspring' applied to an object of class "c('tbl_df', 'tbl', 'data.frame')"
> class(my_tree)
[1] "ggtree" "gg"     "ggplot"

This is my session info:

> sessionInfo()
R version 4.2.2 (2022-10-31 ucrt)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 19045)

Matrix products: default

locale:
[1] LC_COLLATE=English_Australia.utf8  LC_CTYPE=English_Australia.utf8    LC_MONETARY=English_Australia.utf8 LC_NUMERIC=C                      
[5] LC_TIME=English_Australia.utf8    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
 [1] pvclust_2.2-0      lubridate_1.9.3    forcats_1.0.0      stringr_1.5.1      purrr_1.0.2        readr_2.1.5        tidyr_1.3.1       
 [8] tibble_3.2.1       ggplot2_3.5.0      tidyverse_2.0.0    ggtreeDendro_1.0.0 tidytree_0.4.6     treeio_1.22.0      ape_5.7-1         
[15] dplyr_1.1.4        ggtree_3.6.2      

loaded via a namespace (and not attached):
 [1] tidyselect_1.2.1    lattice_0.22-6      ggfun_0.1.4         colorspace_2.1-0    vctrs_0.6.5         generics_0.1.3      utf8_1.2.4         
 [8] gridGraphics_0.5-1  rlang_1.1.3         pillar_1.9.0        glue_1.7.0          withr_3.0.0         lifecycle_1.0.4     munsell_0.5.0      
[15] gtable_0.3.4        memoise_2.0.1       labeling_0.4.3      tzdb_0.4.0          fastmap_1.1.1       parallel_4.2.2      fansi_1.0.6        
[22] Rcpp_1.0.12         scales_1.3.0        BiocManager_1.30.22 cachem_1.0.8        jsonlite_1.8.8      farver_2.1.1        fs_1.6.3           
[29] hms_1.1.3           aplot_0.2.2         digest_0.6.35       stringi_1.8.3       grid_4.2.2          cli_3.6.2           tools_4.2.2        
[36] yulab.utils_0.1.4   magrittr_2.0.3      lazyeval_0.2.2      patchwork_1.2.0     pkgconfig_2.0.3     ggplotify_0.1.2     timechange_0.3.0   
[43] rstudioapi_0.15.0   R6_2.5.1            nlme_3.1-164        compiler_4.2.2