# dendropy.treecalc – Tree Statistics, Metrics and Calculations¶

Tree metrics/statistics calculations.

class dendropy.treecalc.PatristicDistanceMatrix(tree=None)

Calculates and maintains patristic distance information of taxa on a tree. max_dist_taxa and max_dist_nodes will return a tuple of taxon objects and corresponding nodes, respectively, that span the greatest path distance in the tree. The mid-point between the two is guaranteed to be on the closer to the first item of each pair.

calc(tree=None, create_midpoints=None)

Calculates the distances.

distances()

Returns list of patristic distances.

mrca(taxon1, taxon2)

Returns MRCA of two taxon objects.

sum_of_distances()

Returns sum of patristic distances on tree.

dendropy.treecalc.brlen_dists_calc(length_diffs)

Given, length_diffs, a list of pairs of corresponding (length/weight) values of edges from two trees, this returns the branch length distance (square root of the sum of squared differences) between the two trees. This is equivalent to the Euclidean branch length distance between the two trees.

dendropy.treecalc.brlen_scores_calc(length_diffs)

Given, length_diffs, a list of pairs of corresponding (length/weight) values of edges from two trees, this returns the branch length score (sum of squared differences) between the two trees. This is equivalent to the squared Euclidean distance between the two trees.

dendropy.treecalc.euclidean_distance(tree1, tree2, edge_length_attr='length', value_type=<type 'float'>)

Returns Euclidean distance (a.k.a. Felsenstein’s 2004 branch length distance) between two trees based on edge_length_attr. Trees need to have been decorated with the encode_splits method of the splits module.

dendropy.treecalc.false_positives_and_negatives(reference_tree, test_tree)

False pos = splits in test_tree NOT in reference_tree False neg = splits in reference_tree NOT in test_tree

dendropy.treecalc.fitch_down_pass(postorder_node_list, attr_name='state_sets', weight_list=None, taxa_to_state_set_map=None)

Reads attr_name attribute of leaves as an iterable of state sets, and sets that attribute for internal nodes using the “preliminary phase” of Fitch’s (1971) unordered parsimony algorithm. Returns the parsimony score.

weight_list
is an optional vector of weights for each pattern.
taxa_to_state_set_map
if a child node does not have an attribute with name
attr_name
then the nodes.taxon will be used as a key in taxa_to_state_set_map to find the state set. This allows for the scoring of previously undecorated trees.

Currently this requires a bifurcating tree (even at the root).

dendropy.treecalc.fitch_up_pass(preorder_node_list, attr_name='state_sets', taxa_to_state_set_map=None)

Reads attr_name attribute of nodes as an iterable of state sets, and sets that attribute for internal nodes using the “final phase” of Fitch’s (1971) unordered parsimony algorithm.

taxa_to_state_set_map
if a child node does not have an attribute with name
attr_name
then the nodes.taxon will be used as a key in taxa_to_state_set_map to find the state set. This allows for the scoring of previously undecorated trees.

Currently this requires a bifurcating tree (even at the root).

dendropy.treecalc.get_length_diffs(tree1, tree2, edge_length_attr='length', value_type=<type 'float'>, split_length_diff_map=False)

Returns a list of tuples, with the first element of each tuple representing the length of the branch subtending a particular split on tree1, and the second element the length of the same branch on tree2. If a particular split is found on one tree but not in the other, a value of zero is used for the missing split.

dendropy.treecalc.mason_gamer_kellogg_score(tree1, tree2)

Mason-Gamer and Kellogg. Testing for phylogenetic conflict among molecular data sets in the tribe Triticeae (Gramineae). Systematic Biology (1996) vol. 45 (4) pp. 524

dendropy.treecalc.patristic_distance(tree, taxon1, taxon2)

Given a tree with splits encoded, and two taxa on that tree, returns the patristic distance between the two. Much more inefficient than constructing a PatristicDistanceMatrix object.

dendropy.treecalc.robinson_foulds_calc(length_diffs)

Given, length_diffs, a list of pairs of corresponding (length/weight) values of edges from two trees, this returns the Robinson-Foulds distance (sum of absolute differences) between the two trees.

dendropy.treecalc.robinson_foulds_distance(tree1, tree2, edge_length_attr='length')

Returns Robinson-Foulds distance between two trees based on edge_length_attr. Trees need to have been decorated with the encode_splits method of the splits module.

dendropy.treecalc.splits_distance(tree1, tree2, dist_func=<function robinson_foulds_calc at 0x101a44c08>, edge_length_attr='length', value_type=<type 'float'>)

Returns distance between two trees, each represented by a dictionary of splits (as split_mask strings) to edges, using dist_func to calculate the distance based on edge_length_attr of the edges. dist_func is a function that takes a list of pairs of values, where the values correspond to the edge lengths of a given split on tree1 and tree2 respectively.

dendropy.treecalc.symmetric_difference(tree1, tree2)

Returns the number of splits that are present in only 1 of the 2 trees.

#### Previous topic

dendropy.reconcile – Tree Reconciliation and Fitting

#### Next topic

dendropy.treemanip – Tree Manipulation

### Announcements

Join the "DendroPy Announcements" group to receive announcements of new releases, updates, changes and other news of interest to DendroPy users and developers.

Enter your e-mail address in the box above and click the "subscribe" button to subscribe to the "dendropy-announce" group, or click here to visit this group page directly.

### Discussion

Join the "DendroPy Users" group to follow and participate in discussion, troubleshooting, help, information, suggestions, etc. on the usage and development of the DendroPy phylogenetic computing library.

Enter your e-mail address in the box above and click the "subscribe" button to subscribe to the "dendropy-users" group, or click here to visit this group page directly.