YuLab-SMU / treeio

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

add as.phylo for list #86

Closed xiangpin closed 1 year ago

xiangpin commented 1 year ago

Description

add as.phylo for list class

Related Issue

Example

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

If you use the ggtree package suite in published research, please cite
the appropriate paper(s):

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

Guangchuang Yu, Tommy Tsan-Yuk Lam, Huachen Zhu, Yi Guan. Two methods
for mapping and visualizing associated data on phylogeny using ggtree.
Molecular Biology and Evolution. 2018, 35(12):3041-3043.
doi:10.1093/molbev/msy194

S Xu, Z Dai, P Guo, X Fu, S Liu, L Zhou, W Tang, T Feng, M Chen, L
Zhan, T Wu, E Hu, Y Jiang, X Bo, G Yu. ggtreeExtra: Compact
visualization of richly annotated phylogenetic data. Molecular Biology
and Evolution. 2021, 38(9):4039-4042. doi: 10.1093/molbev/msab166
> library(ggtree)
ggtree v3.5.3 For help: https://yulab-smu.top/treedata-book/

If you use the ggtree package suite in published research, please cite
the appropriate paper(s):

Guangchuang Yu, David Smith, Huachen Zhu, Yi Guan, Tommy Tsan-Yuk Lam.
ggtree: an R package for visualization and annotation of phylogenetic
trees with their covariates and other associated data. Methods in
Ecology and Evolution. 2017, 8(1):28-36. doi:10.1111/2041-210X.12628

Guangchuang Yu. (2022). Data Integration, Manipulation and
Visualization of Phylogenetic Trees (1st edition). Chapman and
Hall/CRC.

Guangchuang Yu. Using ggtree to visualize data on tree-like structures.
Current Protocols in Bioinformatics. 2020, 69:e96. doi:10.1002/cpbi.96
> x1=letters[1:3]
> x2=letters[4:5]
> x3=letters[1:8]
> toy_list=list(list(list("ABX",x1),
                     list("ZHK",x2)),
                list(list("CCC",x3)))
> toy_list
[[1]]
[[1]][[1]]
[[1]][[1]][[1]]
[1] "ABX"

[[1]][[1]][[2]]
[1] "a" "b" "c"

[[1]][[2]]
[[1]][[2]][[1]]
[1] "ZHK"

[[1]][[2]][[2]]
[1] "d" "e"

[[2]]
[[2]][[1]]
[[2]][[1]][[1]]
[1] "CCC"

[[2]][[1]][[2]]
[1] "a" "b" "c" "d" "e" "f" "g" "h"
> ggtree(as.phylo(toy_list)) + geom_tiplab()

xx

> l1 <- list(1, 2, 3)
> l2 <- list(1, 2, l1, 4)
> l3 <- list(1, l1, l2, 5)
> l3
[[1]]
[1] 1

[[2]]
[[2]][[1]]
[1] 1

[[2]][[2]]
[1] 2

[[2]][[3]]
[1] 3

[[3]]
[[3]][[1]]
[1] 1

[[3]][[2]]
[1] 2

[[3]][[3]]
[[3]][[3]][[1]]
[1] 1

[[3]][[3]][[2]]
[1] 2

[[3]][[3]][[3]]
[1] 3

[[3]][[4]]
[1] 4

[[4]]
[1] 5

> ggtree(as.phylo(l3)) + geom_tiplab()

xx

GuangchuangYu commented 1 year ago
> args(utils:::str.default)
function (object, max.level = NA, vec.len = strO$vec.len, digits.d = strO$digits.d, 
    nchar.max = 128, give.attr = TRUE, drop.deparse.attr = strO$drop.deparse.attr, 
    give.head = TRUE, give.length = give.head, width = getOption("width"), 
    nest.lev = 0, indent.str = paste(rep.int(" ", max(0, nest.lev + 
        1)), collapse = ".."), comp.str = "$ ", no.list = FALSE, 
    envir = baseenv(), strict.width = strO$strict.width, formatNum = strO$formatNum, 
    list.len = strO$list.len, deparse.lines = strO$deparse.lines, 
    ...) 
NULL

我觉得可以像str()一样有max.level参数。

GuangchuangYu commented 1 year ago

@xiangpin 搞一下这个max.level参数,因为像这种比如说递归式地列出文件目录,可能嵌套的list很深。