I am working on large scale biodiversity simulations and have collected a lot of data on simulated phylogenies. I have a list of child-parent edgelist species in the form:
list = [1, 1, 2, 2]
/-- 3
1 -- 2
\-- 4
children = [1, 2, 3, 4]
parents = [1, 1, 2, 2]
Where the index is the child and the value is the parent. 1 is it's own parent (the root).
I have such a tree for a large dataset upwards of 1000 individuals. I can build the tree programmatically in igraph or networkx easily and visualise it. However, I cannot find a way to convert the tree into a format for phylogenetic analysis. There are function to convert dendropy and ete trees from igraph/networkx into their own formats but no way to re-import the igraph/networkx trees. There also appear to be no way to write the igraph/networkx trees into phylo formats (newick).
There also seems to be no support in dendropy or ete to programmatically build trees and it would be infeasible to manually build all the trees I have.
Is there a way to build the trees so I can analyse and visualise them as phylogenies?
Tried approach
library(ape)
p <- c(NA, 1, 1, 3, 3, 4, 4)
x<-data.frame(name=as.character(c(1:7)) , id=1:7, parent = c(NA, 1, 1, 3, 3, 4, 4))
x1<-na.omit(x)[,3:2]
n <- c(c(1, 3, 4), c(2, 5, 6, 7))
edges <- matrix(c( x1$parent, x1$id), ncol=2)
tree<-list(edge=edges, Nnode = 3, tip.label = as.character(x$name[c(2, 5, 6, 7)]), node.label = as.character(x$name[c(1, 3, 4)]))
class(tree)<-"phylo"
#plot.phylo(tree, show.node.label=TRUE)
The plot command just causes R to crash and the tree object has an invalid structure.
graph.adjlist(mylist, mode = 'out')
$\endgroup$ – Sanalphatau Aug 22 '15 at 14:44