Taxonomy

class pyham.taxonomy.Taxonomy(tree, **kwargs)[source]

Taxonomy is a class to wrap the ete4 tree used as reference species tree by Ham.

Attributes:
tree_str (str): newick tree string used to build the ete4 Tree object.
tree (ete4 Tree): species ete4 Tree tree.
internal_nodes (set): Set of Tree node that contained a AncestralGenome.
leaves (set): Set of Tree node that contained a ExtantGenome.
Args:
tree_file (str): Path to the file that contained the taxonomy information.
tree_format (str): type of inputted tree file. Defaults to newick_string. Can be ‘newick’, ‘phyloxml, ‘newick_string’.
use_internal_name (Boolean, optional): Specify wheter using the given internal node name or use the
concatenatation of the children name. Defaults to False.
quoted_node_names (:obj:’Boolean’, optional): Specify whether newick file has quoted node names.
add_genome_to_node(node, genome)[source]

add the given genome to the node attribute “genome”.

Args:
node (node): receptor node.
genome (Genome): Genome to attach.
classmethod from_newick(tree: str | PathLike, use_internal_name=False, quoted_node_names=True)[source]

Create a Taxonomy object from a newick file or string.

Args:
tree (str): Path to the file that contained the taxonomy information, or a newick string.
use_internal_name (Boolean, optional): Specify whether using the given internal node name or use the
concatenatation of the children name. Defaults to False.
quoted_node_names (:obj:’Boolean’, optional): Specify whether the newick tree has quoted node names. Defaults to True.
Returns:

obj:Taxonomy: Taxonomy object with the ete3 tree.

get_extant_taxa_by_name(name)[source]

Return the extant taxa with the given name.

Args:
name (str): name of the node to search.
Returns:

ete4.TreeNode: node with the given name.

get_genome_from_taxnode(node)[source]

return the genome attached to the node.

Args:
node (node): node to get the genome from.
Returns:

Genome: genome attached to the node.

get_mrca_taxnode(*tax_nodes)[source]

return the most recent common ancestor of the given tax nodes.

get_newick_from_tree(node)[source]

return the newick tree string (format 8: all names) rooted at the given node.

Args:

node (node): root node.

Returns:

str of the subtree.

get_node_by_name(name)[source]

Return the node with the given name.

Args:
name (str): name of the node to search.
Returns:

ete4.TreeNode: node with the given name.

get_path_up(lowest_node, ancestor_node)[source]

Return the internal node in between two nodes sorted by recentness. The query nodes are not included.

Args:
lowest_node (node): Youngest node.
ancestor_node (node): Oldest node.
Returns:

list of node sorted from most recent to oldest.

is_child_recursive(node, ancestor_node)[source]

Check if the node is a child of the ancestor node.

Args:
node (node): node to check.
ancestor_node (node): ancestor node.
Returns:

obj:bool True if the node is a child of the ancestor node.