-
Notifications
You must be signed in to change notification settings - Fork 14
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
added tree_subset function #6
Conversation
…ching to ensure treeio is installed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks for the PR. I have commented some of your source codes. Please create a new PR to the treeio
package.
"for the development version.", | ||
call. = FALSE) | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this function should goes to treeio
pkg, as it depends on treeio and the output is also a tree object instead of tbl_tree.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
another reason is that treeio depends on tidytree and tidytree can't depends on treeio, otherwise there will be a circle dependency and all of these pkgs will fail to compile and install.
dplyr::mutate(isTip = (!node %in% parent)) %>% | ||
dplyr::filter(isTip) %>% | ||
dplyr::pull(label) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do you think group_labels is necessary?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you mean that the entire code chunk seems unnecessary or it is improperly named? I think I agree if the latter, and will rename it to subset_labels
but I do think its functionality is necessary as it is the chunk that is isolating the related nodes
# This drops all of the tips that are not included in group_nodes | ||
subtree <- treeio:::gfocus(tree, group_labels, "focus") %>% | ||
treeio:::drop.tip(., .$tip.label[-group_nodes], rooted = TRUE) %>% | ||
treeio:::groupOTU.phylo(.node = node) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the drop.tip function supports treedata
object as well as phylo
and it would be better to support treedata
object to maintain associated data with nodes in the subtree.
@GuangchuangYu I have started working on the PR for this in the It looks like the Other than that, the PR is almost ready to submit, but I will wait for your feedback before I move forward with it. |
@tbradley1013 thanks for pointing this out. With the commit, YuLab-SMU/treeio@1c8627e, |
This PR relates to the discussion in #5. It adds a function
tree_subset
that takes a tree of classphylo
and a selected node of said tree and returns a subset of the tree (still with classphylo
) with the relatives of the specified node back to a specified level.Tests have also been added to ensure that the expected tips and nodes are added and that the branch lengths are preserved during subsetting.