I am working on to create a newick tree out of list of childs. I have a list of lists where the list name is the parent name and list element are the childs. Here is an example:
$`825`
[1] 824
$`824`
[1] 823
$`823`
[1] 822
$`822`
[1] 821
$`821`
[1] 820 777
$`820`
[1] 819 816 789 787 785 783
$`789`
[1] 788
$`787`
[1] 786
$`785`
[1] 784
$`783`
[1] 782
$`777`
[1] 776
Hence the output I want is phylo tree in newick format as follows:
825(824(823(822(821(820(819,816,789(788),787,785(784),783(782)),777(776)))))
What is the best way to do this? One way is to write a recursive function that traverses in depth first order and creates the tree. But in R recursions are known to be bad.
Thanks.