# Understanding strain\_transmission.py output and "list index out of range" error

**URL:** https://forum.biobakery.org/t/understanding-strain-transmission-py-output-and-list-index-out-of-range-error/7767
**Category:** StrainPhlAn
**Created:** [January 23, 2025, 4:43pm UTC](https://forum.biobakery.org/t/understanding-strain-transmission-py-output-and-list-index-out-of-range-error/7767 "2025-01-23T16:43:02Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![Laura](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.biobakery.org/laura/32/2781_2.png) [@Laura](https://forum.biobakery.org/u/Laura)
#### Post date: [January 23, 2025, 4:43pm UTC](https://forum.biobakery.org/t/understanding-strain-transmission-py-output-and-list-index-out-of-range-error/7767/1 "2025-01-23T16:43:02Z")

</div>

Thank you for making MetaPhlAn 4.1.1.

I have an FMT dataset with 79 longitudinal samples and 3 donors. When I run `strain_transmission.py` I encounter several issues:

1. I found a bug where some of the output files were being written in the input folder rather than the specified output path. I was wondering if you found the same problem.

2. For some of the SGB the “transmission\_events.info” file was not computed and I got the following error:

```auto
Traceback (most recent call last):
  File "/shared/team/conda/mpa_411/bin/strain_transmission.py", line 10, in <module>
    sys.exit(main())
             ^^^^^^
  File "/shared/team/conda/mpa_411/lib/python3.12/site-packages/metaphlan/utils/strain_transmission.py", line 322, in main
    strain_transmission(args.tree, args.metadata, args.threshold, args.sgb_id,
  File "/shared/team/conda/mpa_411/lib/python3.12/site-packages/metaphlan/utils/strain_transmission.py", line 307, in strain_transmission
    threshold = get_threshold(training_distances, distr_threshold)
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/shared/team/conda/mpa_411/lib/python3.12/site-packages/metaphlan/utils/strain_transmission.py", line 214, in get_threshold
    return distances[int(len(distances)*distr_threshold)]
           ~~~~~~~~~ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
IndexError: list index out of range

```

Do you know what could be the issue? The trees have some extra samples (e.g. other donors that were not used in the end) so they are not included in the metadata file. Could this be a possible reason for this error? These samples would not have any common “relation\_id” with the others, but they would still appear as transmission events for some SGB anyway, even if not specified in the metadata.

1. For some of the SGB where transmission events were detected, it seems it is not reporting all the events below the threshold. For example, for this SGB14993:

> Selected strain-transmission threshold: 0.059109782214254836  
> Number of transmission events: 12
> 
> 47542\_1\_51 ↔ 47542\_1\_72  
> 47542\_1\_72 ↔ 47542\_1\_81  
> 47542\_1\_118 ↔ 47542\_1\_81  
> 47542\_1\_118 ↔ 47542\_1\_51  
> 47542\_1\_118 ↔ 47542\_1\_72  
> 47542\_1\_118 ↔ 47542\_1\_68  
> 47542\_1\_118 ↔ 47542\_1\_173  
> 47542\_1\_68 ↔ 47542\_1\_72  
> 47542\_1\_173 ↔ 47542\_1\_81  
> 47542\_1\_173 ↔ 47542\_1\_51  
> 47542\_1\_173 ↔ 47542\_1\_72  
> 47542\_1\_173 ↔ 47542\_1\_68

However, if I look at the pairwise distance file tre.dist I see there are other pairs with a distance smaller than the threshold value 0.059109782214254836:

> |47542\_1\_103|47542\_1\_38|0.08866441350825625|  
> |47542\_1\_103|47542\_1\_65|0.10706048407387056|  
> |47542\_1\_103|47542\_1\_93|0.10171325409904351|  
> |47542\_1\_103|47542\_1\_53|0.1321989072639618|  
> |47542\_1\_103|47542\_1\_61|0.13002588180336852|  
> |47542\_1\_103|47542\_1\_165|0.11233039054652781|  
> |47542\_1\_103|47542\_1\_131|0.12634654620236924|  
> |47542\_1\_103|47542\_1\_152|0.11775628763430487|  
> |47542\_1\_103|47542\_1\_120|0.10478067496486596|  
> |47542\_1\_103|47542\_1\_89|0.10967240354212773|  
> |47542\_1\_103|47542\_1\_147|0.15089484811037565|  
> |47542\_1\_103|47542\_1\_123|0.11065364475243172|  
> |47542\_1\_103|47542\_1\_160|0.11715830416646209|  
> |47542\_1\_103|47542\_1\_121|0.12767666237362849|  
> |47542\_1\_103|47542\_1\_135|0.1317097231054832|  
> |47542\_1\_103|47542\_1\_150|0.13152440943640867|  
> |47542\_1\_103|47542\_1\_81|0.1144435576139486|  
> |47542\_1\_103|47542\_1\_51|0.12167751703889663|  
> |47542\_1\_103|47542\_1\_72|0.14207036951688737|  
> |47542\_1\_103|47542\_1\_118|0.14668958850580296|  
> |47542\_1\_103|47542\_1\_68|0.14270003771905493|  
> |47542\_1\_103|47542\_1\_173|0.142753601292209|  
> |47542\_1\_103|47542\_1\_162|0.1093315315278234|  
> |47542\_1\_103|47542\_1\_30|0.18922066065884366|  
> |47542\_1\_103|47542\_1\_97|0.17334218666152834|  
> |47542\_1\_103|47542\_1\_49|0.17383563204435526|  
> |47542\_1\_103|47542\_1\_17|0.17390900671794543|  
> |47542\_1\_103|47542\_1\_34|0.1541674613380055|  
> |47542\_1\_103|47542\_1\_36|0.10922587879675272|  
> |47542\_1\_103|47542\_1\_19|0.1090532023026968|  
> **\> |47542\_1\_103|47542\_1\_13|0.0131048763147948|**  
> |47542\_1\_38|47542\_1\_65|0.09434180764879481|  
> |47542\_1\_38|47542\_1\_93|0.08899457767396775|  
> |47542\_1\_38|47542\_1\_53|0.11948023083888602|  
> |47542\_1\_38|47542\_1\_61|0.11730720537829276|  
> |47542\_1\_38|47542\_1\_89|0.09695372711705195|  
> |47542\_1\_38|47542\_1\_81|0.10172488118887284|  
> |47542\_1\_38|47542\_1\_51|0.10895884061382087|  
> |47542\_1\_38|47542\_1\_72|0.1293516930918116|  
> |47542\_1\_38|47542\_1\_68|0.12998136129397916|  
> |47542\_1\_38|47542\_1\_97|0.16062351023645258|  
> |47542\_1\_38|47542\_1\_49|0.1611169556192795|  
> **\> |47542\_1\_65|47542\_1\_93|0.025995105542266476|**  
> |47542\_1\_65|47542\_1\_89|0.09700482164019344|  
> |47542\_1\_65|47542\_1\_81|0.10177597571201431|  
> |47542\_1\_65|47542\_1\_72|0.12940278761495308|  
> |47542\_1\_65|47542\_1\_68|0.13003245581712067|  
> |47542\_1\_65|47542\_1\_97|0.16602110978937887|  
> |47542\_1\_93|47542\_1\_97|0.1606738798145518|  
> |47542\_1\_53|47542\_1\_65|0.11953132536202749|

Why are these pairs below the threshold not reported in the “transmission\_events.info” output?

Any help with this would be really appreciated.
