ggtree icon indicating copy to clipboard operation
ggtree copied to clipboard

`ggtree::read.tree` crashes RStudio

Open bschilder opened this issue 2 years ago • 7 comments

Hello,

ggtree::read.tree aborts RStudio, both on my Desktop Rstudio and within a Bioconductor Docker container.

Reprex

tree_path <- tempfile()
download.file("http://hgdownload.soe.ucsc.edu/goldenPath/hg38/multiz100way/",
              tree_path)
tr <- ggtree::read.tree(file = tree_path) 

Sounds a bit similar to #428

Session info

R version 4.1.0 (2021-05-18)
Platform: x86_64-apple-darwin17.0 (64-bit)
Running under: macOS Big Sur 11.4

Matrix products: default
LAPACK: /Library/Frameworks/R.framework/Versions/4.1/Resources/lib/libRlapack.dylib

locale:
[1] en_GB.UTF-8/en_GB.UTF-8/en_GB.UTF-8/C/en_GB.UTF-8/en_GB.UTF-8

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

other attached packages:
 [1] phytools_1.0-1  maps_3.4.0      caper_1.0.1     mvtnorm_1.1-3   MASS_7.3-55    
 [6] ape_5.6-1       rotl_3.0.12     orthogene_1.1.2 dplyr_1.0.8     ggplot2_3.3.5  
[11] ggtree_3.2.1   

loaded via a namespace (and not attached):
 [1] nlme_3.1-155              progress_1.2.2            httr_1.4.2               
 [4] numDeriv_2016.8-1.1       tools_4.1.0               backports_1.4.1          
 [7] utf8_1.2.2                R6_2.5.1                  DBI_1.1.2                
[10] lazyeval_0.2.2            colorspace_2.0-2          withr_2.4.3              
[13] prettyunits_1.1.1         tidyselect_1.1.1          mnormt_2.0.2             
[16] phangorn_2.8.1            compiler_4.1.0            cli_3.2.0                
[19] expm_0.999-6              plotly_4.10.0             scales_1.1.1             
[22] quadprog_1.5-8            digest_0.6.29             yulab.utils_0.0.4        
[25] rmarkdown_2.11            rentrez_1.2.3             pkgconfig_2.0.3          
[28] htmltools_0.5.2           plotrix_3.8-2             fastmap_1.1.0            
[31] htmlwidgets_1.5.4         rlang_1.0.1               gridGraphics_0.5-1       
[34] generics_0.1.2            combinat_0.0-8            jsonlite_1.7.3           
[37] car_3.0-12                homologene_1.4.68.19.3.27 magrittr_2.0.2           
[40] ggplotify_0.1.0           GenomeInfoDbData_1.2.7    patchwork_1.1.1          
[43] Matrix_1.4-0              Rcpp_1.0.8                munsell_0.5.0            
[46] fansi_1.0.2               abind_1.4-5               babelgene_21.4           
[49] lifecycle_1.0.1           scatterplot3d_0.3-41      yaml_2.2.2               
[52] carData_3.0-5             clusterGeneration_1.3.7   brio_1.1.3               
[55] grid_4.1.0                parallel_4.1.0            crayon_1.5.0             
[58] rncl_0.8.4                lattice_0.20-45           hms_1.1.1                
[61] magick_2.7.3              tmvnsim_1.0-2             knitr_1.37               
[64] pillar_1.7.0              igraph_1.2.11             ggpubr_0.4.0             
[67] ggsignif_0.6.3            codetools_0.2-18          fastmatch_1.1-3          
[70] XML_3.99-0.8              glue_1.6.1                gprofiler2_0.2.1         
[73] evaluate_0.14             ggimage_0.3.0             ggfun_0.0.5              
[76] data.table_1.14.2         BiocManager_1.30.16       vctrs_0.3.8              
[79] treeio_1.18.1             testthat_3.1.2            gtable_0.3.0             
[82] purrr_0.3.4               tidyr_1.2.0               assertthat_0.2.1         
[85] xfun_0.29                 broom_0.7.12              tidytree_0.3.7           
[88] coda_0.19-4               rstatix_0.7.0             viridisLite_0.4.0        
[91] tibble_3.1.6              aplot_0.1.2               ellipsis_0.3.2  

Many thanks in advance, Brian

bschilder avatar Feb 18 '22 19:02 bschilder

Realizing this was a silly mistake on my part. I was trying to import the link to the README rather than the file itself. Still, unsure why that would cause RStudio to crash.

URL <- "http://hgdownload.soe.ucsc.edu/goldenPath/hg38/multiz100way/hg38.100way.commonNames.nh"
tree_path <- file.path("~/Desktop",basename(URL))
download.file(URL,
              destfile = tree_path,
              method = "wget")
tr <- ggtree::read.tree(tree_path)

Though I am getting an error now:

Error in FUN(X[[i]], ...) : 
  numbers of left and right parentheses in Newick string not equal

bschilder avatar Feb 18 '22 19:02 bschilder

Seems there some issues with reading in tree files with ";".

However, after removing this, read.tree just returns NULL without any messages.

URL <- "http://hgdownload.soe.ucsc.edu/goldenPath/hg38/multiz100way/hg38.100way.commonNames.nh"
tree_path <- file.path("~/Desktop",basename(URL))
download.file(URL,
              destfile = tree_path,
              method = "wget")
#### Remove ";" at the end, which causes errors ####
l <- readLines(tree_path)
l2 <- gsub(";","",l)
writeLines(l2,tree_path)

## Both of these return NULL
tr <- ape::read.tree(file = tree_path)
tr <- ape::read.tree(text = l2)

The only thing that worked for me was using the package aphylo (after removing ";"):

if(!require("aphylo")) remotes::install_github("USCbiostats/aphylo")
tr <- aphylo::read_nhx(tree_path)
Screenshot 2022-02-18 at 15 08 50

bschilder avatar Feb 18 '22 20:02 bschilder

There may actually be an underlying issue with the CommonNames newick itself, because the other two versions that use other taxonomic naming schemes seem to work fine:

hg38.100way.scientificNames.nh hg38.100way.nh

URL <- "http://hgdownload.soe.ucsc.edu/goldenPath/hg38/multiz100way/hg38.100way.scientificNames.nh"
tree_path <- file.path("~/Desktop",basename(URL))
download.file(URL,
              destfile = tree_path,
              method = "wget")
tr <- ape::read.tree(file = tree_path) 
Screenshot 2022-02-18 at 15 27 37

bschilder avatar Feb 18 '22 20:02 bschilder

image

GuangchuangYu avatar Feb 22 '22 07:02 GuangchuangYu

Hm, this is odd, running the same code doesn't seem to produce the same result for me (unless I'm missing something). Same result with both read.newick and read.nhx

Screenshot 2022-02-22 at 09 34 06

Which version of treeio are you using?

thanks, Brian

bschilder avatar Feb 22 '22 14:02 bschilder

v1.18.1 as displayed in the screenshot.

GuangchuangYu avatar Feb 23 '22 02:02 GuangchuangYu

sorry, missed that

weird, that's the same version I'm using. Not sure why we're getting totally different results. Only other thing I can think of is the OS: I'm on macOS Big Sur 11.4

bschilder avatar Feb 23 '22 02:02 bschilder