Skip to content

Commit

Permalink
Merge pull request #264 from nextstrain/fix-fix-tree
Browse files Browse the repository at this point in the history
Check for mutations and clades before removing
  • Loading branch information
joverlee521 authored Jan 21, 2025
2 parents f5bca7b + 443ba6d commit 45a96a0
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions phylogenetic/scripts/fix_tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,14 @@
print(f"Below {clade}: {mut_child} in {child.name} reverted in {grandchild.name}")

for reversion in reversions:
# Remove reversion from grandchild
reversion["grandchild"].relevant_mutations.remove(reversion["mut_grandchild"])
# Remove grandchild from child
reversion["child"].clades.remove(reversion["grandchild"])
if reversion["mut_grandchild"] in reversion["grandchild"].relevant_mutations:
# Remove reversion from grandchild
reversion["grandchild"].relevant_mutations.remove(reversion["mut_grandchild"])

if reversion["grandchild"] in reversion["child"].clades:
# Remove grandchild from child
reversion["child"].clades.remove(reversion["grandchild"])

# If there are mutations, add grandchild as child of parent
if reversion["grandchild"].relevant_mutations != reversion["parent"].relevant_mutations:
reversion["parent"].clades.append(reversion["grandchild"])
Expand Down

0 comments on commit 45a96a0

Please sign in to comment.