# Lefse\_plot\_res.py plot error - TypeError: slice indices must be integers or None or have an \_\_index\_\_ method

**URL:** <https://forum.biobakery.org/t/lefse-plot-res-py-plot-error-typeerror-slice-indices-must-be-integers-or-none-or-have-an-index-method/3530>\
**Category:** LEfSe\
**Created:** [May 4, 2022, 8:38am UTC](https://forum.biobakery.org/t/lefse-plot-res-py-plot-error-typeerror-slice-indices-must-be-integers-or-none-or-have-an-index-method/3530 "2022-05-04T08:38:35Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![cheinle](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.biobakery.org/cheinle/32/1427_2.png) [@cheinle](https://forum.biobakery.org/u/cheinle)\
**Post date:** [May 4, 2022, 8:38am UTC](https://forum.biobakery.org/t/lefse-plot-res-py-plot-error-typeerror-slice-indices-must-be-integers-or-none-or-have-an-index-method/3530/1 "2022-05-04T08:38:35Z")

</div>

I am trying to run lefse (v1.1.2) for metabolic pathway abundances from Humann3 which we joined all of our samples and then normalised to relative abundance. We were able to run lefse formatting and lefse run with the following commands:

> lefse\_format\_input.py all\_pathabundance\_relab\_mod\_lefse\_subcat3.tsv lefse\_subcat3.in -c 2 -u 1 -o 1000000

> lefse\_run.py lefse\_subcat3.in lefse\_subcat3.res

However, when we run lefse\_plot\_res.py we get the following error:

```auto
lefse_plot_res.py lefse_subcat3.res lefse_subcat3.png

Traceback (most recent call last):
  File "/miniconda/envs/myenv/bin/lefse_plot_res.py", line 10, in <module>
    sys.exit(plot_res())
  File "/miniconda/envs/myenv/lib/python3.7/site-packages/lefse/lefse_plot_res.py", line 177, in plot_res
    else: plot_histo_hor(params['output_file'],params,data,len(data['cls']) == 2,params['report_features'])
  File "/miniconda/envs/myenv/lib/python3.7/site-packages/lefse/lefse_plot_res.py", line 104, in plot_histo_hor
    if len(rr) > params['max_feature_len']: rr = rr[:params['max_feature_len']/2-2]+" [..]"+rr[-params['max_feature_len']/2+2:]
TypeError: slice indices must be integers or None or have an __index__ method

```

If we change lefse\_plot\_res.py script to round the data using:

```auto
if len(rr) > params['max_feature_len']: rr = rr[:params['max_feature_len']//2-2]+" [..]"+rr[-params['max_feature_len']//2+2:]

```

we get an image - though I’m not sure it is the correct image then because of the extra rounding.

Our lefse\_subcat3.res file looks like:

> head lefse\_subcat3.res

UNMAPPED 5.698806339377007 MF 4.992992452183536 0.0020039311821839286  
UNINTEGRATED 5.534112533646385 NM 4.691403253999157 0.0016752988184979575  
UNINTEGRATED.g\_\_Achromobacter\_s\_\_Achromobacter\_denitrificans 1.8462237235380918 -  
UNINTEGRATED.g\_\_Achromobacter\_s\_\_Achromobacter\_sp\_ATCC31444 1.4941062290802956 -  
UNINTEGRATED.g\_\_Achromobacter\_s\_\_Achromobacter\_spanius 1.8231784520362997 -  
UNINTEGRATED.g\_\_Acidovorax\_s\_\_Acidovorax\_sp\_OV235 1.3596936023263013 -  
UNINTEGRATED.g\_\_Acinetobacter\_s\_\_Acinetobacter\_albensis 1.7961791945841161 -  
UNINTEGRATED.g\_\_Acinetobacter\_s\_\_Acinetobacter\_bereziniae 0.5660156608292263 -  
UNINTEGRATED.g\_\_Acinetobacter\_s\_\_Acinetobacter\_bohemicus 1.8704551846872188 -  
UNINTEGRATED.g\_\_Acinetobacter\_s\_\_Acinetobacter\_calcoaceticus 1.6186752741067647 -

Can you give advice on what we might be doing incorrectly? Our samples have a single class with 3 types/disease states

Thank you!

---

<div class="post-metadata">

**Author:** ![cheinle](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.biobakery.org/cheinle/32/1427_2.png) [@cheinle](https://forum.biobakery.org/u/cheinle)\
**Post date:** [May 6, 2022, 1:53am UTC](https://forum.biobakery.org/t/lefse-plot-res-py-plot-error-typeerror-slice-indices-must-be-integers-or-none-or-have-an-index-method/3530/2 "2022-05-06T01:53:18Z")

</div>

Good morning - The plot function was working for a result with only 19 significant pathways found, but not 30. We double checked the documentation and we have adjusted the options for our lefse\_plot\_res.py to add `--max_feature_len` and now no longer have the same trouble

> lefse\_plot\_res.py lefse\_subcat3.res lefse\_subcat3.png --max\_feature\_len 100 --width 10 --subclades -1 --dpi 300

---

<div class="post-metadata">

**Author:** ![mishort](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.biobakery.org/mishort/32/556_2.png) [@mishort](https://forum.biobakery.org/u/mishort)\
**Post date:** [May 17, 2022, 8:59pm UTC](https://forum.biobakery.org/t/lefse-plot-res-py-plot-error-typeerror-slice-indices-must-be-integers-or-none-or-have-an-index-method/3530/3 "2022-05-17T20:59:01Z")

</div>

Hi,  
Thank you for your question, and for posting a solution. I will ask the developers about this to see if a more informative error message can be displayed when this happens.  
Best,  
Meg
