# Fix\_tree.py error for mpox trees

**URL:** <https://nextstrain.discourse.group/t/fix-tree-py-error-for-mpox-trees/1762>\
**Category:** General\
**Created:** [October 25, 2024, 8:11pm UTC](https://nextstrain.discourse.group/t/fix-tree-py-error-for-mpox-trees/1762 "2024-10-25T20:11:08Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![dlu](https://avatars.discourse-cdn.com/v4/letter/d/e36b37/32.png) [@dlu](https://nextstrain.discourse.group/u/dlu)\
**Post date:** [October 25, 2024, 8:11pm UTC](https://nextstrain.discourse.group/t/fix-tree-py-error-for-mpox-trees/1762/1 "2024-10-25T20:11:08Z")

</div>

In the step

```auto
python3 scripts/fix_tree.py             
--alignment results/aspen/masked.fasta             
--input-tree results/aspen/tree_raw.nwk                          
--output results/aspen/tree_fixed.nwk

```

For some trees I got this error

```auto
Below NODE_0000128: ('C', 5339, 'T') in NODE_0000129 reverted in NODE_0000130
Below NODE_0000258: ('C', 29762, 'T') in NODE_0000259 reverted in NODE_0000401
Traceback (most recent call last):
  File "/code/mpox/phylogenetic/scripts/fix_tree.py", line 63, in <module>
    reversion["child"].clades.remove(reversion["grandchild"])
ValueError: list.remove(x): x not in list

```

These are trees that were built with somewhat random samples just for testing so they may be strange in biological sense. Is that the reason? I don’t understand the set up enough to debug.

Data and code are latest version.  
Thanks!

---

<div class="post-metadata">

**Author:** ![jlhudd](https://yyz1.discourse-cdn.com/flex031/user_avatar/nextstrain.discourse.group/jlhudd/32/583_2.png) [@jlhudd](https://nextstrain.discourse.group/u/jlhudd)\
**Post date:** [October 25, 2024, 8:58pm UTC](https://nextstrain.discourse.group/t/fix-tree-py-error-for-mpox-trees/1762/2 "2024-10-25T20:58:47Z")

</div>

Hi @dlu, this is an issue that others have run into before, too. A while back, [I pushed a fix to the proximal issue](https://github.com/nextstrain/mpox/pull/264) of the script trying to remove items that don’t exist in the list, but this doesn’t necessarily fix the ultimate issue with the input data that causes that script to fail.

@corneliusroemer, is there anything you’d suggest here? My first thought is that @dlu could try running the mpox workflow from the `fix-fix-tree` branch in the PR linked above…

---

<div class="post-metadata">

**Author:** ![dlu](https://avatars.discourse-cdn.com/v4/letter/d/e36b37/32.png) [@dlu](https://nextstrain.discourse.group/u/dlu)\
**Post date:** [October 28, 2024, 3:23pm UTC](https://nextstrain.discourse.group/t/fix-tree-py-error-for-mpox-trees/1762/3 "2024-10-28T15:23:30Z")

</div>

Hi John, thanks for a quick reply! Let me bring in this change to our system.

---

<div class="post-metadata">

**Author:** ![dlu](https://avatars.discourse-cdn.com/v4/letter/d/e36b37/32.png) [@dlu](https://nextstrain.discourse.group/u/dlu)\
**Post date:** [October 28, 2024, 6:04pm UTC](https://nextstrain.discourse.group/t/fix-tree-py-error-for-mpox-trees/1762/4 "2024-10-28T18:04:44Z")

</div>

With the change, fix tree ran through, but with 2 different test runs, some nodes show up twice in tree\_fixed.nwk which lead to error in `rule export`. With another test run, `rule refine` had an error.

 ![image](https://canada1.discourse-cdn.com/flex031/uploads/nextstrain/original/1X/795da0fbe79ac8885d27198dee9f801c78b2b069.png)  
 ![image](https://canada1.discourse-cdn.com/flex031/uploads/nextstrain/original/1X/75c39838735cb83362bd6d395b6a908d853fd25f.jpeg)

I don’t need to fix these issues, but wanted to better understand them. My intuition is the samples on the trees are just challenging for tree build, like they are too different or too distant, and some of the steps just couldn’t properly handle them. Does that sound right?
