Yes, name.check() will only work with a named vector of data or data frame, so 
Liam's code should work for you. it also looks like your names in the vector 
"species" are different from those of the tip labels, as you say that 
nc$Tree.not.data gives you a bunch of numbers but your vector is made of 
Species underscore number, e.g. Species_1. If that's the case, either change 
your file of species names to be just numbers, or use the following to change 
your tree tip labels before using liam's code.


tree$tip.label <- paste("Species", tree$tip.label, sep = "_")


------------------------------------------------------------
Graham Slater
Department of Ecology and Evolutionary Biology
University of California, Los Angeles
621 Charles E Young Drive South
Los Angeles
CA 90095-1606

(310) 825-4669
gsla...@ucla.edu
www.eeb.ucla.edu/gslater






On Mar 4, 2011, at 7:45 AM, Liam J. Revell wrote:

> Hi Eugen,
> 
> Did you try my suggestion?
> 
> In your case, if the species you want to keep are in a row separated text 
> file, with a header ("species"), first read them in:
> 
> > species.to.keep<-read.table(file="species.list.file",header=T)
> 
> Now, for "phylo" object tree, type:
> 
> > pruned.tree<-drop.tip(tree,tree$tip.label[-match(species.to.keep[,1], 
> > tree$tip.label)])
> 
> - Liam
> 
> -- 
> Liam J. Revell
> University of Massachusetts Boston
> web: http://faculty.umb.edu/liam.revell/
> (new) email: liam.rev...@umb.edu
> (new) blog: http://phytools.blogspot.com
> 
> On 3/4/2011 6:52 AM, Eugen Egorov wrote:
>> First of all, thank you for helping :)
>> 
>> Well, this didn't work out, although it should work perfectly. When I
>> type in "nc <- name.check(tree, data)" and then "nc" I get all tree
>> species (over 3000 species) in the $Tree.not.data part. In the $Data.not
>> tree part I see 281 numbers from "1" to "281", this is the number of
>> species in my data file. Seems like R doesnt recognize the species names
>> in the data file.
>> 
>> The data file is a .csv file and looks like this:
>> 
>> species
>> Species_1
>> Speceis_2
>> Species_3
>> ....
>> Species_281
>> 
>> so its one column and nothing else. What should I do?
>> 
>> Thanks a lot
>> 
>> 
>> ----- Original Message ----- From: "Graham Slater" <gsla...@ucla.edu>
>> To: "Eugen Egorov" <eugen...@online.de>
>> Cc: <r-sig-phylo@r-project.org>
>> Sent: Thursday, March 03, 2011 7:54 PM
>> Subject: Re: [R-sig-phylo] Pruning a tree
>> 
>> 
>> drop.tip assumes you have identified the tips that you want to remove,
>> which you could do using
>> 
>> nc <- name.check(tree, data).
>> newtree <- drop.tip(tree, nc[[1]])
>> 
>> or
>> 
>> newtree <- drop.tip(tree, nc$Tree.not.data) # note that Tree has a caps
>> and not using this could cause a weird tree with no tips to be output.
>> 
>> 
>> But if your data are simply a list of names (and I assume here you mean
>> you have a vector of names rather than an actual list) and you don't
>> know exactly which species are missing then the following might be easier:
>> 
>> 
>> missing <- tree$tip.label[is.na(match(tree$tip.label, listofnames))] ##
>> will use the match() function to identify the tips that are not present
>> in your list - it essentially is trying to match the tip names from the
>> tree to your list and if there is no match it reports NA for that tip.
>> we get the tip names corresponding to those NAs here
>> 
>> newtree <- drop.tip(tree, missing) # this will remove those tips
>> 
>> 
>> graham
>> On Mar 3, 2011, at 9:15 AM, Eugen Egorov wrote:
>> 
>>> Hi all,
>>> 
>>> I have a huge tree and a list with species. Now I want to prune the
>>> tree, so only species appearing in the list are left in the tree. I
>>> tried the geiger package to compare tree species with those in the
>>> list, but that didn't work out, because I recieved a tree with 0 tips
>>> and 1 node after using "drop.tip$tree.not.data". I guess I have to
>>> format the list, but I don't know in which way. Any idea how I do that?
>>> 
>>> greets
>>> 
>>> Eugen
>>> [[alternative HTML version deleted]]
>>> 
>>> _______________________________________________
>>> R-sig-phylo mailing list
>>> R-sig-phylo@r-project.org
>>> https://stat.ethz.ch/mailman/listinfo/r-sig-phylo
>> 
>> ------------------------------------------------------------
>> Graham Slater Ph. D.
>> Department of Ecology and Evolutionary Biology
>> University of California, Los Angeles
>> 610 Charles E. Young Drive South
>> Los Angeles, CA 90095-1606
>> 
>> (424) 442-4348
>> gsla...@ucla.edu
>> www.eeb.ucla.edu/gslater
>> 
>> _______________________________________________
>> R-sig-phylo mailing list
>> R-sig-phylo@r-project.org
>> https://stat.ethz.ch/mailman/listinfo/r-sig-phylo

_______________________________________________
R-sig-phylo mailing list
R-sig-phylo@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-phylo

Reply via email to