emmanuelparadis / ape

analysis of phylogenetics and evolution

Home Page:http://ape-package.ird.fr/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

boot.phylo(): 'Error in 'bitsplits(phy)': INTEGER() can only be applied to a 'integer', not a 'double'

pawelqs opened this issue · comments

Hi!

I have encountered problem when trying to bootstrap my phylogenetic tree using the following code:

my_boots <- boot.phylo(parsimony_trees$NJ, t(VAF_mat_bin),
    function(x) {
        hamming_dist <- hamming.distance(x)
        tree_NJ <- NJ(hamming_dist)
        tree_NJ
        # mutdat <- phyDat(x, type = "USER", levels = c(0, 1))
        # optim.parsimony(tree_NJ, mutdat)
        },
    B = 10
 )

Calculating bootstrap values...Błąd w poleceniu 'bitsplits(phy)':
INTEGER() can only be applied to a 'integer', not a 'double'

parsimony_trees$NJ is a phylogenetic tree obtained with hamming.distance %>% NJ %>% phyDat flow, but I skipped las lines here to simplify the function while debugging this error.

I found that the error is thrown by
ans <- .Call(bitsplits_multiPhylo, x, n, nr) line in bitsplits() function, but I cannot find the definition of bitsplits_multiPhylo to dig it deeper.

What might be the problem?

Best,
Paweł

Hi,
I suggest you build a separate function that returns the tree from your matrix of 0's and 1's, eg:

f <- function(x) {
    x <- phyDat(x, type = "USER", levels = 0:1)
    hamming_dist <- dist.hamming(x)
    NJ(hamming_dist)
}

Then you get your tree with f(X), for instance with some simulated data:

n <- 10
p <- 10
X <- matrix(sample(0:1, n * p, TRUE), n, p)
rownames(X) <- paste0("Sp", 1:n)
tr <- f(X)

The bootstrap is done with:

boot.phylo(tr, X, f)

If you prefer to bootstrap the "phyDat" data, ?bootstrap.phyDat has an example with a parsimony tree.

Hi!

If you prefer to bootstrap the "phyDat" data, ?bootstrap.phyDat has an example with a parsimony tree.

Actually bootstrapping for parsimony might not be necessary any more. pratchet with the argument perturbation = "ratchet", which is the default, implicitly does bootstrapping. I should change this example and highlight it more. Set the argument minit as the minimal number of bootstrap samples, maximum is given by the maxit argument. Note to myself: I should change the default of minit.

tree <- pratchet(x, minit=100)

and the tree will have bootstrap values assigned to it.

Best,
Klaus

Hi!

Finally, I did bootstrapng using bootstrap.phyDat().

What is th pratchet() function? I cannot find this function in phangorn/ape packages.

Best,
Paweł

Hi @pawel125,
pratchet() is in phangorn, the help page is together with all the other parsimony functions. It is a more fancy version of optim.parsimony doing some additional perturbations of the tree during the search. This might result in better trees and does implicit some bootstrapping, but is of course much slower.
Best,
Klaus

Ok, I found it. Thanks!
Paweł