Re: [R-sig-phylo] Adding species to genera tree as polytomies
Thank you both for your kind and helpful answers that have solved my problem! It is very much appreciated :) Best, Liam > On 17 Oct 2018, at 5:01 am, Liam J. Revell wrote: > > 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 - 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/ ___ 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/
Re: [R-sig-phylo] Adding species to genera tree as polytomies
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 < richard.gren...@ouce.ox.ac.uk> 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 on behalf of Liam > J. Revell > Sent: Tuesday, October 16, 2018 7:02 pm > To: Liam Kendall; r-sig-phylo@r-project.org > 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 - 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/ > > > > ___ > R-sig-phylo mailing list - R-si
Re: [R-sig-phylo] Adding species to genera tree as polytomies
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 on behalf of Liam J. Revell Sent: Tuesday, October 16, 2018 7:02 pm To: Liam Kendall; r-sig-phylo@r-project.org 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 - 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/ > ___ 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/
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 - 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/ ___ 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/
Re: [R-sig-phylo] Adding species to genera tree as polytomies
This might be somewhat of a hacky solution, but could you just add "sp." to all of your genus names? The phytools function is looking for "Genus species" in your tree tip names, but none of your tips have binomials, so it's not finding the correct genus. By adding "sp." to all of your original tip names (the genera), this then turns them into binomials and the function should work as expected, I believe. Best, Will On Tue, Oct 16, 2018 at 9:40 AM 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 - 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/ > -- William Gearty PhD Candidate, Paleobiology Department of Geological Sciences Stanford School of Earth, Energy & Environmental Sciences williamgearty.com [[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/
[R-sig-phylo] Adding species to genera tree as polytomies
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 - 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/
[R-sig-phylo] Phylogenetic comparative methods for studying diversification and phenotypic evolution
I thought this course might be of interest to some page members... Phylogenetic comparative methods for studying diversification and phenotypic evolution (PCME01) https://www.prstatistics.com/course/phylogenetic-comparative-methods-for-studying-diversification-and-phenotypic-evolution-pcme01/ This course will be delivered by Dr. Antigoni Kaliontzopoulou from the 5th - 8th November 2018 in Glasgow City Centre. Course Overview: Phylogenetic comparative methods are commonly used nowadays to investigate how species diversification occurs and to test hypotheses about the mechanisms that drive phenotypic evolution, e.g. to model speciation and extinction, to understand why some groups are more diverse than others, to test whether phenotypic traits have evolved under neutral, directional or diversifying selection, to investigate how evolutionary rates are modified across the evolutionary history of a group etc. In all these cases, a phylogenetic hypothesis for the group of interest is combined to phenotypic and ecological data at the species level to understand the tempo and mode of evolutionary change. The objective of this course is to provide an overview of these methods and of the tools available for their implementation in the R statistical language. During theoretical sessions, we will review the main concepts and statistical tools necessary for testing hypotheses about species diversification and phenotypic evolution. These will then be implemented during practicals through worked examples to provide the participants with hands-on experience on data management and the implementation of these methods to real biological data. Monday 5th – Classes from 09:30 – 17:30 Introduction 1-1) Why do we need PCMs? A short history of the field 1-2) Testing for phylogenetic signal 1-3) Ancestral character reconstruction 1-4) PRACTICALS Tuesday 6th – Classes from 09:30 – 17:30 Testing hypotheses on phenotypic evolution 2-1) Phylogenetic independent contrasts and phylogenetic GLS 2-2) Phylogenetically-informed ordination 2-3) PRACTICALS Wednesday 7th – Classes from 09:30 – 17:30 Tempo and mode of evolutionary change 3-1) Evolutionary rates: estimation and tests 3-2) Models of phenotypic evolution 3-3) PRACTICALS Thursday 8th – Classes from 09:30 – 16:00 Miscellanea 4-1) Modelling lineage diversification 4-2) Future perspectives: multivariate extensions to PCMs 4-3) PRACTICALS Email oliverhoo...@prstatistics.com Check out our sister sites, www.PRstatistics.com (Ecology and Life Sciences) www.PRinformatics.com (Bioinformatics and data science) www.PSstatistics.com (Behaviour and cognition) 1. October 15th – 19th 2018 APPLIED BAYESIAN MODELLING FOR ECOLOGISTS AND EPIDEMIOLOGISTS (ABME04) Glasgow, Scotland, Dr. Matt Denwood, Emma Howard http://www.prstatistics.com/course/applied-bayesian-modelling-ecologists-epidemiologists-abme04/ 2. October 23rd – 25th 2018 INTRODUCTIUON TO R (This is a private ‘in-house’ course) London, England, Dr William Hoppitt 3. October 29th – November 2nd 2018 INTRODCUTION TO R AND STATISTICS FOR BIOLOGISTS (IRFB02) Glasgow, Scotland, Dr. Olivier Gauthier https://www.prstatistics.com/course/introduction-to-statistics-and-r-for-biologists-irfb02/ 4. October 29th – November 2nd 2018 INTRODUCTION TO BIOINFORMATICS FOR DNA AND RNA SEQUENCE ANALYSIS (IBDR01) Glasgow, Scotland, Dr Malachi Griffith, Dr. Obi Griffith www.prinformatics.com/course/precision-medicine-bioinformatics-from-raw-genome-and-transcriptome-data-to-clinical-interpretation-pmbi01/ 5. November 5th – 8th 2018 PHYLOGENETIC COMPARATIVE METHODS FOR STUDYING DIVERSIFICATION AND PHENOTYPIC EVOLUTION (PCME01) Glasgow, Scotland, Dr. Antigoni Kaliontzopoulou https://www.prstatistics.com/course/phylogenetic-comparative-methods-for-studying-diversification-and-phenotypic-evolution-pcme01/ 6. November 19th – 23rd 2018 STRUCTUAL EQUATION MODELLING FOR ECOLOGISTS AND EVOLUTIONARY BIOLOGISTS (SEMR02) Glasgow, Scotland, Dr. Jonathan Lefcheck https://www.prstatistics.com/course/structural-equation-modelling-for-ecologists-and-evolutionary-biologists-semr02/ 7. November 26th – 30th 2018 FUNCTIONAL ECOLOGY FROM ORGANISM TO ECOSYSTEM: THEORY AND COMPUTATION (FEER01) Glasgow, Scotland, Dr. Francesco de Bello, Dr. Lars Götzenberger, Dr. Carlos Carmona http://www.prstatistics.com/course/functional-ecology-from-organism-to-ecosystem-theory-and-computation-feer01/ 8. December 3rd – 7th 2018 INTRODUCTION TO BAYESIAN DATA ANALYSIS FOR SOCIAL AND BEHAVIOURAL SCIENCES USING R AND STAN (BDRS01) Glasgow, Dr. Mark Andrews https://www.psstatistics.com/course/introduction-to-bayesian-data-analysis-for-social-and-behavioural-sciences-using-r-and-stan-bdrs01/ 9. January 21st – 25th 2019 STATISTICAL MODELLING OF TIME-TO-EVENT DATA USING SURVIVAL ANALYSIS: AN INTRODUCTION FOR ANIMAL BEHAVIOURISTS, ECOLOGISTS AND EVOLUTIONARY BIOLOGISTS (TTED01) Glasgow, Scotland, Dr. Will Hoppit