PageRenderTime 13ms CodeModel.GetById 10ms app.highlight 1ms RepoModel.GetById 1ms app.codeStats 0ms

/working/auteur/R/ultrametricize.R

http://github.com/eastman/auteur
R | 17 lines | 16 code | 1 blank | 0 comment | 3 complexity | d8607e1c51e00ac26549d28a3cba3256 MD5 | raw file
 1
 2ultrametricize=function(phy, tol=1e-8, trim=c("min","max","mean")){
 3	paths=pathlengths(phy)
 4	trim=switch(match.arg(trim),
 5         min = min(paths),
 6         max = max(paths),
 7         mean = mean(paths))
 8	if(diff(range(paths))<=tol) {
 9		for(i in 1:length(paths)){
10			e=phy$edge.length[which(phy$edge[,2]==i)->bl]
11			phy$edge.length[bl]=e+(trim-paths[i])
12			}
13		return(phy)
14	} else {
15		stop("Difference in path lengths is larger than supplied tolerance")
16	}
17}