How to do it... 

Constructing trees using phangorn can be executed using the following steps:

  1. Load in the libraries and sequences, and make an alignment:
library(Biostrings)
library(msa)
library(phangorn)

seqs <- readAAStringSet(file.path(getwd(), "datasets", "ch4", "abc.fa"))
aln <- msa::msa(seqs, method=c("ClustalOmega"))
  1. Convert the alignment to the phyDat object:
aln <- as.phyDat(aln, type = "AA")
  1. Make UPGMA and neighbor-joining trees from a distance matrix:
dist_mat <- dist.ml(aln)

upgma_tree <- upgma(dist_mat)
plot(upgma_tree, main="UPGMA")

nj_tree <- NJ(dist_mat)
plot(nj_tree,"unrooted", main="NJ")

  1. Calculate the bootstraps and plot:
bootstraps <- bootstrap.phyDat(aln,FUN=function(x) { NJ(dist.ml(x)) } , bs=100)
plotBS(nj_tree, bootstraps, p = 10)
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.135.212.238