-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Preserve branch length in Phylo.TreeMixin.prune if keep_root_length=True #4601
base: master
Are you sure you want to change the base?
Preserve branch length in Phylo.TreeMixin.prune if keep_root_length=True #4601
Conversation
e942cf8
to
d12da3b
Compare
d12da3b
to
0717412
Compare
Ok, the tests are now passing. Before some doctests failed because the |
@michaelfm1211 I don't have a strong opinion about this PR, but can you explain when the new argument would be used in practice? |
@mdehoon It would allow users to prune a tree and have the branch lengths of the resulting tree add up to what they did before the pruning. For example, consider this tree (a simplified version of the example in the linked issue #4460):
After pruning the node with
In the original, the branch length of the If the same pruning was done with |
@michaelfm1211 Thank you. Do you think that the default behavior is a bug? (I am not an expert in this area.) |
I would defer to @etal - I have worked with trees but not recently enough to have a quick judgement. |
@mdehoon The current code explicitly states in a comment that the current behavior is not a bug, so I think it would be best for compatibility for the default behavior to not change. |
I hereby agree to dual licence this and any previous contributions under both
the Biopython License Agreement AND the BSD 3-Clause License.
I have read the
CONTRIBUTING.rst
file, have runpre-commit
locally, and understand that continuous integration checks will be used to
confirm the Biopython unit tests and style checks pass with these changes.
I have added my name to the alphabetical contributors listings in the files
NEWS.rst
andCONTRIB.rst
as part of this pull request, am listedalready, or do not wish to be listed. (This acknowledgement is optional.)
Closes #4460
Currently, when running
.prune()
on a taxon in a bifurcation from the root, the root is collapsed so the other node has its length set to zero and becomes the new root. In the linked issue, setting the length to zero was causing problems.The length-to-zero behavior is explicitly commented as being intentional, however, the cookbook documentation for
.prune()
admits "[the branch length] might no longer be a meaningful value".This PR adds a new
keep_root_length
keyword argument to the.prune()
method that, when set toTrue
, adds the parent and remaining node lengths together like any other bifurcation. To keep compatibility and because this behavior intentional,keep_root_length
's default value isFalse
so this PR only does anything if the end-user opts-in.