Stuff for the Jupyter notebook which you can ignore...
In [86]:
library(repr)
options(repr.plot.width = 8, repr.plot.height = 3)
To retrieve topologies from the Open Tree of Life, we need the rotl
R package. We'll also load the ape package to manipulate the tree.
In [91]:
install.packages("rotl")
library("rotl")
library("ape")
Now, let's create a vector of species names for which we want a tree topology and match them to those of the Open Tree taxonomy:
In [94]:
species <- c(
"Homo sapiens", "Felis catus", "Crocodylus niloticus", "Nymphicus hollandicus",
"Vitis vinifera", "Geobacter daltonii", "Thermoplasma acidophilum", "Caulophacus agassizi",
"Caulophacus arcticus", "Caulophacus cyanae", "Caulophacus galatheae"
)
resolved_names <- tnrs_match_names(species)
resolved_names
Return the subset of the Open Tree of Life that contains the matched species:
In [81]:
tree <- tol_induced_subtree(ott_ids=ott_id(resolved_names))
plot(tree, cex = 0.8, no.margin = TRUE)
The tree may also contain the names of some of its clades:
In [80]:
plot(tree, cex = 0.8, show.node.label = TRUE, no.margin = TRUE)
To infer phylogenies under the constraints of this tree, we have to remove the ott* IDs from species names and save the tree to a file.
The former can be done with a small regular expression:
In [92]:
tree$tip.label <- gsub("_ott\\d+$", "", tree$tip.label)
tree$tip.label
write.tree(tree, file = 'constraint_tree.phy')
Ta-daaa! Our constraint tree is ready! A number of phylogeny inference programs can use it to constrain topological exploration:
createMrBayesConstraints
in the R package paleotree
to generate a MrBayes NEXUS block of topological constraints from the tree. Next, paste the block to the input file to be read by MrBayes.