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

matUtils extract --reroot: retain rerooted leaf, rename leaf from former internal node #380

Merged
merged 1 commit into from
Oct 4, 2024

Conversation

AngieHinrichs
Copy link
Contributor

This addresses two corner cases that we hadn't thought through yet for --reroot:

  • First, when rerooting to a leaf node, that node was converted into an internal node (the new root), losing its leaf status, so when the result was written out, the tree no longer had that leaf. To fix this, when rerooting to a leaf, we add a new leaf with the same name on the new root node.

  • Second, when the old root had no leaf children and only one internal node child, after rerooting it became a new leaf node, keeping its original ID of node_1. However, the saved protobuf could not be read back in by matUtils because when parsing the Newick string, node_1 is assigned to the first node encountered, and it is an error for any subsequent node to have the name node_1 (even a leaf) because node_1 is already in the tree. To prevent that error, when the old root becomes a leaf node, we change the old-root-new-leaf's name to former_root -- unless there is already a former_root in the tree, in which case we make a new former_root_serialNumber that does not already exist in the tree.

…mer internal node

This addresses two corner cases that we hadn't thought through yet for --reroot:

* First, when rerooting to a leaf node, that node was converted into an internal node (the new root), losing its leaf status, so when the result was written out, the tree no longer had that leaf.  To fix this, when rerooting to a leaf, we add a new leaf with the same name on the new root node.

* Second, when the old root had no leaf children and only one internal node child, after rerooting it became a new leaf node, keeping its original ID of 'node_1'.  However, the saved protobuf could not be read back in by matUtils because when parsing the Newick string, 'node_1' is assigned to the first node encountered, and it is an error for any subsequent node to have the name 'node_1' (even a leaf) because node_1 is already in the tree.  To prevent that error, when the old root becomes a leaf node, we change the old root's name to former_root -- unless there is already a former_root in the tree, in which case we make a new former_root_<serialNumber> that does not already exist in the tree.
@yatisht yatisht merged commit 6d2799c into yatisht:master Oct 4, 2024
2 of 3 checks passed
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.

2 participants