skbio.tree.TreeNode.depth#
- TreeNode.depth(ancestor=None, include_root=False, use_length=True, missing_as_zero=False)[source]#
Calculate the depth of the current node.
Changed in version 0.6.3: Renamed from
accumulate_to_ancestor
. The old name is kept as an alias.The depth of a node is the sum of branch lengths from it to the root of the tree.
- Parameters:
- ancestorTreeNode, optional
An ancestral node of self. If provided, the distance from self to this node instead of the root node will be calculated.
Changed in version 0.6.3: Becomes optional.
- include_rootbool, optional
If True, the distance will include the length of the root node, or the given ancestral node if
ancestor
is provided. Default is False.Added in version 0.6.3.
- use_lengthbool, optional
Whether to return the sum of branch lengths (True, default) or the number of branches (False) from self to root.
Added in version 0.6.3.
- missing_as_zerobool, optional
When a node without an associated branch length is encountered, raise an error (False, default) or use 0 (True). Applicable when
use_length
is True.Added in version 0.6.3.
- Returns:
- float
The depth of self.
- Raises:
- NoParentError
If the given ancestral node is not an ancestor of self.
- NoLengthError
If nodes without branch length are encountered, but
missing_as_zero
is False.
Examples
>>> from skbio import TreeNode >>> tree = TreeNode.read(["((a:1,b:2)c:3,(d:4,e:5)f:6)root;"]) >>> tree.find('a').depth() 4.0 >>> tree.find('a').depth(tree.find('c')) 1.0