[Adephylo-commits] r18 - in pkg: . R

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Fri Nov 21 15:53:51 CET 2008


Author: jombart
Date: 2008-11-21 15:53:51 +0100 (Fri, 21 Nov 2008)
New Revision: 18

Modified:
   pkg/DESCRIPTION
   pkg/R/distances.R
Log:
adephylo peut ?\195?\170tre install?\195?\169


Modified: pkg/DESCRIPTION
===================================================================
--- pkg/DESCRIPTION	2008-11-21 13:23:56 UTC (rev 17)
+++ pkg/DESCRIPTION	2008-11-21 14:53:51 UTC (rev 18)
@@ -9,4 +9,4 @@
 Description: Multivariate tools to analyze comparative data, i.e. a phylogeny and some traits measured for each taxa.
 License: GPL (>=2)
 LazyLoad: yes
-Collate: zzz.R
+Collate: utils.R partition.R s.phylo4d.R distances.R
\ No newline at end of file

Modified: pkg/R/distances.R
===================================================================
--- pkg/R/distances.R	2008-11-21 13:23:56 UTC (rev 17)
+++ pkg/R/distances.R	2008-11-21 14:53:51 UTC (rev 18)
@@ -1,7 +1,53 @@
+############
+# distNodes
+############
+distNodes <- function(x, node1, node2, method=c("brlength","nAncestors","Abouheif")){
+    if(!require(phylobase)) stop("phylobase package is not installed")
+
+    ## conversion from phylo, phylo4 and phylo4d
+    x <- as(x, "phylo4")
+    method <- match.arg(method)
+
+    ## some checks
+    if (is.character(checkval <- check_phylo4(x))) stop(checkval)
+    t1 <- getnodes(x, node1)
+    t2 <- getnodes(x, node2)
+    if(any(is.na(c(t1,t2)))) stop("wrong node specified")
+    if(t1==t2) return(0)
+
+    ## get the path between node1 and node2
+    path <- shortestPath(x, node1, node2)
+
+    ## compute distances
+    if(method=="brlength"){
+        if(!hasEdgeLength(x)) stop("x does not have branch length")
+        path <- c(node1, node2, path)
+        edge.idx <- getedges(x, path)
+        res <- sum(edgeLength(x)[edge.idx])
+        return(res)
+    } # end brlength
+
+    if(method=="nAncestors"){
+        res <- length(path)
+        return(res)
+    } # end nAncestors
+
+    if(method=="Abouheif"){
+
+    } # end Abouheif
+
+
+
+    return(res)
+} # end distNodes
+
+
+
+
 ###########
 # distRoot
 ###########
-distRoot <- function(x, tip){
+distRoot <- function(x, method=c("brlength","nAncestors","Abouheif")){
     if(!require(phylobase)) stop("phylobase package is not installed")
 
     ## conversion from phylo, phylo4 and phylo4d



More information about the Adephylo-commits mailing list