library(ape) library(phangorn)
I have some trees for which I'm trying to input their branch heights, but there seems to be an issue which I can't pin down:
tree1 <- ape::read.tree(text = "(((((t1:1,t2:1)n5:1,(((t3:1,t4:1)n8:1,(t5:1,t6:1)n9:1)n7:1,(t7:1,(t8:1,t9:1)n11:1)n10:1)n6:1,(t10:1,t11:1,((t12:1,t13:1,t14:1)n14:1,(t15:1,t16:1,t17:1,t18:1)n15:1)n13:1)n12:1)n4:1,(((t19:1,(t20:1,(t21:1,t22:1)n20:1)n19:1)n18:1,t23:1)n17:1,(t24:1,(t25:1,t26:1)n22:1,(t27:1,t28:1,t29:1,t30:1)n23:1)n21:1)n16:1,(t31:1)n24:1,(t32:1,t33:1,t34:1)n25:1)n3:1,t35:1)n2:1)n1;")
nnls.tree(cophenetic(tree1), tree1)
Error in fixupDN.if.valid(value, x@Dim) : length of Dimnames[[2]] (58) is not equal to Dim[2] (57)
However:
tree2 <- drop.tip(tree1, "t35")
nnls.tree(cophenetic(tree2), tree2)
Works as expected:
Phylogenetic tree with 34 tips and 22 internal nodes.
Tip labels: t1, t2, t3, t4, t5, t6, ... Node labels: n3, n4, n5, n6, n7, n8, ...
Unrooted; includes branch lengths.
what is going on here?
I got an answer from the dev, the problem are the single nodes.
tree1 <- collapse.singles(tree1)
does the trick.