gtdblib.tree package

Submodules

gtdblib.tree.bootstrap_merge module

Non-parametric bootstrap support from replicate trees.

Splits are compared using XOR hashing: every taxon is assigned a random 128-bit value and the hash of a split is the XOR of the values of the taxa on one side of it, normalised as min(h, h ^ h_all) so both sides of a bipartition give the same value. This makes the cost of each replicate linear in the number of taxa, so trees with hundreds of thousands of taxa can be processed in seconds per replicate.

Support for an edge in the input tree is the percentage of replicates that contain the same bipartition, after restricting both trees to the taxa they have in common. Replicates in which the edge is trivial after this restriction (fewer than two taxa on either side) are excluded from that edge’s denominator, so replicates containing a subset of the taxa (e.g. jackknifed taxa) are handled correctly.

The text of the input tree (rooting, branch lengths, quoting, comments) is preserved. Only internal node labels are changed: the support value is combined with any existing taxon label as support:taxon (see gtdblib.util.bio.newick.create_label()), replacing any existing support value. The label of the root node is left unchanged as it does not correspond to an edge. If the root is bifurcating, both of its children represent the same bipartition and receive the same support value.

gtdblib.tree.bootstrap_merge.bootstrap_merge_replicates(input_tree: Union[str, PathLike], output_tree: Union[str, PathLike], replicate_trees: Collection[Union[str, PathLike]], cpus: int = 1)

Calculates non-parametric bootstrap support for the edges of a tree and writes them as internal node labels.

Parameters:
  • input_tree – The tree to merge the bootstraps to.

  • output_tree – The path to write the tree to.

  • replicate_trees – The trees to calculate the bootstraps from. These may contain a subset (or superset) of the taxa in the input tree.

  • cpus – The number of processes to use.

gtdblib.tree.convert_accession module

gtdblib.tree.convert_accession.convert_tree_accessions_to_canonical(input_path: Path, output_path: Path)

Convert all accessions in a tree to their canonical form.

gtdblib.tree.get_node_depth module

gtdblib.tree.get_node_depth.get_tree_node_depth(tree: Tree) → Dict[int, Set[Node]]

Calculate the depth of all nodes in the tree.

Parameters:

tree – The dendropy tree object to calculate the depths for.

Returns:

A dictionary of depths to nodes at that depth.

gtdblib.tree.get_node_to_desc_taxa module

gtdblib.tree.get_node_to_desc_taxa.get_tree_node_to_desc_taxa(tree: Tree) → Dict[Node, FrozenSet[str]]

Get each node and the taxa that are descendants of this node.

Parameters:

tree – The dendropy tree object to get descendant taxa for.

Returns:

A dictionary of nodes and their descendant taxa.

gtdblib.tree.get_unique_mrca_for_internal_nodes module

gtdblib.tree.get_unique_mrca_for_internal_nodes.get_tree_unique_mrca_for_internal_nodes(tree: Tree) → Dict[Node, Tuple[str, str]]

Calculate a unique MRCA for each internal node, i.e. using these taxa will always yield the same internal node.

Parameters:

tree – The dendropy tree object to calculate unique MRCAs for.

Returns:

A dictionary of nodes and a tuple of each taxon that identifies the node.

gtdblib.tree.polytomy module

gtdblib.tree.polytomy.collapse_polytomy(path_in: Path, path_out: Path, support: float)

Collapse nodes with low bootstrap support.

Parameters:
  • path_in – Tree to collapse.

  • path_out – The path to write the tree to.

  • support – Collapse nodes that have a support less than this value.

gtdblib.tree.polytomy.collapse_polytomy_tree(tree: Tree, support: float)

Collapse nodes with low bootstrap support, works on the Tree object.

Parameters:
  • tree – Tree to collapse.

  • support – Collapse nodes that have a support less than this value.

Module contents