YuLab-SMU / ggtree

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

I get an error with "flip" in v1.16.1, but not in v1.14.4, with annotated trees #237

Closed SalvaE closed 5 years ago

SalvaE commented 5 years ago

I am producing some phylogeny, in which I color the branches. I made it to work with ggtree v1.14.4, but the newer version 1.16.1 produces an error:

Error in UseMethod("offspring") : no applicable method for 'offspring' applied to an object of class "data.frame"

I made a little reproducible example:

library(ape)
library(ggtree)
#t<-rtree(5)
#t$node.labels<-6:9
#write.tree(t,digits=0) # "(t2:0.5,((t4:0.6,t5:0.6)8:0.2,(t1:0.3,t3:0.7)9:1)7:0.1)6;"# This is a nice one, because it has two clades around node 7
t<-read.tree(text="(t2:0.5,((t4:0.6,t5:0.6)8:0.2,(t1:0.3,t3:0.7)9:1)7:0.1)6;")
plot(t)
nodelabels(t$node.labels)

dcolors<-data.frame(node=1:9,color=c("orange","red","red","green","orange","red","red","green","black")) # I put colors in the branches

gt<-ggtree(t) %<+% dcolors
gt.flipped<-flip(gt,8,9) # It works in v1.14.4, it doesn't in v1.16.1. It gives the error: 
## " Error in UseMethod("offspring") : no applicable method for 'offspring' applied to an object of class "data.frame" "
gt.flipped

The session info of the two different settings I used are these:

sessionInfo() # The settings that give the error with the v1.16.1 of ggtree
## R version 3.6.0 (2019-04-26)
## Platform: x86_64-apple-darwin15.6.0 (64-bit)
## Running under: macOS Mojave 10.14.1
##
## Matrix products: default
## BLAS:   /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib
## LAPACK: /Library/Frameworks/R.framework/Versions/3.6/Resources/lib/libRlapack.dylib
## 
## Random number generation:
##   RNG:     Mersenne-Twister 
## Normal:  Inversion 
## Sample:  Rounding 
## 
## locale:
##   [1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
## 
## attached base packages:
##  [1] stats     graphics  grDevices utils     datasets  methods   base     
## 
## other attached packages:
##   [1] ggtree_1.16.1  tidytree_0.2.4 ape_5.3       
## 
## loaded via a namespace (and not attached):
##  [1] Rcpp_1.0.1       rstudioapi_0.10  knitr_1.23       magrittr_1.5     tidyselect_0.2.5 munsell_0.5.0    colorspace_1.4-1 lattice_0.20-38  R6_2.4.0        
## [10] rlang_0.4.0      dplyr_0.8.1      tools_3.6.0      parallel_3.6.0   grid_3.6.0       nlme_3.1-140     gtable_0.3.0     xfun_0.8         lazyeval_0.2.2  
## [19] assertthat_0.2.1 tibble_2.1.3     crayon_1.3.4     treeio_1.8.1     tidyr_0.8.3      purrr_0.3.2      ggplot2_3.2.0    glue_1.3.1       labeling_0.3    
## [28] compiler_3.6.0   pillar_1.4.1     rvcheck_0.1.3    scales_1.0.0     jsonlite_1.6     pkgconfig_2.0.2 

sessionInfo() # The settings that give no error with the v1.14.4 of ggtree

## R version 3.5.1 (2018-07-02)
## Platform: x86_64-apple-darwin15.6.0 (64-bit)
## Running under: macOS High Sierra 10.13.6
## 
## Matrix products: default
## BLAS: /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib
## LAPACK: /Library/Frameworks/R.framework/Versions/3.5/Resources/lib/libRlapack.dylib
## 
## locale:
##   [1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
## 
## attached base packages:
##   [1] stats     graphics  grDevices utils     datasets  methods   base     
## 
## other attached packages:
##   [1] ggtree_1.14.4 ape_5.2      
## 

Thanks for helping!

SalvaE commented 5 years ago

Is this fixing the issue?

