Closed jmonroynieto closed 3 years ago
it seems that not all phylo objects are the same, running str on my output:
Class "multiPhylo"
List of 3
$ 1:List of 3
..$ edge : int [1:23, 1:2] 17 18 24 24 24 18 19 19 17 17 ...
..$ Nnode : int 8
..$ tip.label: chr [1:16] "sequence6" "sequence15" "sequence16" "sequence13" ...
..- attr(*, "class")= chr "phylo"
..- attr(*, "pscore")= num 85
..- attr(*, "order")= chr "cladewise"
$ 2:List of 3
..$ edge : int [1:29, 1:2] 18 18 28 28 20 20 19 19 22 22 ...
..$ tip.label: chr [1:16] "sequence1" "sequence7" "sequence8" "sequence9" ...
..$ Nnode : num 14
..- attr(*, "class")= chr "phylo"
..- attr(*, "order")= chr "postorder"
..- attr(*, "pscore")= num 85
$ 3:List of 3
..$ edge : int [1:23, 1:2] 17 18 18 20 19 19 20 24 24 24 ...
..$ Nnode : int 8
..$ tip.label: chr [1:16] "sequence14" "sequence16" "sequence4" "sequence6" ...
..- attr(*, "class")= chr "phylo"
..- attr(*, "pscore")= num 85
..- attr(*, "order")= chr "cladewise"
The only difference is the order of the attributes, which reliably comes out switched.
The solution I found is a little ugly but is works:
sapply(lapply(treeList, attributes), function(x) x [["pscore"]]
Hi @jmonroynieto ,
I just rewrote a lot of the parsimony code (Fitch algorithm), so you want to try the version on github. Please keep me updated if you discover any problems. It should be faster and use less memory, but sometimes results can differ slightly. I will try to upload it the next days on CRAN.
Generally with S3 classes, I would not bet that the order of attributes. So extract them by name, either with $
or attr
.
There are quite a few optional arguments to phylo
obejects, like edge.length
, node.label
, order
, pscore
.
You can extract (if exists) the pscore with attr(x, "pscore")
This line is a bit less "ugly" and more readable:
sapply(treeList, function(x) attr(x, "pscore"))
Cheers, Klaus
I have an asynchronous function that outputs a multiphylo list of trees. When extracting the pscore from the attributes using
sapply(treeList, attributes)["pscore",]
some trees have the order parameter switched with score. I believe the bug to be related tortree()
since I am runningpratchet()
as follows :When running random.addition() as a starting tree, this does not happen.
The following workaround does not work, this leads me to think that the funky behaviour come from some interactions with
sapply()
EDIT: a previous version of this issue indicated that random.addition() was the culprit. Developing the workaround, the real crook was revealed.