Skip to content

Class `baltic.leaf`

Barney Potter edited this page Oct 14, 2024 · 1 revision

BALTIC leaf Class

The leaf class in BALTIC represents a leaf (also known as a tip) in a phylogenetic tree. This class is crucial for representing the terminal nodes of the tree, typically corresponding to sampled organisms or sequences.

Class Overview

class leaf:
    def __init__(self):
        # ... (initialization of attributes)

    def is_leaflike(self):
        return True

    def is_leaf(self):
        return True

    def is_node(self):
        return False

Attributes

Attribute Type Description
branchType str The type of branch. Default is 'leaf'.
name str The name of the tip after translation. Assigned in make_tree().
index int The index of the character that defines this object in the tree string. Assigned in make_tree().
length float The length of the branch. Assigned in make_tree().
absoluteTime float or None The position of the tip in absolute time. Assigned in setAbsoluteTime().
height float The height of the tip. Assigned in traverse_tree().
parent node The parent node. Assigned in make_tree().
traits dict Dictionary containing traits associated with the leaf. Assigned in make_tree().
x float or None The x-coordinate for plotting. Default is None.
y float or None The y-coordinate for plotting. Default is None.

Methods

is_leaflike()

def is_leaflike(self):
    return True

Indicates whether the object is leaf-like. Always returns True for leaf objects.

is_leaf()

def is_leaf(self):
    return True

Indicates whether the object is a leaf. Always returns True for leaf objects.

is_node()

def is_node(self):
    return False

Indicates whether the object is a node. Always returns False for leaf objects.

Usage

The leaf class is used internally by BALTIC to represent the tips of phylogenetic trees. Users typically don't create leaf objects directly, but interact with them when analyzing or visualizing trees.

Example of accessing leaf attributes after tree construction:

# Assuming 'tree' is a BALTIC tree object
for obj in tree.Objects:
    if obj.is_leaf():
        print(f"Leaf {obj.index}:")
        print(f"  Name: {obj.name}")
        print(f"  Branch length: {obj.length}")
        print(f"  Absolute time: {obj.absoluteTime}")
        print(f"  Traits: {obj.traits}")

Notes

  • The leaf class is essential for representing the tips of the phylogenetic tree, which often correspond to sampled sequences or organisms.
  • The name attribute is particularly important as it identifies the specific entity represented by this leaf.
  • The traits dictionary can contain various metadata associated with the leaf, such as sampling date, location, or any other relevant information provided in the input tree.
  • The x and y attributes are used for plotting and visualization purposes and are typically set by BALTIC's tree drawing functions.
  • The absoluteTime attribute is useful for time-calibrated trees, representing the sampling time or age of the tip.

For more information on how leaf objects are used in tree construction and analysis, refer to the BALTIC documentation on tree building, traversal, and visualization functions.

Clone this wiki locally