LEfSe after QIIME2 to test at all taxonomic levels

Hi @sbslee

I found a problem with installing LEfSe within python 3.8
I tried with the commands you provided here but with the last one, there was a problem that the environment is unsuitable


solving the environment was running for hours and eventually not solved,
another trying for installing from other sources detected that the python version is an unappropriated for this tool
any suggestions, please?

thank you

@Jalalalzanin,

First of all, you should install the lower version of Python in order to run LEfSe (2.7.15), not 3.8:

conda create -n lefse -c conda-forge python=2.7.15

Next, when I tried to install LEfSe with:

$ conda install -c bioconda -c conda-forge lefse

like you said, I also could not download properly because it took forever to solve the environment. It turns out, there was a new release of LEfSe in bionconda (v1.1.1) a couple months ago. We want the other version (v1.0.8.post1):

$ conda install -c bioconda lefse=1.0.8.post1

This allowed me to download properly. So in summary, follow the these commands:

$ conda create -n lefse -c conda-forge python=2.7.15
$ conda activate lefse
$ conda install -c bioconda lefse=1.0.8.post1

This should solve your problem.

2 Likes

Thank you @sbslee

Yes, problem solved.

I appreciated your help

1 Like

Hello,

I have a quick question. The numbers reported in a table (lefse) reports the abundance of bacteria at which level? genus? family?

Thanks!

Hello @Barandouzi,

Please see my reply above: LEfSe after QIIME2 to test at all taxonomic levels - #3 by sbslee.

Feel free to ask further if it doesn't answer your question.

Hi Steven,

Sorry for the double post.

Do you have any idea how to fix this error

Miniconda3\envs\lefse\bin\lefse-format_input.py", line 109
return int(a[u] > b[u])*2-1
TabError: inconsistent use of tabs and spaces in indentation

My understanding is there is an error in the python script itself (as opposed to my input file). But when opening and looking at the script it looks ok...

Any advice would be greatly appreciated

@Labm,

The error is indeed a Python script issue. It's likely that you are using an incompatible Python version. Take a look at my previous reply and see if the program versions there match yours.

Hi @sbslee!
I got an error when running the code below

dokdo prepare-lefse -t dada2_table.qza -x taxonomy.qza -m sample-metadata2.tsv -o input_table.tsv -c type -u SampleID

The error is
Traceback (most recent call last):
File "/Users/lymots/anaconda3/envs/qiime2-2022.2/lib/python3.8/site-packages/pandas/core/indexes/base.py", line 3081, in get_loc
return self._engine.get_loc(casted_key)
File "pandas/_libs/index.pyx", line 70, in pandas._libs.index.IndexEngine.get_loc
File "pandas/_libs/index.pyx", line 101, in pandas._libs.index.IndexEngine.get_loc
File "pandas/_libs/hashtable_class_helper.pxi", line 4554, in pandas._libs.hashtable.PyObjectHashTable.get_item
File "pandas/_libs/hashtable_class_helper.pxi", line 4562, in pandas._libs.hashtable.PyObjectHashTable.get_item
KeyError: 'SampleID'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File "/Users/lymots/anaconda3/envs/qiime2-2022.2/bin/dokdo", line 8, in
sys.exit(main())
File "/Users/lymots/anaconda3/envs/qiime2-2022.2/lib/python3.8/site-packages/dokdo/main.py", line 294, in main
commandscommand
File "/Users/lymots/anaconda3/envs/qiime2-2022.2/lib/python3.8/site-packages/dokdo/cli/prepare_lefse.py", line 96, in prepare_lefse
df.insert(1, subject_col, df.pop(subject_col))
File "/Users/lymots/anaconda3/envs/qiime2-2022.2/lib/python3.8/site-packages/pandas/core/frame.py", line 4512, in pop
return super().pop(item=item)
File "/Users/lymots/anaconda3/envs/qiime2-2022.2/lib/python3.8/site-packages/pandas/core/generic.py", line 769, in pop
result = self[item]
File "/Users/lymots/anaconda3/envs/qiime2-2022.2/lib/python3.8/site-packages/pandas/core/frame.py", line 3024, in getitem
indexer = self.columns.get_loc(key)
File "/Users/lymots/anaconda3/envs/qiime2-2022.2/lib/python3.8/site-packages/pandas/core/indexes/base.py", line 3083, in get_loc
raise KeyError(key) from err
KeyError: 'SampleID'

And when I delete the -u SampleID, there is no error.

Do you know how could I fixed this?
Thank you!

@Mirror,

The -u argument is used to provide information on paired samples. If you look at the example I provided above:

$ dokdo prepare-lefse \
-t data/moving-pictures-tutorial/table.qza \
-x data/moving-pictures-tutorial/taxonomy.qza \
-m data/moving-pictures-tutorial/sample-metadata.tsv \
-o output/Useful-Information/input_table.tsv \
-c body-site \
-u subject \
-w "[body-site] IN ('tongue', 'gut', 'left palm')"

-u subject means there is a column named subject in the sample-metadata.tsv file which should tell which samples are from which subject (e.g. a tongue sample and a gut sample could come from the same subject). In other words, these samples are paired and this fact should be accounted when performing linear discriminant analysis because in addition to variability from body-site there can be also subject-specific variability that can affect the analysis.

That being said, it looks like you are incorrectly using -u SampleID because that column just provides sample names, and nothing about paring of the samples. That's why the program runs if you don't give -u SampleID. And this is fine if your samples are not grouped in any meaningful way. This is more of a study design question.

Hope this helps.

Steven

Thank you for your reply!

I would like to use QIIME2 analysis to analyze LEfSe only at the "genus" level. I request your advice

Hi @yxa, qiime taxa collapse will let you collapse your feature table to genus level. This is illustrated in the QIIME 2 docs here. From there you can follow the typical steps to run LEFSe (I haven't used LEFSe in a while myself, so I can't tell you exactly what those steps are).

Hi @yxa,

I just wanted to extend @gregcaporaso's comment, with a few additional options:

  1. Use qiime rescript edit-taxonomy ... to remove everything but the genus ranks. You can enable the --p-use-regex flag to make this easier. Then you can feed this output into the dokdo prepare-lefse ... command

  2. Or after you run dokdo prepare-lefse..., open the resulting text file. You'll see that LEfSe delimits that taxonomic ranks with a | character. You can simply find and replace all of the | with . or _ characters so that that taxonomy is simply one long string. You can feed this into LEfSe for analyses. Note the taxonomic cladogram will not be informative, as it'll look like a "star" w/o hierarchy. Or remove as many of these delimiters you'd like up to the rank you want to focus on, then run LEfSe.

3 Likes

Hi @sbslee

i really appreciate about your comments above. I found it very helpful!!

But, at the last step, i've got a "AttributeError: Unknown property axis_bgcolor" error and tried to change the version of matplotlib 2.1.2 as you said and actually did.

But after that change, all the commands of lefse such as "lefse-plot_res.py, lefse-format_input.py" don't work. If lefse is normal, lefse and tab should show me some commands, but just error sounds...

Could you provide advice about this situation? Thanks.

Hi @bandy134,

Please provide the exact error message and also the output of $ conda list.

An off-topic reply has been split into a new topic: Questions about Dokdo and LEfSe

Please keep replies on-topic in the future.

An off-topic reply has been split into a new topic: TabError when running LefSe

Please keep replies on-topic in the future.