El vie., 28 jun. 2019 a las 8:38, Guangchuang Yu (notifications@github.com) escribió:

Closed #237 https://github.com/GuangchuangYu/ggtree/issues/237 via cd1fefe https://github.com/GuangchuangYu/ggtree/commit/cd1fefefd2878b174cf3495e35978ce9514d2b20 .

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/GuangchuangYu/ggtree/issues/237?email_source=notifications&email_token=ACQSJQN4DXFXZ5ICOKRUDVTP4WWXJA5CNFSM4H34JDQKYY3PNVWWK3TUL52HS4DFWZEXG43VMVCXMZLOORHG65DJMZUWGYLUNFXW5KTDN5WW2ZLOORPWSZGOSHIJTHQ#event-2446367134, or mute the thread https://github.com/notifications/unsubscribe-auth/ACQSJQNHBXQQ4DGCPQHBX3DP4WWXJANCNFSM4H34JDQA .

-- Salvador Espada Hinojosa Monika Bright's Lab Division of Marine Biology Department of Limnology and Biological Oceanography (LIMBO) University of Vienna Althanstraße, 14 1090 Vienna (Austria) Work: (+43) 1 4277 76437 Mobile: (+43) 660 5952724 skype: salva_e http://salvae.net http://about.me/salvae

GuangchuangYu commented 5 years ago

yes.

SalvaE commented 5 years ago

thanks a lot!!

^_^

El vie., 28 jun. 2019 a las 14:23, Guangchuang Yu (notifications@github.com) escribió:

yes.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/GuangchuangYu/ggtree/issues/237?email_source=notifications&email_token=ACQSJQKDVXRKFCESEGYOR7LP4X7CTA5CNFSM4H34JDQKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGODYZ5TJI#issuecomment-506714533, or mute the thread https://github.com/notifications/unsubscribe-auth/ACQSJQMQ6WILYETEYTE22VDP4X7CTANCNFSM4H34JDQA .

-- Salvador Espada Hinojosa Monika Bright's Lab Division of Marine Biology Department of Limnology and Biological Oceanography (LIMBO) University of Vienna Althanstraße, 14 1090 Vienna (Austria) Work: (+43) 1 4277 76437 Mobile: (+43) 660 5952724 skype: salva_e http://salvae.net http://about.me/salvae

jlrolando commented 3 years ago

Hi! I am getting the same error when using flip in v. 2.0.4. I am using a phyloseq object

Error in UseMethod("offspring") : no applicable method for 'offspring' applied to an object of class "data.frame"

This is the structure of my phylogenetic tree in phyloseq

str(phy_tree(phyloseq_object)) List of 4 $ edge : int [1:142, 1:2] 73 74 75 76 77 77 76 78 78 79 ... $ edge.length: num [1:142] 0.7472 0.1442 0.1098 0.1234 0.0117 ... $ Nnode : int 71 $ tip.label : chr [1:72] "TACCAGCTCTCCGAGTGGTGTGGATGTTTATTGGGCCTAAAGCATCCGTAGCTGGCTGGGCAAGTCCCCTGTTAAATCCACCGATTTAATCGTTGGTGTGCGGGGGATACT"| truncated "TACCAGCTCTCCGAGTGGTGTGGATGTTTATTGGGCCTAAAGCATCCGTAGCTGGCTGGGCAAGTCCCCTGTTAAATCCACCGATTTAATCGTTGGTGTGCGGGGGATACT"| truncated "TACCAGCTCTCCGAGTGGTAGGGATGATTATTGGGCTTAAAGCGTCCGTAGCCGGCTTAGCAAGTCTCCTGTTAAATTCAGCGACCTAATCGTTGAGCCGCGGGAGATACT"| truncated "TACCAGCTCTCCGAGTGGTAGGGATGATTATTGGGCTTAAAGCGTCCGTAGCCGGCTTAGCAAGTTTCCTGTTAAATTCAGCGACCTAATCGTTGAGCCGCGGGAAATACT"| truncated ...