Peter's function works but it only returns sister pairs in which both of the sisters are tips.
Here's another alternative that uses phangorn & gives you a list of all the sister pairs in which at least one of the sisters is a tip (and it also works for terminal multifurcations). parents<-unique(sapply(1:Ntip(tree),Ancestors,x=tree,type="parent")) pairs<-lapply(parents,Descendants,x=tree,type="children") ## you can stop here if you are content to have your tips & nodes ## represented using their numerical indices, otherwise: foo<-function(i,phy) if(i<=Ntip(phy)) phy$tip.label[i] else i labels<-lapply(pairs,function(x,phy) sapply(x,foo,phy=phy),phy=tree) 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 Academic Director UMass Boston Chile Abroad: https://www.umb.edu/academics/caps/international/biology_chile On 1/9/2020 11:04 PM, Peter Cowman wrote: > [EXTERNAL SENDER] > > HI Max, > > Not entirely sure if this is what you want but i did come across a script to > extract direct sister pairs (tips) in a tree > > From the dryad supplement of Grossenbacher D, Briscoe Runquist R, Goldberg > EE, Brandvain Y (2015) Geographic range size is predicted by plant mating > system. Ecology Letters 18(7): 706-713. > > https://nam01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fdoi.org%2F10.5061%2Fdryad.hv117%2F6&data=02%7C01%7Cliam.revell%40umb.edu%7C90a597b4b91d49de99c908d79571b556%7Cb97188711ee94425953c1ace1373eb38%7C0%7C1%7C637142187929613195&sdata=nf%2FSkFBV4EHIQhikHeTLk86YOxu2j1MA5Fp3TmYPVVk%3D&reserved=0 > > <https://nam01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fdoi.org%2F10.5061%2Fdryad.hv117%2F6&data=02%7C01%7Cliam.revell%40umb.edu%7C90a597b4b91d49de99c908d79571b556%7Cb97188711ee94425953c1ace1373eb38%7C0%7C1%7C637142187929613195&sdata=nf%2FSkFBV4EHIQhikHeTLk86YOxu2j1MA5Fp3TmYPVVk%3D&reserved=0> > > The script grabs sister pairs across a sample of tree and gives their > distance - i.e. pairs of tips that are monophyletic > > here is the code I have from that script (might be worth getting it from the > source script again) > > ##### > # Get all sisters > GetSisters = function(TREE){ > tips = TREE$edge[TREE$edge[,2]<=length(TREE$tip.label),] > sis.nodes = tips[duplicated(tips[,1]),1] > > tmp=data.frame(cbind(sis.nodes,do.call(rbind,lapply(sis.nodes,function(NODE){ > this = TREE$edge[,1]==NODE > c(TREE$edge[this,2][1:2],sum(TREE$edge.length[this][1:2])) > })))) > colnames(tmp) = c("internal","A","B","dist") > > tmp$a = TREE$tip.label[tmp$A]; tmp$b = TREE$tip.label[tmp$B] > tmp > } > ##### > > Hope it helps > > Cheers > > Pete > > > ======================================= > Peter F Cowman, Ph.D. > Senior Research Fellow in Ecosystem Dynamics > ARC Discovery Fellow (DECRA) > > ARC Centre of Excellence for Coral Reef Studies > <https://nam01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fwww.coralcoe.org.au%2F&data=02%7C01%7Cliam.revell%40umb.edu%7C90a597b4b91d49de99c908d79571b556%7Cb97188711ee94425953c1ace1373eb38%7C0%7C1%7C637142187929623185&sdata=sC6e6ZSJ7BlEWYhN6jn4don4IEoRS0s65M2ZXMaFt2w%3D&reserved=0> > James Cook University, Townsville, QLD, 4811, Australia > > Office: +61 7 4781 3194 | Rm 128 Bld DB019 > Email: peter.cow...@jcu.edu.au <mailto:peter.cow...@jcu.edu.au> > Twitter: @pete_cowman > ORCID ID: orcid.org/0000-0001-5977-5327 > <https://nam01.safelinks.protection.outlook.com/?url=http%3A%2F%2Forcid.org%2F0000-0001-5977-5327&data=02%7C01%7Cliam.revell%40umb.edu%7C90a597b4b91d49de99c908d79571b556%7Cb97188711ee94425953c1ace1373eb38%7C0%7C1%7C637142187929623185&sdata=g5uHfG1qDpUjquyAKfV6NUvHp9mVIupG1hKS6ubfHHo%3D&reserved=0> > >> On 10 Jan 2020, at 07:36, Max Shpak <shpak....@gmail.com> wrote: >> >> If I have an object of class "phylo" in the ape, with attributes edge, >> Nnode, node.label, and tip.label, is there some straightforward way for me >> to extract a list of sister taxon pairs (whether the sister taxa are two >> edges or an edge and a node)? >> >> I wrote to E. Paradis (the author of ape), and he said that he didn't know >> of a direct way to do this, but it may be possible through some >> manipulation of the mrca functions. >> >> Does anybody on this board have any suggestions for how to go about this? >> >> Thank you, Max Shpak >> >> -- >> ======================= >> Max Shpak, Ph.D. >> Center for Systems and Synthetic Biology >> University of Texas at Austin >> Austin, TX 78712 >> >> [[alternative HTML version deleted]] >> >> _______________________________________________ >> R-sig-phylo mailing list - R-sig-phylo@r-project.org >> https://nam01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fstat.ethz.ch%2Fmailman%2Flistinfo%2Fr-sig-phylo&data=02%7C01%7Cliam.revell%40umb.edu%7C90a597b4b91d49de99c908d79571b556%7Cb97188711ee94425953c1ace1373eb38%7C0%7C1%7C637142187929623185&sdata=xiGcF2HLz%2Ffv6B1h0tKuQFmwLOfaneTjrXDgFNv4glA%3D&reserved=0 >> Searchable archive at >> https://nam01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww.mail-archive.com%2Fr-sig-phylo%40r-project.org%2F&data=02%7C01%7Cliam.revell%40umb.edu%7C90a597b4b91d49de99c908d79571b556%7Cb97188711ee94425953c1ace1373eb38%7C0%7C1%7C637142187929623185&sdata=XdPCQsFlTHWdRx8G6OgTczvvLEInBWVoNflalBdpkFY%3D&reserved=0 > > > [[alternative HTML version deleted]] > > _______________________________________________ > R-sig-phylo mailing list - R-sig-phylo@r-project.org > https://nam01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fstat.ethz.ch%2Fmailman%2Flistinfo%2Fr-sig-phylo&data=02%7C01%7Cliam.revell%40umb.edu%7C90a597b4b91d49de99c908d79571b556%7Cb97188711ee94425953c1ace1373eb38%7C0%7C1%7C637142187929623185&sdata=xiGcF2HLz%2Ffv6B1h0tKuQFmwLOfaneTjrXDgFNv4glA%3D&reserved=0 > Searchable archive at > https://nam01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww.mail-archive.com%2Fr-sig-phylo%40r-project.org%2F&data=02%7C01%7Cliam.revell%40umb.edu%7C90a597b4b91d49de99c908d79571b556%7Cb97188711ee94425953c1ace1373eb38%7C0%7C1%7C637142187929623185&sdata=XdPCQsFlTHWdRx8G6OgTczvvLEInBWVoNflalBdpkFY%3D&reserved=0 > _______________________________________________ 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/