skbio.tree.TreeNode.compare_tip_distances#
- TreeNode.compare_tip_distances(other, sample=None, dist_f=None, shuffle_f=None)[source]#
Compare self to other using tip-to-tip distance matrices.
- Parameters:
- otherTreeNode
The tree to compare.
- sampleint, optional
Randomly subsample this number of tips in common between the trees to compare. This is useful when comparing very large trees.
- dist_fcallable, optional
The distance function used to compare two the tip-tip distance matrices. Default is \((1-r)/2\), where \(r\) is the Pearson correlation coefficient between the two matrices.
- shuffle_fint, np.random.Generator or callable, optional
The shuffling function used if
sample
is specified. Default is theshuffle
method of a NumPy random generator. If an integer is provided, a random generator will be constructed using this number as the seed.Changed in version 0.6.3: Switched to NumPy’s new random generator. Can accept a random seed or random generator instance.
- Returns:
- float
The distance between the trees.
- Raises:
- ValueError
If there does not exist common tips between the trees.
Notes
This method automatically strips out the names that do not match. This is necessary for this method because the distance between non-matching names and matching names is undefined in the tree where they don’t match, and because one needs to reorder the names in the two trees to match up the distance matrices.
Examples
Calculate the distance between two trees. Note that only three taxa are shared between the trees.
>>> from skbio import TreeNode >>> tree1 = TreeNode.read(["((a:1,b:1):2,(c:0.5,X:0.7):3);"]) >>> tree2 = TreeNode.read(["(((a:1,b:1,Y:1):2,c:3):1,Z:4);"]) >>> dist = tree1.compare_tip_distances(tree2) >>> print("%.9f" % dist) 0.000133446