How about something like this: H<-nodeHeights(tree) t<-max(H)-25 ## for 25 mybp h1<-which(H[,1]<t) h2<-which(H[,2]>t) ii<-intersect(h1,h2) nodes<-tree$edge[ii,2] getDescendants<-phytools:::getDescendants ## get internal function tips<-lapply(nodes,getDescendants,tree=tree) tips<-tree$tip.label[sapply(tips,function(x,y) x[x<=Ntip(y)][1],y=tree)] tt<-drop.tip(tree,setdiff(tree$tip.label,tips))
Let us know if this works. All the best, Liam Liam J. Revell, Assistant Professor of Biology University of Massachusetts Boston web: http://faculty.umb.edu/liam.revell/ email: [email protected] blog: http://blog.phytools.org On 11/3/2014 3:44 PM, Susan Kapust wrote:
Dear Liam (and the others that responded directly to my email), I tested the provided code and it works beautifully. Thanks! Any suggestions about the second problem I indicated in the original email? Thanks! Susan On Mon, Nov 3, 2014 at 1:36 PM, Liam J. Revell <[email protected] <mailto:[email protected]>> wrote: You could try something like the following: tips<-tree$tip.label genera<-unique(sapply(__strsplit(tips,"_"),function(x) x[1])) ii<-sapply(genera,function(x,__y) grep(x,y)[1],y=tips) tree<-drop.tip(tree,setdiff(__tree$tip.label,tips[ii])) Let us know if this works. All the best, Liam Liam J. Revell, Assistant Professor of Biology University of Massachusetts Boston web: http://faculty.umb.edu/liam.__revell/ <http://faculty.umb.edu/liam.revell/> email: [email protected] <mailto:[email protected]> blog: http://blog.phytools.org On 11/3/2014 11:56 AM, Susan Kapust wrote: Dear colleagues, I have a large species-level phylogeny in which the tip labels are indicated as "Genus_species". All genera are monophyletic. I have two things I'm struggling with: (1) I'd like to drop all but one of the tips in each genus (i.e. to generate a genus-level phylogeny). Given that all genera are monophyletic, it shouldn't matter which species I pick. (2) I'd like to establish an era (e.g. 25 Mya) and leave only one representative of the clades there were present at that point in time. Given that I actually have a post-burnin set of trees, once I figure out how to do the steps above I could (hopefully) do that for all trees. thanks so much for your help. Susan. [[alternative HTML version deleted]] _________________________________________________ R-sig-phylo mailing list - [email protected] <mailto:[email protected]> https://stat.ethz.ch/mailman/__listinfo/r-sig-phylo <https://stat.ethz.ch/mailman/listinfo/r-sig-phylo> Searchable archive at http://www.mail-archive.com/[email protected]/ <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]/
