huaxia1985 / ProSSE

Protracted Speciation Extinction
0 stars 0 forks source link

Error in make.prosse (when recovering ancestral nodes for monophyletic clades) #1

Open Jeremy-Andreoletti opened 4 months ago

Jeremy-Andreoletti commented 4 months ago

Hi!

Context: running make.prosse on this phylogeny phylo_incipient.tree.zip

Error:

Error in edge[max(which(is.element(edge[, 2], which(tip.species[, i])))) -  : only 0's may be mixed with negative subscripts

Source of the error: function make.cache.tree.prosse, line to recover the ancestral nodes of a monophyletic clade

group.tmp <- lapply(clade[mono],function (i) edge[max(which(is.element(edge[,2],which(tip.species[,i]))))-c(0:(n.tip.species[i]*2-2)),2])

The resulting vector should indeed have length 1+n.tip.species[i]*2-2, but - at least for my tree - this method does not work to get the correct nodes (it produces some negative indices, hence the error).

Potential solution: I replaced this line by

group.tmp <- lapply(clade[mono],function (i) {
    MRCA_i <- getMRCA(tree, which(tip.species[,i]))
    descendants_i <- TreeTools::DescendantEdges(edge[,1], edge[,2], node=MRCA_i)
    c(edge[descendants_i,2],MRCA_i)
    })

This seems to work, but I haven't checked if there are similar problems elsewhere in the code.

huaxia1985 commented 4 months ago

Hello, Thanks for your email. I’m on parental leave at the moment, but I’ll have a look at your tree and get back to you as soon as I can. Xia

On Thu, 20 Jun 2024 at 1:43 AM, Jérémy Andréoletti @.***> wrote:

Context: running make.prosse on this phylogeny phylo_incipient.tree.zip https://github.com/user-attachments/files/15903207/phylo_incipient.tree.zip

Error:

Error in edge[max(which(is.element(edge[, 2], which(tip.species[, i])))) - : only 0's may be mixed with negative subscripts

Source of the error: function make.cache.tree.prosse, line to recover the ancestral nodes of a monophyletic clade

group.tmp <- lapply(clade[mono],function (i) edge[max(which(is.element(edge[,2],which(tip.species[,i]))))-c(0:(n.tip.species[i]*2-2)),2])

The resulting vector should indeed have length n.tip.species[i]*2-2, but

  • at least for my tree - this method does not work to get the correct nodes (it produces some negative indices, hence the error).

Potential solution: I replaced this line by

group.tmp <- lapply(clade[mono],function (i) { MRCA_i <- getMRCA(tree, which(tip.species[,i])) descendants_i <- TreeTools::DescendantEdges(edge[,1], edge[,2], node=MRCA_i) c(edge[descendants_i,2],MRCA_i) })

This seems to work, but I haven't checked if there are similar problems elsewhere in the code.

— Reply to this email directly, view it on GitHub https://github.com/huaxia1985/ProSSE/issues/1, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABBVS2ECJZO3EM4J676HG7TZIGRITAVCNFSM6AAAAABJSKAWESVHI2DSMVQWIX3LMV43ASLTON2WKOZSGM3DENRYGUYDKOI . You are receiving this because you are subscribed to this thread.Message ID: @.***>