validate_tree: Validate and Parse a Phylogenetic Tree

View source: R/summaryStatistics.R

validate_treeR Documentation

Validate and Parse a Phylogenetic Tree

Description

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.

Usage

validate_tree(tree)

Arguments

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.

Details

  • 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.

Value

A phylo object representing the validated and parsed tree.


MethEvolSIM documentation built on April 12, 2025, 1:30 a.m.