treeio icon indicating copy to clipboard operation
treeio copied to clipboard

tbl_tree object to phylo object lost bootstrap column

Open ypchan opened this issue 3 years ago • 2 comments

Dear author and users,

axmlng_phylo <-  read.newick('concatenate_raxmlng_addoutgroup.raxml.support', node.label='support')
raxmlng_tibble <- as_tibble(raxmlng_phylo)
raxmlng_phylo_again < as.phylo(raxmlng_tibble )
raxmlng_phylo_tibble <- as_tibble(raxmlng_phylo_again)

the latter tibble lost the column bootstrap, how to avoid this?

ypchan avatar Mar 10 '21 08:03 ypchan

Dropping the support column is the desired behaviour of as.phylo. This is because as.phylo returns a phylo object that cannot contain data. One way to fix this would be to join the tibbles.

@GuangchuangYu maybe you should add a way to get from a tibble to treedata

brj1 avatar Mar 10 '21 18:03 brj1

you can convert tbl_tree to treedata class, which contains phylo class and annotation data ..., using as.treedata, since tbl_tree contained support information. If you convert it to phylo class using as.phylo, it will not extract support or other annotation information, just return phylo class, because standard phylo class does not contain attributes to save annotation data information.

> library(treeio)
> library(tidytree)
> raxml_file <- system.file("extdata/RAxML", "RAxML_bipartitionsBranchLabels.H3", package="treeio")
> tr <- read.raxml(raxml_file)
> tab1 <- as_tibble(tr)
> tr
'treedata' S4 object that stored information of
        '/mnt/d/UbuntuApps/R/4.0.3/lib/R/library/treeio/extdata/RAxML/RAxML_bipartitionsBranchLabels.H3'.

...@ phylo:
Phylogenetic tree with 64 tips and 62 internal nodes.

Tip labels:
  A_Hokkaido_M1_2014_H3N2_2014, A_Czech_Republic_1_2014_H3N2_2014, FJ532080_A_California_09_2008_H3N2_2008, EU199359_A_Pennsylvania_05_2007_H3N2_2007, EU857080_A_Hong_Kong_CUHK69904_2006_H3N2_2006, EU857082_A_Hong_Kong_CUHK7047_2005_H3N2_2005, ...

Unrooted; includes branch lengths.

with the following features available:
        'bootstrap'.
> tab1
# A tibble: 126 x 5
   parent  node branch.length label                                    bootstrap
    <int> <int>         <dbl> <chr>                                        <dbl>
 1     66     1     0.00418   A_Hokkaido_M1_2014_H3N2_2014                    NA
 2     66     2     0.00239   A_Czech_Republic_1_2014_H3N2_2014               NA
 3     74     3     0.00601   FJ532080_A_California_09_2008_H3N2_2008         NA
 4     76     4     0.00594   EU199359_A_Pennsylvania_05_2007_H3N2_20…        NA
 5     77     5     0.00469   EU857080_A_Hong_Kong_CUHK69904_2006_H3N…        NA
 6     80     6     0.00234   EU857082_A_Hong_Kong_CUHK7047_2005_H3N2…        NA
 7     82     7     0.0000786 YGSIV1046_Sw_Binh_Duong_03_10_2010              NA
 8     82     8     0.00111   YGSIV1044_Sw_Binh_Duong_03_08_2010              NA
 9     85     9     0.00604   YGSIV1522_SW_HK_1071_2012                       NA
10     85    10     0.00362   YGSIV1534_SW_HK_2454_2012                       NA
# … with 116 more rows
> tr2 <- as.treedata(tab1)
> tr2
'treedata' S4 object'.

...@ phylo:
Phylogenetic tree with 64 tips and 62 internal nodes.

Tip labels:
  A_Hokkaido_M1_2014_H3N2_2014, A_Czech_Republic_1_2014_H3N2_2014, FJ532080_A_California_09_2008_H3N2_2008, EU199359_A_Pennsylvania_05_2007_H3N2_2007, EU857080_A_Hong_Kong_CUHK69904_2006_H3N2_2006, EU857082_A_Hong_Kong_CUHK7047_2005_H3N2_2005, ...

Unrooted; includes branch lengths.

with the following features available:
        'bootstrap'.
> as_tibble(tr2)
# A tibble: 126 x 5
   parent  node branch.length label                                    bootstrap
    <int> <int>         <dbl> <chr>                                        <dbl>
 1     66     1     0.00418   A_Hokkaido_M1_2014_H3N2_2014                    NA
 2     66     2     0.00239   A_Czech_Republic_1_2014_H3N2_2014               NA
 3     74     3     0.00601   FJ532080_A_California_09_2008_H3N2_2008         NA
 4     76     4     0.00594   EU199359_A_Pennsylvania_05_2007_H3N2_20…        NA
 5     77     5     0.00469   EU857080_A_Hong_Kong_CUHK69904_2006_H3N…        NA
 6     80     6     0.00234   EU857082_A_Hong_Kong_CUHK7047_2005_H3N2…        NA
 7     82     7     0.0000786 YGSIV1046_Sw_Binh_Duong_03_10_2010              NA
 8     82     8     0.00111   YGSIV1044_Sw_Binh_Duong_03_08_2010              NA
 9     85     9     0.00604   YGSIV1522_SW_HK_1071_2012                       NA
10     85    10     0.00362   YGSIV1534_SW_HK_2454_2012                       NA
# … with 116 more rows

xiangpin avatar Mar 11 '21 02:03 xiangpin