Tree algorithms - #1
Open
akdel wants to merge 42 commits into
Open
Conversation
added 30 commits
August 1, 2020 20:53
1. leaves property is a generator 2. added names to from_dict method 3. root property 4. find leaf by name
added 8 commits
August 5, 2020 01:38
holmrenser
reviewed
Aug 13, 2020
holmrenser
left a comment
Owner
There was a problem hiding this comment.
I have some comments on the clade and clades classes.
Comment on lines
+13
to
+42
| @dataclass | ||
| class Clade: | ||
| internode: Tree | ||
| clade: Set[str] | ||
| depth: int | ||
|
|
||
| @classmethod | ||
| def from_internode(cls, internode: Tree, banned: [None, Set[str]] = None) -> 'Clade': | ||
| """ | ||
| Creates Clade from a given internode. | ||
| :param internode: A node which is not a leaf. | ||
| :param banned: banned node names. | ||
| :return: Clade instance | ||
| """ | ||
| assert internode.children is not None # makes sure that it's not a leaf | ||
| if banned is None: | ||
| banned = set() | ||
| clade: Set[str] = {x.name for x in internode.leaves if x.name not in banned} # removes any banned leaves. this is used in bootstrapping. | ||
| return cls(internode, clade, internode.depth) | ||
|
|
||
| def compare_to(self, other: 'Clade') -> bool: | ||
| """ | ||
| Compares the clade leaves to another. | ||
| :param other: Clade instance to be compared | ||
| :return: returns True if clades are equal. | ||
| """ | ||
| if self.clade == other.clade: | ||
| return True | ||
| else: | ||
| return False |
Owner
There was a problem hiding this comment.
In my perspective a clade is a subtree. What is the use of making this a separate class?
Author
There was a problem hiding this comment.
yes, you're right. I wasn't sure where I was going in the beginning, that's why I didn't want to touch the main class. I'll add them as a Tree method
added 4 commits
August 13, 2020 14:52
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Nj-tree with bootstrapping