I vaguely remember similar issues in my own simulator long ago, and the
solution was:

tr2 = read.tree(file="", text=write.tree(simtree, file=""))

Cheers!
Nick


On Wed, Nov 20, 2024 at 3:12 PM Alex Skeels <[email protected]>
wrote:

> Hi everyone,
>
> I have a problem that I've been stuck on for a bit. I am running a custom
> simulation which keeps track of species divergences in an edge table
> containing parent, descendent, and branch length information. Because it is
> a forward-in-time sim it starts labelling nodes at "1" which is different
> to how nodes are labelled in ape.
>
> This is giving me problems reconstructing a tree from this table as I get
> the Error in plot.phylo(tree) : tree badly conformed; cannot plot. Check
> the edge matrix." when using my numbering system. It's not super intuitive
> to know exactly what ape is expecting here and I'm wondering if anyone
> knows and whether there's a straight forward way to convert to that format?
>
> Here's a reproducible example of what I'm talking about. Any ideas how to
> resolve this?
>
> library(ape)
>
> # set up an edgetable
> edgetable <- data.frame(parent=c(0, 1, 1, 3, 3, 4, 5),
> node=c(1,2,3,4,5,6,7), brlen=c(0.7, 5.6, 4.9, 0.6, 0.7, 0.1, 0.1))
>
> # get the tips "nodes"
> terminal_branches <- edgetable$node[which(edgetable$node %in%
> edgetable$parent)]
>
> # create list with necessary ingredients
> tree <- list(edge=edgetable[,c("parent", "node")],
>              edge.length=edgetable[,"brlen"],
>              tip.label = paste0("species_", terminal_branches),
>              Nnode = length(terminal_branches)-1)
>
> # turn list into phylo
> class(tree) <- "phylo"
>
> # ok looks good
> tree
>
> # plot
> plot(tree)
> # "Error in plot.phylo(tree) : tree badly conformed; cannot plot. Check the
> edge matrix."
>
> Thanks in advance!!
>
> Cheers,
>
> Alex Skeels
>
>         [[alternative HTML version deleted]]
>
> _______________________________________________
> R-sig-phylo mailing list - [email protected]
> https://stat.ethz.ch/mailman/listinfo/r-sig-phylo
> Searchable archive at
> http://www.mail-archive.com/[email protected]/
>

        [[alternative HTML version deleted]]

_______________________________________________
R-sig-phylo mailing list - [email protected]
https://stat.ethz.ch/mailman/listinfo/r-sig-phylo
Searchable archive at http://www.mail-archive.com/[email protected]/

Reply via email to