treeflow.tree package
Classes for representing trees in Tensorflow
We use attr based classes as they are supported by tf.nest. Custom behaviour can be added subclassing attr classes as long as support for the standard constructor argument order is preserved.
- treeflow.tree.parse_newick(newick_file: str, remove_zero_edges: bool = True, epsilon: float = 1e-06, subnewick_format=0) NumpyRootedTree
Read a rooted TreeFlow Numpy tree from a Newick file
- Parameters:
newick_file (str) – File to read tree from
remove_zero_edges (bool) – Whether to expand zero-length edges (default: True)
epsilon (float) – Value to expand zero-length edges to (default: 1e-6)
subnewick_format (int) – Format passed to ete3.Tree (default: 0) (see documentation at http://etetoolkit.org/docs/latest/reference/reference_tree.html)
- Returns:
Parsed TreeFlow tree composed of Numpy arrays
- Return type:
- treeflow.tree.convert_tree_to_tensor(numpy_tree: NumpyRootedTree, height_dtype: DType = tf.float64) TensorflowRootedTree
Convert a TreeFlow tree composed to Numpy arrays to one composed of TensorFlow Tensors
- Parameters:
numpy_tree (NumpyRootedTree) – Tree to convert
height_dtype (tf.DType) – TensorFlow datatype to use for tree times (defaults to TreeFlow default)
- Returns:
Tree with arrays converted to Tensors
- Return type:
- treeflow.tree.write_tensor_trees(topology_file: str, branch_lengths: Tensor, output_file: str, branch_metadata: Mapping[str, Tensor] | None = None)
Write a collection of Tensor tree branch lengths, and possibly branch metadata, to a Nexus file
- Parameters:
topology_file (str) – Newick file to read tree topology from
branch_lengths (Tensor) – Tensor of branch lengths with dimensions (num_samples, num_branches)
output_file (str) – File to write trees to in Nexus format
branch_metadata (Mapping[str, Tensor] (optional)) – Mapping from keys to Tensors with dimensions (num_samples, num_branches) containing branch metadata