Skip to content

Commit

Permalink
Check for mutations and clades before removing
Browse files Browse the repository at this point in the history
Fixes a bug in the fix_tree script when trying to remove mutations or
clades from lists where those values don't exist. The short-term fix is
to check for the presence of the values in the lists before trying to
remove them. The long term fix is to use a different tree builder than
eliminates the need for a "fix tree" script.
  • Loading branch information
huddlej committed Jul 29, 2024
1 parent 1889dff commit 443ba6d
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 443ba6d

Please sign in to comment.