# Generate dummy four taxon trees (where taxa B, D and F were
# previously safely excluded):
trees <- ape::read.tree(text = c("(A,(C,(E,G)));", "(A,(E,(C,G)));"))
# Write trees to file:
ape::write.tree(phy = trees, file = "test_in.tre")
# Make dummy safe taxonomic reduction taxon list:
str_taxa <- matrix(data = c("B", "A", "rule_2b", "D", "C", "rule_2b",
"F", "A", "rule_2b", "F", "C", "rule_2b"), byrow = TRUE, ncol = 3,
dimnames = list(c(), c("junior", "senior", "rule")))
# Show that taxa B and D have a single possible resinsertion position,
# but that taxon F has two possible positions (with A or with C):
str_taxa
# Resinsert taxa safely (F will be excluded due to the ambiguity of
# its' position - multiple_placement_option = "exclude"):
safe_taxonomic_reinsertion(input_filename = "test_in.tre",
output_filename = "test_out.tre", str_taxa = str_taxa,
multiple_placement_option = "exclude")
# Read in trees with F excluded:
exclude_str_trees <- ape::read.tree(file = "test_out.tre")
# Show first tree with B and D reinserted:
ape::plot.phylo(x = exclude_str_trees[[1]])
# Repeat, but now with F also reinserted with its' position (with
# A or with C) chosen at random:
safe_taxonomic_reinsertion(input_filename = "test_in.tre",
output_filename = "test_out.tre", str_taxa = str_taxa,
multiple_placement_option = "random")
# Read in trees with F included:
random_str_trees <- ape::read.tree(file = "test_out.tre")
# Confirm F has now also been reinserted:
ape::plot.phylo(x = random_str_trees[[1]])
# Clean up example files:
file.remove(file1 = "test_in.tre", file2 = "test_out.tre")
Run the code above in your browser using DataLab