We can also compare the original tree with the updated tree.

We can prune the updated tree, so it is a more straight forward comparison:

original_tree_taxonname <- ape::read.tree(file = "../data/ilex-local/inputs_T1281-M2478/taxonname.tre")
tips2keep <- match(original_tree_taxonname$tip.label,updated_tree_taxonname$tip.label)

pruned_updated_tree_taxonname <- ape::drop.tip(updated_tree_taxonname, updated_tree_taxonname$tip.label[-tips2keep])
original_tree_taxonname$edge.length <- NULL
original_tree_taxonname2 <- original_tree_taxonname
original_tree_taxonname2$tip.label <- gsub("_otu.*", "", original_tree_taxonname$tip.label)

pruned_updated_tree_taxonname2 <- pruned_updated_tree_taxonname
pruned_updated_tree_taxonname2$tip.label <- gsub("_otu.*", "", pruned_updated_tree_taxonname$tip.label)

cotree1 <- phytools::cophylo(ape::ladderize(original_tree_taxonname2), ape::ladderize(pruned_updated_tree_taxonname2), rotate.multi =TRUE)

phytools::plot.cophylo(
  x = cotree1,
  fsize = 2,
  lwd = 0.4,
  mar=c(.1,.1,8,.3),
  ylim=c(-.1,1),
  scale.bar=c(0, 0.5),
  link.lwd=5,
  link.lty="solid",
  link.col=phytools::make.transparent("#8B008B",0.5))
mtext(expression(bold("Original tree")), cex = 4.5, side= 3, line = 0, adj = 0.2)
mtext(expression(bold("Pruned updated tree")), cex = 4.5, side= 3, line = 0, adj = 0.9)

But, comparing vs the whole updated tree is more interesting:

updated_tree_taxonname2 <- updated_tree_taxonname
updated_tree_taxonname2$tip.label <- gsub("_otu.*", "", updated_tree_taxonname$tip.label)
# updated_tree_taxonname2$edge.length <- updated_tree_taxonname$edge.length*10 # for viz purposes! did not work
# updated_tree_taxonname2$edge.length <- NULL # does not work either
cotree2 <-  phytools::cophylo(
  ape::ladderize(original_tree_taxonname2),
  ape::ladderize(updated_tree_taxonname2)) #,
  #rotate.multi =TRUE) # it does not work with these trees for some reason.
phytools::plot.cophylo(
  x = cotree2,
  fsize = 1,
  lwd = 0.4,
  mar=c(.1,.1,8,.5),
  ylim=c(-.1,1),
  # xlim=c(-1,1),
  scale.bar=c(0, 1),
  # link.type="curved",
  link.lwd=2,
  link.lty="solid",
  link.col=phytools::make.transparent("#8B008B",0.5))
mtext(expression(bold("Original tree")), cex = 4, side = 3, line = 0, adj =0.2)
mtext(expression(bold("Updated tree")), cex = 4, side = 3, line = 0, adj = 0.8)

Now, compare the updated tree with the newer tree

par(mar=c(0,0,1,0), xpd=NA)  # adjust margins for all plots after this?
newer_tree <- rotl::get_study_tree(study_id = "ot_1984", tree_id = "tree1")
ape::plot.phylo(ape::ladderize(newer_tree), type = "fan", cex = 0.3, label.offset = 0.5, edge.width = 0.5)
mtext("Newer tree - matched labels", side = 3, cex = 0.6)
cotree3 <-  phytools::cophylo(
  ape::ladderize(newer_tree),
  ape::ladderize(updated_tree_taxonname2)) #,
  #rotate.multi =TRUE) # it does not work with these trees for some reason.
phytools::plot.cophylo(
  x = cotree3,
  fsize = 1,
  lwd = 0.4,
  mar=c(.1,.1,8,.5),
  ylim=c(-.1,1),
  # xlim=c(-1,1),
  scale.bar=c(0, 1),
  # link.type="curved",
  link.lwd=2,
  link.lty="solid",
  link.col=phytools::make.transparent("#FF1493",0.5))
mtext(expression(bold("Newer tree")), cex = 4, side = 3, line = 0, adj =0.2)
mtext(expression(bold("Updated old tree")), cex = 4, side = 3, line = 0, adj = 0.8)


McTavishLab/physcraperex documentation built on April 10, 2021, 12:02 a.m.