pycldf.trees
Support for the CLDF TreeTable component.
The peculiarity of a tree object in CLDF lies in the fact that the actual tree data is pulled in
from a media file in newick or Nexus format. This “pulling in” is implemented in the method
Tree.newick()
.
Accessing Tree instances associated with a dataset is done using a Trees
instance.
>>> from pycldf import Dataset
>>> from pycldf.trees import TreeTable
>>> ds = Dataset.from_metadata('tests/data/dataset_with_trees/metadata.json')
>>> trees = list(TreeTable(ds))
>>> print(trees[0].newick().ascii_art())
┌─l1
┌────┤
│ └─l2
─────┤
├─l3
└─l4
- class pycldf.trees.Tree(trees, row, file)[source]
Represents a tree object as specified in a row of TreeTable.
- Parameters:
trees (
pycldf.trees.TreeTable
) –row (
dict
) –file (
pycldf.media.File
) –
- newick(d=None, strip_comments=False)[source]
Retrieve a newick.Node instance for the tree from the associated tree file.
- Parameters:
d (
typing.Optional
[pathlib.Path
]) – Directory where the tree file was saved earlier, usingpycldf.media.File.save()
.strip_comments (
bool
) – Flag signaling whether to strip comments enclosed in square brackets.
- Return type:
newick.Node
- Returns:
newick.Node representing the root of the associated tree.
- newick_string(d=None)[source]
Retrieve the Newick representation of the tree from the associated tree file.
- Parameters:
d (
typing.Optional
[pathlib.Path
]) – Directory where the tree file was saved earlier, usingpycldf.media.File.save()
.- Return type:
str
- Returns:
Newick representation of the associated tree.
- class pycldf.trees.TreeTable(ds)[source]
Container class for a Dataset’s TreeTable.
- Parameters:
ds (
pycldf.dataset.Dataset
) –