This function checks whether the input is a valid phylogenetic tree, either as a character string in Newick format
or as an object of class phylo
from the ape
package. If the input is a Newick string, it is parsed into
a phylo
object. The function also ensures that the tree contains at least two tips.
validate_tree(tree)
A phylo
object representing the validated and parsed tree.
A phylogenetic tree in Newick format (as a character string) or an object of class phylo
from the ape
package.
If the input is a character string, it must follow the Newick format (e.g., "((tip_1:1,tip_2:1):5,tip_3:6);"
).
If an object of class phylo
is provided, it should be a valid phylogenetic tree.
The function first verifies that the input is either a valid phylo
object or a character string.
If the input is a Newick string, it attempts to parse it into a phylo
object using ape::read.tree()
.
If parsing fails, an informative error message is returned.
The function also checks that the tree contains at least two tips, as a valid phylogenetic tree should have at least one split.