#install the phangorn library with its dependencies; load the library
install.packages("phangorn")
library(phangorn) #attach the library to your session
data(yeast) #attach a dataset provided as an example
yeast #find out what it contains
names(yeast) #names of the species
dml<-dist.ml(yeast,model="JC69") # compute Jukes-Cantor distance matrix
yav<-hclust(dml,method="average") # are the distances ultrametric?
dmlmat<-as.matrix(dml)
dmlmat["Scer","Spar"]
dmlmat["Scer","Smik"]
dmlmat["Spar","Smik"]
plot(yav,hang=-1)
yml<-NJ(dml) #compute a neighbor-joining tree...
quartz() #open a new plotting device
plot(yml) #...and plot it; note the absence of the root
#but do we really have an additive distance matrix?
dml #display the matrix and spot-test it
dmlmat<-as.matrix(dml)
dmlmat["Scer","Spar"]
dmlmat["Scer","Smik"]
dmlmat["Spar","Smik"]
dml[1]+dml[14]
dml[3]+dml[8]
dml[2]+dml[9] #is the test a success?
yopt<-optim.parsimony(yml,yeast) #optimally parsimonious tree
quartz()
plot(yopt)
quartz()
ypml<-pml(yml, yeast) #initialize ML calculation
ypmltree<-optim.pml(ypml,optNni=T,optEdge=T) #plot the resulting tree
rm(yeast,dml,yav,yml,yopt,ypml,ypmltree)