Betty Gilbert
2006-May-09 01:37 UTC
[R] problem accessing trees after read.nexus from ape package
Hello, I've been trying to figure out how to access the individual elements from an object of class phylo. I am reading in 201 trees created by paup as below.> read.nexus("A_30knj_200t.txt", tree.names= NULL) -> anj30 > anj30[1]$tree1 $edge [,1] [,2] [1,] "-1" "-2" [2,] "-2" "-3" [3,] "-3" "1" [4,] "-3" "2" [5,] "-2" "-4" [6,] "-4" "3" [7,] "-4" "4" [8,] "-1" "-5" [9,] "-5" "-6" [10,] "-6" "5" [11,] "-6" "6" [12,] "-5" "7" $edge.length [1] 0.00000 0.00412 0.01012 0.00625 0.00576 0.00519 0.00536 0.01817 0.00713 0.00772 0.00913 0.01506 $tip.label [1] "H" "G" "F" "E" "D" "C" "B" attr(,"class") [1] "phylo" The only problem is i can't access or save the individual trees after importing. What i want to do is calculate the cophenetic distance for each tree and take the correlation between pairs of trees. I keep getting errors like this: x<- anj30[1]> class(x)[1] "list"> as.phylo(x)Error in as.phylo(x) : no applicable method for "as.phylo"> cophenetic.phylo(x)Error in cophenetic.phylo(x) : your tree has no branch lengths defined and> cophenetic.phylo(anj30[1])Error in cophenetic.phylo(anj30[1]) : your tree has no branch lengths defined If i paste the tree directly into read.tree() on the console then it works but I can't do this for thousands of trees ( which i have to process according to my PhD committee :) ) Does anyone know how to get the individual trees into usable variables? I apologize for my lack of familiarity with the package. thanks, betty -- Betty Gilbert lgilbert@berkeley.edu Taylor Lab Plant and Microbial Biology 321 Koshland Hall U.C. Berkeley Berkeley, Ca 94720 [[alternative HTML version deleted]]
Ben Bolker
2006-May-09 17:23 UTC
[R] problem accessing trees after read.nexus from ape package
Betty Gilbert <lgilbert <at> berkeley.edu> writes:> > Hello, > I've been trying to figure out how to access the individual elements > from an object of class phylo. > I am reading in 201 trees created by paup as below. > > > read.nexus("A_30knj_200t.txt", tree.names= NULL) -> anj30[snip]> > x<- anj30[1] > > class(x) > [1] "list" > > > as.phylo(x) > Error in as.phylo(x) : no applicable method for "as.phylo" > > cophenetic.phylo(x) > Error in cophenetic.phylo(x) : your tree has no branch lengths defined > > and > > cophenetic.phylo(anj30[1]) > Error in cophenetic.phylo(anj30[1]) : your tree has no branch lengths defined >(1) using [[ instead of [ will help; [ returns a LIST (possibly just a one-element list), while [[ returns an ELEMENT of the list. e.g.:> x <- list("a","b","c") > x[1][[1]] [1] "a"> class(x[1])[1] "list"> x[[1]][1] "a"> class(x[[1]])[1] "character" (2) cophy <- lapply(anj30,cophenetic.phylo) should process all of your phylogenies and return the answer as a list of cophylogenies. good luck, Ben Bolker
Maybe Matching Threads
- possible bug in ape::extract.clade()
- cor of two matrices whose columns got shuffled
- "cophenetic" function for objects of class "dendrogram"
- "cophenetic" function for objects of class "dendrogram"
- compute the associate vector of distances between leaves in a binary non-rooted tree