YuLab-SMU / treeio

:seedling: Base Classes and Functions for Phylogenetic Tree Input and Output
https://yulab-smu.top/treedata-book/
96 stars 26 forks source link

fix outgroup (character type) of root for treedata #67

Closed xiangpin closed 3 years ago

xiangpin commented 3 years ago

Description

fix the issue about the outgroup (character type) of root

Related Issue

because the tip.label of tree for the root.treedata method has bee replaced by the temporary labels. If the outgroup is from the tip label of original tree, this will generate error.

Example

> library(treeio)
treeio v1.17.2  For help: https://yulab-smu.top/treedata-book/

If you use treeio in published research, please cite:

LG Wang, TTY Lam, S Xu, Z Dai, L Zhou, T Feng, P Guo, CW Dunn, BR Jones, T Bradley, H Zhu, Y Guan, Y Jiang, G Yu. treeio: an R package for phylogenetic tree input and output with richly annotated and associated data. Molecular Biology and Evolution 2020, 37(2):599-603. doi: 10.1093/molbev/msz240

> tr <- rtree(6)
> N <- Nnode(tr, internal.only=F)
> da <- data.frame(id=seq_len(N), value=seq_len(N)*2)
> da
   id value
1   1     2
2   2     4
3   3     6
4   4     8
5   5    10
6   6    12
7   7    14
8   8    16
9   9    18
10 10    20
11 11    22
> tr %<>% tidytree::left_join(da, by=c("node"="id"))
> tr
'treedata' S4 object'.

...@ phylo:

Phylogenetic tree with 6 tips and 5 internal nodes.

Tip labels:
  t5, t2, t3, t1, t4, t6

Rooted; includes branch lengths.

with the following features available:
        '',     'value'.

# The associated data tibble abstraction: 11 × 4
# The 'node', 'label' and 'isTip' are from the phylo tree.
    node label isTip value
   <int> <chr> <lgl> <dbl>
 1     1 t5    TRUE      2
 2     2 t2    TRUE      4
 3     3 t3    TRUE      6
 4     4 t1    TRUE      8
 5     5 t4    TRUE     10
 6     6 t6    TRUE     12
 7     7 NA    FALSE    14
 8     8 NA    FALSE    16
 9     9 NA    FALSE    18
10    10 NA    FALSE    20
11    11 NA    FALSE    22
> tr %>% root(outgroup="t6")
'treedata' S4 object'.

...@ phylo:

Phylogenetic tree with 6 tips and 4 internal nodes.

Tip labels:
  t5, t2, t3, t1, t4, t6
Node labels:
  , NA, NA, NA

Unrooted; includes branch lengths.

with the following features available:
        '',     'value'.

# The associated data tibble abstraction: 10 × 4
# The 'node', 'label' and 'isTip' are from the phylo tree.
    node label isTip value
   <int> <chr> <lgl> <dbl>
 1     1 "t5"  TRUE      2
 2     2 "t2"  TRUE      4
 3     3 "t3"  TRUE      6
 4     4 "t1"  TRUE      8
 5     5 "t4"  TRUE     10
 6     6 "t6"  TRUE     12
 7     7 ""    FALSE    NA
 8     8  NA   FALSE    16
 9     9  NA   FALSE    20
10    10  NA   FALSE    22