Hi there, If I read this right, you're also wanting to loop this over multiple genera. If so, it might save some time to try this with the addTaxa package (https://github.com/eliotmiller/addTaxa/blob/master/DESCRIPTION). I haven't worked on this project in a while, and I left the documentation in an unfortunate place where it might not match exactly how the functions work these days. But, it should do what you want it to if you can get it to go.
Rich's idea is good if you want to learn a bit more about Newick formats. Count your parentheses up when you can't figure out how you broke it. Eliot On Tue, Oct 16, 2018 at 2:30 PM Richard Grenyer < [email protected]> wrote: > In the interests of furthering appalling hackery of the worst kind, on the > assumption you want to replace *all* generic nodes with their descendants > (or you don’t care about ultrametricity), you can do this easily with a > good text editor and the genus tree in one of the parenthetical notation > formats: > > Find: Genus_name > Replace: (Species_one:x, Species_n:x) > > You could even do it *in R* with grep(). Obviously there’s no error > checking and you can end up with horrible downstream problems. It will > however give you the true experience of phyloinformatics in the 1990s. > > Good luck! > > Rich > > > > Rich Grenyer > Associate Professor of Biogeography and Biodiversity, SOGE & Fellow of > Jesus College > University of Oxford > > > ________________________________ > From: R-sig-phylo <[email protected]> on behalf of Liam > J. Revell <[email protected]> > Sent: Tuesday, October 16, 2018 7:02 pm > To: Liam Kendall; [email protected] > Subject: Re: [R-sig-phylo] Adding species to genera tree as polytomies > > Hi Liam. > > First of all, great choice of names! > > Secondly, add.species.to.genus is a very old function & I wouldn't be > surprised to find that it had some bugs. Be forewarned! > > Thirdly, I used Will's suggestion & got the function to work in the > script you sent to me off-list, but with one additional modification > that in your 'for' loop you were not replacing the tree with the added > tip in each iteration of the loop. I.e.: > > new.tree<-tree > for (i in 1:length(tips)){ > new.tree<-add.species.to.genus(tree,tips[i]) > } > > will only result in a tree with one more tip than the original tree. > Your script should instead have the form: > > new.tree<-tree > for (i in 1:length(tips)){ > new.tree<-add.species.to.genus(new.tree,tips[i]) > } > > Note that where="root" does not work if a genus is monotypic (as yours > will be the first time a new tip is added to a given genus) & instead > the species will be added halfway along the edge leading to that genus. > Henceforward, additional species will be added to this point. This (or > some variant thereof) must be the case, because if new tips were instead > added at the start of this edge then sister genera would invariably form > single, polytomous combs. (Draw it on a piece of paper. You'll see what > I mean.) > > Finally, I noticed that some of your edge lengths in the original tree > have negative lengths. This is not a problem for the method, as it turns > out, but it will create an interesting visualization when graphed. > > Here is your fully modified script: > > library(phytools) > bee_tree=read.tree("bee_tree.nex") > species=read.csv("species.csv",stringsAsFactors = FALSE) > beetree<-bee_tree > ## Will's suggestion > beetree$tip.label<-paste(beetree$tip.label,"_sp.",sep="") > for(i in 1:length(species$Genus_species)){ > beetree<-add.species.to.genus(beetree,species$Genus_species[i], > where="root") > } > ## prune out these same taxa > ii<-grep("sp.",beetree$tip.label) > beetree<-drop.tip(beetree,beetree$tip.label[ii]) > > I hope this is helpful. > > All the best, Liam > > Liam J. Revell > Associate Professor, University of Massachusetts Boston > Profesor Asistente, Universidad Católica de la Ssma Concepción > web: http://faculty.umb.edu/liam.revell/, http://www.phytools.org > > On 10/15/2018 11:01 PM, Liam Kendall wrote: > > Hi members, > > > > I am struggling with what I think is a relatively simple problem. I have > a genera tree (i.e. genera are the branch tips) that I need to add 390 > species to as polytomies with equal branch lengths below the genera > tips/nodes. > > > > Can anyone help me do this in R? I have tried a for loop using > add.species.to.genus from phytools but it doesn’t work, I am guessing this > is because the genera are tips rather than nodes (and I cant debug the code > to find a solution). > > > > Is there another function in the R universe that might work? > > > > Any help would be much appreciated. > > > > Best, > > Liam > > _______________________________________________ > > R-sig-phylo mailing list - [email protected] > > https://stat.ethz.ch/mailman/listinfo/r-sig-phylo > > Searchable archive at > http://www.mail-archive.com/[email protected]/ > > > > _______________________________________________ > R-sig-phylo mailing list - [email protected] > https://stat.ethz.ch/mailman/listinfo/r-sig-phylo > Searchable archive at > http://www.mail-archive.com/[email protected]/ > > [[alternative HTML version deleted]] > > _______________________________________________ > R-sig-phylo mailing list - [email protected] > https://stat.ethz.ch/mailman/listinfo/r-sig-phylo > Searchable archive at > http://www.mail-archive.com/[email protected]/ > [[alternative HTML version deleted]] _______________________________________________ R-sig-phylo mailing list - [email protected] https://stat.ethz.ch/mailman/listinfo/r-sig-phylo Searchable archive at http://www.mail-archive.com/[email protected]/
