You might need to reindex each time, something like (pseudocode): bad.nodes <- function_to_get_node_numbers_with_support_less_than_90(phy) while(length(bad.nodes>0)) { phy <- collapse.to.star(phy, bad.nodes[1]) bad.nodes <- function_to_get_node_numbers_with_support_less_than_90(phy) }
But this will collapse the bad node and all its descendants. I don't see a function that just collapses at a node and leaves descendants intact, but this may be what you're looking for (the stuff that ape::collapse.singles does is similar, and could perhaps be modified). One pedantic point -- we often talk about node support, collapsing nodes, etc., but it's really about the branch: the node doesn't have 83% bootstrap support but the bipartition created by the edge subtending it does. For example, if the tree is (A,(B,(C,(D,E)))), if the support for the CDE clade is 83%, it's actually the proportion of trees that have a split between AB | CDE, so the branch separating the CDE clade from everything else. The node itself there has one branch coming in (that comes from the rest of the tree containing A and B) and two branches coming out (one going to C, one going to DE). We could summarize trees by actual node support: how many times we have a node that has an edge going to AB, an edge going to C, and an edge going to DE, but we typically don't. [For example, the branch could separate AB | CDE, and the node is AB | C | DE, but one could also have a node that is AB | CD | E for the same bipartition on the subtending edge]. I only bring it up here because if you end up having to write code to do collapsing, it can be important to remember that what is actually being collapsed is the edge subtending the labeled node because it is the the edge with low support. Best, Brian _______________________________________________________________________ Brian O'Meara Professor, Dept. of Ecology & Evolutionary Biology, UT Knoxville Associate Head, Dept. of Ecology & Evolutionary Biology, UT Knoxville He/Him/His On Fri, May 22, 2020 at 9:42 AM Karla Shikev <karlashi...@gmail.com> wrote: > Dear all, > > I'm surprised I could not find a simple function to do this in any of the > packages I know. I just want to take a tree with node labels (e.g. > bootstrap values from a RAxML analysis) and collapse all nodes with support > values below, say, 90%. I tried to do this recursively using > collapse.to.star in phytools, but node numbers change after the first > collapsed node and my indexing gets completely off. > > with best regards, > > Karla > > [[alternative HTML version deleted]] > > _______________________________________________ > R-sig-phylo mailing list - R-sig-phylo@r-project.org > https://stat.ethz.ch/mailman/listinfo/r-sig-phylo > Searchable archive at > http://www.mail-archive.com/r-sig-phylo@r-project.org/ > [[alternative HTML version deleted]] _______________________________________________ R-sig-phylo mailing list - R-sig-phylo@r-project.org https://stat.ethz.ch/mailman/listinfo/r-sig-phylo Searchable archive at http://www.mail-archive.com/r-sig-phylo@r-project.org/