Turn a newick format tree to a matrix of edges

newick_to_edges(newick, node = "R", edgemat = matrix(NA, 0, 2))

Arguments

newick

Tree in newick format.

node

Root label of the tree.

edgemat

Used for recursive function calls.

Value

Tree as two column matrix of edges (adjacency list)

Examples

newick = random_newick(c('a', 'b', 'c', 'd'))
newick
#> [1] "(a,((b,c),d))"
newick_to_edges(newick)
#>      [,1]  [,2] 
#> [1,] "R"   "a"  
#> [2,] "R"   "Rr" 
#> [3,] "Rr"  "Rrl"
#> [4,] "Rrl" "b"  
#> [5,] "Rrl" "c"  
#> [6,] "Rr"  "d"