Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix buildNewick Formula and Update Dendrogram Branch Representation #15

Open
wants to merge 7 commits into
base: dev
Choose a base branch
from

Conversation

kylacochrane
Copy link
Collaborator

@kylacochrane kylacochrane commented Nov 19, 2024

This PR (currently indirectly) addresses ISSUE13.

Changes:

  • Fixed the buildNewick formula to adjust branch lengths (both internal and leaf branches) to represent cophenetic distances rather than patristic distances.
  • Branch lengths now reflect the distance from all samples to their most recent common ancestor.

Benefits:

  • This approach mirrors how BioNumerics currently displays dendrograms.
  • It aligns with how GAS's fcluster generates flat clusters based on user-provided thresholds, ensuring the dendrogram allows users to visually interpret cluster levels by assessing branch heights between clusters.

Key Considerations:
This method deviates from the traditional representation of distances in dendrograms. As noted in ISSUE13, branch lengths are typically represented by patristic distances along a tree typically correspond to the values in the distance matrix (i.e., the sum of branch lengths from Sample A to Sample B should equal the distance provided in the matrix).

To align buildNewick with this traditional approach, the formula can be updated with the following adjustments:

def buildNewick(self,node, newick, parentdist, leaf_names):
        if node.is_leaf():
            return "%s:%f%s" % (leaf_names[node.id], (parentdist - node.dist / 2), newick)
        else:
            if len(newick) > 0:
                newick = f"):{(parentdist - node.dist/2)}{newick}"
            else:
                newick = ");"
            newick = self.buildNewick(node.get_left(), newick, node.dist, leaf_names)
            newick = self.buildNewick(node.get_right(), ",%s" % (newick), node.dist, leaf_names)
            newick = "(%s" % (newick)
            return newick

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant