Can I calculate the patristic distance from a subtree from opentree?

19 views Asked by At

I am trying to calculate the patristic distance but I keep getting "0.0" or NaN for the distance between all taxa. I do get a result for the hierarchical count (e.g. steps between taxa using path_edge_count), but I trying to get a distance metric. Link to open tree of life

def convert_subtree_to_dendropy(retrieved_subtree):
    newick_string = retrieved_subtree["newick"]
    tree = dendropy.Tree.get(data=newick_string, schema="newick")
    taxa_count_tree1 = 0
    for leaf in tree.leaf_node_iter():
        taxa_count_tree1 += 1
    return tree

tree = convert_subtree_to_dendropy(retrieved_subtree)

def calculate_patristic_distances(tree):
    pdm = tree.phylogenetic_distance_matrix()
    taxa = pdm.taxon_namespace.labels()
    patristic_distance_matrix_df = pd.DataFrame(index=taxa, columns=taxa)
    for idx1, taxon1 in enumerate(tree.taxon_namespace):
        for taxon2 in tree.taxon_namespace:
            patristic_distance = pdm.patristic_distance(taxon1, taxon2)
    return patristic_distance_matrix_df

patristic_distance_matrix_df = calculate_patristic_distances(tree)

Result

0

There are 0 answers