format_input.py error when using LEfSe

736 views
Skip to first unread message

Jessie HOU

unread,
Dec 16, 2017, 1:49:27 AM12/16/17
to MetaPhlAn-users
Hello guys,

Recently I am following a metaphlan2 tutorial. But I got an error in step 4 (Taxonomic biomarker discovery with LEfSe). The command is:
$ format_input.py tmp/merged_abundance_table.4lefse.txt tmp/merged_abundance_table.lefse -c 1 -o 1000000

Then I got the following error:

Traceback (most recent call last):
File "/expt/expt_5/jessie/src/lefse/format_input.py", line 415, in <module>
params['subject']-1 if not params['subject'] is None else None)))
File "/expt/expt_5/jessie/src/lefse/format_input.py", line 123, in sort_by_cl
if n == 1: data.sort(sort_lines1)
TypeError: must use keyword argument for key function

I am using python 3.6 to run this command. But this script seems to be written with python2. I am a newbie to python and I have tried to debug some other errors so far. However, I cannot fix this error. Anyone who can help me? Any suggestions would be greatly appreciated.

Best Regards,
Jessie

Francesco Asnicar

unread,
Jan 12, 2018, 9:03:43 AM1/12/18
to Jessie HOU, MetaPhlAn-users
Hello Jessie,

I believe your problem is due to the python version you're using for running the command.

Recent systems are running python3 as default, but I think if you look at your bash commands you should still have a command for running python2, most likely it will be "python2.7".
In this case, you just have to run the same command you posted with the python2 command in front, probably something like:
$ python2.7 format_input.py tmp/merged_abundance_table.4lefse.txt tmp/merged_abundance_table.lefse -c 1 -o 1000000

Another way that you can use to solve also future issues related to the python version is to install anaconda in your system and create an environment where the default python is python2, so you'll just need to run this environment to have python2 as default python distribution.

Please, let me know if you managed to solve your problem.

Many thanks,
Francesco

--
You received this message because you are subscribed to the Google Groups "MetaPhlAn-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to metaphlan-use...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Jessie HOU

unread,
Jan 26, 2018, 6:01:53 AM1/26/18
to MetaPhlAn-users
Dear Francesco,

Thank you so much for your kindly reply. As you suggested, I have tried using python2.7 to run the above command. But again I got an another error.

First I checked my current python version by typing:
$ python
Python 2.7.12 (default, Jul 1 2016, 15:12:24)
[GCC 5.4.0 20160609] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> exit()

Then I use python2.7 to run the following command:
$ python ~/src/lefse/format_input.py tmp/merged_abundance_table.4lefse.txt tmp/merged_abundance_table.lefse -c 1 -o 1000000
Traceback (most recent call last):
File "/expt/expt_5/jessie/src/lefse/format_input.py", line 435, in <module>
feats = numerical_values(feats,params['norm_v'])
File "/expt/expt_5/jessie/src/lefse/format_input.py", line 174, in numerical_values
feats[k] = [float(val) for val in v]
ValueError: could not convert string to float: Metaphlan2_Analysis

------------------------------------------------------------------------------

In fact, I have miniconda3 installed in my system, in which there is python3.6. When I use the python3.6 to run the command, there is still an error. Just like the following:

$ python3.6 format_input.py tmp/merged_abundance_table.4lefse.txt tmp/merged_abundance_table.lefse -c 1 -o 1000000
File "format_input.py", line 109
return int(a[u] > b[u])*2-1
^
TabError: inconsistent use of tabs and spaces in indentation

It seems that the "format_input.py" script is written by python2. After googling, I have sucessfully solved the "TabError" above by using IDLE to convert all tabs into spaces for the script. (Referring to this post: https://www.reddit.com/r/learnprogramming/comments/4gt6wc/python_inconsistent_use_of_tabs_and_spaces_in/). But I kept getting various errors due to python version issue. So I wonder whether I can use python2.7 to run this command successfully.

Bests
Jessie


Francesco Asnicar

unread,
Feb 7, 2018, 6:25:10 PM2/7/18
to Jinpao Hou, MetaPhlAn-users
Hi Jessies,

About the error you reported:
"ValueError: could not convert string to float: Metaphlan2_Analysis"
I think you can solve this by either removing the line which contains "Metaphlan2_Analysis" in your "tmp/merged_abundance_table.4lefse.txt " file, or specify it as one of class, subclass, or subject via the  -c, -s, or -u  options.

I'll check the code for the "TabError: inconsistent use of tabs and spaces in indentation", so to avoid other users will experience your problem in the future.

Please, let me know in case you should still experience problems in running LEfSe.

Many thanks,
Francesco

On Fri, Jan 26, 2018 at 3:11 PM Jinpao Hou <jpho...@gmail.com> wrote:
Jessie


--
You received this message because you are subscribed to a topic in the Google Groups "MetaPhlAn-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/metaphlan-users/8GzrXbRWUIE/unsubscribe.
To unsubscribe from this group and all its topics, send an email to metaphlan-use...@googlegroups.com.

Jinpao Hou

unread,
Feb 12, 2018, 11:01:38 PM2/12/18
to Francesco Asnicar, MetaPhlAn-users
Dear  Francesco,

I have fixed this error by removing the line which contains "Metaphlan2_Analysis" in my "tmp/merged_abundance_table.4lefse.txt " file. In other words, I have successfully run this command with python 2.7. Thank you so much for your kindly patience and help.

Best regards,
Jessie

To unsubscribe from this group and all its topics, send an email to metaphlan-users+unsubscribe@googlegroups.com.

Nhung Doan

unread,
Nov 28, 2019, 4:48:47 AM11/28/19
to MetaPhlAn-users


Hi guys,

I am using the following command 

(lefse) Nguyens-iMac:~ Bioinformatics$ /Users/Bioinformatics/Downloads/nsegata-lefse-9adc3a62460e/format_input.py /Users/Bioinformatics/Downloads/genus-lefse.txt /Users/Bioinformatics/Desktop/genus-lefse.in -c 1 -s 1 -o 1000000

Traceback (most recent call last):

  File "/Users/Bioinformatics/Downloads/nsegata-lefse-9adc3a62460e/format_input.py", line 427, in <module>

    first_line = modify_feature_names(list(first_line))

  File "/Users/Bioinformatics/Downloads/nsegata-lefse-9adc3a62460e/format_input.py", line 278, in modify_feature_names

    if r[0] in ['0','1','2','3','4','5','6','7','8','9','_']:

IndexError: string index out of range

(lefse) Nguyens-iMac:~ Bioinformatics$ /Users/Bioinformatics/Downloads/nsegata-lefse-9adc3a62460e/format_input.py /Users/Bioinformatics/Downloads/genus-lefse.txt /Users/Bioinformatics/Desktop/genus-lefse.in -c Status -s 1 -o 1000000

usage: format_input.py [-h] [--output_table OUTPUT_TABLE] [-f {c,r}]

                       [-c [1..n_feats]] [-s [1..n_feats]] [-o float]

                       [-u [1..n_feats]] [-m {f,s}] [-n int]

                       [-biom_c BIOM_CLASS] [-biom_s BIOM_SUBCLASS]

                       INPUT_FILE OUTPUT_FILE

format_input.py: error: argument -c: invalid int value: 'Status' 

So, what should I set in -c to fix this error?
Thank all,

Nhung Doan
Reply all
Reply to author
Forward
0 new messages