`sptree.maxtree` <-
function(genetreevector,spname,taxaname,species.structure)
{
ntree<-length(genetreevector)
nodes1<-read.tree.nodes(genetreevector[1],taxaname)$nodes
nspecies<-length(spname)
ntaxa<-length(taxaname)
#calculate pairwise distance
dist<-dist.taxa(nodes1,ntaxa)
for(i in 2:ntree){
nodes1<-read.tree.nodes(genetreevector[i],taxaname)$nodes
dist1<-dist.taxa(nodes1,ntaxa)
dist<-pmin(dist,dist1)
}
spdist1<-matrix(0,nrow=nspecies,ncol=ntaxa)
for(i in 1:nspecies){
taxa<-species.structure[i,]*(1:ntaxa)
taxa<-taxa[taxa>0]
if(length(taxa)>1) spdist1[i,]<-apply(dist[taxa,],2,min)
else spdist1[i,]<-dist[taxa,]
}
spdist<-matrix(0,nrow=nspecies,ncol=nspecies)
for(i in 1:nspecies){
taxa<-species.structure[i,]*(1:ntaxa)
taxa<-taxa[taxa>0]
if(length(taxa)>1) spdist[,i]<-apply(spdist1[,taxa],1,min)
else spdist[,i]<-spdist1[,taxa]
}
dist<-spdist/2
treestr<-tree.upgma(dist,spname,method="min")$treestr
return(treestr)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.